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

Check whether WP is still installing before accessing site option can_compress_scripts #2054

Conversation

schlessera
Copy link
Member

When installing a multisite, there is a potential access to a non-existent database table that needs to be skipped to avoid warnings/errors.

001 Scenario: Install WordPress multisite with existing multisite constants in wp-config file                                                                         # features/core-install.feature:204
      When I run `wp core multisite-install --url=foobar.org --title=Test --admin_user=wpcli --admin_email=admin@example.com --admin_password=password --skip-config` # features/core-install.feature:226
        $ wp core multisite-install --url=foobar.org --title=Test --admin_user=wpcli --admin_email=admin@example.com --admin_password=password --skip-config
        WP-CLI test suite: Sent email to admin@example.com.
        Created single site database tables.
        Set up multisite database tables.
        Success: Network installed. Don't forget to set up rewrite rules (and a .htaccess file, if using Apache).

        WordPress database error Table 'wp_cli_test.wp_sitemeta' doesn't exist for query SELECT meta_value FROM wp_sitemeta WHERE meta_key = 'can_compress_scripts' AND site_id = 1 made by require_once('vendor/wp-cli/wp-cli/php/wp-cli.php'), WP_CLI\bootstrap, WP_CLI\Bootstrap\LaunchRunner->process, WP_CLI\Runner->start, WP_CLI\Runner->load_wordpress, require('wp-settings.php'), do_action('init'), WP_Hook->do_action, WP_Hook->apply_filters, register_block_core_file, register_block_type_from_metadata, register_block_script_handle, wp_register_script, wp_scripts, WP_Scripts->__construct, WP_Scripts->init, do_action_ref_array('wp_default_scripts'), WP_Hook->do_action, WP_Hook->apply_filters, wp_default_packages, wp_register_tinymce_scripts, script_concat_settings, get_site_option, get_network_option
        cwd: /tmp/wp-cli-test-run--61ba15774b81d8.03513765/
        run time: 1.1995339393616
        exit status: 0 (RuntimeException)

The problem comes from the script_concat_settings() function (triggered by 'wp_default_scripts' => wp_register_tinymce_scripts()), which tries to retrieve the site option 'can_compress_scripts'.

This PR adapts the code so that it first checks whether WP is installing before trying to retrieve the site option. During WP installation, script compression defaults to false.

This PR also optimizes the check by storing the DB request, instead of executing it twice.

Trac ticket: https://core.trac.wordpress.org/ticket/54634


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions
Copy link

Hi @schlessera! 👋

Thank you for your contribution to WordPress! 💖

It looks like this is your first pull request to wordpress-develop. Here are a few things to be aware of that may help you out!

No one monitors this repository for new pull requests. Pull requests must be attached to a Trac ticket to be considered for inclusion in WordPress Core. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description.

Pull requests are never merged on GitHub. The WordPress codebase continues to be managed through the SVN repository that this GitHub repository mirrors. Please feel free to open pull requests to work on any contribution you are making.

More information about how GitHub pull requests can be used to contribute to WordPress can be found in this blog post.

Please include automated tests. Including tests in your pull request is one way to help your patch be considered faster. To learn about WordPress' test suites, visit the Automated Testing page in the handbook.

If you have not had a chance, please review the Contribute with Code page in the WordPress Core Handbook.

The Developer Hub also documents the various coding standards that are followed:

Thank you,
The WordPress Project

@hellofromtonya
Copy link
Contributor

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