elementor / elementor/wp2static

500 Error when generating static site on Multisite

Open
#913 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
1.5k
Forks
294
PR merge metrics
No merged PRs in 30d

Description

When trying to generate a static site on my locally-hosted WordPress Multisite installation, I consistently hit a 500 error. Examining the WordPress debug log, I saw this:

```
[28-Feb-2024 22:16:34 UTC] PHP Fatal error: Uncaught TypeError: array_keys(): Argument #1 ($array) must be of type array, bool given in /srv/www/vhosts/my_site/wp-content/plugins/wp2static/src/DetectPluginAssets.php:42
Stack trace:
#0 /srv/www/vhosts/my_site/wp-content/plugins/wp2static/src/DetectPluginAssets.php(42): array_keys()
#1 /srv/www/vhosts/my_site/wp-content/plugins/wp2static/src/URLDetector.php(119): WP2Static\DetectPluginAssets::detect()
#2 /srv/www/vhosts/my_site/wp-content/plugins/wp2static/src/URLDetector.php(196): WP2Static\URLDetector::detectURLs()
#3 /srv/www/vhosts/my_site/wp-content/plugins/wp2static/src/Controller.php(699): WP2Static\URLDetector::enqueueURLs()
#4 /srv/www/vhosts/my_site/wp-content/plugins/wp2static/src/Controller.php(811): WP2Static\Controller::wp2staticHeadless()
#5 /srv/www/vhosts/my_site/wp-includes/class-wp-hook.php(306): WP2Static\Controller::wp2staticRun()
#6 /srv/www/vhosts/my_site/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters()
#7 /srv/www/vhosts/my_site/wp-includes/plugin.php(517): WP_Hook->do_action()
#8 /srv/www/vhosts/my_site/wp-admin/admin-ajax.php(188): do_action()
#9 {main}
thrown in /srv/www/vhosts/my_site/wp-content/plugins/wp2static/src/DetectPluginAssets.php on line 42
```

Line 42 in `src/DetectPluginAssets.php` was doing `array_keys( $active_sitewide_plugins )`. A little earlier, line 36 was this:

```php
$active_sitewide_plugins = get_option( 'active_sitewide_plugins' );
```

...which when I tested it returned `false`. Changing line 36 to

```php
$active_sitewide_plugins = get_site_option( 'active_sitewide_plugins' );
```
solved the problem. (`'active_sitewide_plugins'` is a network option, it appears.)

My recommended fix modifies lines 33-45 or so:

```php

33
34 if ( is_multisite() ) {
35 /**
36 * @var string[] $active_sitewide_plugins
37 */
38 $active_sitewide_plugins = get_site_option( 'active_sitewide_plugins', array() );
39 $active_plugins = array_unique(
40 array_merge(
41 $active_plugins,
42 array_keys( $active_sitewide_plugins )
43 )
44 );
45 }
```

Without the line numbers:

```php

if ( is_multisite() ) {
/**
* @var string[] $active_sitewide_plugins
*/
$active_sitewide_plugins = get_site_option( 'active_sitewide_plugins', array() );
$active_plugins = array_unique(
array_merge(
$active_plugins,
array_keys( $active_sitewide_plugins )
)
);
}
```

If needed I can make this into a pull request.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.