wp-cli silently fails with 255 when running wp core install

I was missing some php extensions that wp-cli and/or WordPress needed but there is no error output stating as much. I’m guessing it was specifically the missing mysqli extension. I used a WP-CLI command to test the base container for missing extensions and now I have sudo docker-php-ext-install gd sockets mysqli exif in my config.yml. … Read more

What tools respect `.distignore`?

This is file for WP CLI. the command dist-archive: wp dist-archive . Note that you need to install both WP CLI and this plugin: wp package install wp-cli/dist-archive-command

Can I create (or update) user password with WP-CLI by hash?

There is not “one command” in WordPress CLI that does the job: https://github.com/wp-cli/wp-cli/issues/2270 However using other commands, you can overide the user password directly in the database using the following: USER_ID=$(wp user list –login=”$USR_LOGIN” –format=ids) wp db query “UPDATE wp_users SET user_pass=”$HASHED_PASS” WHERE ID = $USER_ID;” First line is optional if you already know the … Read more

WPCLI search and replace variants for all tables

In a WordPress installation, a certain number of database tables are registered in the $wpdb object. To see what they are, you can run the WP-CLI command wp db tables. On my local WP installation, these are the $wpdb-registered tables: wp_users wp_usermeta wp_posts wp_comments wp_links wp_options wp_postmeta wp_terms wp_term_taxonomy wp_term_relationships wp_termmeta wp_commentmeta wp_blogs wp_signups wp_site … Read more

WP-CLI with theme: Uncaught Error: Class ‘WP_CLI’ not found

You’ll need to wrap your statement within a class_exists() check: function foo_command( $args ) { WP_CLI::success( $args[0] ); } if ( class_exists( ‘WP_CLI’ ) ) { WP_CLI::add_command( ‘foo’, ‘foo_command’ ); } This way, the command is only registered when the WP_CLI class exists — because the WP_CLI class will only exist when WP-CLI is running.

Is it possible to use WP-CLI via PHP-framework?

The WP_CLI class has a runcommand method that launches a new child process to run a specified WP-CLI command. According to the docs, you can use it like this: $options = array( ‘return’ => true, // Return ‘STDOUT’; use ‘all’ for full object. ‘parse’ => ‘json’, // Parse captured STDOUT to JSON array. ‘launch’ => … Read more