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/Database
File: SubmissionExpirationCron.php
<?php
[0] Fix | Delete
final class NF_Database_SubmissionExpirationCron
[1] Fix | Delete
{
[2] Fix | Delete
[3] Fix | Delete
/**
[4] Fix | Delete
* NF_Database_SubmissionExpirationCron constructor.
[5] Fix | Delete
* Sets up our our submission expiration CRON job.
[6] Fix | Delete
*
[7] Fix | Delete
*/
[8] Fix | Delete
public function __construct()
[9] Fix | Delete
{
[10] Fix | Delete
// Retrieves the option that contains all of our expiration data.
[11] Fix | Delete
$options = get_option( 'nf_sub_expiration', false );
[12] Fix | Delete
[13] Fix | Delete
// Schedules our CRON job.
[14] Fix | Delete
if( ! wp_next_scheduled( 'nf_submission_expiration_cron' ) && ! empty( $options ) ) {
[15] Fix | Delete
wp_schedule_event( time(), 'daily', 'nf_submission_expiration_cron' );
[16] Fix | Delete
}
[17] Fix | Delete
add_action( 'nf_submission_expiration_cron', array( $this, 'expired_submission_cron' ) );
[18] Fix | Delete
}
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* Expired Submission Cron
[22] Fix | Delete
* Checks our subs to see if any are expired and sends them to be
[23] Fix | Delete
* deleted if there are any that need to be removed.
[24] Fix | Delete
*
[25] Fix | Delete
* @param $options
[26] Fix | Delete
* @return void
[27] Fix | Delete
*/
[28] Fix | Delete
public function expired_submission_cron()
[29] Fix | Delete
{
[30] Fix | Delete
$options = get_option( 'nf_sub_expiration', false );
[31] Fix | Delete
[32] Fix | Delete
// If options are empty bail..
[33] Fix | Delete
if( ! $options || ! is_array( $options ) ) return;
[34] Fix | Delete
[35] Fix | Delete
// Loop over our options and ...
[36] Fix | Delete
foreach( $options as $option ) {
[37] Fix | Delete
/*
[38] Fix | Delete
* Separate our $option values into two positions
[39] Fix | Delete
* $option[ 0 ] = ( int ) form_id
[40] Fix | Delete
* $option[ 1 ] = ( int ) expiration time in days.
[41] Fix | Delete
*/
[42] Fix | Delete
$option = explode( ',', $option );
[43] Fix | Delete
[44] Fix | Delete
// Use the helper method to build an array of expired subs.
[45] Fix | Delete
$expired_subs[] = $this->get_expired_subs( $option[ 0 ], $option[ 1 ] );
[46] Fix | Delete
}
[47] Fix | Delete
// If the expired subs array is empty bail.
[48] Fix | Delete
if( empty( $expired_subs ) ) return;
[49] Fix | Delete
// Call the helper method that deletes the expired subs.
[50] Fix | Delete
$this->delete_expired_subs( $expired_subs );
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
/**
[54] Fix | Delete
* Get Expired Subs
[55] Fix | Delete
* Gathers our expired subs puts them into an array and returns it.
[56] Fix | Delete
*
[57] Fix | Delete
* @param $form_id - ( int ) ID of the Form.
[58] Fix | Delete
* @param $expiration_time - ( int ) number of days the submissions
[59] Fix | Delete
* are set to expire in
[60] Fix | Delete
*
[61] Fix | Delete
* @return array of all the expired subs that were found.
[62] Fix | Delete
*/
[63] Fix | Delete
public function get_expired_subs( $form_id, $expiration_time )
[64] Fix | Delete
{
[65] Fix | Delete
// Create the that will house our expired subs.
[66] Fix | Delete
$expired_subs = array();
[67] Fix | Delete
[68] Fix | Delete
// Create our deletion timestamp.
[69] Fix | Delete
$deletion_timestamp = time() - ( 24 * 60 * 60 * $expiration_time );
[70] Fix | Delete
[71] Fix | Delete
// Get our subs and loop over them.
[72] Fix | Delete
$sub = Ninja_Forms()->form( $form_id )->get_subs();
[73] Fix | Delete
foreach( $sub as $sub_model ) {
[74] Fix | Delete
// Get the sub date and change it to a UNIX time stamp.
[75] Fix | Delete
$sub_timestamp = strtotime( $sub_model->get_sub_date( 'Y-m-d') );
[76] Fix | Delete
// Compare our timestamps and any expired subs to the array.
[77] Fix | Delete
if( $sub_timestamp <= $deletion_timestamp ) {
[78] Fix | Delete
$expired_subs[] = $sub_model->get_id();
[79] Fix | Delete
}
[80] Fix | Delete
}
[81] Fix | Delete
return $expired_subs;
[82] Fix | Delete
}
[83] Fix | Delete
[84] Fix | Delete
/**
[85] Fix | Delete
* Delete Expired Subs
[86] Fix | Delete
* Helper method that removes our expired subs.
[87] Fix | Delete
*
[88] Fix | Delete
* @param $expired_subs - array of sub ids that need to be deleted.
[89] Fix | Delete
* @param $cap - The cap of the amount of subs you want deleted at 1 time.
[90] Fix | Delete
*
[91] Fix | Delete
* @return void
[92] Fix | Delete
*/
[93] Fix | Delete
public function delete_expired_subs( $expired_subs )
[94] Fix | Delete
{
[95] Fix | Delete
$i = 0;
[96] Fix | Delete
// Loop over our subs
[97] Fix | Delete
foreach( $expired_subs as $subs ) {
[98] Fix | Delete
foreach( $subs as $sub ) {
[99] Fix | Delete
if( $i >= 100 ) break;
[100] Fix | Delete
wp_trash_post( $sub );
[101] Fix | Delete
$i++;
[102] Fix | Delete
}
[103] Fix | Delete
}
[104] Fix | Delete
}
[105] Fix | Delete
}
[106] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function