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.../core
File: class-stats.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Class that is responsible for all stats calculations.
[2] Fix | Delete
*
[3] Fix | Delete
* @since 3.4.0
[4] Fix | Delete
* @package Smush\Core
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
namespace Smush\Core;
[8] Fix | Delete
[9] Fix | Delete
use Smush\Core\Media\Media_Item;
[10] Fix | Delete
use Smush\Core\Media\Media_Item_Query;
[11] Fix | Delete
use Smush\Core\Png2Jpg\Png2Jpg_Optimization;
[12] Fix | Delete
use Smush\Core\Resize\Resize_Optimization;
[13] Fix | Delete
use Smush\Core\Smush\Smush_Optimization;
[14] Fix | Delete
use Smush\Core\Smush\Smush_Optimization_Global_Stats;
[15] Fix | Delete
use Smush\Core\Stats\Global_Stats;
[16] Fix | Delete
use stdClass;
[17] Fix | Delete
use WP_Query;
[18] Fix | Delete
[19] Fix | Delete
if ( ! defined( 'WPINC' ) ) {
[20] Fix | Delete
die;
[21] Fix | Delete
}
[22] Fix | Delete
[23] Fix | Delete
/**
[24] Fix | Delete
* Class Stats
[25] Fix | Delete
*/
[26] Fix | Delete
class Stats {
[27] Fix | Delete
[28] Fix | Delete
/**
[29] Fix | Delete
* Stores the stats for all the images.
[30] Fix | Delete
*
[31] Fix | Delete
* @var array $stats
[32] Fix | Delete
*/
[33] Fix | Delete
public $stats;
[34] Fix | Delete
[35] Fix | Delete
/**
[36] Fix | Delete
* Compressed attachments from selected directories.
[37] Fix | Delete
*
[38] Fix | Delete
* @var array $dir_stats
[39] Fix | Delete
*/
[40] Fix | Delete
public $dir_stats;
[41] Fix | Delete
[42] Fix | Delete
/**
[43] Fix | Delete
* Set a limit of MySQL query. Default: 3000.
[44] Fix | Delete
*
[45] Fix | Delete
* @var int $query_limit
[46] Fix | Delete
*/
[47] Fix | Delete
private $query_limit;
[48] Fix | Delete
[49] Fix | Delete
/**
[50] Fix | Delete
* Set a limit to max number of rows in MySQL query. Default: 5000.
[51] Fix | Delete
*
[52] Fix | Delete
* @var int $max_rows
[53] Fix | Delete
*/
[54] Fix | Delete
private $max_rows;
[55] Fix | Delete
[56] Fix | Delete
/**
[57] Fix | Delete
* Attachment IDs.
[58] Fix | Delete
*
[59] Fix | Delete
* @var array $attachments
[60] Fix | Delete
*/
[61] Fix | Delete
public $attachments = array();
[62] Fix | Delete
[63] Fix | Delete
/**
[64] Fix | Delete
* Image ids that needs to be resmushed.
[65] Fix | Delete
*
[66] Fix | Delete
* @var array $resmush_ids
[67] Fix | Delete
*/
[68] Fix | Delete
public $resmush_ids = array();
[69] Fix | Delete
[70] Fix | Delete
/**
[71] Fix | Delete
* Percentage of the smushed images.
[72] Fix | Delete
*
[73] Fix | Delete
* @var float
[74] Fix | Delete
*/
[75] Fix | Delete
public $percent_optimized;
[76] Fix | Delete
[77] Fix | Delete
/**
[78] Fix | Delete
* Percentage metric.
[79] Fix | Delete
*
[80] Fix | Delete
* @var float
[81] Fix | Delete
*/
[82] Fix | Delete
public $percent_metric;
[83] Fix | Delete
[84] Fix | Delete
/**
[85] Fix | Delete
* Class name of grade type.
[86] Fix | Delete
*
[87] Fix | Delete
* @var string
[88] Fix | Delete
*/
[89] Fix | Delete
public $percent_grade;
[90] Fix | Delete
[91] Fix | Delete
/**
[92] Fix | Delete
* Protected init class, used in child methods instead of constructor.
[93] Fix | Delete
*
[94] Fix | Delete
* @since 3.4.0
[95] Fix | Delete
*/
[96] Fix | Delete
protected function init() {}
[97] Fix | Delete
[98] Fix | Delete
/**
[99] Fix | Delete
* Stats constructor.
[100] Fix | Delete
*/
[101] Fix | Delete
public function __construct() {
[102] Fix | Delete
$this->init();
[103] Fix | Delete
[104] Fix | Delete
$this->query_limit = apply_filters( 'wp_smush_query_limit', 3000 );
[105] Fix | Delete
$this->max_rows = apply_filters( 'wp_smush_max_rows', 5000 );
[106] Fix | Delete
[107] Fix | Delete
// Recalculate resize savings.
[108] Fix | Delete
add_action(
[109] Fix | Delete
'wp_smush_image_resized',
[110] Fix | Delete
function() {
[111] Fix | Delete
return $this->get_savings( 'resize' );
[112] Fix | Delete
}
[113] Fix | Delete
);
[114] Fix | Delete
[115] Fix | Delete
// Update Conversion savings.
[116] Fix | Delete
add_action(
[117] Fix | Delete
'wp_smush_png_jpg_converted',
[118] Fix | Delete
function() {
[119] Fix | Delete
return $this->get_savings( 'pngjpg' );
[120] Fix | Delete
}
[121] Fix | Delete
);
[122] Fix | Delete
[123] Fix | Delete
// Update the media_attachments list.
[124] Fix | Delete
add_action( 'add_attachment', array( $this, 'add_to_media_attachments_list' ) );
[125] Fix | Delete
add_action( 'delete_attachment', array( $this, 'update_lists' ), 12 );
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
/**
[129] Fix | Delete
* Runs the expensive queries to get our global smush stats
[130] Fix | Delete
*
[131] Fix | Delete
* @param bool $force_update Whether to force update the global stats or not.
[132] Fix | Delete
*/
[133] Fix | Delete
public function setup_global_stats( $force_update = false ) {
[134] Fix | Delete
if ( ! $this->mod->dir ) {
[135] Fix | Delete
$this->mod->dir = new Modules\Dir();
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
// Set directory smush status.
[139] Fix | Delete
$this->dir_stats = Modules\Dir::should_continue() ? $this->mod->dir->total_stats() : array();
[140] Fix | Delete
[141] Fix | Delete
// Set Attachment IDs, and total count.
[142] Fix | Delete
$this->attachments = $this->get_media_attachments();
[143] Fix | Delete
[144] Fix | Delete
// Set total count.
[145] Fix | Delete
$this->total_count = ! empty( $this->attachments ) && is_array( $this->attachments ) ? count( $this->attachments ) : 0;
[146] Fix | Delete
[147] Fix | Delete
$this->stats = $this->global_stats( $force_update );
[148] Fix | Delete
[149] Fix | Delete
if ( empty( $this->smushed_attachments ) ) {
[150] Fix | Delete
// Get smushed attachments.
[151] Fix | Delete
$this->smushed_attachments = $this->get_smushed_attachments( $force_update );
[152] Fix | Delete
}
[153] Fix | Delete
[154] Fix | Delete
// Get super smushed images count.
[155] Fix | Delete
if ( ! $this->super_smushed ) {
[156] Fix | Delete
$this->super_smushed = count( $this->get_super_smushed_attachments() );
[157] Fix | Delete
}
[158] Fix | Delete
[159] Fix | Delete
// Get skipped attachments.
[160] Fix | Delete
$this->skipped_attachments = $this->skipped_count( $force_update );
[161] Fix | Delete
$this->skipped_count = count( $this->skipped_attachments );
[162] Fix | Delete
[163] Fix | Delete
// Set smushed count.
[164] Fix | Delete
$this->smushed_count = ! empty( $this->smushed_attachments ) ? count( $this->smushed_attachments ) : 0;
[165] Fix | Delete
$this->remaining_count = $this->remaining_count();
[166] Fix | Delete
[167] Fix | Delete
list( $percent_optimized, $percent_metric, $grade ) = $this->get_grade_data(
[168] Fix | Delete
$this->remaining_count,
[169] Fix | Delete
$this->total_count,
[170] Fix | Delete
$this->skipped_count
[171] Fix | Delete
);
[172] Fix | Delete
$this->percent_grade = $grade;
[173] Fix | Delete
$this->percent_metric = $percent_metric;
[174] Fix | Delete
$this->percent_optimized = $percent_optimized;
[175] Fix | Delete
}
[176] Fix | Delete
[177] Fix | Delete
/**
[178] Fix | Delete
* Get the savings from image resizing or PNG -> JPG conversion savings.
[179] Fix | Delete
*
[180] Fix | Delete
* @param string $type Savings type. Accepts: resize, pngjpg.
[181] Fix | Delete
* @param bool $force_update Force update to re-calculate all stats. Default: false.
[182] Fix | Delete
* @param bool $format Format the bytes in readable format. Default: false.
[183] Fix | Delete
* @param bool $return_count Return the resized image count. Default: false.
[184] Fix | Delete
*
[185] Fix | Delete
* @return int|array
[186] Fix | Delete
*/
[187] Fix | Delete
public function get_savings( $type, $force_update = true, $format = false, $return_count = false ) {
[188] Fix | Delete
$key = 'wp-smush-' . $type . '_savings';
[189] Fix | Delete
$key_count = 'wp-smush-resize_count';
[190] Fix | Delete
[191] Fix | Delete
if ( ! $force_update ) {
[192] Fix | Delete
$savings = wp_cache_get( $key, 'wp-smush' );
[193] Fix | Delete
if ( ! $return_count && $savings ) {
[194] Fix | Delete
return $savings;
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
$count = wp_cache_get( $key_count, 'wp-smush' );
[198] Fix | Delete
if ( $return_count && false !== $count ) {
[199] Fix | Delete
return $count;
[200] Fix | Delete
}
[201] Fix | Delete
}
[202] Fix | Delete
[203] Fix | Delete
// If savings or resize image count is not stored in db, recalculate.
[204] Fix | Delete
$count = 0;
[205] Fix | Delete
$offset = 0;
[206] Fix | Delete
$query_next = true;
[207] Fix | Delete
[208] Fix | Delete
$savings = array(
[209] Fix | Delete
'resize' => array(
[210] Fix | Delete
'bytes' => 0,
[211] Fix | Delete
'size_before' => 0,
[212] Fix | Delete
'size_after' => 0,
[213] Fix | Delete
),
[214] Fix | Delete
'pngjpg' => array(
[215] Fix | Delete
'bytes' => 0,
[216] Fix | Delete
'size_before' => 0,
[217] Fix | Delete
'size_after' => 0,
[218] Fix | Delete
),
[219] Fix | Delete
);
[220] Fix | Delete
[221] Fix | Delete
global $wpdb;
[222] Fix | Delete
[223] Fix | Delete
while ( $query_next ) {
[224] Fix | Delete
$query_data = $wpdb->get_results(
[225] Fix | Delete
$wpdb->prepare(
[226] Fix | Delete
"SELECT post_id, meta_value FROM {$wpdb->postmeta} WHERE meta_key=%s LIMIT %d, %d",
[227] Fix | Delete
$key,
[228] Fix | Delete
$offset,
[229] Fix | Delete
$this->query_limit
[230] Fix | Delete
)
[231] Fix | Delete
); // Db call ok.
[232] Fix | Delete
[233] Fix | Delete
// No results - break out of loop.
[234] Fix | Delete
if ( empty( $query_data ) ) {
[235] Fix | Delete
break;
[236] Fix | Delete
}
[237] Fix | Delete
[238] Fix | Delete
foreach ( $query_data as $data ) {
[239] Fix | Delete
// Skip resmush IDs.
[240] Fix | Delete
if ( ! empty( $this->resmush_ids ) && in_array( $data->post_id, $this->resmush_ids, true ) ) {
[241] Fix | Delete
continue;
[242] Fix | Delete
}
[243] Fix | Delete
[244] Fix | Delete
$count++;
[245] Fix | Delete
[246] Fix | Delete
if ( empty( $data ) ) {
[247] Fix | Delete
continue;
[248] Fix | Delete
}
[249] Fix | Delete
[250] Fix | Delete
$meta = maybe_unserialize( $data->meta_value );
[251] Fix | Delete
[252] Fix | Delete
// Resize mete already contains all the stats.
[253] Fix | Delete
if ( ! empty( $meta ) && ! empty( $meta['bytes'] ) ) {
[254] Fix | Delete
$savings['resize']['bytes'] += $meta['bytes'];
[255] Fix | Delete
$savings['resize']['size_before'] += $meta['size_before'];
[256] Fix | Delete
$savings['resize']['size_after'] += $meta['size_after'];
[257] Fix | Delete
}
[258] Fix | Delete
[259] Fix | Delete
// PNG - JPG conversion meta contains stats by attachment size.
[260] Fix | Delete
if ( is_array( $meta ) ) {
[261] Fix | Delete
foreach ( $meta as $size ) {
[262] Fix | Delete
$savings['pngjpg']['bytes'] += isset( $size['bytes'] ) ? $size['bytes'] : 0;
[263] Fix | Delete
$savings['pngjpg']['size_before'] += isset( $size['size_before'] ) ? $size['size_before'] : 0;
[264] Fix | Delete
$savings['pngjpg']['size_after'] += isset( $size['size_after'] ) ? $size['size_after'] : 0;
[265] Fix | Delete
}
[266] Fix | Delete
}
[267] Fix | Delete
}
[268] Fix | Delete
[269] Fix | Delete
// Update the offset.
[270] Fix | Delete
$offset += $this->query_limit;
[271] Fix | Delete
[272] Fix | Delete
// Compare the offset value to total images.
[273] Fix | Delete
$query_next = $this->total_count > $offset;
[274] Fix | Delete
}
[275] Fix | Delete
[276] Fix | Delete
if ( $format ) {
[277] Fix | Delete
$savings[ $type ]['bytes'] = size_format( $savings[ $type ]['bytes'], 1 );
[278] Fix | Delete
}
[279] Fix | Delete
[280] Fix | Delete
wp_cache_set( 'wp-smush-resize_savings', $savings['resize'], 'wp-smush' );
[281] Fix | Delete
wp_cache_set( 'wp-smush-pngjpg_savings', $savings['pngjpg'], 'wp-smush' );
[282] Fix | Delete
wp_cache_set( $key_count, $count, 'wp-smush' );
[283] Fix | Delete
[284] Fix | Delete
return $return_count ? $count : $savings[ $type ];
[285] Fix | Delete
}
[286] Fix | Delete
[287] Fix | Delete
/**
[288] Fix | Delete
* Get the media attachment IDs.
[289] Fix | Delete
*
[290] Fix | Delete
* @param bool $force_update Force update.
[291] Fix | Delete
*
[292] Fix | Delete
* @return array
[293] Fix | Delete
*/
[294] Fix | Delete
public function get_media_attachments( $force_update = false ) {
[295] Fix | Delete
// Return results from cache.
[296] Fix | Delete
if ( ! $force_update ) {
[297] Fix | Delete
$posts = wp_cache_get( 'media_attachments', 'wp-smush' );
[298] Fix | Delete
if ( $posts ) {
[299] Fix | Delete
return $posts;
[300] Fix | Delete
}
[301] Fix | Delete
}
[302] Fix | Delete
[303] Fix | Delete
// Remove the Filters added by WP Media Folder.
[304] Fix | Delete
do_action( 'wp_smush_remove_filters' );
[305] Fix | Delete
[306] Fix | Delete
global $wpdb;
[307] Fix | Delete
[308] Fix | Delete
$posts = $wpdb->get_col(
[309] Fix | Delete
$wpdb->prepare(
[310] Fix | Delete
sprintf(
[311] Fix | Delete
'SELECT ID FROM `%s` WHERE post_type = "attachment" AND post_mime_type IN (%s)',
[312] Fix | Delete
$wpdb->posts,
[313] Fix | Delete
implode( ',', array_fill( 0, count( Core::$mime_types ), '%s' ) )
[314] Fix | Delete
),
[315] Fix | Delete
Core::$mime_types
[316] Fix | Delete
)
[317] Fix | Delete
); // Db call ok.
[318] Fix | Delete
[319] Fix | Delete
// Add the attachments to cache.
[320] Fix | Delete
wp_cache_set( 'media_attachments', $posts, 'wp-smush' );
[321] Fix | Delete
[322] Fix | Delete
return $posts;
[323] Fix | Delete
}
[324] Fix | Delete
[325] Fix | Delete
/**
[326] Fix | Delete
* Adds the ID of the smushed image to the media_attachments list.
[327] Fix | Delete
*
[328] Fix | Delete
* @since 3.7.1
[329] Fix | Delete
*
[330] Fix | Delete
* @param int $id Attachment's ID.
[331] Fix | Delete
*/
[332] Fix | Delete
public function add_to_media_attachments_list( $id ) {
[333] Fix | Delete
$posts = wp_cache_get( 'media_attachments', 'wp-smush' );
[334] Fix | Delete
[335] Fix | Delete
// Return if there's no list to update.
[336] Fix | Delete
if ( ! $posts ) {
[337] Fix | Delete
return;
[338] Fix | Delete
}
[339] Fix | Delete
[340] Fix | Delete
$mime_type = get_post_mime_type( $id );
[341] Fix | Delete
$id_string = (string) $id;
[342] Fix | Delete
[343] Fix | Delete
// Add the ID if the mime type is allowed and the ID isn't in the list already.
[344] Fix | Delete
if ( $mime_type && in_array( $mime_type, Core::$mime_types, true ) && ! in_array( $id_string, $posts, true ) ) {
[345] Fix | Delete
$posts[] = $id_string;
[346] Fix | Delete
wp_cache_set( 'media_attachments', $posts, 'wp-smush' );
[347] Fix | Delete
}
[348] Fix | Delete
}
[349] Fix | Delete
[350] Fix | Delete
/**
[351] Fix | Delete
* Updates the IDs lists when an attachment is deleted.
[352] Fix | Delete
*
[353] Fix | Delete
* @since 3.7.2
[354] Fix | Delete
*
[355] Fix | Delete
* @param integer $id Deleted attachment ID.
[356] Fix | Delete
*/
[357] Fix | Delete
public function update_lists( $id ) {
[358] Fix | Delete
$this->remove_from_media_attachments_list( $id );
[359] Fix | Delete
self::remove_from_smushed_list( $id );
[360] Fix | Delete
}
[361] Fix | Delete
[362] Fix | Delete
/**
[363] Fix | Delete
* Removes the ID of the deleted image from the media_attachments list.
[364] Fix | Delete
*
[365] Fix | Delete
* @since 3.7.1
[366] Fix | Delete
*
[367] Fix | Delete
* @param int $id Attachment's ID.
[368] Fix | Delete
*/
[369] Fix | Delete
private function remove_from_media_attachments_list( $id ) {
[370] Fix | Delete
$posts = wp_cache_get( 'media_attachments', 'wp-smush' );
[371] Fix | Delete
[372] Fix | Delete
// Return if there's no list to update.
[373] Fix | Delete
if ( ! $posts ) {
[374] Fix | Delete
return;
[375] Fix | Delete
}
[376] Fix | Delete
[377] Fix | Delete
$index = array_search( (string) $id, $posts, true );
[378] Fix | Delete
if ( false !== $index ) {
[379] Fix | Delete
unset( $posts[ $index ] );
[380] Fix | Delete
wp_cache_set( 'media_attachments', $posts, 'wp-smush' );
[381] Fix | Delete
}
[382] Fix | Delete
}
[383] Fix | Delete
[384] Fix | Delete
/**
[385] Fix | Delete
* Optimised image IDs.
[386] Fix | Delete
*
[387] Fix | Delete
* @param bool $force_update Force update.
[388] Fix | Delete
*
[389] Fix | Delete
* @return array
[390] Fix | Delete
*/
[391] Fix | Delete
public function get_smushed_attachments( $force_update = false ) {
[392] Fix | Delete
// Remove the Filters added by WP Media Folder.
[393] Fix | Delete
do_action( 'wp_smush_remove_filters' );
[394] Fix | Delete
[395] Fix | Delete
global $wpdb;
[396] Fix | Delete
[397] Fix | Delete
$posts = $wpdb->get_col(
[398] Fix | Delete
$wpdb->prepare(
[399] Fix | Delete
"SELECT DISTINCT post_id FROM {$wpdb->postmeta} WHERE meta_key=%s",
[400] Fix | Delete
Modules\Smush::$smushed_meta_key
[401] Fix | Delete
)
[402] Fix | Delete
);
[403] Fix | Delete
[404] Fix | Delete
return $posts;
[405] Fix | Delete
}
[406] Fix | Delete
[407] Fix | Delete
/**
[408] Fix | Delete
* Adds an ID to the smushed IDs list from the object cache.
[409] Fix | Delete
*
[410] Fix | Delete
* @since 3.7.2
[411] Fix | Delete
*
[412] Fix | Delete
* @param integer $attachment_id ID of the smushed attachment.
[413] Fix | Delete
*/
[414] Fix | Delete
public static function add_to_smushed_list( $attachment_id ) {
[415] Fix | Delete
$smushed_ids = wp_cache_get( 'wp-smush-smushed_ids', 'wp-smush' );
[416] Fix | Delete
[417] Fix | Delete
if ( ! empty( $smushed_ids ) ) {
[418] Fix | Delete
$attachment_id = strval( $attachment_id );
[419] Fix | Delete
[420] Fix | Delete
if ( ! in_array( $attachment_id, $smushed_ids, true ) ) {
[421] Fix | Delete
$smushed_ids[] = $attachment_id;
[422] Fix | Delete
[423] Fix | Delete
// Set in cache.
[424] Fix | Delete
wp_cache_set( 'wp-smush-smushed_ids', $smushed_ids, 'wp-smush' );
[425] Fix | Delete
}
[426] Fix | Delete
}
[427] Fix | Delete
}
[428] Fix | Delete
[429] Fix | Delete
/**
[430] Fix | Delete
* Removes an ID from the smushed IDs list from the object cache.
[431] Fix | Delete
*
[432] Fix | Delete
* @since 3.7.2
[433] Fix | Delete
*
[434] Fix | Delete
* @param integer $attachment_id ID of the smushed attachment.
[435] Fix | Delete
*/
[436] Fix | Delete
public static function remove_from_smushed_list( $attachment_id ) {
[437] Fix | Delete
$smushed_ids = wp_cache_get( 'wp-smush-smushed_ids', 'wp-smush' );
[438] Fix | Delete
[439] Fix | Delete
if ( ! empty( $smushed_ids ) ) {
[440] Fix | Delete
$index = array_search( strval( $attachment_id ), $smushed_ids, true );
[441] Fix | Delete
if ( false !== $index ) {
[442] Fix | Delete
unset( $smushed_ids[ $index ] );
[443] Fix | Delete
wp_cache_set( 'wp-smush-smushed_ids', $smushed_ids, 'wp-smush' );
[444] Fix | Delete
}
[445] Fix | Delete
}
[446] Fix | Delete
}
[447] Fix | Delete
[448] Fix | Delete
/**
[449] Fix | Delete
* Get all the attachments with wp-smush-lossy.
[450] Fix | Delete
*
[451] Fix | Delete
* @return array
[452] Fix | Delete
*/
[453] Fix | Delete
public function get_super_smushed_attachments() {
[454] Fix | Delete
$meta_query = array(
[455] Fix | Delete
array(
[456] Fix | Delete
'key' => 'wp-smush-lossy',
[457] Fix | Delete
'value' => 1,
[458] Fix | Delete
),
[459] Fix | Delete
);
[460] Fix | Delete
[461] Fix | Delete
return $this->run_query( $meta_query );
[462] Fix | Delete
}
[463] Fix | Delete
[464] Fix | Delete
/**
[465] Fix | Delete
* Fetch all the unsmushed attachments.
[466] Fix | Delete
*
[467] Fix | Delete
* @return array
[468] Fix | Delete
*/
[469] Fix | Delete
public function get_unsmushed_attachments() {
[470] Fix | Delete
return $this->run_query( self::get_unsmushed_meta_query() );
[471] Fix | Delete
}
[472] Fix | Delete
[473] Fix | Delete
/**
[474] Fix | Delete
* Temporary remove Smush metadata.
[475] Fix | Delete
*
[476] Fix | Delete
* We use this in order to temporary remove the stats metadata,
[477] Fix | Delete
* e.g While generating thumbnail or wp_generate_ when disabled auto smush.
[478] Fix | Delete
*
[479] Fix | Delete
* Note, if member's site allows compression of the original file,
[480] Fix | Delete
* when we remove stats, we might lose a large amount of storage (stats) that we saved for the member's site.
[481] Fix | Delete
* => TODO: Delete stats or just update new stats with re-smush?
[482] Fix | Delete
*
[483] Fix | Delete
* @since 3.9.6
[484] Fix | Delete
*
[485] Fix | Delete
* @param int $attachment_id Attachment ID.
[486] Fix | Delete
*/
[487] Fix | Delete
public function remove_stats( $attachment_id ) {
[488] Fix | Delete
// Main stats.
[489] Fix | Delete
delete_post_meta( $attachment_id, Modules\Smush::$smushed_meta_key );
[490] Fix | Delete
// Lossy flag.
[491] Fix | Delete
delete_post_meta( $attachment_id, 'wp-smush-lossy' );
[492] Fix | Delete
// Finally, remove the attachment ID from cache.
[493] Fix | Delete
self::remove_from_smushed_list( $attachment_id );
[494] Fix | Delete
}
[495] Fix | Delete
[496] Fix | Delete
/**
[497] Fix | Delete
* Get unsmushed meta query.
[498] Fix | Delete
*
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function