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/popup-ma.../classes/Abstract/Batch
File: Process.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Batch Process Handler.
[2] Fix | Delete
*
[3] Fix | Delete
* @package PUM
[4] Fix | Delete
* @copyright Copyright (c) 2023, Code Atlantic LLC
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[8] Fix | Delete
exit;
[9] Fix | Delete
}
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* Implements a basic batch process.
[13] Fix | Delete
*
[14] Fix | Delete
* @since 1.7.0
[15] Fix | Delete
*/
[16] Fix | Delete
abstract class PUM_Abstract_Batch_Process implements PUM_Interface_Batch_Process {
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* Batch process ID.
[20] Fix | Delete
*
[21] Fix | Delete
* @var string
[22] Fix | Delete
*/
[23] Fix | Delete
public $batch_id;
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* The current step being processed.
[27] Fix | Delete
*
[28] Fix | Delete
* @var int|string Step number or 'done'.
[29] Fix | Delete
*/
[30] Fix | Delete
public $step;
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* Number of items to process per step.
[34] Fix | Delete
*
[35] Fix | Delete
* @var int
[36] Fix | Delete
*/
[37] Fix | Delete
public $per_step = 100;
[38] Fix | Delete
[39] Fix | Delete
/**
[40] Fix | Delete
* Capability needed to perform the current batch process.
[41] Fix | Delete
*
[42] Fix | Delete
* @var string
[43] Fix | Delete
*/
[44] Fix | Delete
public $capability = 'manage_options';
[45] Fix | Delete
[46] Fix | Delete
/**
[47] Fix | Delete
* Sets up the batch process.
[48] Fix | Delete
*
[49] Fix | Delete
* @param int|string $step Step number or 'done'.
[50] Fix | Delete
*/
[51] Fix | Delete
public function __construct( $step = 1 ) {
[52] Fix | Delete
[53] Fix | Delete
$this->step = $step;
[54] Fix | Delete
[55] Fix | Delete
if ( has_filter( "pum_batch_per_step_{$this->batch_id}" ) ) {
[56] Fix | Delete
/**
[57] Fix | Delete
* Filters the number of items to process per step for the given batch process.
[58] Fix | Delete
*
[59] Fix | Delete
* The dynamic portion of the hook name, `$this->export_type` refers to the export
[60] Fix | Delete
* type defined in each sub-class.
[61] Fix | Delete
*
[62] Fix | Delete
* @param int $per_step The number of items to process for each step. Default 100.
[63] Fix | Delete
* @param PUM_Abstract_Batch_Process $this Batch process instance.
[64] Fix | Delete
*/
[65] Fix | Delete
$this->per_step = apply_filters( "pum_batch_per_step_{$this->batch_id}", $this->per_step, $this );
[66] Fix | Delete
}
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
/**
[70] Fix | Delete
* Determines if the current user can perform the current batch process.
[71] Fix | Delete
*
[72] Fix | Delete
* @return bool True if the current user has the needed capability, otherwise false.
[73] Fix | Delete
*/
[74] Fix | Delete
public function can_process() {
[75] Fix | Delete
return current_user_can( $this->capability );
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
/**
[79] Fix | Delete
* Executes a single step in the batch process.
[80] Fix | Delete
*
[81] Fix | Delete
* @return int|string|WP_Error Next step number, 'done', or a WP_Error object.
[82] Fix | Delete
*/
[83] Fix | Delete
public function process_step() {
[84] Fix | Delete
return 'done';
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
/**
[88] Fix | Delete
* Retrieves the calculated completion percentage.
[89] Fix | Delete
*
[90] Fix | Delete
* @return int Percentage completed.
[91] Fix | Delete
*/
[92] Fix | Delete
public function get_percentage_complete() {
[93] Fix | Delete
$percentage = 0;
[94] Fix | Delete
[95] Fix | Delete
$current_count = $this->get_current_count();
[96] Fix | Delete
$total_count = $this->get_total_count();
[97] Fix | Delete
[98] Fix | Delete
if ( $total_count > 0 ) {
[99] Fix | Delete
$percentage = ( $current_count / $total_count ) * 100;
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
if ( $percentage > 100 ) {
[103] Fix | Delete
$percentage = 100;
[104] Fix | Delete
}
[105] Fix | Delete
[106] Fix | Delete
return $percentage;
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
/**
[110] Fix | Delete
* Retrieves a message based on the given message code.
[111] Fix | Delete
*
[112] Fix | Delete
* @param string $code Message code.
[113] Fix | Delete
*
[114] Fix | Delete
* @return string Message.
[115] Fix | Delete
*/
[116] Fix | Delete
public function get_message( $code ) {
[117] Fix | Delete
switch ( $code ) {
[118] Fix | Delete
[119] Fix | Delete
case 'done':
[120] Fix | Delete
$final_count = $this->get_current_count();
[121] Fix | Delete
[122] Fix | Delete
$message = sprintf( _n( '%s item was successfully processed.', '%s items were successfully processed.', $final_count, 'popup-maker' ), number_format_i18n( $final_count ) );
[123] Fix | Delete
break;
[124] Fix | Delete
[125] Fix | Delete
default:
[126] Fix | Delete
$message = '';
[127] Fix | Delete
break;
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
return $message;
[131] Fix | Delete
}
[132] Fix | Delete
[133] Fix | Delete
/**
[134] Fix | Delete
* Defines logic to execute once batch processing is complete.
[135] Fix | Delete
*/
[136] Fix | Delete
public function finish() {
[137] Fix | Delete
PUM_DataStorage::delete_by_match( "^{$this->batch_id}[0-9a-z\_]+" );
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
/**
[141] Fix | Delete
* Calculates and retrieves the offset for the current step.
[142] Fix | Delete
*
[143] Fix | Delete
* @return int Number of items to offset.
[144] Fix | Delete
*/
[145] Fix | Delete
public function get_offset() {
[146] Fix | Delete
return ( $this->step - 1 ) * $this->per_step;
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
/**
[150] Fix | Delete
* Retrieves the current, stored count of processed items.
[151] Fix | Delete
*
[152] Fix | Delete
* @see get_percentage_complete()
[153] Fix | Delete
*
[154] Fix | Delete
* @return int Current number of processed items. Default 0.
[155] Fix | Delete
*/
[156] Fix | Delete
protected function get_current_count() {
[157] Fix | Delete
return PUM_DataStorage::get( "{$this->batch_id}_current_count", 0 );
[158] Fix | Delete
}
[159] Fix | Delete
[160] Fix | Delete
/**
[161] Fix | Delete
* Sets the current count of processed items.
[162] Fix | Delete
*
[163] Fix | Delete
* @param int $count Number of processed items.
[164] Fix | Delete
*/
[165] Fix | Delete
protected function set_current_count( $count ) {
[166] Fix | Delete
PUM_DataStorage::write( "{$this->batch_id}_current_count", $count );
[167] Fix | Delete
}
[168] Fix | Delete
[169] Fix | Delete
/**
[170] Fix | Delete
* Retrieves the total, stored count of items to process.
[171] Fix | Delete
*
[172] Fix | Delete
* @see get_percentage_complete()
[173] Fix | Delete
*
[174] Fix | Delete
* @return int Current number of processed items. Default 0.
[175] Fix | Delete
*/
[176] Fix | Delete
protected function get_total_count() {
[177] Fix | Delete
return PUM_DataStorage::get( "{$this->batch_id}_total_count", 0 );
[178] Fix | Delete
}
[179] Fix | Delete
[180] Fix | Delete
/**
[181] Fix | Delete
* Sets the total count of items to process.
[182] Fix | Delete
*
[183] Fix | Delete
* @param int $count Number of items to process.
[184] Fix | Delete
*/
[185] Fix | Delete
protected function set_total_count( $count ) {
[186] Fix | Delete
PUM_DataStorage::write( "{$this->batch_id}_total_count", $count );
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
/**
[190] Fix | Delete
* Deletes the stored current and total counts of processed items.
[191] Fix | Delete
*/
[192] Fix | Delete
protected function delete_counts() {
[193] Fix | Delete
PUM_DataStorage::delete( "{$this->batch_id}_current_count" );
[194] Fix | Delete
PUM_DataStorage::delete( "{$this->batch_id}_total_count" );
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
}
[198] Fix | Delete
[199] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function