From e52cea8ef4da8f6c3df0915de6ca121f6885bd80 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Fri, 25 Oct 2024 10:03:45 -0700 Subject: [PATCH 01/14] Fix inconsistent and confusing order of runtime environment setup execution for WP-CLI and simplify WP-CLI command implementation accordingly. --- includes/CLI/Plugin_Check_Command.php | 39 ---------------------- includes/Checker/Abstract_Check_Runner.php | 18 +++++++--- includes/Checker/CLI_Runner.php | 25 ++++++++++++++ 3 files changed, 39 insertions(+), 43 deletions(-) diff --git a/includes/CLI/Plugin_Check_Command.php b/includes/CLI/Plugin_Check_Command.php index 05f93faad..255af27c3 100644 --- a/includes/CLI/Plugin_Check_Command.php +++ b/includes/CLI/Plugin_Check_Command.php @@ -13,8 +13,6 @@ use WordPress\Plugin_Check\Checker\Check_Repository; use WordPress\Plugin_Check\Checker\CLI_Runner; use WordPress\Plugin_Check\Checker\Default_Check_Repository; -use WordPress\Plugin_Check\Checker\Runtime_Check; -use WordPress\Plugin_Check\Checker\Runtime_Environment_Setup; use WordPress\Plugin_Check\Plugin_Context; use WordPress\Plugin_Check\Utilities\Plugin_Request_Utility; use WP_CLI; @@ -192,25 +190,16 @@ static function ( $dirs ) use ( $excluded_files ) { ); } - $checks_to_run = array(); try { $runner->set_experimental_flag( $options['include-experimental'] ); $runner->set_check_slugs( $checks ); $runner->set_plugin( $plugin ); $runner->set_categories( $categories ); $runner->set_slug( $options['slug'] ); - - $checks_to_run = $runner->get_checks_to_run(); } catch ( Exception $error ) { WP_CLI::error( $error->getMessage() ); } - if ( $this->has_runtime_check( $checks_to_run ) ) { - WP_CLI::line( __( 'Setting up runtime environment.', 'plugin-check' ) ); - $runtime_setup = new Runtime_Environment_Setup(); - $runtime_setup->set_up(); - } - $result = false; // Run checks against the plugin. try { @@ -218,21 +207,11 @@ static function ( $dirs ) use ( $excluded_files ) { } catch ( Exception $error ) { Plugin_Request_Utility::destroy_runner(); - if ( isset( $runtime_setup ) ) { - $runtime_setup->clean_up(); - WP_CLI::line( __( 'Cleaning up runtime environment.', 'plugin-check' ) ); - } - WP_CLI::error( $error->getMessage() ); } Plugin_Request_Utility::destroy_runner(); - if ( isset( $runtime_setup ) ) { - $runtime_setup->clean_up(); - WP_CLI::line( __( 'Cleaning up runtime environment.', 'plugin-check' ) ); - } - // Get errors and warnings from the results. $errors = array(); if ( $result && empty( $assoc_args['ignore-errors'] ) ) { @@ -642,24 +621,6 @@ private function display_results( $formatter, $file_name, $file_results ) { WP_CLI::line(); } - /** - * Checks for a Runtime_Check in a list of checks. - * - * @since 1.0.0 - * - * @param array $checks An array of Check instances. - * @return bool True if a Runtime_Check exists in the array, false if not. - */ - private function has_runtime_check( array $checks ) { - foreach ( $checks as $check ) { - if ( $check instanceof Runtime_Check ) { - return true; - } - } - - return false; - } - /** * Returns check results filtered by severity level. * diff --git a/includes/Checker/Abstract_Check_Runner.php b/includes/Checker/Abstract_Check_Runner.php index 368418da3..9fe8262d3 100644 --- a/includes/Checker/Abstract_Check_Runner.php +++ b/includes/Checker/Abstract_Check_Runner.php @@ -310,8 +310,6 @@ final public function set_categories( $categories ) { * @throws Exception Thrown exception when preparation fails. */ final public function prepare() { - $cleanup_functions = array(); - if ( $this->initialized_early ) { /* * When initialized early, plugins are not loaded yet when this method is called. @@ -334,9 +332,9 @@ final public function prepare() { $initialize_runtime = $this->has_runtime_check( $this->get_checks_to_run() ); } + $cleanup_functions = array(); if ( $initialize_runtime ) { - $preparation = new Universal_Runtime_Preparation( $this->get_check_context() ); - $cleanup_functions[] = $preparation->prepare(); + $cleanup_functions = $this->initialize_runtime(); } if ( $this->delete_plugin_folder ) { @@ -489,6 +487,18 @@ final public function get_checks_to_run() { return $collection->to_map(); } + /** + * Initializes the runtime environment so that runtime checks can be run against a separate set of database tables. + * + * @since n.e.x.t + * + * @return callable[] Array of cleanup functions to run after the process has completed. + */ + protected function initialize_runtime(): array { + $preparation = new Universal_Runtime_Preparation( $this->get_check_context() ); + return array( $preparation->prepare() ); + } + /** * Checks whether the current environment allows for runtime checks to be used. * diff --git a/includes/Checker/CLI_Runner.php b/includes/Checker/CLI_Runner.php index 53ba12224..2ddf4684a 100644 --- a/includes/Checker/CLI_Runner.php +++ b/includes/Checker/CLI_Runner.php @@ -178,6 +178,31 @@ protected function get_slug_param() { return $slug; } + /** + * Initializes the runtime environment so that runtime checks can be run against a separate set of database tables. + * + * @since n.e.x.t + * + * @return callable[] Array of cleanup functions to run after the process has completed. + */ + protected function initialize_runtime(): array { + /* + * Since for WP-CLI all checks are run in a single process, we should set up the runtime environment (i.e. + * install the separate database tables) as part of this step. + * This way it runs before the regular runtime preparations, just like it does for the AJAX based flow, where + * they are invoked in a separate request prior to the requests performing actual checks. + */ + $runtime_setup = new Runtime_Environment_Setup(); + $runtime_setup->set_up(); + + $cleanup_functions = parent::initialize_runtime(); + $cleanup_functions[] = function () use ( $runtime_setup ) { + $runtime_setup->clean_up(); + }; + + return $cleanup_functions; + } + /** * Checks whether the current environment allows for runtime checks to be used. * From 6f80889b420baae7fe5293cc37d82159bd7a4596 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Fri, 25 Oct 2024 10:24:13 -0700 Subject: [PATCH 02/14] Ensure WP_DEFAULT_THEME constant is always set before installing WordPress. --- includes/Checker/Runtime_Environment_Setup.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/includes/Checker/Runtime_Environment_Setup.php b/includes/Checker/Runtime_Environment_Setup.php index bd84b784c..3683f353b 100644 --- a/includes/Checker/Runtime_Environment_Setup.php +++ b/includes/Checker/Runtime_Environment_Setup.php @@ -31,6 +31,9 @@ public function set_up() { // Get the existing active plugins. $active_plugins = get_option( 'active_plugins' ); + // Get the existing active theme. + $active_theme = get_option( 'stylesheet' ); + // Get the existing permalink structure. $permalink_structure = get_option( 'permalink_structure' ); @@ -60,6 +63,11 @@ static function () use ( $permalink_structure ) { // Do not send post-install notification email, see https://github.com/WordPress/plugin-check/issues/424. add_filter( 'pre_wp_mail', '__return_false' ); + // The `wp_install()` function requires the WP_DEFAULT_THEME constant to be set. + if ( ! defined( 'WP_DEFAULT_THEME' ) ) { + define( 'WP_DEFAULT_THEME', $active_theme ); + } + wp_install( 'Plugin Check', 'plugincheck', From 6409b35bafd2d663c160a13d9c77c112e2a455f4 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Fri, 25 Oct 2024 10:35:58 -0700 Subject: [PATCH 03/14] Ensure get_user_by() is available early when needed. --- .../Checker/Runtime_Environment_Setup.php | 21 ++++++++++++++ runtime-content/get-user-by.php | 28 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 runtime-content/get-user-by.php diff --git a/includes/Checker/Runtime_Environment_Setup.php b/includes/Checker/Runtime_Environment_Setup.php index 3683f353b..bc65ecd8c 100644 --- a/includes/Checker/Runtime_Environment_Setup.php +++ b/includes/Checker/Runtime_Environment_Setup.php @@ -68,6 +68,11 @@ static function () use ( $permalink_structure ) { define( 'WP_DEFAULT_THEME', $active_theme ); } + // The `wp_install()` function requires the `get_user_by()` function to be loaded. + if ( ! function_exists( 'get_user_by' ) ) { + require_once $this->get_runtime_content_path() . 'get-user-by.php'; + } + wp_install( 'Plugin Check', 'plugincheck', @@ -194,4 +199,20 @@ public function can_set_up() { return false; } + + /** + * Gets the path to the Plugin Check's runtime content directory. + * + * @since n.e.x.t + * + * @return string The path to the runtime content directory. + */ + private function get_runtime_content_path(): string { + if ( ! defined( 'WP_PLUGIN_CHECK_PLUGIN_DIR_PATH' ) ) { + $plugins_dir = defined( 'WP_PLUGIN_DIR' ) ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/plugins'; + return $plugins_dir . '/plugin-check/runtime-content/'; + } + + return WP_PLUGIN_CHECK_PLUGIN_DIR_PATH . 'runtime-content/'; + } } diff --git a/runtime-content/get-user-by.php b/runtime-content/get-user-by.php new file mode 100644 index 000000000..8102d65d3 --- /dev/null +++ b/runtime-content/get-user-by.php @@ -0,0 +1,28 @@ +init( $userdata ); + + return $user; +} From 87c4b37cef6f94251b8953b3d5bf6f7f39939368 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Fri, 25 Oct 2024 11:04:26 -0700 Subject: [PATCH 04/14] Specify demo password for separate test tables to avoid use of wp_generate_password(). --- includes/Checker/Runtime_Environment_Setup.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/Checker/Runtime_Environment_Setup.php b/includes/Checker/Runtime_Environment_Setup.php index bc65ecd8c..9e42cb7a5 100644 --- a/includes/Checker/Runtime_Environment_Setup.php +++ b/includes/Checker/Runtime_Environment_Setup.php @@ -77,7 +77,9 @@ static function () use ( $permalink_structure ) { 'Plugin Check', 'plugincheck', 'demo@plugincheck.test', - false + false, + '', + 'password' ); remove_filter( 'pre_wp_mail', '__return_false' ); From a0dbc508d317bc0e6f23f069dc93212a1c79ce6e Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Fri, 25 Oct 2024 11:09:17 -0700 Subject: [PATCH 05/14] Load pluggable functions early for the various functions needed by wp_install() to be available. --- .../Checker/Runtime_Environment_Setup.php | 20 ++----------- runtime-content/get-user-by.php | 28 ------------------- 2 files changed, 2 insertions(+), 46 deletions(-) delete mode 100644 runtime-content/get-user-by.php diff --git a/includes/Checker/Runtime_Environment_Setup.php b/includes/Checker/Runtime_Environment_Setup.php index 9e42cb7a5..d6a9fcee8 100644 --- a/includes/Checker/Runtime_Environment_Setup.php +++ b/includes/Checker/Runtime_Environment_Setup.php @@ -68,9 +68,9 @@ static function () use ( $permalink_structure ) { define( 'WP_DEFAULT_THEME', $active_theme ); } - // The `wp_install()` function requires the `get_user_by()` function to be loaded. + // The `wp_install()` function requires some pluggable functions like `get_user_by()` to be loaded. if ( ! function_exists( 'get_user_by' ) ) { - require_once $this->get_runtime_content_path() . 'get-user-by.php'; + require_once ABSPATH . '/wp-includes/pluggable.php'; } wp_install( @@ -201,20 +201,4 @@ public function can_set_up() { return false; } - - /** - * Gets the path to the Plugin Check's runtime content directory. - * - * @since n.e.x.t - * - * @return string The path to the runtime content directory. - */ - private function get_runtime_content_path(): string { - if ( ! defined( 'WP_PLUGIN_CHECK_PLUGIN_DIR_PATH' ) ) { - $plugins_dir = defined( 'WP_PLUGIN_DIR' ) ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/plugins'; - return $plugins_dir . '/plugin-check/runtime-content/'; - } - - return WP_PLUGIN_CHECK_PLUGIN_DIR_PATH . 'runtime-content/'; - } } diff --git a/runtime-content/get-user-by.php b/runtime-content/get-user-by.php deleted file mode 100644 index 8102d65d3..000000000 --- a/runtime-content/get-user-by.php +++ /dev/null @@ -1,28 +0,0 @@ -init( $userdata ); - - return $user; -} From ace9bf47b8b597151ba62ebdee0d43d45498ddea Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Fri, 25 Oct 2024 11:10:06 -0700 Subject: [PATCH 06/14] Remove unnecessary parameters. --- includes/Checker/Runtime_Environment_Setup.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/includes/Checker/Runtime_Environment_Setup.php b/includes/Checker/Runtime_Environment_Setup.php index d6a9fcee8..0336911dc 100644 --- a/includes/Checker/Runtime_Environment_Setup.php +++ b/includes/Checker/Runtime_Environment_Setup.php @@ -77,9 +77,7 @@ static function () use ( $permalink_structure ) { 'Plugin Check', 'plugincheck', 'demo@plugincheck.test', - false, - '', - 'password' + false ); remove_filter( 'pre_wp_mail', '__return_false' ); From 7c8726bd6d2ce719319dbe160b626cd1da17c6f5 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Fri, 25 Oct 2024 11:34:41 -0700 Subject: [PATCH 07/14] Avoid trying to determine the current user too early. --- .../Checker/Runtime_Environment_Setup.php | 18 +++++++++++++++ runtime-content/wp-get-current-user.php | 23 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 runtime-content/wp-get-current-user.php diff --git a/includes/Checker/Runtime_Environment_Setup.php b/includes/Checker/Runtime_Environment_Setup.php index 0336911dc..b32ae3780 100644 --- a/includes/Checker/Runtime_Environment_Setup.php +++ b/includes/Checker/Runtime_Environment_Setup.php @@ -70,6 +70,8 @@ static function () use ( $permalink_structure ) { // The `wp_install()` function requires some pluggable functions like `get_user_by()` to be loaded. if ( ! function_exists( 'get_user_by' ) ) { + // Override `wp_get_current_user()`. + require_once $this->get_runtime_content_path() . 'wp-get-current-user.php'; require_once ABSPATH . '/wp-includes/pluggable.php'; } @@ -199,4 +201,20 @@ public function can_set_up() { return false; } + + /** + * Gets the path to the Plugin Check's runtime content directory. + * + * @since n.e.x.t + * + * @return string The path to the runtime content directory. + */ + private function get_runtime_content_path(): string { + if ( ! defined( 'WP_PLUGIN_CHECK_PLUGIN_DIR_PATH' ) ) { + $plugins_dir = defined( 'WP_PLUGIN_DIR' ) ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/plugins'; + return $plugins_dir . '/plugin-check/runtime-content/'; + } + + return WP_PLUGIN_CHECK_PLUGIN_DIR_PATH . 'runtime-content/'; + } } diff --git a/runtime-content/wp-get-current-user.php b/runtime-content/wp-get-current-user.php new file mode 100644 index 000000000..e0d888aa7 --- /dev/null +++ b/runtime-content/wp-get-current-user.php @@ -0,0 +1,23 @@ + Date: Fri, 25 Oct 2024 11:48:46 -0700 Subject: [PATCH 08/14] Avoid flushing rewrite rules even when pretty permalinks are not used (see #334). --- includes/Checker/Runtime_Environment_Setup.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/includes/Checker/Runtime_Environment_Setup.php b/includes/Checker/Runtime_Environment_Setup.php index b32ae3780..db1300216 100644 --- a/includes/Checker/Runtime_Environment_Setup.php +++ b/includes/Checker/Runtime_Environment_Setup.php @@ -51,6 +51,20 @@ public function set_up() { add_action( 'populate_options', static function () use ( $permalink_structure ) { + /* + * If pretty permalinks are not used, temporarily enable them by setting a permalink structure, to + * avoid flushing rewrite rules in wp_install_maybe_enable_pretty_permalinks(). + * Afterwards, on the 'wp_install' action, set the original (empty) permalink structure. + */ + if ( ! $permalink_structure ) { + add_action( + 'wp_install', + static function () use ( $permalink_structure ) { + update_option( 'permalink_structure', $permalink_structure ); + } + ); + $permalink_structure = '/%postname%/'; + } add_option( 'permalink_structure', $permalink_structure ); } ); From 930f03e6fdbc3fadc2db3fcd3c89a634bd5ebcbf Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Fri, 25 Oct 2024 12:07:36 -0700 Subject: [PATCH 09/14] Reduce complexity by using separate method to install WordPress including its tweaks. --- .../Checker/Runtime_Environment_Setup.php | 80 +++++++++++-------- 1 file changed, 48 insertions(+), 32 deletions(-) diff --git a/includes/Checker/Runtime_Environment_Setup.php b/includes/Checker/Runtime_Environment_Setup.php index db1300216..886dd93a3 100644 --- a/includes/Checker/Runtime_Environment_Setup.php +++ b/includes/Checker/Runtime_Environment_Setup.php @@ -26,7 +26,8 @@ final class Runtime_Environment_Setup { public function set_up() { global $wpdb, $table_prefix, $wp_filesystem; - require_once ABSPATH . '/wp-admin/includes/upgrade.php'; + // Get the existing site URL. + $site_url = get_option( 'siteurl' ); // Get the existing active plugins. $active_plugins = get_option( 'active_plugins' ); @@ -69,37 +70,7 @@ static function () use ( $permalink_structure ) { } ); - if ( ! isset( $_SERVER['HTTP_HOST'] ) ) { - $site_url = get_option( 'siteurl' ); - $_SERVER['HTTP_HOST'] = preg_replace( '#^https?://#', '', rtrim( $site_url, '/' ) ); - } - - // Do not send post-install notification email, see https://github.com/WordPress/plugin-check/issues/424. - add_filter( 'pre_wp_mail', '__return_false' ); - - // The `wp_install()` function requires the WP_DEFAULT_THEME constant to be set. - if ( ! defined( 'WP_DEFAULT_THEME' ) ) { - define( 'WP_DEFAULT_THEME', $active_theme ); - } - - // The `wp_install()` function requires some pluggable functions like `get_user_by()` to be loaded. - if ( ! function_exists( 'get_user_by' ) ) { - // Override `wp_get_current_user()`. - require_once $this->get_runtime_content_path() . 'wp-get-current-user.php'; - require_once ABSPATH . '/wp-includes/pluggable.php'; - } - - wp_install( - 'Plugin Check', - 'plugincheck', - 'demo@plugincheck.test', - false - ); - - remove_filter( 'pre_wp_mail', '__return_false' ); - - // Activate the same plugins in the test environment. - update_option( 'active_plugins', $active_plugins ); + $this->install_wordpress( $site_url, $active_theme, $active_plugins ); } // Restore the old prefix. @@ -216,6 +187,51 @@ public function can_set_up() { return false; } + /** + * Installs WordPress, while providing tweaks to allow for early execution of the install process. + * + * @since n.e.x.t + * + * @param string $active_siteurl The actual site's site URL. + * @param string $active_theme The actual site's theme slug. + * @param string[] $active_plugins The actual site's list of plugin basenames. + */ + private function install_wordpress( string $active_siteurl, string $active_theme, array $active_plugins ): void { + require_once ABSPATH . '/wp-admin/includes/upgrade.php'; + + if ( ! isset( $_SERVER['HTTP_HOST'] ) ) { + $site_url = $active_siteurl; + $_SERVER['HTTP_HOST'] = preg_replace( '#^https?://#', '', rtrim( $site_url, '/' ) ); + } + + // Do not send post-install notification email, see https://github.com/WordPress/plugin-check/issues/424. + add_filter( 'pre_wp_mail', '__return_false' ); + + // The `wp_install()` function requires the WP_DEFAULT_THEME constant to be set. + if ( ! defined( 'WP_DEFAULT_THEME' ) ) { + define( 'WP_DEFAULT_THEME', $active_theme ); + } + + // The `wp_install()` function requires some pluggable functions like `get_user_by()` to be loaded. + if ( ! function_exists( 'get_user_by' ) ) { + // Override `wp_get_current_user()`. + require_once $this->get_runtime_content_path() . 'wp-get-current-user.php'; + require_once ABSPATH . '/wp-includes/pluggable.php'; + } + + wp_install( + 'Plugin Check', + 'plugincheck', + 'demo@plugincheck.test', + false + ); + + remove_filter( 'pre_wp_mail', '__return_false' ); + + // Activate the same plugins in the test environment. + update_option( 'active_plugins', $active_plugins ); + } + /** * Gets the path to the Plugin Check's runtime content directory. * From 7d7fa78c4e3f264ec29a9b0339660d486e97f331 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Fri, 25 Oct 2024 12:35:38 -0700 Subject: [PATCH 10/14] Ensure cookie constants are set in time. --- .../Checker/Runtime_Environment_Setup.php | 30 ++++++++----------- runtime-content/wp-get-current-user.php | 23 -------------- 2 files changed, 12 insertions(+), 41 deletions(-) delete mode 100644 runtime-content/wp-get-current-user.php diff --git a/includes/Checker/Runtime_Environment_Setup.php b/includes/Checker/Runtime_Environment_Setup.php index 886dd93a3..cde29da84 100644 --- a/includes/Checker/Runtime_Environment_Setup.php +++ b/includes/Checker/Runtime_Environment_Setup.php @@ -214,11 +214,21 @@ private function install_wordpress( string $active_siteurl, string $active_theme // The `wp_install()` function requires some pluggable functions like `get_user_by()` to be loaded. if ( ! function_exists( 'get_user_by' ) ) { - // Override `wp_get_current_user()`. - require_once $this->get_runtime_content_path() . 'wp-get-current-user.php'; require_once ABSPATH . '/wp-includes/pluggable.php'; } + /* + * Cookie constants need to be set before installation, which normally happens immediately after + * 'muplugins_loaded', which is when the logic here typically runs. It is therefore safe to call these + * functions here already. + */ + if ( doing_action( 'muplugins_loaded' ) || ! did_action( 'muplugins_loaded' ) ) { + if ( is_multisite() ) { + ms_cookie_constants(); + } + wp_cookie_constants(); + } + wp_install( 'Plugin Check', 'plugincheck', @@ -231,20 +241,4 @@ private function install_wordpress( string $active_siteurl, string $active_theme // Activate the same plugins in the test environment. update_option( 'active_plugins', $active_plugins ); } - - /** - * Gets the path to the Plugin Check's runtime content directory. - * - * @since n.e.x.t - * - * @return string The path to the runtime content directory. - */ - private function get_runtime_content_path(): string { - if ( ! defined( 'WP_PLUGIN_CHECK_PLUGIN_DIR_PATH' ) ) { - $plugins_dir = defined( 'WP_PLUGIN_DIR' ) ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/plugins'; - return $plugins_dir . '/plugin-check/runtime-content/'; - } - - return WP_PLUGIN_CHECK_PLUGIN_DIR_PATH . 'runtime-content/'; - } } diff --git a/runtime-content/wp-get-current-user.php b/runtime-content/wp-get-current-user.php deleted file mode 100644 index e0d888aa7..000000000 --- a/runtime-content/wp-get-current-user.php +++ /dev/null @@ -1,23 +0,0 @@ - Date: Fri, 25 Oct 2024 12:40:19 -0700 Subject: [PATCH 11/14] Revert moving upgrade.php require statement as it needs to be loaded when database is present. --- includes/Checker/Runtime_Environment_Setup.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/Checker/Runtime_Environment_Setup.php b/includes/Checker/Runtime_Environment_Setup.php index cde29da84..da7ba176b 100644 --- a/includes/Checker/Runtime_Environment_Setup.php +++ b/includes/Checker/Runtime_Environment_Setup.php @@ -26,6 +26,8 @@ final class Runtime_Environment_Setup { public function set_up() { global $wpdb, $table_prefix, $wp_filesystem; + require_once ABSPATH . '/wp-admin/includes/upgrade.php'; + // Get the existing site URL. $site_url = get_option( 'siteurl' ); @@ -197,8 +199,6 @@ public function can_set_up() { * @param string[] $active_plugins The actual site's list of plugin basenames. */ private function install_wordpress( string $active_siteurl, string $active_theme, array $active_plugins ): void { - require_once ABSPATH . '/wp-admin/includes/upgrade.php'; - if ( ! isset( $_SERVER['HTTP_HOST'] ) ) { $site_url = $active_siteurl; $_SERVER['HTTP_HOST'] = preg_replace( '#^https?://#', '', rtrim( $site_url, '/' ) ); From b5972b9e42ba61b2e2e8d6f994e6e7b62fd019cb Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Fri, 25 Oct 2024 12:47:05 -0700 Subject: [PATCH 12/14] Remove log expectations about runtime environment from Behat tests as this is no longer being logged by the CLI command. --- tests/behat/features/plugin-check.feature | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/behat/features/plugin-check.feature b/tests/behat/features/plugin-check.feature index f7bca75a5..6cd718bd2 100644 --- a/tests/behat/features/plugin-check.feature +++ b/tests/behat/features/plugin-check.feature @@ -548,14 +548,6 @@ Feature: Test that the WP-CLI command works. # Running runtime checks, including the one from pcp-addon When I run the WP-CLI command `plugin check foo-sample --fields=code,type --format=csv --require=./wp-content/plugins/plugin-check/cli.php` Then STDOUT should contain: - """ - Setting up runtime environment. - """ - And STDOUT should contain: - """ - Cleaning up runtime environment. - """ - And STDOUT should contain: """ WordPress.WP.EnqueuedResourceParameters.NotInFooter,WARNING """ From 69b9c8d29c12865e81aae92a342d45daab0a813f Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Fri, 25 Oct 2024 12:53:54 -0700 Subject: [PATCH 13/14] Remove log expectations about runtime environment from Behat tests as this is no longer being logged by the CLI command. --- tests/behat/features/plugin-check.feature | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/behat/features/plugin-check.feature b/tests/behat/features/plugin-check.feature index 6cd718bd2..287c14a51 100644 --- a/tests/behat/features/plugin-check.feature +++ b/tests/behat/features/plugin-check.feature @@ -560,14 +560,6 @@ Feature: Test that the WP-CLI command works. # Same again, to verify object-cache.php was properly cleared again When I run the WP-CLI command `plugin check foo-sample --fields=code,type --format=csv --require=./wp-content/plugins/plugin-check/cli.php` Then STDOUT should contain: - """ - Setting up runtime environment. - """ - And STDOUT should contain: - """ - Cleaning up runtime environment. - """ - And STDOUT should contain: """ WordPress.WP.EnqueuedResourceParameters.NotInFooter,WARNING """ From 3dcd99c78e95636d79e07f6e59c991977c22e8f9 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Fri, 25 Oct 2024 15:25:17 -0700 Subject: [PATCH 14/14] Use 1.3.0 version annotation. --- includes/Checker/Abstract_Check_Runner.php | 2 +- includes/Checker/CLI_Runner.php | 2 +- includes/Checker/Runtime_Environment_Setup.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/Checker/Abstract_Check_Runner.php b/includes/Checker/Abstract_Check_Runner.php index 9fe8262d3..001f1b3f5 100644 --- a/includes/Checker/Abstract_Check_Runner.php +++ b/includes/Checker/Abstract_Check_Runner.php @@ -490,7 +490,7 @@ final public function get_checks_to_run() { /** * Initializes the runtime environment so that runtime checks can be run against a separate set of database tables. * - * @since n.e.x.t + * @since 1.3.0 * * @return callable[] Array of cleanup functions to run after the process has completed. */ diff --git a/includes/Checker/CLI_Runner.php b/includes/Checker/CLI_Runner.php index 2ddf4684a..7b92dcf9f 100644 --- a/includes/Checker/CLI_Runner.php +++ b/includes/Checker/CLI_Runner.php @@ -181,7 +181,7 @@ protected function get_slug_param() { /** * Initializes the runtime environment so that runtime checks can be run against a separate set of database tables. * - * @since n.e.x.t + * @since 1.3.0 * * @return callable[] Array of cleanup functions to run after the process has completed. */ diff --git a/includes/Checker/Runtime_Environment_Setup.php b/includes/Checker/Runtime_Environment_Setup.php index da7ba176b..40c14dd95 100644 --- a/includes/Checker/Runtime_Environment_Setup.php +++ b/includes/Checker/Runtime_Environment_Setup.php @@ -192,7 +192,7 @@ public function can_set_up() { /** * Installs WordPress, while providing tweaks to allow for early execution of the install process. * - * @since n.e.x.t + * @since 1.3.0 * * @param string $active_siteurl The actual site's site URL. * @param string $active_theme The actual site's theme slug.