Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/ninja-fo.../includes/Abstract...
File: BatchProcess.php
<?php if ( ! defined( 'ABSPATH' ) ) exit;
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* Class NF_Abstracts_Batch_Process
[3] Fix | Delete
*/
[4] Fix | Delete
abstract class NF_Abstracts_BatchProcess
[5] Fix | Delete
{
[6] Fix | Delete
protected $_db;
[7] Fix | Delete
protected $_flag;
[8] Fix | Delete
[9] Fix | Delete
/**
[10] Fix | Delete
* Array that holds data we're sending back to the JS front-end.
[11] Fix | Delete
* @var array
[12] Fix | Delete
*/
[13] Fix | Delete
protected $response = array(
[14] Fix | Delete
'batch_complete' => false
[15] Fix | Delete
);
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* Constructor
[19] Fix | Delete
*/
[20] Fix | Delete
public function __construct( $data = array() )
[21] Fix | Delete
{
[22] Fix | Delete
//Bail if we aren't in the admin.
[23] Fix | Delete
if ( ! is_admin() ||
[24] Fix | Delete
! is_user_logged_in() ||
[25] Fix | Delete
! current_user_can( apply_filters('ninja_forms_admin_all_forms_capabilities', 'manage_options') ) )
[26] Fix | Delete
{
[27] Fix | Delete
return false;
[28] Fix | Delete
}
[29] Fix | Delete
[30] Fix | Delete
global $wpdb;
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* Set $_db to $wpdb.
[34] Fix | Delete
* This helps us by not requiring us to declare global $wpdb in every class method.
[35] Fix | Delete
*/
[36] Fix | Delete
$this->_db = $wpdb;
[37] Fix | Delete
[38] Fix | Delete
// Run init.
[39] Fix | Delete
$this->init();
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
/**
[43] Fix | Delete
* Decides whether we need to run startup or restart and then calls processing.
[44] Fix | Delete
*
[45] Fix | Delete
* @since 3.4.0
[46] Fix | Delete
* @return void
[47] Fix | Delete
*/
[48] Fix | Delete
public function init()
[49] Fix | Delete
{
[50] Fix | Delete
$this->_flag = 'nf_doing_' . $this->_slug;
[51] Fix | Delete
[52] Fix | Delete
if ( ! $this->flag( $this->_flag, 'check' ) ) {
[53] Fix | Delete
// Run the startup process.
[54] Fix | Delete
$this->startup();
[55] Fix | Delete
} else {
[56] Fix | Delete
// Otherwise... (We've already run startup.)
[57] Fix | Delete
$this->restart();
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
// Determine how many steps this will take.
[61] Fix | Delete
$this->response[ 'step_total' ] = $this->get_steps();
[62] Fix | Delete
[63] Fix | Delete
$this->flag( $this->_flag, 'add' );
[64] Fix | Delete
[65] Fix | Delete
// Run processing
[66] Fix | Delete
$this->process();
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
/**
[70] Fix | Delete
* Function to loop over the batch.
[71] Fix | Delete
*
[72] Fix | Delete
* @since 3.4.0
[73] Fix | Delete
* @return void
[74] Fix | Delete
*/
[75] Fix | Delete
public function process()
[76] Fix | Delete
{
[77] Fix | Delete
/**
[78] Fix | Delete
* This function intentionlly left empty.
[79] Fix | Delete
*/
[80] Fix | Delete
}
[81] Fix | Delete
[82] Fix | Delete
/**
[83] Fix | Delete
* Function to run any setup steps necessary to begin processing.
[84] Fix | Delete
*
[85] Fix | Delete
* @since 3.4.0
[86] Fix | Delete
* @return void
[87] Fix | Delete
*/
[88] Fix | Delete
public function startup()
[89] Fix | Delete
{
[90] Fix | Delete
/**
[91] Fix | Delete
* This function intentionally left empty.
[92] Fix | Delete
*/
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
/**
[96] Fix | Delete
* Function to run any setup steps necessary to begin processing for steps after the first.
[97] Fix | Delete
*
[98] Fix | Delete
* @since 3.4.0
[99] Fix | Delete
* @return void
[100] Fix | Delete
*/
[101] Fix | Delete
public function restart()
[102] Fix | Delete
{
[103] Fix | Delete
/**
[104] Fix | Delete
* This function intentionally left empty.
[105] Fix | Delete
*/
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
/**
[109] Fix | Delete
* Returns how many steps we have in this process.
[110] Fix | Delete
*
[111] Fix | Delete
* If this method isn't overwritten by a child, it defaults to 1.
[112] Fix | Delete
*
[113] Fix | Delete
* @since 3.4.0
[114] Fix | Delete
* @return int
[115] Fix | Delete
*/
[116] Fix | Delete
public function get_steps()
[117] Fix | Delete
{
[118] Fix | Delete
return 1;
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
/**
[122] Fix | Delete
* Adds an error to the response object.
[123] Fix | Delete
*
[124] Fix | Delete
* @param $slug (String) The slug for this error code.
[125] Fix | Delete
* @param $msg (String) The error message to be displayed.
[126] Fix | Delete
* @param $type (String) warning or fatal, depending on the error.
[127] Fix | Delete
* Defaults to warning.
[128] Fix | Delete
*
[129] Fix | Delete
* @since 3.4.11
[130] Fix | Delete
*/
[131] Fix | Delete
public function add_error( $slug, $msg, $type = 'warning' )
[132] Fix | Delete
{
[133] Fix | Delete
// Setup our errors array if it doesn't exist already.
[134] Fix | Delete
if ( ! isset( $this->response[ 'errors' ] ) ) {
[135] Fix | Delete
$this->response[ 'errors' ] = array();
[136] Fix | Delete
}
[137] Fix | Delete
$this->response[ 'errors' ][] = array(
[138] Fix | Delete
'code' => $slug,
[139] Fix | Delete
'message' => $msg,
[140] Fix | Delete
'type' => $type
[141] Fix | Delete
);
[142] Fix | Delete
}
[143] Fix | Delete
[144] Fix | Delete
/**
[145] Fix | Delete
* Function to cleanup any lingering temporary elements of a batch process after completion.
[146] Fix | Delete
*
[147] Fix | Delete
* @since 3.4.0
[148] Fix | Delete
* @return void
[149] Fix | Delete
*/
[150] Fix | Delete
public function cleanup()
[151] Fix | Delete
{
[152] Fix | Delete
/**
[153] Fix | Delete
* This function intentionally left empty.
[154] Fix | Delete
*/
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
/**
[158] Fix | Delete
* Method called when we are finished with this process.
[159] Fix | Delete
*
[160] Fix | Delete
* Deletes our "doing" option.
[161] Fix | Delete
* Set's our response 'batch_complete' to true.
[162] Fix | Delete
* Runs cleanup().
[163] Fix | Delete
* Responds to the JS front-end.
[164] Fix | Delete
*
[165] Fix | Delete
* @since 3.4.0
[166] Fix | Delete
* @return void
[167] Fix | Delete
*/
[168] Fix | Delete
public function batch_complete()
[169] Fix | Delete
{
[170] Fix | Delete
// Delete our options.
[171] Fix | Delete
$this->flag( $this->_flag, 'remove' );
[172] Fix | Delete
// Tell our JS that we're done.
[173] Fix | Delete
$this->response[ 'batch_complete' ] = true;
[174] Fix | Delete
[175] Fix | Delete
$this->cleanup();
[176] Fix | Delete
$this->respond();
[177] Fix | Delete
}
[178] Fix | Delete
[179] Fix | Delete
/**
[180] Fix | Delete
* Method that immediately moves on to the next step.
[181] Fix | Delete
*
[182] Fix | Delete
* Used in child methods to stop processing the current step an dmove to the next.
[183] Fix | Delete
*
[184] Fix | Delete
* @since 3.4.0
[185] Fix | Delete
* @return void
[186] Fix | Delete
*/
[187] Fix | Delete
public function next_step()
[188] Fix | Delete
{
[189] Fix | Delete
// ..see how many steps we have left, update our option, and send the remaining step to the JS.
[190] Fix | Delete
$this->response[ 'step_remaining' ] = $this->get_steps();
[191] Fix | Delete
$this->respond();
[192] Fix | Delete
}
[193] Fix | Delete
[194] Fix | Delete
/**
[195] Fix | Delete
* Method that encodes $this->response and sends the data to the front-end.
[196] Fix | Delete
*
[197] Fix | Delete
* @since 3.4.0
[198] Fix | Delete
* @updated 3.4.11
[199] Fix | Delete
* @return void
[200] Fix | Delete
*/
[201] Fix | Delete
public function respond()
[202] Fix | Delete
{
[203] Fix | Delete
if ( ! empty( $this->response[ 'errors' ] ) ) {
[204] Fix | Delete
$this->response[ 'errors' ] = array_unique( $this->response[ 'errors' ] );
[205] Fix | Delete
}
[206] Fix | Delete
[207] Fix | Delete
echo wp_json_encode( $this->response );
[208] Fix | Delete
wp_die();
[209] Fix | Delete
}
[210] Fix | Delete
[211] Fix | Delete
/**
[212] Fix | Delete
* Method to check or modify our processor flag.
[213] Fix | Delete
*
[214] Fix | Delete
* @since 3.5.0
[215] Fix | Delete
* @param $flag (String) The flag to check
[216] Fix | Delete
* @param $action (String) The type of interaction to be performed
[217] Fix | Delete
* @return Mixed
[218] Fix | Delete
*/
[219] Fix | Delete
public function flag( $flag, $action )
[220] Fix | Delete
{
[221] Fix | Delete
switch($action) {
[222] Fix | Delete
case 'add':
[223] Fix | Delete
return add_option($flag, true);
[224] Fix | Delete
case 'remove':
[225] Fix | Delete
return delete_option($flag);
[226] Fix | Delete
default:
[227] Fix | Delete
// Default to 'check'.
[228] Fix | Delete
return get_option($flag);
[229] Fix | Delete
}
[230] Fix | Delete
}
[231] Fix | Delete
[232] Fix | Delete
}
[233] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function