diff --git a/README.md b/README.md index e68f25c..1fe7383 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,30 @@ function my_callback_function( $result ) { } ``` +#### Custom Processor +Using a custom processor requires using the `loco_register_batch_processor` filter to register the processor type and a processor class that extends the `Rkv\Locomotive\Abstracts\Batch` class. + +Register your custom callback to be used when the type matches your process type: +``` +add_filter( 'loco_register_batch_processor', function( $return_value, $type, $args){ + if( 'hiroy' == $type' ){ + // Return name of class, not class instance + return 'HiRoyProcessor'; + }elseif( 'hishawn' == $type ){ + // Return name of class, not class instance + return 'HiShawnProcessor'; + }else{ + // No custom type matched + // Return filter default to allow for other custom types or defaults + return $return_value; + } + + +}, 10, 3 ); + + + + #### Start Batch Process ![Locomotive Menu](screenshot.gif?raw=true "Locomotive Menu") diff --git a/includes/functions.php b/includes/functions.php index 82cc250..a314cfd 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -23,6 +23,25 @@ function register_batch_process( $args ) { $args['type'] = ''; } + /** + * Filter to register custom batch process types. + * + * Return the name (fully namespaced) of a your batch processor class NOT an object instance + * + * @param string $batch_processor Batch processor class, must extend Rkv\Locomotive\Abstracts\Batch + * @param string $type Type of processor + * @param array $args Args passed to register_batch_process + */ + $batch_processor = apply_filters( 'loco_register_batch_processor', null, $args['type'], $args ); + + // Check if filter returned a valid processor. + // If so, use that, else continue to defaults. + if ( is_string( $batch_processor ) && is_subclass_of( $batch_processor, 'Rkv\Locomotive\Abstracts\Batch' ) ) { + $batch_process = new $batch_processor(); + $batch_process->register( $args ); + return; + } + switch ( $args['type'] ) { case 'post': $batch_process = new Posts();