: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
<?php if ( ! defined( 'ABSPATH' ) ) exit;
* Class NF_Abstracts_Batch_Process
abstract class NF_Abstracts_BatchProcess
* Array that holds data we're sending back to the JS front-end.
protected $response = array(
'batch_complete' => false
public function __construct( $data = array() )
//Bail if we aren't in the admin.
! current_user_can( apply_filters('ninja_forms_admin_all_forms_capabilities', 'manage_options') ) )
* This helps us by not requiring us to declare global $wpdb in every class method.
* Decides whether we need to run startup or restart and then calls processing.
$this->_flag = 'nf_doing_' . $this->_slug;
if ( ! $this->flag( $this->_flag, 'check' ) ) {
// Run the startup process.
// Otherwise... (We've already run startup.)
// Determine how many steps this will take.
$this->response[ 'step_total' ] = $this->get_steps();
$this->flag( $this->_flag, 'add' );
* Function to loop over the batch.
public function process()
* This function intentionlly left empty.
* Function to run any setup steps necessary to begin processing.
public function startup()
* This function intentionally left empty.
* Function to run any setup steps necessary to begin processing for steps after the first.
public function restart()
* This function intentionally left empty.
* Returns how many steps we have in this process.
* If this method isn't overwritten by a child, it defaults to 1.
public function get_steps()
* Adds an error to the response object.
* @param $slug (String) The slug for this error code.
* @param $msg (String) The error message to be displayed.
* @param $type (String) warning or fatal, depending on the error.
public function add_error( $slug, $msg, $type = 'warning' )
// Setup our errors array if it doesn't exist already.
if ( ! isset( $this->response[ 'errors' ] ) ) {
$this->response[ 'errors' ] = array();
$this->response[ 'errors' ][] = array(
* Function to cleanup any lingering temporary elements of a batch process after completion.
public function cleanup()
* This function intentionally left empty.
* Method called when we are finished with this process.
* Deletes our "doing" option.
* Set's our response 'batch_complete' to true.
* Responds to the JS front-end.
public function batch_complete()
$this->flag( $this->_flag, 'remove' );
// Tell our JS that we're done.
$this->response[ 'batch_complete' ] = true;
* Method that immediately moves on to the next step.
* Used in child methods to stop processing the current step an dmove to the next.
public function next_step()
// ..see how many steps we have left, update our option, and send the remaining step to the JS.
$this->response[ 'step_remaining' ] = $this->get_steps();
* Method that encodes $this->response and sends the data to the front-end.
public function respond()
if ( ! empty( $this->response[ 'errors' ] ) ) {
$this->response[ 'errors' ] = array_unique( $this->response[ 'errors' ] );
echo wp_json_encode( $this->response );
* Method to check or modify our processor flag.
* @param $flag (String) The flag to check
* @param $action (String) The type of interaction to be performed
public function flag( $flag, $action )
return add_option($flag, true);
return delete_option($flag);
return get_option($flag);