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/wp-smush.../core/integrat.../nextgen
File: class-admin.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Adds the Bulk Page and Smush Column to NextGen Gallery
[2] Fix | Delete
*
[3] Fix | Delete
* @package Smush\Core\Integrations\NextGen
[4] Fix | Delete
* @version 1.0
[5] Fix | Delete
*
[6] Fix | Delete
* @author Umesh Kumar <umesh@incsub.com>
[7] Fix | Delete
*
[8] Fix | Delete
* @copyright (c) 2016, Incsub (http://incsub.com)
[9] Fix | Delete
*/
[10] Fix | Delete
[11] Fix | Delete
namespace Smush\Core\Integrations\NextGen;
[12] Fix | Delete
[13] Fix | Delete
use C_Component_Registry;
[14] Fix | Delete
use C_Gallery_Storage;
[15] Fix | Delete
use nggdb;
[16] Fix | Delete
use Smush\App\Media_Library;
[17] Fix | Delete
use Smush\Core\Core;
[18] Fix | Delete
use Smush\Core\Helper;
[19] Fix | Delete
use Smush\Core\Integrations\NextGen;
[20] Fix | Delete
use Smush\Core\Settings;
[21] Fix | Delete
use stdClass;
[22] Fix | Delete
use WP_Smush;
[23] Fix | Delete
[24] Fix | Delete
if ( ! defined( 'WPINC' ) ) {
[25] Fix | Delete
die;
[26] Fix | Delete
}
[27] Fix | Delete
[28] Fix | Delete
/**
[29] Fix | Delete
* Class Admin
[30] Fix | Delete
*/
[31] Fix | Delete
class Admin extends NextGen {
[32] Fix | Delete
[33] Fix | Delete
/**
[34] Fix | Delete
* Total image count.
[35] Fix | Delete
*
[36] Fix | Delete
* @var int $total_count
[37] Fix | Delete
*/
[38] Fix | Delete
public $total_count = 0;
[39] Fix | Delete
[40] Fix | Delete
/**
[41] Fix | Delete
* Count of images ( Attachments ), Does not includes additional sizes that might have been created.
[42] Fix | Delete
*
[43] Fix | Delete
* @var int $smushed_count
[44] Fix | Delete
*/
[45] Fix | Delete
public $smushed_count = 0;
[46] Fix | Delete
[47] Fix | Delete
/**
[48] Fix | Delete
* Includes the count of different sizes an image might have
[49] Fix | Delete
*
[50] Fix | Delete
* @var int $image_count
[51] Fix | Delete
*/
[52] Fix | Delete
public $image_count = 0;
[53] Fix | Delete
[54] Fix | Delete
/**
[55] Fix | Delete
* Remaining count.
[56] Fix | Delete
*
[57] Fix | Delete
* @var int $remaining_count
[58] Fix | Delete
*/
[59] Fix | Delete
public $remaining_count = 0;
[60] Fix | Delete
[61] Fix | Delete
/**
[62] Fix | Delete
* Super Smushed.
[63] Fix | Delete
*
[64] Fix | Delete
* @var int $super_smushed
[65] Fix | Delete
*/
[66] Fix | Delete
public $super_smushed = 0;
[67] Fix | Delete
[68] Fix | Delete
/**
[69] Fix | Delete
* Smushed images.
[70] Fix | Delete
*
[71] Fix | Delete
* @var array $smushed
[72] Fix | Delete
*/
[73] Fix | Delete
public $smushed = array();
[74] Fix | Delete
[75] Fix | Delete
/**
[76] Fix | Delete
* Stores all lossless smushed IDs.
[77] Fix | Delete
*
[78] Fix | Delete
* @var array $resmush_ids
[79] Fix | Delete
*/
[80] Fix | Delete
public $resmush_ids = array();
[81] Fix | Delete
[82] Fix | Delete
/**
[83] Fix | Delete
* Stats class object.
[84] Fix | Delete
*
[85] Fix | Delete
* @var Stats
[86] Fix | Delete
*/
[87] Fix | Delete
public $ng_stats;
[88] Fix | Delete
[89] Fix | Delete
protected $settings;
[90] Fix | Delete
[91] Fix | Delete
/**
[92] Fix | Delete
* Admin constructor.
[93] Fix | Delete
*
[94] Fix | Delete
* @param Stats $stats Class object.
[95] Fix | Delete
*/
[96] Fix | Delete
public function __construct( Stats $stats ) {
[97] Fix | Delete
$this->ng_stats = $stats;
[98] Fix | Delete
$this->settings = Settings::get_instance();
[99] Fix | Delete
[100] Fix | Delete
// Update the number of columns.
[101] Fix | Delete
add_filter( 'ngg_manage_images_number_of_columns', array( $this, 'wp_smush_manage_images_number_of_columns' ) );
[102] Fix | Delete
[103] Fix | Delete
// Update resmush list, if a NextGen image is deleted.
[104] Fix | Delete
add_action( 'ngg_delete_picture', array( $this, 'update_resmush_list' ) );
[105] Fix | Delete
[106] Fix | Delete
// Update Stats, if a NextGen image is deleted.
[107] Fix | Delete
add_action( 'ngg_delete_picture', array( $this, 'update_nextgen_stats' ) );
[108] Fix | Delete
[109] Fix | Delete
// Update Stats, Lists - if a NextGen Gallery is deleted.
[110] Fix | Delete
add_action( 'ngg_delete_gallery', array( $this->ng_stats, 'update_stats_cache' ) );
[111] Fix | Delete
[112] Fix | Delete
// Update the Super Smush count, after the smushing.
[113] Fix | Delete
add_action( 'wp_smush_image_optimised_nextgen', array( $this, 'update_lists_after_optimizing' ), '', 2 );
[114] Fix | Delete
[115] Fix | Delete
// Reset smush data after restoring the image.
[116] Fix | Delete
add_action( 'ngg_recovered_image', array( $this, 'reset_smushdata' ) );
[117] Fix | Delete
[118] Fix | Delete
add_action( 'wp_ajax_nextgen_get_stats', array( $this, 'ajax_get_stats' ) );
[119] Fix | Delete
[120] Fix | Delete
add_filter( 'wp_smush_nextgen_scan_stats', array( $this, 'scan_images' ) );
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
/**
[124] Fix | Delete
* Returns a column name for WP Smush.
[125] Fix | Delete
*
[126] Fix | Delete
* @param array $columns Current columns.
[127] Fix | Delete
*
[128] Fix | Delete
* @return array|string
[129] Fix | Delete
*/
[130] Fix | Delete
public function wp_smush_image_column_name( $columns ) {
[131] Fix | Delete
// Latest next gen takes string, while the earlier WP Smush plugin shows there use to be a array.
[132] Fix | Delete
if ( is_array( $columns ) ) {
[133] Fix | Delete
$columns['wp_smush_image'] = esc_html__( 'Smush', 'wp-smushit' );
[134] Fix | Delete
} else {
[135] Fix | Delete
$columns = esc_html__( 'Smush', 'wp-smushit' );
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
return $columns;
[139] Fix | Delete
}
[140] Fix | Delete
[141] Fix | Delete
/**
[142] Fix | Delete
* Returns Smush option / Stats, depending if image is already smushed or not.
[143] Fix | Delete
*
[144] Fix | Delete
* @param string $column_name Column name.
[145] Fix | Delete
* @param object|int $id Image object or ID.
[146] Fix | Delete
*
[147] Fix | Delete
* @return array|bool|string|void
[148] Fix | Delete
*/
[149] Fix | Delete
public function wp_smush_column_options( $column_name, $id ) {
[150] Fix | Delete
// NExtGen Doesn't returns Column name, weird? yeah, right, it is proper because hook is called for the particular column.
[151] Fix | Delete
if ( 'wp_smush_image' === $column_name || '' === $column_name ) {
[152] Fix | Delete
// We're not using our in-house function Smush\Core\Integrations\Nextgen::get_nextgen_image_from_id()
[153] Fix | Delete
// as we're already instializing the nextgen gallery object, we need $storage instance later.
[154] Fix | Delete
// Registry Object for NextGen Gallery.
[155] Fix | Delete
$registry = C_Component_Registry::get_instance();
[156] Fix | Delete
[157] Fix | Delete
/**
[158] Fix | Delete
* Gallery Storage Object.
[159] Fix | Delete
*
[160] Fix | Delete
* @var C_Gallery_Storage $storage
[161] Fix | Delete
*/
[162] Fix | Delete
$storage = $registry->get_utility( 'I_Gallery_Storage' );
[163] Fix | Delete
[164] Fix | Delete
// We'll get the image object in $id itself, else fetch it using Gallery Storage.
[165] Fix | Delete
if ( is_object( $id ) ) {
[166] Fix | Delete
$image = $id;
[167] Fix | Delete
} else {
[168] Fix | Delete
// get an image object.
[169] Fix | Delete
$image = $storage->object->_image_mapper->find( $id );
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
// Check if it is supported image format, get image type to do that get the absolute path.
[173] Fix | Delete
$file_path = $storage->get_image_abspath( $image, 'full' );
[174] Fix | Delete
[175] Fix | Delete
// Get image type from file path.
[176] Fix | Delete
$image_type = $this->get_file_type( $file_path );
[177] Fix | Delete
[178] Fix | Delete
// If image type not supported.
[179] Fix | Delete
if ( ! $image_type || ! in_array( $image_type, Core::$mime_types, true ) ) {
[180] Fix | Delete
return;
[181] Fix | Delete
}
[182] Fix | Delete
[183] Fix | Delete
$image->meta_data = $this->get_combined_stats( $image->meta_data );
[184] Fix | Delete
[185] Fix | Delete
// Check Image metadata, if smushed, print the stats or super smush button.
[186] Fix | Delete
if ( ! empty( $image->meta_data['wp_smush'] ) ) {
[187] Fix | Delete
// Echo the smush stats.
[188] Fix | Delete
return $this->show_stats( $image->pid, $image->meta_data['wp_smush'], $image_type );
[189] Fix | Delete
}
[190] Fix | Delete
[191] Fix | Delete
// Print the status of image, if Not smushed.
[192] Fix | Delete
return $this->set_status( $image->pid );
[193] Fix | Delete
}
[194] Fix | Delete
}
[195] Fix | Delete
[196] Fix | Delete
/**
[197] Fix | Delete
* Localize Translations And Stats
[198] Fix | Delete
*/
[199] Fix | Delete
public function localize() {
[200] Fix | Delete
$handle = 'smush-admin';
[201] Fix | Delete
[202] Fix | Delete
$upgrade_url = add_query_arg(
[203] Fix | Delete
array(
[204] Fix | Delete
'utm_source' => 'smush',
[205] Fix | Delete
'utm_medium' => 'plugin',
[206] Fix | Delete
'utm_campaign' => 'smush_bulksmush_issues_filesizelimit_notice',
[207] Fix | Delete
),
[208] Fix | Delete
'https://wpmudev.com/project/wp-smush-pro/'
[209] Fix | Delete
);
[210] Fix | Delete
[211] Fix | Delete
if ( WP_Smush::is_pro() ) {
[212] Fix | Delete
$error_in_bulk = esc_html__( '{{smushed}}/{{total}} images were successfully compressed, {{errors}} encountered issues.', 'wp-smushit' );
[213] Fix | Delete
} else {
[214] Fix | Delete
$error_in_bulk = sprintf(
[215] Fix | Delete
/* translators: %1$s - opening link tag, %2$s - Close the link </a> */
[216] Fix | Delete
esc_html__( '{{smushed}}/{{total}} images were successfully compressed, {{errors}} encountered issues. Are you hitting the 5MB "size limit exceeded" warning? %1$sUpgrade to Smush Pro%2$s to optimize unlimited image files.', 'wp-smushit' ),
[217] Fix | Delete
'<a href="' . esc_url( $upgrade_url ) . '" target="_blank">',
[218] Fix | Delete
'</a>'
[219] Fix | Delete
);
[220] Fix | Delete
}
[221] Fix | Delete
[222] Fix | Delete
$wp_smush_msgs = array(
[223] Fix | Delete
'nonce' => wp_create_nonce( 'wp-smush-ajax' ),
[224] Fix | Delete
'resmush' => esc_html__( 'Super-Smush', 'wp-smushit' ),
[225] Fix | Delete
'smush_now' => esc_html__( 'Smush Now', 'wp-smushit' ),
[226] Fix | Delete
'error_in_bulk' => $error_in_bulk,
[227] Fix | Delete
'all_resmushed' => esc_html__( 'All images are fully optimized.', 'wp-smushit' ),
[228] Fix | Delete
'restore' => esc_html__( 'Restoring image...', 'wp-smushit' ),
[229] Fix | Delete
'smushing' => esc_html__( 'Smushing image...', 'wp-smushit' ),
[230] Fix | Delete
);
[231] Fix | Delete
[232] Fix | Delete
wp_localize_script( $handle, 'wp_smush_msgs', $wp_smush_msgs );
[233] Fix | Delete
[234] Fix | Delete
$data = $this->ng_stats->get_global_stats();
[235] Fix | Delete
[236] Fix | Delete
wp_localize_script( $handle, 'wp_smushit_data', $data );
[237] Fix | Delete
}
[238] Fix | Delete
[239] Fix | Delete
/**
[240] Fix | Delete
* Increase the count of columns for Nextgen Gallery Manage page.
[241] Fix | Delete
*
[242] Fix | Delete
* @param int $count Current columns count.
[243] Fix | Delete
*
[244] Fix | Delete
* @return int
[245] Fix | Delete
*/
[246] Fix | Delete
public function wp_smush_manage_images_number_of_columns( $count ) {
[247] Fix | Delete
$count ++;
[248] Fix | Delete
[249] Fix | Delete
// Add column Heading.
[250] Fix | Delete
add_filter( "ngg_manage_images_column_{$count}_header", array( $this, 'wp_smush_image_column_name' ) );
[251] Fix | Delete
[252] Fix | Delete
// Add Column data.
[253] Fix | Delete
add_filter( "ngg_manage_images_column_{$count}_content", array( $this, 'wp_smush_column_options' ), 10, 2 );
[254] Fix | Delete
[255] Fix | Delete
return $count;
[256] Fix | Delete
}
[257] Fix | Delete
[258] Fix | Delete
/**
[259] Fix | Delete
* Set send button status
[260] Fix | Delete
*
[261] Fix | Delete
* @param int $pid ID.
[262] Fix | Delete
*
[263] Fix | Delete
* @return string
[264] Fix | Delete
*/
[265] Fix | Delete
private function set_status( $pid ) {
[266] Fix | Delete
// the status.
[267] Fix | Delete
$status_txt = __( 'Not processed', 'wp-smushit' );
[268] Fix | Delete
[269] Fix | Delete
// we need to show the smush button.
[270] Fix | Delete
$show_button = true;
[271] Fix | Delete
[272] Fix | Delete
// the button text.
[273] Fix | Delete
$button_txt = __( 'Smush', 'wp-smushit' );
[274] Fix | Delete
[275] Fix | Delete
// If we are not showing smush button, append progress bar, else it is already there.
[276] Fix | Delete
if ( ! $show_button ) {
[277] Fix | Delete
$status_txt .= Media_Library::progress_bar();
[278] Fix | Delete
}
[279] Fix | Delete
[280] Fix | Delete
return $this->column_html( $pid, $status_txt, $button_txt, $show_button );
[281] Fix | Delete
}
[282] Fix | Delete
[283] Fix | Delete
/**
[284] Fix | Delete
* Print the column html
[285] Fix | Delete
*
[286] Fix | Delete
* @param string $pid Media id.
[287] Fix | Delete
* @param string $status_txt Status text.
[288] Fix | Delete
* @param string $button_txt Button label.
[289] Fix | Delete
* @param boolean $show_button Whether to shoe the button.
[290] Fix | Delete
* @param bool $smushed Image compressed or not.
[291] Fix | Delete
*
[292] Fix | Delete
* @return string|void
[293] Fix | Delete
*/
[294] Fix | Delete
public function column_html( $pid, $status_txt = '', $button_txt = '', $show_button = true, $smushed = false ) {
[295] Fix | Delete
$class = $smushed ? '' : ' sui-hidden';
[296] Fix | Delete
$html = '<p class="smush-status' . $class . '">' . $status_txt . '</p>';
[297] Fix | Delete
[298] Fix | Delete
// if we aren't showing the button.
[299] Fix | Delete
if ( ! $show_button ) {
[300] Fix | Delete
return $html;
[301] Fix | Delete
}
[302] Fix | Delete
[303] Fix | Delete
$html .= '<div class="sui-smush-media smush-status-links">';
[304] Fix | Delete
$html .= wp_nonce_field( 'wp_smush_nextgen', '_wp_smush_nonce', '', false );
[305] Fix | Delete
$html .= '<button class="button button-primary wp-smush-nextgen-send" data-id="' . $pid . '">
[306] Fix | Delete
<span>' . $button_txt . '</span>
[307] Fix | Delete
</button>';
[308] Fix | Delete
$html .= '</div>';
[309] Fix | Delete
return $html;
[310] Fix | Delete
}
[311] Fix | Delete
[312] Fix | Delete
/**
[313] Fix | Delete
* Updates the resmush list for NextGen gallery, remove the given id
[314] Fix | Delete
*
[315] Fix | Delete
* @param int $attachment_id Attachment ID.
[316] Fix | Delete
*/
[317] Fix | Delete
public function update_resmush_list( $attachment_id ) {
[318] Fix | Delete
if ( $this->ng_stats->get_reoptimize_list()->has_id( $attachment_id ) ) {
[319] Fix | Delete
return $this->ng_stats->get_reoptimize_list()->remove_id( $attachment_id );
[320] Fix | Delete
}
[321] Fix | Delete
return $this->ng_stats->get_reoptimize_list()->add_id( $attachment_id );
[322] Fix | Delete
}
[323] Fix | Delete
[324] Fix | Delete
/**
[325] Fix | Delete
* Fetch the stats for the given attachment id, and subtract them from Global stats
[326] Fix | Delete
*
[327] Fix | Delete
* @param int $attachment_id Attachment ID.
[328] Fix | Delete
*
[329] Fix | Delete
* @return bool
[330] Fix | Delete
*/
[331] Fix | Delete
public function update_nextgen_stats( $attachment_id ) {
[332] Fix | Delete
if ( empty( $attachment_id ) ) {
[333] Fix | Delete
return false;
[334] Fix | Delete
}
[335] Fix | Delete
[336] Fix | Delete
$image_id = absint( (int) $attachment_id );
[337] Fix | Delete
[338] Fix | Delete
// Get the absolute path for original image.
[339] Fix | Delete
$image = $this->get_nextgen_image_from_id( $image_id );
[340] Fix | Delete
[341] Fix | Delete
// Image Metadata.
[342] Fix | Delete
$metadata = ! empty( $image ) ? $image->meta_data : '';
[343] Fix | Delete
[344] Fix | Delete
$smush_stats = ! empty( $metadata['wp_smush'] ) ? $metadata['wp_smush'] : '';
[345] Fix | Delete
[346] Fix | Delete
if ( empty( $smush_stats ) ) {
[347] Fix | Delete
return false;
[348] Fix | Delete
}
[349] Fix | Delete
[350] Fix | Delete
$nextgen_stats = get_option( 'wp_smush_stats_nextgen', false );
[351] Fix | Delete
if ( ! $nextgen_stats ) {
[352] Fix | Delete
return false;
[353] Fix | Delete
}
[354] Fix | Delete
[355] Fix | Delete
if ( ! empty( $nextgen_stats['size_before'] ) && ! empty( $nextgen_stats['size_after'] ) && $nextgen_stats['size_before'] > 0 && $nextgen_stats['size_after'] > 0 && $nextgen_stats['size_before'] >= $smush_stats['stats']['size_before'] ) {
[356] Fix | Delete
$nextgen_stats['size_before'] = $nextgen_stats['size_before'] - $smush_stats['stats']['size_before'];
[357] Fix | Delete
$nextgen_stats['size_after'] = $nextgen_stats['size_after'] - $smush_stats['stats']['size_after'];
[358] Fix | Delete
$nextgen_stats['bytes'] = $nextgen_stats['size_before'] - $nextgen_stats['size_after'];
[359] Fix | Delete
if ( 0 === $nextgen_stats['bytes'] && 0 === $nextgen_stats['size_before'] ) {
[360] Fix | Delete
$nextgen_stats['percent'] = 0;
[361] Fix | Delete
} else {
[362] Fix | Delete
$nextgen_stats['percent'] = ( $nextgen_stats['bytes'] / $nextgen_stats['size_before'] ) * 100;
[363] Fix | Delete
}
[364] Fix | Delete
$nextgen_stats['human'] = size_format( $nextgen_stats['bytes'], 1 );
[365] Fix | Delete
}
[366] Fix | Delete
[367] Fix | Delete
// Update Stats.
[368] Fix | Delete
update_option( 'wp_smush_stats_nextgen', $nextgen_stats, false );
[369] Fix | Delete
[370] Fix | Delete
// Remove from Super Smush list.
[371] Fix | Delete
$this->ng_stats->get_supper_smushed_list()->remove_id( $image_id );
[372] Fix | Delete
}
[373] Fix | Delete
[374] Fix | Delete
/**
[375] Fix | Delete
* Update the Super Smush count for NextGen Gallery
[376] Fix | Delete
*
[377] Fix | Delete
* @param int $image_id Image ID.
[378] Fix | Delete
* @param array $stats Stats.
[379] Fix | Delete
*/
[380] Fix | Delete
public function update_lists_after_optimizing( $image_id, $stats ) {
[381] Fix | Delete
if ( isset( $stats['stats']['lossy'] ) && 1 === (int) $stats['stats']['lossy'] ) {
[382] Fix | Delete
$this->ng_stats->get_supper_smushed_list()->add_id( $image_id );
[383] Fix | Delete
}
[384] Fix | Delete
$this->update_resmush_list( $image_id );
[385] Fix | Delete
}
[386] Fix | Delete
[387] Fix | Delete
/**
[388] Fix | Delete
* Initialize NextGen Gallery Stats
[389] Fix | Delete
*/
[390] Fix | Delete
public function setup_image_counts() {
[391] Fix | Delete
$this->total_count = $this->ng_stats->total_count();
[392] Fix | Delete
$this->smushed_count = $this->ng_stats->get_smushed_count();
[393] Fix | Delete
$this->image_count = $this->ng_stats->get_smushed_image_count();
[394] Fix | Delete
$this->resmush_ids = $this->ng_stats->get_reoptimize_list()->get_ids();
[395] Fix | Delete
$this->super_smushed = $this->ng_stats->get_supper_smushed_count();
[396] Fix | Delete
$this->remaining_count = $this->ng_stats->get_remaining_count();
[397] Fix | Delete
}
[398] Fix | Delete
[399] Fix | Delete
/**
[400] Fix | Delete
* Get the image count for nextgen images
[401] Fix | Delete
*
[402] Fix | Delete
* @param array $images Array of attachments to get the image count for.
[403] Fix | Delete
* @param bool $exclude_resmush_ids Whether to exclude resmush ids or not.
[404] Fix | Delete
*
[405] Fix | Delete
* @return int
[406] Fix | Delete
*/
[407] Fix | Delete
public function get_image_count( $images = array(), $exclude_resmush_ids = true ) {
[408] Fix | Delete
if ( empty( $images ) || ! is_array( $images ) ) {
[409] Fix | Delete
return 0;
[410] Fix | Delete
}
[411] Fix | Delete
[412] Fix | Delete
$image_count = 0;
[413] Fix | Delete
// $image in here is expected to be metadata array
[414] Fix | Delete
foreach ( $images as $image_k => $image ) {
[415] Fix | Delete
// Get image object if not there already.
[416] Fix | Delete
if ( ! is_array( $image ) ) {
[417] Fix | Delete
$image = $this->get_nextgen_image_from_id( $image );
[418] Fix | Delete
// Get the meta.
[419] Fix | Delete
$image = ! empty( $image->meta_data ) ? $image->meta_data : '';
[420] Fix | Delete
}
[421] Fix | Delete
// If there are no smush stats, skip.
[422] Fix | Delete
if ( empty( $image['wp_smush'] ) ) {
[423] Fix | Delete
continue;
[424] Fix | Delete
}
[425] Fix | Delete
[426] Fix | Delete
// If resmush ids needs to be excluded.
[427] Fix | Delete
if ( $exclude_resmush_ids && ( ! empty( $this->resmush_ids ) && in_array( $image_k, $this->resmush_ids ) ) ) {
[428] Fix | Delete
continue;
[429] Fix | Delete
}
[430] Fix | Delete
[431] Fix | Delete
// Get the image count.
[432] Fix | Delete
if ( ! empty( $image['wp_smush']['sizes'] ) ) {
[433] Fix | Delete
$image_count += count( $image['wp_smush']['sizes'] );
[434] Fix | Delete
}
[435] Fix | Delete
}
[436] Fix | Delete
[437] Fix | Delete
return $image_count;
[438] Fix | Delete
}
[439] Fix | Delete
[440] Fix | Delete
/**
[441] Fix | Delete
* Combine the resizing stats and smush stats , One time operation - performed during the image optimization
[442] Fix | Delete
*
[443] Fix | Delete
* @param array $metadata Image metadata.
[444] Fix | Delete
*
[445] Fix | Delete
* @return mixed
[446] Fix | Delete
*/
[447] Fix | Delete
private function get_combined_stats( $metadata ) {
[448] Fix | Delete
if ( empty( $metadata ) ) {
[449] Fix | Delete
return $metadata;
[450] Fix | Delete
}
[451] Fix | Delete
[452] Fix | Delete
$smush_stats = ! empty( $metadata['wp_smush'] ) ? $metadata['wp_smush'] : '';
[453] Fix | Delete
$resize_savings = ! empty( $metadata['wp_smush_resize_savings'] ) ? $metadata['wp_smush_resize_savings'] : '';
[454] Fix | Delete
[455] Fix | Delete
if ( empty( $resize_savings ) || empty( $smush_stats ) ) {
[456] Fix | Delete
return $metadata;
[457] Fix | Delete
}
[458] Fix | Delete
[459] Fix | Delete
$smush_stats['stats']['bytes'] = ! empty( $resize_savings['bytes'] ) ? $smush_stats['stats']['bytes'] + $resize_savings['bytes'] : $smush_stats['stats']['bytes'];
[460] Fix | Delete
$smush_stats['stats']['size_before'] = ! empty( $resize_savings['size_before'] ) ? $smush_stats['stats']['size_before'] + $resize_savings['size_before'] : $smush_stats['stats']['size_before'];
[461] Fix | Delete
$smush_stats['stats']['size_after'] = ! empty( $resize_savings['size_after'] ) ? $smush_stats['stats']['size_after'] + $resize_savings['size_after'] : $smush_stats['stats']['size_after'];
[462] Fix | Delete
$smush_stats['stats']['percent'] = ! empty( $resize_savings['size_before'] ) ? ( $smush_stats['stats']['bytes'] / $smush_stats['stats']['size_before'] ) * 100 : $smush_stats['stats']['percent'];
[463] Fix | Delete
[464] Fix | Delete
// Round off.
[465] Fix | Delete
$smush_stats['stats']['percent'] = round( $smush_stats['stats']['percent'], 2 );
[466] Fix | Delete
[467] Fix | Delete
if ( ! empty( $smush_stats['sizes']['full'] ) ) {
[468] Fix | Delete
// Full Image.
[469] Fix | Delete
$smush_stats['sizes']['full']['bytes'] = ! empty( $resize_savings['bytes'] ) ? $smush_stats['sizes']['full']['bytes'] + $resize_savings['bytes'] : $smush_stats['sizes']['full']['bytes'];
[470] Fix | Delete
$smush_stats['sizes']['full']['size_before'] = ! empty( $resize_savings['size_before'] ) ? $smush_stats['sizes']['full']['size_before'] + $resize_savings['size_before'] : $smush_stats['sizes']['full']['size_before'];
[471] Fix | Delete
$smush_stats['sizes']['full']['size_after'] = ! empty( $resize_savings['size_after'] ) ? $smush_stats['sizes']['full']['size_after'] + $resize_savings['size_after'] : $smush_stats['sizes']['full']['size_after'];
[472] Fix | Delete
$smush_stats['sizes']['full']['percent'] = ! empty( $smush_stats['sizes']['full']['bytes'] ) && $smush_stats['sizes']['full']['size_before'] > 0 ? ( $smush_stats['sizes']['full']['bytes'] / $smush_stats['sizes']['full']['size_before'] ) * 100 : $smush_stats['sizes']['full']['percent'];
[473] Fix | Delete
[474] Fix | Delete
$smush_stats['sizes']['full']['percent'] = round( $smush_stats['sizes']['full']['percent'], 2 );
[475] Fix | Delete
} else {
[476] Fix | Delete
$smush_stats['sizes']['full'] = $resize_savings;
[477] Fix | Delete
}
[478] Fix | Delete
[479] Fix | Delete
$metadata['wp_smush'] = $smush_stats;
[480] Fix | Delete
[481] Fix | Delete
return $metadata;
[482] Fix | Delete
}
[483] Fix | Delete
[484] Fix | Delete
/**
[485] Fix | Delete
* Reset smush data after restoring the image.
[486] Fix | Delete
*
[487] Fix | Delete
* @since 3.10.0
[488] Fix | Delete
*
[489] Fix | Delete
* @param stdClass $image Image object for NextGen gallery.
[490] Fix | Delete
* @param false|string $attachment_file_path The full file path, if it's provided we will reset the dimension.
[491] Fix | Delete
*/
[492] Fix | Delete
public function reset_smushdata( $image, $attachment_file_path = false ) {
[493] Fix | Delete
if ( empty( $image->meta_data['wp_smush'] ) && empty( $image->meta_data['wp_smush_resize_savings'] ) ) {
[494] Fix | Delete
return;
[495] Fix | Delete
}
[496] Fix | Delete
[497] Fix | Delete
$this->ng_stats->subtract_image_stats( $image );
[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