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

Backport: Fix wp-cli to bring $cp_version into scope #268

Merged
merged 6 commits into from
Feb 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Loading