Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

500 Error when generating static site on Multisite #913

Open
pjohanneson opened this issue Feb 28, 2024 · 0 comments
Open

500 Error when generating static site on Multisite #913

pjohanneson opened this issue Feb 28, 2024 · 0 comments

Comments

@pjohanneson
Copy link

pjohanneson commented Feb 28, 2024

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:

$active_sitewide_plugins = get_option( 'active_sitewide_plugins' );

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

$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:

 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:

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant