Closed renatonascalves closed 7 months ago
Bulk_Task_Side_Effects
Here is an example:
class Command extends WPCOM_VIP_CLI_Command { use Bulk_Task_Side_Effects; /** * Command description. * * ## OPTIONS * * [--dry-run] * : Resets the cursor before starting the command. */ public function example_command( $args, $assoc_args ) { $this->pause_side_effects(); // Optionally handle `--rewind`, `--from-scratch`, or user input here. $bulk_task->run( [ /* WP_Query arguments */ ], function( $post ) use ( $dry_run ) { $new_value = str_replace( 'apple', 'banana', $post->post_content ); if ( $dry_run ) { WP_CLI::log( 'Old post_content: ' . $post->post_content ); WP_CLI::log( 'New post_content: ' . $new_value ); } else { $post->post_content = $new_value; wp_update_post( $post ); } } ); $this->resume_side_effects(); } }
The documentation suggestion will go in a different pr, with changelog changes. :)
Bulk_Task_Side_Effects
, to optionally disable common integrationsHere is an example: