Skip to content

Commit

Permalink
Merge branch 'trunk' into 587-check-dont-force-set-php-limits-globally
Browse files Browse the repository at this point in the history
  • Loading branch information
davidperezgar authored Sep 2, 2024
2 parents baef8d6 + 7e5bcd9 commit e974a0a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 4 deletions.
3 changes: 3 additions & 0 deletions includes/Admin/Admin_AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ public function set_up_environment() {
* Handles the AJAX request to cleanup the runtime environment.
*
* @since 1.0.0
*
* @global wpdb $wpdb WordPress database abstraction object.
* @global string $table_prefix The database table prefix.
*/
public function clean_up_environment() {
global $wpdb, $table_prefix;
Expand Down
23 changes: 19 additions & 4 deletions includes/Checker/Abstract_Check_Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ final public function prepare() {
*
* @since 1.0.0
*
* @global wpdb $wpdb WordPress database abstraction object.
* @global string $table_prefix The database table prefix.
*
* @return Check_Result An object containing all check results.
*/
final public function run() {
Expand Down Expand Up @@ -416,14 +419,11 @@ private function get_shared_preparations( array $checks ) {
* @throws Exception Thrown when invalid flag is passed, or Check slug does not exist.
*/
final public function get_checks_to_run() {
// Include file to use is_plugin_active() in CLI context.
require_once ABSPATH . 'wp-admin/includes/plugin.php';

$check_slugs = $this->get_check_slugs();
$check_flags = Check_Repository::TYPE_STATIC;

// Check if conditions are met in order to perform Runtime Checks.
if ( ( $this->initialized_early || $this->runtime_environment->can_set_up() ) && is_plugin_active( $this->get_plugin_basename() ) ) {
if ( $this->allow_runtime_checks() ) {
$check_flags = Check_Repository::TYPE_ALL;
}

Expand All @@ -448,6 +448,21 @@ final public function get_checks_to_run() {
return $collection->to_map();
}

/**
* Checks whether the current environment allows for runtime checks to be used.
*
* @since n.e.x.t
*
* @return bool True if runtime checks are allowed, false otherwise.
*/
protected function allow_runtime_checks(): bool {
// Ensure that is_plugin_active() is available.
require_once ABSPATH . 'wp-admin/includes/plugin.php';

return ( $this->initialized_early || $this->runtime_environment->can_set_up() )
&& is_plugin_active( $this->get_plugin_basename() );
}

/**
* Creates and returns the Check instance.
*
Expand Down
19 changes: 19 additions & 0 deletions includes/Checker/CLI_Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,23 @@ protected function get_categories_param() {

return $categories;
}

/**
* Checks whether the current environment allows for runtime checks to be used.
*
* @since n.e.x.t
*
* @return bool True if runtime checks are allowed, false otherwise.
*/
protected function allow_runtime_checks(): bool {
/*
* For WP-CLI, everything happens in one request. So if the runner was not initialized early, we won't be
* able to set that up, since the object-cache.php drop-in would only become effective in subsequent requests.
*/
if ( ! $this->initialized_early ) {
return false;
}

return parent::allow_runtime_checks();
}
}
4 changes: 4 additions & 0 deletions includes/Checker/Runtime_Environment_Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ final class Runtime_Environment_Setup {
* Sets up the WordPress environment for runtime checks
*
* @since 1.0.0
*
* @global wpdb $wpdb WordPress database abstraction object.
* @global string $table_prefix The database table prefix.
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
*/
public function set_up() {
global $wpdb, $table_prefix, $wp_filesystem;
Expand Down
2 changes: 2 additions & 0 deletions includes/Utilities/Plugin_Request_Utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ public static function get_files_to_ignore() {
*
* @since 1.1.0
*
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
*
* @param string $plugin_url The URL of the plugin to download.
* @return string The plugin basename after downloading and installing the plugin.
*
Expand Down

0 comments on commit e974a0a

Please sign in to comment.