Edit File by line
/home/barbar84/www/wp-conte.../plugins/ninja-fo.../includes/Admin/Processe...
File: ExpiredSubmissionCleanup.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
class NF_Admin_Processes_ExpiredSubmissionCleanup extends NF_Abstracts_BatchProcess
[5] Fix | Delete
{
[6] Fix | Delete
protected $_slug = 'expired_submission_cleanup';
[7] Fix | Delete
protected $expired_subs = array();
[8] Fix | Delete
[9] Fix | Delete
/**
[10] Fix | Delete
* Function to run any setup steps necessary to begin processing.
[11] Fix | Delete
*/
[12] Fix | Delete
public function startup()
[13] Fix | Delete
{
[14] Fix | Delete
// Retrieves the option that contains all of our expiration data.
[15] Fix | Delete
$expired_sub_option = get_option( 'nf_sub_expiration', array() );
[16] Fix | Delete
[17] Fix | Delete
// Loop over our options and ...
[18] Fix | Delete
foreach( $expired_sub_option as $sub ) {
[19] Fix | Delete
/*
[20] Fix | Delete
* Separate our $option values into two positions
[21] Fix | Delete
* $option[ 0 ] = ( int ) form_id
[22] Fix | Delete
* $option[ 1 ] = ( int ) expiration time in days.
[23] Fix | Delete
*/
[24] Fix | Delete
$sub = explode( ',', $sub );
[25] Fix | Delete
[26] Fix | Delete
$expired_subs = $this->get_expired_subs( $sub[ 0 ], $sub[ 1 ] );
[27] Fix | Delete
[28] Fix | Delete
// Use the helper method to build an array of expired subs.
[29] Fix | Delete
$this->expired_subs = array_merge( $this->expired_subs, $expired_subs );
[30] Fix | Delete
}
[31] Fix | Delete
}
[32] Fix | Delete
[33] Fix | Delete
/**
[34] Fix | Delete
* Function to run any setup steps necessary to begin processing for steps after the first.
[35] Fix | Delete
*
[36] Fix | Delete
* @since 3.4.0
[37] Fix | Delete
* @return void
[38] Fix | Delete
*/
[39] Fix | Delete
public function restart()
[40] Fix | Delete
{
[41] Fix | Delete
// Get our remaining submissions from record.
[42] Fix | Delete
$this->expired_subs = get_option( 'nf_expired_submissions', array() );
[43] Fix | Delete
}
[44] Fix | Delete
[45] Fix | Delete
/**
[46] Fix | Delete
* Function to loop over the batch.
[47] Fix | Delete
*
[48] Fix | Delete
* @since 3.4.0
[49] Fix | Delete
* @return void
[50] Fix | Delete
*/
[51] Fix | Delete
public function process()
[52] Fix | Delete
{
[53] Fix | Delete
[54] Fix | Delete
// For the first 250 in the array.
[55] Fix | Delete
for( $i = 0; $i < 250; $i++ ){
[56] Fix | Delete
// if we've already finished bail..
[57] Fix | Delete
if( empty( $this->expired_subs ) ) break;
[58] Fix | Delete
[59] Fix | Delete
// Pop off a sub and delete it.
[60] Fix | Delete
$sub = array_pop( $this->expired_subs );
[61] Fix | Delete
wp_trash_post( $sub );
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
// If our subs array isn't empty...
[65] Fix | Delete
if( ! empty( $this->expired_subs ) ) {
[66] Fix | Delete
// Update nf_expired_submissions so that we can use it in our next step.
[67] Fix | Delete
update_option( 'nf_expired_submissions', $this->expired_subs );
[68] Fix | Delete
// End processing and move to the next step.
[69] Fix | Delete
$this->next_step();
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
// If we get here, then we're ready to end batch processing.
[73] Fix | Delete
$this->batch_complete();
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
/**
[77] Fix | Delete
* Function to cleanup any lingering temporary elements of a batch process after completion.
[78] Fix | Delete
*
[79] Fix | Delete
* @since 3.4.0
[80] Fix | Delete
* @return void
[81] Fix | Delete
*/
[82] Fix | Delete
public function cleanup()
[83] Fix | Delete
{
[84] Fix | Delete
delete_option( 'nf_expired_submissions' );
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
/**
[88] Fix | Delete
* Get Steps
[89] Fix | Delete
* Determines the amount of steps needed for the step processors.
[90] Fix | Delete
*
[91] Fix | Delete
* @since 3.4.0
[92] Fix | Delete
* @return int of the number of steps.
[93] Fix | Delete
*/
[94] Fix | Delete
public function get_steps()
[95] Fix | Delete
{
[96] Fix | Delete
// Convent our number from int to float
[97] Fix | Delete
$steps = count( $this->expired_subs );
[98] Fix | Delete
$steps = floatval( $steps );
[99] Fix | Delete
[100] Fix | Delete
// Get the amount of steps and return.
[101] Fix | Delete
$steps = ceil( $steps / 250.0 );
[102] Fix | Delete
return $steps;
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
/**
[106] Fix | Delete
* Get Expired Subs
[107] Fix | Delete
* Gathers our expired subs puts them into an array and returns it.
[108] Fix | Delete
*
[109] Fix | Delete
* @param $form_id - ( int ) ID of the Form.
[110] Fix | Delete
* @param $expiration_time - ( int ) number of days the submissions
[111] Fix | Delete
* are set to expire in
[112] Fix | Delete
*
[113] Fix | Delete
* @return array of all the expired subs that were found.
[114] Fix | Delete
*/
[115] Fix | Delete
public function get_expired_subs( $form_id, $expiration_time )
[116] Fix | Delete
{
[117] Fix | Delete
// Create the that will house our expired subs.
[118] Fix | Delete
$expired_subs = array();
[119] Fix | Delete
[120] Fix | Delete
// Create our deletion timestamp.
[121] Fix | Delete
$deletion_timestamp = time() - ( 24 * 60 * 60 * $expiration_time );
[122] Fix | Delete
[123] Fix | Delete
// Get our subs and loop over them.
[124] Fix | Delete
$sub = Ninja_Forms()->form( $form_id )->get_subs();
[125] Fix | Delete
foreach( $sub as $sub_model ) {
[126] Fix | Delete
// Get the sub date and change it to a UNIX time stamp.
[127] Fix | Delete
$sub_timestamp = strtotime( $sub_model->get_sub_date( 'Y-m-d') );
[128] Fix | Delete
// Compare our timestamps and any expired subs to the array.
[129] Fix | Delete
if( $sub_timestamp <= $deletion_timestamp ) {
[130] Fix | Delete
$expired_subs[] = $sub_model->get_id();
[131] Fix | Delete
}
[132] Fix | Delete
}
[133] Fix | Delete
return $expired_subs;
[134] Fix | Delete
}
[135] Fix | Delete
}
[136] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function