How to implement a custom post task using hooks?

Home Forums WordPress Plugins Bulk Task Editor How to implement a custom post task using hooks?

Tagged: 

Viewing 0 reply threads
  • Author
    Posts
    • #8906
      Rafasashi
      Keymaster

      To implement a custom post task using hooks with Bulk Task Editor register the task:

      add_action( 'rewbe_post_type_actions', function($actions,$post_type){
      
           if( $post_type == 'your-custom-post-type' ){
      
                $actions[] = array(
      
                     'label'  => 'Name of your task',
                     'id'     => 'bulk_task_name',
                     'fields' => array(
                          array(
                               'name'    => 'var_1',
                               'type'    => 'select',
                               'options' => array(
                                    'value_1' => 'Option 1',
                                    'value_2' => 'Option 2',
                                    'value_3' => 'Option 3',
                               ),                    
                          ),
                          array(
                               'name' => 'var_2',
                               'type' => 'text',
                          ),
                     ),
                );
           }
           
           return $actions;
           
      },10,2);
      

      Add the callback function of your task:

      add_action('rewbe_do_post_{bulk_task_name}',function($post,$args){
           
           if( !empty($args['var_1']) && !empty($args['var_2']) ){
                
                $var_1 = sanitize_title($args['var_1']);
      
                $var_2 = sanitize_text_field($args['var_2']);
                
                // your logic here
           }
           
           return $post;
           
      },10,2);
      
Viewing 0 reply threads
  • You must be logged in to reply to this topic.