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/AJAX/Controll...
File: DeleteAllData.php
<?php if ( ! defined( 'ABSPATH' ) ) exit;
[0] Fix | Delete
[1] Fix | Delete
class NF_AJAX_Controllers_DeleteAllData extends NF_Abstracts_Controller
[2] Fix | Delete
{
[3] Fix | Delete
public function __construct()
[4] Fix | Delete
{
[5] Fix | Delete
// Ajax call handled in 'delete_all_data' in this file.
[6] Fix | Delete
add_action( 'wp_ajax_nf_delete_all_data', array( $this, 'delete_all_data' ) );
[7] Fix | Delete
}
[8] Fix | Delete
[9] Fix | Delete
public function delete_all_data()
[10] Fix | Delete
{
[11] Fix | Delete
// Does the current user have admin privileges
[12] Fix | Delete
if (!current_user_can(apply_filters('ninja_forms_admin_all_forms_capabilities', 'manage_options'))) {
[13] Fix | Delete
$this->_data['errors'] = esc_html__('Access denied. You must have admin privileges to perform this action.', 'ninja-forms');
[14] Fix | Delete
$this->_respond();
[15] Fix | Delete
}
[16] Fix | Delete
[17] Fix | Delete
// If we don't have a nonce...
[18] Fix | Delete
// OR if the nonce is invalid...
[19] Fix | Delete
if (!isset($_REQUEST['security']) || !wp_verify_nonce($_REQUEST['security'], 'ninja_forms_settings_nonce')) {
[20] Fix | Delete
// Kick the request out now.
[21] Fix | Delete
$this->_data['errors'] = esc_html__('Request forbidden.', 'ninja-forms');
[22] Fix | Delete
$this->_respond();
[23] Fix | Delete
}
[24] Fix | Delete
[25] Fix | Delete
check_ajax_referer( 'ninja_forms_settings_nonce', 'security' );
[26] Fix | Delete
[27] Fix | Delete
global $wpdb;
[28] Fix | Delete
$total_subs_deleted = 0;
[29] Fix | Delete
$post_result = 0;
[30] Fix | Delete
$max_cnt = 500;
[31] Fix | Delete
[32] Fix | Delete
if (!isset($_POST['form']) || empty($_POST['form'])) {
[33] Fix | Delete
$this->_respond();
[34] Fix | Delete
}
[35] Fix | Delete
[36] Fix | Delete
$form_id = absint($_POST[ 'form' ]);
[37] Fix | Delete
// SQL for getting 250 subs at a time
[38] Fix | Delete
$sub_sql = "SELECT id FROM `" . $wpdb->prefix . "posts` AS p
[39] Fix | Delete
LEFT JOIN `" . $wpdb->prefix . "postmeta` AS m ON p.id = m.post_id
[40] Fix | Delete
WHERE p.post_type = 'nf_sub' AND m.meta_key = '_form_id'
[41] Fix | Delete
AND m.meta_value = %s LIMIT " . $max_cnt;
[42] Fix | Delete
[43] Fix | Delete
while ($post_result <= $max_cnt ) {
[44] Fix | Delete
$subs = $wpdb->get_col( $wpdb->prepare( $sub_sql, $form_id ),0 );
[45] Fix | Delete
// if we are out of subs, then stop
[46] Fix | Delete
if( 0 === count( $subs ) ) break;
[47] Fix | Delete
// otherwise, let's delete the postmeta as well
[48] Fix | Delete
$delete_meta_query = "DELETE FROM `" . $wpdb->prefix . "postmeta` WHERE post_id IN ( [IN] )";
[49] Fix | Delete
$delete_meta_query = $this->prepare_in( $delete_meta_query, $subs );
[50] Fix | Delete
$meta_result = $wpdb->query( $delete_meta_query );
[51] Fix | Delete
if ( $meta_result > 0 ) {
[52] Fix | Delete
// now we actually delete the posts(nf_sub)
[53] Fix | Delete
$delete_post_query = "DELETE FROM `" . $wpdb->prefix . "posts` WHERE id IN ( [IN] )";
[54] Fix | Delete
$delete_post_query = $this->prepare_in( $delete_post_query, $subs );
[55] Fix | Delete
$post_result = $wpdb->query( $delete_post_query );
[56] Fix | Delete
$total_subs_deleted = $total_subs_deleted + $post_result;
[57] Fix | Delete
[58] Fix | Delete
}
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
$this->_data[ 'form_id' ] = $form_id;
[62] Fix | Delete
$this->_data[ 'delete_count' ] = $total_subs_deleted;
[63] Fix | Delete
$this->_data[ 'success' ] = true;
[64] Fix | Delete
[65] Fix | Delete
if ( 1 == $_POST[ 'last_form' ] ) {
[66] Fix | Delete
//if we are on the last form, then deactivate and nuke db tables
[67] Fix | Delete
$migrations = new NF_Database_Migrations();
[68] Fix | Delete
$migrations->nuke(TRUE, TRUE);
[69] Fix | Delete
$migrations->nuke_settings(TRUE, TRUE);
[70] Fix | Delete
$migrations->nuke_deprecated(TRUE, TRUE);
[71] Fix | Delete
deactivate_plugins( 'ninja-forms/ninja-forms.php' );
[72] Fix | Delete
$this->_data[ 'plugin_url' ] = admin_url( 'plugins.php' );
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
$this->_respond();
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
private function prepare_in( $sql, $vals ) {
[79] Fix | Delete
global $wpdb;
[80] Fix | Delete
$not_in_count = substr_count( $sql, '[IN]' );
[81] Fix | Delete
if ( $not_in_count > 0 ) {
[82] Fix | Delete
$args = array( str_replace( '[IN]', implode( ', ', array_fill( 0, count( $vals ), '%d' ) ), str_replace( '%', '%%', $sql ) ) );
[83] Fix | Delete
// This will populate ALL the [IN]'s with the $vals, assuming you have more than one [IN] in the sql
[84] Fix | Delete
for ( $i=0; $i < substr_count( $sql, '[IN]' ); $i++ ) {
[85] Fix | Delete
$args = array_merge( $args, $vals );
[86] Fix | Delete
}
[87] Fix | Delete
$sql = call_user_func_array( array( $wpdb, 'prepare' ), array_merge( $args ) );
[88] Fix | Delete
}
[89] Fix | Delete
return $sql;
[90] Fix | Delete
}
[91] Fix | Delete
[92] Fix | Delete
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function