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/wp-conte.../plugins/wp-smush.../app
File: class-ajax.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Smush class for storing all Ajax related functionality: Ajax class
[2] Fix | Delete
*
[3] Fix | Delete
* @package Smush\App
[4] Fix | Delete
* @since 2.9.0
[5] Fix | Delete
*
[6] Fix | Delete
* @copyright (c) 2018, Incsub (http://incsub.com)
[7] Fix | Delete
*/
[8] Fix | Delete
[9] Fix | Delete
namespace Smush\App;
[10] Fix | Delete
[11] Fix | Delete
use Smush\Core\Configs;
[12] Fix | Delete
use Smush\Core\Core;
[13] Fix | Delete
use Smush\Core\Error_Handler;
[14] Fix | Delete
use Smush\Core\Helper;
[15] Fix | Delete
use Smush\Core\Media\Media_Item_Cache;
[16] Fix | Delete
use Smush\Core\Modules\Smush;
[17] Fix | Delete
use Smush\Core\Settings;
[18] Fix | Delete
use WP_Smush;
[19] Fix | Delete
[20] Fix | Delete
if ( ! defined( 'WPINC' ) ) {
[21] Fix | Delete
die;
[22] Fix | Delete
}
[23] Fix | Delete
[24] Fix | Delete
/**
[25] Fix | Delete
* Class Ajax for storing all Ajax related functionality.
[26] Fix | Delete
*
[27] Fix | Delete
* @since 2.9.0
[28] Fix | Delete
*/
[29] Fix | Delete
class Ajax {
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* Settings instance.
[33] Fix | Delete
*
[34] Fix | Delete
* @since 3.3.0
[35] Fix | Delete
* @var Settings
[36] Fix | Delete
*/
[37] Fix | Delete
private $settings;
[38] Fix | Delete
[39] Fix | Delete
/**
[40] Fix | Delete
* Ajax constructor.
[41] Fix | Delete
*/
[42] Fix | Delete
public function __construct() {
[43] Fix | Delete
$this->settings = Settings::get_instance();
[44] Fix | Delete
[45] Fix | Delete
/**
[46] Fix | Delete
* QUICK SETUP
[47] Fix | Delete
*/
[48] Fix | Delete
// Handle skip quick setup action.
[49] Fix | Delete
add_action( 'wp_ajax_skip_smush_setup', array( $this, 'skip_smush_setup' ) );
[50] Fix | Delete
// Ajax request for quick setup.
[51] Fix | Delete
add_action( 'wp_ajax_smush_setup', array( $this, 'smush_setup' ) );
[52] Fix | Delete
[53] Fix | Delete
// Hide tutorials.
[54] Fix | Delete
add_action( 'wp_ajax_smush_hide_tutorials', array( $this, 'hide_tutorials' ) );
[55] Fix | Delete
[56] Fix | Delete
/**
[57] Fix | Delete
* NOTICES
[58] Fix | Delete
*/
[59] Fix | Delete
// Handle the smush pro dismiss features notice ajax.
[60] Fix | Delete
add_action( 'wp_ajax_dismiss_upgrade_notice', array( $this, 'dismiss_upgrade_notice' ) );
[61] Fix | Delete
// Handle the smush pro dismiss features notice ajax.
[62] Fix | Delete
add_action( 'wp_ajax_dismiss_update_info', array( $this, 'dismiss_update_info' ) );
[63] Fix | Delete
// Handle ajax request to dismiss the s3 warning.
[64] Fix | Delete
add_action( 'wp_ajax_dismiss_s3support_alert', array( $this, 'dismiss_s3support_alert' ) );
[65] Fix | Delete
// Hide API message.
[66] Fix | Delete
add_action( 'wp_ajax_hide_api_message', array( $this, 'hide_api_message' ) );
[67] Fix | Delete
add_action( 'wp_ajax_smush_show_warning', array( $this, 'show_warning_ajax' ) );
[68] Fix | Delete
// Detect conflicting plugins.
[69] Fix | Delete
add_action( 'wp_ajax_smush_dismiss_notice', array( $this, 'dismiss_notice' ) );
[70] Fix | Delete
[71] Fix | Delete
/**
[72] Fix | Delete
* SMUSH
[73] Fix | Delete
*/
[74] Fix | Delete
// Handle Smush Single Ajax.
[75] Fix | Delete
add_action( 'wp_ajax_wp_smushit_manual', array( $this, 'smush_manual' ) );
[76] Fix | Delete
// Handle resmush operation.
[77] Fix | Delete
add_action( 'wp_ajax_smush_resmush_image', array( $this, 'resmush_image' ) );
[78] Fix | Delete
// Scan images as per the latest settings.
[79] Fix | Delete
add_action( 'wp_ajax_scan_for_resmush', array( $this, 'scan_images' ) );
[80] Fix | Delete
// Send smush stats.
[81] Fix | Delete
add_action( 'wp_ajax_get_stats', array( $this, 'get_stats' ) );
[82] Fix | Delete
[83] Fix | Delete
/**
[84] Fix | Delete
* BULK SMUSH
[85] Fix | Delete
*/
[86] Fix | Delete
// Ignore image from bulk Smush.
[87] Fix | Delete
add_action( 'wp_ajax_wp_smushit_bulk', array( $this, 'process_smush_request' ) );
[88] Fix | Delete
// Remove from skip list.
[89] Fix | Delete
[90] Fix | Delete
/**
[91] Fix | Delete
* DIRECTORY SMUSH
[92] Fix | Delete
*/
[93] Fix | Delete
// Handle Ajax request for directory smush stats (stats meta box).
[94] Fix | Delete
add_action( 'wp_ajax_get_dir_smush_stats', array( $this, 'get_dir_smush_stats' ) );
[95] Fix | Delete
[96] Fix | Delete
/**
[97] Fix | Delete
* LAZY LOADING
[98] Fix | Delete
*/
[99] Fix | Delete
add_action( 'wp_ajax_smush_toggle_lazy_load', array( $this, 'smush_toggle_lazy_load' ) );
[100] Fix | Delete
add_action( 'wp_ajax_smush_remove_icon', array( $this, 'remove_icon' ) );
[101] Fix | Delete
[102] Fix | Delete
/**
[103] Fix | Delete
* Configs
[104] Fix | Delete
*/
[105] Fix | Delete
add_action( 'wp_ajax_smush_upload_config', array( $this, 'upload_config' ) );
[106] Fix | Delete
add_action( 'wp_ajax_smush_save_config', array( $this, 'save_config' ) );
[107] Fix | Delete
add_action( 'wp_ajax_smush_apply_config', array( $this, 'apply_config' ) );
[108] Fix | Delete
[109] Fix | Delete
/**
[110] Fix | Delete
* SETTINGS
[111] Fix | Delete
*/
[112] Fix | Delete
add_action( 'wp_ajax_recheck_api_status', array( $this, 'recheck_api_status' ) );
[113] Fix | Delete
[114] Fix | Delete
/**
[115] Fix | Delete
* MODALS
[116] Fix | Delete
*/
[117] Fix | Delete
// Hide the new features modal.
[118] Fix | Delete
add_action( 'wp_ajax_hide_new_features', array( $this, 'hide_new_features_modal' ) );
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
/***************************************
[122] Fix | Delete
*
[123] Fix | Delete
* QUICK SETUP
[124] Fix | Delete
*/
[125] Fix | Delete
[126] Fix | Delete
/**
[127] Fix | Delete
* Process ajax action for skipping Smush setup.
[128] Fix | Delete
*/
[129] Fix | Delete
public function skip_smush_setup() {
[130] Fix | Delete
check_ajax_referer( 'smush_quick_setup' );
[131] Fix | Delete
// Check capability.
[132] Fix | Delete
if ( ! Helper::is_user_allowed( 'manage_options' ) ) {
[133] Fix | Delete
wp_die( esc_html__( 'Unauthorized', 'wp-smushit' ), 403 );
[134] Fix | Delete
}
[135] Fix | Delete
update_option( 'skip-smush-setup', true );
[136] Fix | Delete
wp_send_json_success();
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
/**
[140] Fix | Delete
* Ajax action to save settings from quick setup.
[141] Fix | Delete
*/
[142] Fix | Delete
public function smush_setup() {
[143] Fix | Delete
check_ajax_referer( 'smush_quick_setup', '_wpnonce' );
[144] Fix | Delete
[145] Fix | Delete
// Check capability.
[146] Fix | Delete
if ( ! Helper::is_user_allowed( 'manage_options' ) ) {
[147] Fix | Delete
wp_die( esc_html__( 'Unauthorized', 'wp-smushit' ), 403 );
[148] Fix | Delete
}
[149] Fix | Delete
[150] Fix | Delete
$quick_settings = array();
[151] Fix | Delete
// Get the settings from $_POST.
[152] Fix | Delete
if ( ! empty( $_POST['smush_settings'] ) ) {
[153] Fix | Delete
// Required $quick_settings data is escaped later on in code.
[154] Fix | Delete
$quick_settings = json_decode( wp_unslash( $_POST['smush_settings'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
// Check the last settings stored in db.
[158] Fix | Delete
$settings = $this->settings->get();
[159] Fix | Delete
[160] Fix | Delete
// Available settings for free/pro version.
[161] Fix | Delete
$available = array( 'auto', 'lossy', 'strip_exif', 'original', 'lazy_load', 'usage' );
[162] Fix | Delete
$highest_lossy_level = $this->settings->get_highest_lossy_level();
[163] Fix | Delete
[164] Fix | Delete
foreach ( $settings as $name => $values ) {
[165] Fix | Delete
// Update only specified settings.
[166] Fix | Delete
if ( ! in_array( $name, $available, true ) ) {
[167] Fix | Delete
continue;
[168] Fix | Delete
}
[169] Fix | Delete
[170] Fix | Delete
// Skip premium features if not a member.
[171] Fix | Delete
if ( ! in_array( $name, Settings::$basic_features, true ) && 'usage' !== $name && ! WP_Smush::is_pro() ) {
[172] Fix | Delete
continue;
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
// Update value in settings.
[176] Fix | Delete
if ( 'lossy' === $name ) {
[177] Fix | Delete
$settings['lossy'] = ! empty( $quick_settings->{$name} ) ? $highest_lossy_level : Settings::LEVEL_LOSSLESS;
[178] Fix | Delete
} else {
[179] Fix | Delete
$settings[ $name ] = (bool) $quick_settings->{$name};
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
// If Smush originals is selected, enable backups.
[183] Fix | Delete
if ( 'original' === $name && $settings[ $name ] && WP_Smush::is_pro() ) {
[184] Fix | Delete
$settings['backup'] = true;
[185] Fix | Delete
}
[186] Fix | Delete
[187] Fix | Delete
// If lazy load enabled - init defaults.
[188] Fix | Delete
if ( 'lazy_load' === $name && $quick_settings->{$name} ) {
[189] Fix | Delete
$this->settings->init_lazy_load_defaults();
[190] Fix | Delete
}
[191] Fix | Delete
}
[192] Fix | Delete
[193] Fix | Delete
// Update the resize sizes.
[194] Fix | Delete
$this->settings->set_setting( 'wp-smush-settings', $settings );
[195] Fix | Delete
[196] Fix | Delete
update_option( 'skip-smush-setup', true );
[197] Fix | Delete
[198] Fix | Delete
wp_send_json_success();
[199] Fix | Delete
}
[200] Fix | Delete
[201] Fix | Delete
/**
[202] Fix | Delete
* Hide tutorials.
[203] Fix | Delete
*
[204] Fix | Delete
* @sinde 3.8.6
[205] Fix | Delete
*/
[206] Fix | Delete
public function hide_tutorials() {
[207] Fix | Delete
check_ajax_referer( 'wp-smush-ajax' );
[208] Fix | Delete
[209] Fix | Delete
// Check capability.
[210] Fix | Delete
if ( ! Helper::is_user_allowed( 'manage_options' ) ) {
[211] Fix | Delete
wp_die( esc_html__( 'Unauthorized', 'wp-smushit' ), 403 );
[212] Fix | Delete
}
[213] Fix | Delete
[214] Fix | Delete
update_option( 'wp-smush-hide-tutorials', true, false );
[215] Fix | Delete
[216] Fix | Delete
wp_send_json_success();
[217] Fix | Delete
}
[218] Fix | Delete
[219] Fix | Delete
/***************************************
[220] Fix | Delete
*
[221] Fix | Delete
* NOTICES
[222] Fix | Delete
*/
[223] Fix | Delete
[224] Fix | Delete
/**
[225] Fix | Delete
* Store a key/value to hide the smush features on bulk page
[226] Fix | Delete
*
[227] Fix | Delete
* There is no js code related to this action, it seems we are no longer use it, better to clean it?
[228] Fix | Delete
*/
[229] Fix | Delete
public function dismiss_upgrade_notice() {
[230] Fix | Delete
check_ajax_referer( 'wp-smush-ajax' );
[231] Fix | Delete
[232] Fix | Delete
// Check capability.
[233] Fix | Delete
if ( ! Helper::is_user_allowed( 'manage_options' ) ) {
[234] Fix | Delete
wp_die( esc_html__( 'Unauthorized', 'wp-smushit' ), 403 );
[235] Fix | Delete
}
[236] Fix | Delete
update_site_option( 'wp-smush-hide_upgrade_notice', true );
[237] Fix | Delete
// No Need to send json response for other requests.
[238] Fix | Delete
wp_send_json_success();
[239] Fix | Delete
}
[240] Fix | Delete
[241] Fix | Delete
/**
[242] Fix | Delete
* Remove the Update info
[243] Fix | Delete
*
[244] Fix | Delete
* @param bool $remove_notice Remove notice.
[245] Fix | Delete
*/
[246] Fix | Delete
public function dismiss_update_info( $remove_notice = false ) {
[247] Fix | Delete
check_ajax_referer( 'wp-smush-ajax' );
[248] Fix | Delete
[249] Fix | Delete
// Check capability.
[250] Fix | Delete
if ( ! Helper::is_user_allowed( 'manage_options' ) ) {
[251] Fix | Delete
wp_die( esc_html__( 'Unauthorized', 'wp-smushit' ), 403 );
[252] Fix | Delete
}
[253] Fix | Delete
WP_Smush::get_instance()->core()->mod->smush->dismiss_update_info( $remove_notice );
[254] Fix | Delete
}
[255] Fix | Delete
[256] Fix | Delete
/**
[257] Fix | Delete
* Hide S3 support alert by setting a flag.
[258] Fix | Delete
*/
[259] Fix | Delete
public function dismiss_s3support_alert() {
[260] Fix | Delete
check_ajax_referer( 'wp-smush-ajax' );
[261] Fix | Delete
// Check capability.
[262] Fix | Delete
if ( ! Helper::is_user_allowed( 'manage_options' ) ) {
[263] Fix | Delete
wp_die( esc_html__( 'Unauthorized', 'wp-smushit' ), 403 );
[264] Fix | Delete
}
[265] Fix | Delete
// Just set a flag.
[266] Fix | Delete
update_site_option( 'wp-smush-hide_s3support_alert', 1 );
[267] Fix | Delete
wp_send_json_success();
[268] Fix | Delete
}
[269] Fix | Delete
[270] Fix | Delete
/**
[271] Fix | Delete
* Hide API Message
[272] Fix | Delete
*/
[273] Fix | Delete
public function hide_api_message() {
[274] Fix | Delete
check_ajax_referer( 'wp-smush-ajax' );
[275] Fix | Delete
[276] Fix | Delete
// Check capability.
[277] Fix | Delete
if ( ! Helper::is_user_allowed( 'manage_options' ) ) {
[278] Fix | Delete
wp_die( esc_html__( 'Unauthorized', 'wp-smushit' ), 403 );
[279] Fix | Delete
}
[280] Fix | Delete
[281] Fix | Delete
$api_message = get_site_option( 'wp-smush-api_message', array() );
[282] Fix | Delete
if ( ! empty( $api_message ) && is_array( $api_message ) ) {
[283] Fix | Delete
$api_message[ key( $api_message ) ]['status'] = 'hide';
[284] Fix | Delete
update_site_option( 'wp-smush-api_message', $api_message );
[285] Fix | Delete
}
[286] Fix | Delete
[287] Fix | Delete
wp_send_json_success();
[288] Fix | Delete
}
[289] Fix | Delete
[290] Fix | Delete
/**
[291] Fix | Delete
* Send JSON response whether to show or not the warning
[292] Fix | Delete
*/
[293] Fix | Delete
public function show_warning_ajax() {
[294] Fix | Delete
check_ajax_referer( 'wp-smush-ajax' );
[295] Fix | Delete
// Check capability.
[296] Fix | Delete
if ( ! Helper::is_user_allowed( 'manage_options' ) ) {
[297] Fix | Delete
wp_die( esc_html__( 'Unauthorized', 'wp-smushit' ), 403 );
[298] Fix | Delete
}
[299] Fix | Delete
$show = WP_Smush::get_instance()->core()->mod->smush->show_warning();
[300] Fix | Delete
wp_send_json( (int) $show );
[301] Fix | Delete
}
[302] Fix | Delete
[303] Fix | Delete
/**
[304] Fix | Delete
* Dismiss the plugin conflicts notice.
[305] Fix | Delete
*
[306] Fix | Delete
* @since 3.6.0
[307] Fix | Delete
*/
[308] Fix | Delete
public function dismiss_notice() {
[309] Fix | Delete
check_ajax_referer( 'wp-smush-ajax' );
[310] Fix | Delete
[311] Fix | Delete
// Check capability.
[312] Fix | Delete
if ( ! Helper::is_user_allowed( 'manage_options' ) ) {
[313] Fix | Delete
wp_die( esc_html__( 'Unauthorized', 'wp-smushit' ), 403 );
[314] Fix | Delete
}
[315] Fix | Delete
[316] Fix | Delete
if ( empty( $_REQUEST['key'] ) ) {
[317] Fix | Delete
wp_send_json_error();
[318] Fix | Delete
}
[319] Fix | Delete
[320] Fix | Delete
$this->set_notice_dismissed( sanitize_key( $_REQUEST['key'] ) );
[321] Fix | Delete
wp_send_json_success();
[322] Fix | Delete
}
[323] Fix | Delete
[324] Fix | Delete
private function set_notice_dismissed( $notice ) {
[325] Fix | Delete
$option_id = 'wp-smush-dismissed-notices';
[326] Fix | Delete
$dismissed_notices = get_option( $option_id, array() );
[327] Fix | Delete
$dismissed_notices[ $notice ] = true;
[328] Fix | Delete
update_option( $option_id, $dismissed_notices );
[329] Fix | Delete
}
[330] Fix | Delete
[331] Fix | Delete
/***************************************
[332] Fix | Delete
*
[333] Fix | Delete
* SMUSH
[334] Fix | Delete
*/
[335] Fix | Delete
[336] Fix | Delete
/**
[337] Fix | Delete
* Handle the Ajax request for smushing single image
[338] Fix | Delete
*
[339] Fix | Delete
* @uses smush_single()
[340] Fix | Delete
*/
[341] Fix | Delete
public function smush_manual() {
[342] Fix | Delete
if ( ! check_ajax_referer( 'wp-smush-ajax', '_nonce', false ) ) {
[343] Fix | Delete
wp_send_json_error(
[344] Fix | Delete
array(
[345] Fix | Delete
'error_msg' => esc_html__( 'Nonce verification failed', 'wp-smushit' ),
[346] Fix | Delete
)
[347] Fix | Delete
);
[348] Fix | Delete
}
[349] Fix | Delete
[350] Fix | Delete
if ( ! Helper::is_user_allowed( 'upload_files' ) ) {
[351] Fix | Delete
wp_send_json_error(
[352] Fix | Delete
array(
[353] Fix | Delete
'error_msg' => esc_html__( "You don't have permission to work with uploaded files.", 'wp-smushit' ),
[354] Fix | Delete
)
[355] Fix | Delete
);
[356] Fix | Delete
}
[357] Fix | Delete
[358] Fix | Delete
if ( ! isset( $_GET['attachment_id'] ) ) {
[359] Fix | Delete
wp_send_json_error(
[360] Fix | Delete
array(
[361] Fix | Delete
'error_msg' => esc_html__( 'No attachment ID was provided.', 'wp-smushit' ),
[362] Fix | Delete
)
[363] Fix | Delete
);
[364] Fix | Delete
}
[365] Fix | Delete
[366] Fix | Delete
$attachment_id = (int) $_GET['attachment_id'];
[367] Fix | Delete
[368] Fix | Delete
// Pass on the attachment id to smush single function.
[369] Fix | Delete
WP_Smush::get_instance()->core()->mod->smush->smush_single( $attachment_id );
[370] Fix | Delete
}
[371] Fix | Delete
[372] Fix | Delete
/**
[373] Fix | Delete
* Resmush the image
[374] Fix | Delete
*
[375] Fix | Delete
* @uses smush_single()
[376] Fix | Delete
*/
[377] Fix | Delete
public function resmush_image() {
[378] Fix | Delete
// Check empty fields.
[379] Fix | Delete
if ( empty( $_POST['attachment_id'] ) || empty( $_POST['_nonce'] ) ) {
[380] Fix | Delete
wp_send_json_error(
[381] Fix | Delete
array(
[382] Fix | Delete
'error_msg' => esc_html__( 'Image not smushed, fields empty.', 'wp-smushit' ),
[383] Fix | Delete
)
[384] Fix | Delete
);
[385] Fix | Delete
}
[386] Fix | Delete
[387] Fix | Delete
// Check nonce.
[388] Fix | Delete
if ( ! wp_verify_nonce( wp_unslash( $_POST['_nonce'] ), 'wp-smush-resmush-' . (int) $_POST['attachment_id'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
[389] Fix | Delete
wp_send_json_error(
[390] Fix | Delete
array(
[391] Fix | Delete
'error_msg' => esc_html__( "Image couldn't be smushed as the nonce verification failed, try reloading the page.", 'wp-smushit' ),
[392] Fix | Delete
)
[393] Fix | Delete
);
[394] Fix | Delete
}
[395] Fix | Delete
[396] Fix | Delete
if ( ! Helper::is_user_allowed( 'upload_files' ) ) {
[397] Fix | Delete
wp_send_json_error(
[398] Fix | Delete
array(
[399] Fix | Delete
'error_msg' => esc_html__( "You don't have permission to work with uploaded files.", 'wp-smushit' ),
[400] Fix | Delete
)
[401] Fix | Delete
);
[402] Fix | Delete
}
[403] Fix | Delete
[404] Fix | Delete
$image_id = (int) $_POST['attachment_id'];
[405] Fix | Delete
[406] Fix | Delete
WP_Smush::get_instance()->core()->mod->smush->smush_single( $image_id );
[407] Fix | Delete
}
[408] Fix | Delete
[409] Fix | Delete
/**
[410] Fix | Delete
* Scans all the smushed attachments to check if they need to be resmushed as per the
[411] Fix | Delete
* current settings, as user might have changed one of the configurations "Lossy", "Keep Original", "Preserve Exif"
[412] Fix | Delete
*
[413] Fix | Delete
* @todo: Needs some refactoring big time
[414] Fix | Delete
*/
[415] Fix | Delete
public function scan_images() {
[416] Fix | Delete
check_ajax_referer( 'save_wp_smush_options', 'wp_smush_options_nonce' );
[417] Fix | Delete
[418] Fix | Delete
// Check capability.
[419] Fix | Delete
if ( ! Helper::is_user_allowed( 'manage_options' ) ) {
[420] Fix | Delete
wp_send_json_error(
[421] Fix | Delete
array(
[422] Fix | Delete
'notice' => esc_html__( "You don't have permission to do this.", 'wp-smushit' ),
[423] Fix | Delete
'noticeType' => 'error',
[424] Fix | Delete
)
[425] Fix | Delete
);
[426] Fix | Delete
}
[427] Fix | Delete
[428] Fix | Delete
// Scanning for NextGen or Media Library.
[429] Fix | Delete
$type = isset( $_REQUEST['type'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['type'] ) ) : '';
[430] Fix | Delete
[431] Fix | Delete
/**
[432] Fix | Delete
* @hooked wp_smush_nextgen_scan_stats Smush\Core\Integrations\NextGen\Admin::scan_images()
[433] Fix | Delete
*/
[434] Fix | Delete
$stats = apply_filters( "wp_smush_{$type}_scan_stats", array() );
[435] Fix | Delete
[436] Fix | Delete
return wp_send_json_success( $stats );
[437] Fix | Delete
}
[438] Fix | Delete
[439] Fix | Delete
/**
[440] Fix | Delete
* Return Latest stats.
[441] Fix | Delete
*/
[442] Fix | Delete
public function get_stats() {
[443] Fix | Delete
check_ajax_referer( 'wp-smush-ajax', '_nonce' );
[444] Fix | Delete
[445] Fix | Delete
// Check capability.
[446] Fix | Delete
if ( ! Helper::is_user_allowed( 'manage_options' ) ) {
[447] Fix | Delete
wp_die( esc_html__( 'Unauthorized', 'wp-smushit' ), 403 );
[448] Fix | Delete
}
[449] Fix | Delete
[450] Fix | Delete
$admin = WP_Smush::get_instance()->admin();
[451] Fix | Delete
$stats = $admin->get_global_stats_with_bulk_smush_content();
[452] Fix | Delete
[453] Fix | Delete
wp_send_json_success( $stats );
[454] Fix | Delete
}
[455] Fix | Delete
[456] Fix | Delete
/***************************************
[457] Fix | Delete
*
[458] Fix | Delete
* BULK SMUSH
[459] Fix | Delete
*/
[460] Fix | Delete
[461] Fix | Delete
/**
[462] Fix | Delete
* Bulk Smushing Handler.
[463] Fix | Delete
*
[464] Fix | Delete
* Processes the Smush request and sends back the next id for smushing.
[465] Fix | Delete
*/
[466] Fix | Delete
public function process_smush_request() {
[467] Fix | Delete
check_ajax_referer( 'wp-smush-ajax', '_nonce' );
[468] Fix | Delete
[469] Fix | Delete
// Check capability.
[470] Fix | Delete
if ( ! Helper::is_user_allowed( 'manage_options' ) ) {
[471] Fix | Delete
wp_send_json_error(
[472] Fix | Delete
array(
[473] Fix | Delete
'error' => 'unauthorized',
[474] Fix | Delete
'error_message' => esc_html__( "You don't have permission to do this.", 'wp-smushit' ),
[475] Fix | Delete
),
[476] Fix | Delete
403
[477] Fix | Delete
);
[478] Fix | Delete
}
[479] Fix | Delete
[480] Fix | Delete
$new_bulk_smush = ! empty( $_REQUEST['new_bulk_smush_started'] ) && $_REQUEST['new_bulk_smush_started'] !== 'false';
[481] Fix | Delete
if ( $new_bulk_smush ) {
[482] Fix | Delete
do_action( 'wp_smush_bulk_smush_start' );
[483] Fix | Delete
}
[484] Fix | Delete
[485] Fix | Delete
// If the bulk smush needs to be stopped.
[486] Fix | Delete
if ( ! WP_Smush::is_pro() && ! Core::check_bulk_limit() ) {
[487] Fix | Delete
wp_send_json_error(
[488] Fix | Delete
array(
[489] Fix | Delete
'error' => 'limit_exceeded',
[490] Fix | Delete
'continue' => false,
[491] Fix | Delete
)
[492] Fix | Delete
);
[493] Fix | Delete
}
[494] Fix | Delete
[495] Fix | Delete
$attachment_id = 0;
[496] Fix | Delete
if ( ! empty( $_REQUEST['attachment_id'] ) ) {
[497] Fix | Delete
$attachment_id = (int) $_REQUEST['attachment_id'];
[498] Fix | Delete
}
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function