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

Trying to install WordPress on WSL Windows 10, and running into issues with wp-cli and “wp db create”

The error has nothing to do with your setup. It says that your connection credential to MySQL database is incorrect. ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES) When you were setting up the MySQL by following the tutorial sudo apt install -y lamp-server^ It probably did ask you to set a … Read more

What’s a better workflow for database migration?

I use this for search and replace on databases – https://interconnectit.com/products/search-and-replace-for-wordpress-databases/ Simply move files with FTP, export and import database and then run the script searching for old URL and replacing with the new URL. Then I resave permalinks and I’m done. I’ve moved WP thousands of times using this. I’ve got the old script … Read more

How do I update a nested option?

wp option does all you need. See wp option patch in particular. Updates a nested value in an option. Get a nested option value: $ wp option pluck ez-toc-settings auto_insert_post_types Set a nested option value (with an array): $ wp option patch update ez-toc-settings auto_insert_post_types ‘{“post”:”post”}’ –format=json

WP CLI – show users whose ID is larger than given ID

One way to work with existing WP-CLI commands is through the WP_CLI::runcommand(). Here are two examples how we can filter an existing WP-CLI command, namely the wp user list command based on WP_User_Query and it’s pre_user_query hook: Run a custom script in WP-CLI Let’s write our script.php file with: <?php add_action( ‘pre_user_query’, ‘wpse_pre_user_query’ ); WP_CLI::runcommand( … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)