$cp_version and WP-CLI

Ok, seems to be the same problem because WP-CLI is loading version.php in this way here.

/*
 * These can't be directly globalized in version.php. When updating,
 * we're including version.php from another installation and don't want
 * these values to be overridden if already set.
 */
global $wp_version, $wp_db_version, $tinymce_version, $required_php_version, $required_mysql_version, $wp_local_package;
require ABSPATH . WPINC . '/version.php';

I’ve tried this (within a plugin) and seems to work, but it’s really over my skills to understand if this can break something.
Edit: I’ve tried to upgrade and it works both from backend and CLI, but i’m not sure of whatelse can break.

if (defined('WP_CLI') && WP_CLI) {
	WP_CLI::add_hook('before_wp_config_load', 'cp_version_globalize');
}

function cp_version_globalize() {
	global $cp_version;
	require ABSPATH . WPINC . '/version.php';
}
1 Like