Skip to content

Commit

Permalink
Fix: Add $cp_version to scope for wp-cli (#268)
Browse files Browse the repository at this point in the history
Backport: Fix `wp-cli` to bring `$cp_version` into scope
  • Loading branch information
mattyrob authored Feb 11, 2024
2 parents 5a4ea21 + df78aec commit 48c2581
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/wp-includes/class-fix-wpcli.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,31 @@ class Fix_WPCLI {
* @since CP-1.5.0
*/
public function __construct() {
WP_CLI::add_hook( 'after_wp_load', array( __CLASS__, 'add_cp_version_to_scope' ) );
WP_CLI::add_hook( 'before_invoke:core check-update', array( __CLASS__, 'correct_core_check_update' ) );
}

/**
* Add $cp_version to scope.
*
* @since CP-1.7.3
*/
public static function add_cp_version_to_scope() {
// Add $cp_version to scope.
if ( ! isset( $GLOBALS['cp_version'] ) ) {
global $cp_version;
require ABSPATH . WPINC . '/version.php';
}
}

/**
* Fix wp core check-update command.
*
* @since CP-1.5.0
*/
public static function correct_core_check_update() {
// Add $cp_version to scope.
global $cp_version;

// Check for updates. Bail on error.
// When playing with versions, an empty array is returned if it's not on api.
Expand Down Expand Up @@ -71,12 +87,6 @@ public static function correct_core_check_update() {

$major = preg_match( '/ --major */', $current_command );

// Put $cp_version into scope.
if ( ! isset( $GLOBALS['cp_version'] ) ) {
global $cp_version;
require ABSPATH . WPINC . '/version.php';
}

// Prepare output array.
$table_output = array();

Expand Down Expand Up @@ -112,7 +122,6 @@ public static function correct_core_check_update() {
// Exit to prevent the core check-update command to continue his work.
exit;
}

}

new Fix_WPCLI();

0 comments on commit 48c2581

Please sign in to comment.