alleyinteractive / wp-bulk-task

A library to assist with running performant bulk tasks against WordPress database objects.
GNU General Public License v2.0
13 stars 0 forks source link

Disable common integrations #11

Closed renatonascalves closed 7 months ago

renatonascalves commented 7 months ago

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();
    }
}
renatonascalves commented 7 months ago

The documentation suggestion will go in a different pr, with changelog changes. :)