I’ve noticed that wp-cli in not able to determine if CP should be updated.
Most functions are still working.
There is any idea about supporting wp-cli or forking to cp-cli?
Hope to be in the right place
I’ve noticed that wp-cli in not able to determine if CP should be updated.
Most functions are still working.
There is any idea about supporting wp-cli or forking to cp-cli?
Hope to be in the right place
We discused in the past and we saw that CP works without any issues with WP-CLI.
We tested also with updates from wp-cli and we didn’t found any problem.
About updates it is something thatwe can investigate further.
This is the output testing WP-CLI 2.1.0 with ClassicPress 1.0.0-rc1.
wp core check-update
**Success:** WordPress is at the latest version.
wp core version --extra
WordPress version:
Database revision:
TinyMCE version:
Package language: en_US
Looking at the code the big problem is that we don’t have anymore $wp_version
as example core-command/features/core-update.feature at d2e7425d765117960d448bcc8fa1ff97864a37e9 · wp-cli/core-command · GitHub
Looking at the code is used core-command/src/Core_Command.php at d2e7425d765117960d448bcc8fa1ff97864a37e9 · wp-cli/core-command · GitHub
So maybe we can think to add a check for wpcli that create this variable so WP-CLI will works correct.
Right now do a fork of wpcli only to changethis variable is not so easy because there are a lot of repository and replicate also the bulding system is not very easy.
What do you think @james?
Some of the details here are not quite right, I think. We do have the $wp_version
variable here, it is set to 4.9.9
.
I will do some testing here. For now, this should work on sites that have automatic updates enabled:
wp eval 'wp_maybe_auto_update();'
Thank you @Pross and @Mte90 for investigating this.
A fix for wp core version --extra
is merged into our source tree and will be included in 1.0.1
(no date set yet) and future nightly builds:
A fix for wp core check-update
will likely need another patch.
Wordpress.org is hardcoded in wp-cli, so it’s impossible to update from command line.
As I can see wp-cli can be extended with custom commands.
Those commands can be included from a plugin.
if ( defined( ‘WP_CLI’ ) && WP_CLI ) {
require_once dirname( FILE ) . ‘/inc/class-plugin-cli-command.php’;
}
Maybe a “core plugin” could be a solution.
Just a quick test, becouse I’m a very bad coder…
// only for wp-cli
if ( defined( 'WP_CLI' ) && WP_CLI ) {
// add a hook that runs before the command
WP_CLI::add_hook( 'before_invoke:core check-update', 'cp_correct_core_update' );
}
function cp_correct_core_update() {
// if we have ClassicPress
if ( function_exists( 'classicpress_version' ) ) {
// warn the user
WP_CLI::warning( "wp-cli can't check this on ClassicPress" );
// or do something better there
// then exit to prevent the core-update command to
// continue his work
exit;
};
};
Yes, something like this (and actually checking / doing the upgrade before exit
) would work well.
Another idea I’ve had is to release a cpress-cli
that is not a full fork, but rather a customized build of WP-CLI where we override the few commands that need to work differently in ClassicPress.
You can actually just overide the original function by extending the class too, but i like the idea of the before_invoke hook as its more update proof.
if ( class_exists( 'WP_CLI_Command' ) ) {
class CP_Core_Command extends Core_Command {
/**
* Checks for ClasicPress updates via Version Check API.
*
* Lists the most recent versions when there are updates available,
* or success message when up to date.
*
* @subcommand check-update
*/
function check_update( $_, $assoc_args ) {
WP_CLI::success( 'ClassicPress is at the latest version.' );
}
}
WP_CLI::add_command( 'core', 'CP_Core_Command' );
}
A custom build means that in the majority of hosting will be not possible to use it. There are a a lot that provide wpcli already or that not enable to add new scripts.
If we can be at the moment backward comaptible will be not bad also because in case we can ask to them to add support for what we need if are little things.
that not enable to add new scripts
Do you mean that you can’t add packages to wp-cli?
no create new scripts as example, there are hosting that are very strict for that reason they release already a global wp-cli to the machine
It would be interesting to see if in those envirovments wp-cli can be altered/expanded from a plugin…
Not impossible - in any hosting environment that gives you SSH access (which is required to use WP-CLI), you can still drop whatever you want into the /home/yourusername/bin
folder and run it from there.
I see your point though, it is an additional step that people would have to follow.
I don’t love the idea of including hacks for WP-CLI in the ClassicPress core code either. Maybe we could try this as a plugin that you install in your ClassicPress sites, or in your ~/.wp-cli/config.yml
file (details).
Just to follow-up on this specifically - anywhere WP-CLI will run (that I have ever seen) it can be expanded using a plugin. It follows most of the normal WordPress loading process.
And as far as WP-CLI update compatibility - this will tell you that “WordPress updated successfully” but otherwise it works fine:
wp core update https://github.com/ClassicPress/ClassicPress-release/archive/1.0.1.zip
In versions 1.0.0 and earlier you would get “Warning: Failed to find WordPress version. Please cleanup files manually.” However the change from @Pross has fixed this in 1.0.1 and for future versions.
For now, I’m going to mark this answer as a solution, not because it fixes all the issues, but because it is still possible to update sites using WP-CLI and so that it’s easy to find the right way to do this.
Great.
Tested and it works with just “wp core update”.
Works perfect with my scripts and my hook in a plugin!
// only for wp-cli
if ( defined( 'WP_CLI' ) && WP_CLI ) {
// add a hook that runs before the command
WP_CLI::add_hook( 'before_invoke:core check-update', 'cp_correct_check_update' );
}
function cp_correct_check_update() {
// if we have ClassicPress
if ( function_exists( 'classicpress_version' ) ) {
$gcu = get_core_updates();
if ( 'latest' == $gcu[0]->{'response'} ){
WP_CLI::success( "ClassicPress is up-to-date." );
} else {
WP_CLI::warning( "ClassicPress needs you: response=" . $gcu[0]->{'response'} . "." );
};
// then exit to prevent the core check-update command to
// continue his work
exit;
};
};