: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* @package Smush\App\Pages
namespace Smush\App\Pages;
use Smush\App\Abstract_Summary_Page;
use Smush\App\Interface_Page;
use Smush\Core\Array_Utils;
use Smush\Core\Stats\Global_Stats;
use Smush\Core\Media_Library\Background_Media_Library_Scanner;
use Smush\Core\Backups\Backups;
if ( ! defined( 'WPINC' ) ) {
class Bulk extends Abstract_Summary_Page implements Interface_Page {
* Function triggered when the page is loaded before render any content.
public function on_load() {
// If a free user, update the limits.
if ( ! WP_Smush::is_pro() ) {
Core::check_bulk_limit( true );
add_action( 'smush_setting_column_tag', array( $this, 'add_pro_tag' ) );
add_action( 'smush_setting_column_right_inside', array( $this, 'settings_desc' ), 10, 2 );
add_action( 'smush_setting_column_right_inside', array( $this, 'auto_smush' ), 15, 2 );
add_action( 'smush_setting_column_right_outside', array( $this, 'image_sizes' ), 15, 2 );
add_action( 'smush_setting_column_right_additional', array( $this, 'resize_settings' ), 20 );
add_action( 'smush_setting_column_right_outside', array( $this, 'full_size_options' ), 20, 2 );
add_action( 'smush_setting_column_right_outside', array( $this, 'scale_options' ), 20, 2 );
add_action( 'wp_smush_render_setting_row', array( $this, 'set_background_email_setting_visibility' ) );
public function enqueue_scripts( $hook ) {
parent::enqueue_scripts( $hook );
$this->enqueue_lib_scanner_scripts();
protected function enqueue_lib_scanner_scripts() {
WP_SMUSH_URL . 'app/assets/js/smush-library-scanner.min.js',
wp_localize_script( 'smush-library-scanner', 'mediaLibraryScan', array(
'nonce' => wp_create_nonce( 'wp_smush_media_library_scanner' ),
public function register_meta_boxes() {
if ( ! is_network_admin() ) {
array( $this, 'recheck_images_notice_meta_box' ),
'box_class' => 'sui-box wp-smush-recheck-images-notice-box sui-hidden',
'box_content_class' => false,
$bg_optimization = WP_Smush::get_instance()->core()->mod->bg_optimization;
$scan_background_process = Background_Media_Library_Scanner::get_instance()->get_background_process();
$is_scan_process_dead = $scan_background_process->get_status()->is_dead();
$show_bulk_smush_inline_notice = $bg_optimization->is_background_enabled() && $bg_optimization->is_dead();
// Do not show failed bulk smush inline notice when required re-check images.
$show_bulk_smush_inline_notice = $show_bulk_smush_inline_notice && ! $is_scan_process_dead;
if ( $show_bulk_smush_inline_notice ) {
'inline-retry-bulk-smush-notice',
array( $this, 'inline_retry_bulk_smush_notice_box' ),
'box_class' => 'sui-box wp-smush-inline-retry-bulk-smush-notice-box',
'box_content_class' => false,
parent::register_meta_boxes();
if ( ! is_network_admin() ) {
__( 'Bulk Smush', 'wp-smushit' ),
array( $this, 'bulk_smush_metabox' ),
'box_class' => 'sui-box bulk-smush-wrapper',
$class = WP_Smush::is_pro() ? 'wp-smush-pro' : '';
__( 'Settings', 'wp-smushit' ),
array( $this, 'bulk_settings_meta_box' ),
array( $this, 'common_meta_box_footer' ),
'box_class' => "sui-box smush-settings-wrapper {$class}",
$this->modals['restore-images'] = array();
* Prints Dimensions required for Resizing
* @param string $name Setting name.
public function resize_settings( $name = '' ) {
// Add only to full size settings.
if ( 'resize' !== $name ) {
$resize_sizes = $this->settings->get_setting(
$max_sizes = WP_Smush::get_instance()->core()->get_max_image_dimensions();
$setting_status = $this->settings->get( 'resize' );
<div tabindex="0" class="sui-toggle-content">
<div class="sui-border-frame<?php echo $setting_status ? '' : ' sui-hidden'; ?>" id="smush-resize-settings-wrap" style="margin-bottom: 10px;">
<div class="sui-col-md-6">
<div class="sui-form-field">
<label aria-labelledby="wp-smush-label-max-width" for="<?php echo 'wp-smush-' . esc_attr( $name ) . '_width'; ?>" class="sui-label">
<?php esc_html_e( 'Max width', 'wp-smushit' ); ?>
<input aria-required="true" type="number" class="sui-form-control wp-smush-resize-input"
aria-describedby="wp-smush-resize-note"
id="<?php echo 'wp-smush-' . esc_attr( $name ) . '_width'; ?>"
name="<?php echo 'wp-smush-' . esc_attr( $name ) . '_width'; ?>"
value="<?php echo isset( $resize_sizes['width'] ) && ! empty( $resize_sizes['width'] ) ? absint( $resize_sizes['width'] ) : 2560; ?>">
<div class="sui-col-md-6">
<div class="sui-form-field">
<label aria-labelledby="wp-smush-label-max-height" for="<?php echo 'wp-smush-' . esc_attr( $name ) . '_height'; ?>" class="sui-label">
<?php esc_html_e( 'Max height', 'wp-smushit' ); ?>
<input aria-required="true" type="number" class="sui-form-control wp-smush-resize-input"
aria-describedby="wp-smush-resize-note"
id="<?php echo 'wp-smush-' . esc_attr( $name ) . '_height'; ?>"
name="<?php echo 'wp-smush-' . esc_attr( $name ) . '_height'; ?>"
value="<?php echo isset( $resize_sizes['height'] ) && ! empty( $resize_sizes['height'] ) ? absint( $resize_sizes['height'] ) : 2560; ?>">
<div class="sui-description" id="wp-smush-resize-note">
printf( /* translators: %1$s: strong tag, %2$d: max width size, %3$s: tag, %4$d: max height size, %5$s: closing strong tag */
esc_html__( 'Currently, your largest image size is set at %1$s%2$dpx wide %3$s %4$dpx high%5$s.', 'wp-smushit' ),
esc_html( $max_sizes['width'] ),
esc_html( $max_sizes['height'] ),
<div class="sui-notice sui-notice-info wp-smush-update-width sui-no-margin-bottom sui-hidden">
<div class="sui-notice-content">
<div class="sui-notice-message">
<i class="sui-notice-icon sui-icon-info sui-md" aria-hidden="true"></i>
<p><?php esc_html_e( "Just to let you know, the width you've entered is less than your largest image and may result in pixelation.", 'wp-smushit' ); ?></p>
<div class="sui-notice sui-notice-info wp-smush-update-height sui-no-margin-bottom sui-hidden">
<div class="sui-notice-content">
<div class="sui-notice-message">
<i class="sui-notice-icon sui-icon-info sui-md" aria-hidden="true"></i>
<p><?php esc_html_e( 'Just to let you know, the height you’ve entered is less than your largest image and may result in pixelation.', 'wp-smushit' ); ?></p>
<span class="sui-description">
printf( /* translators: %s: link to gifgifs.com */
'Note: Image resizing happens automatically when you upload attachments. To support retina devices, we recommend using 2x the dimensions of your image size. Animated GIFs will not be resized as they will lose their animation, please use a tool such as %s to resize then re-upload.',
'<a href="http://gifgifs.com/resizer/" target="_blank">http://gifgifs.com/resizer/</a>'
* Show additional descriptions for settings.
* @param string $setting_key Setting key.
public function settings_desc( $setting_key = '' ) {
if ( empty( $setting_key ) || ! in_array(
array( 'resize', 'original', 'strip_exif', 'png_to_jpg', 'background_email' ),
if ( 'png_to_jpg' === $setting_key ) {
<div class="sui-toggle-content">
<div class="sui-notice sui-notice-info" style="margin-top: 10px">
<div class="sui-notice-content">
<div class="sui-notice-message smush-png2jpg-setting-note">
<i class="sui-notice-icon sui-icon-info sui-md" aria-hidden="true"></i>
/* translators: 1: <strong> 2: </strong> */
printf( esc_html__( 'Note: Any PNGs with transparency will be ignored. Smush will only convert PNGs if it results in a smaller file size. The original PNG file will be deleted, and the resulting file will have a new filename and extension (JPEG). %1$sAny hard-coded URLs on your site that contain the original PNG filename will need to be updated manually.%2$s', 'wp-smushit' ), '<strong>', '</strong>' ); ?>
/* translators: 1: <strong> 2: </strong> */
printf( esc_html__( '%1$sBackup original images%2$s must be enabled if you wish to retain the original PNG image as a backup.', 'wp-smushit' ), '<strong>', '</strong>' );
<span class="sui-description sui-toggle-description" id="<?php echo esc_attr( $setting_key . '-desc' ); ?>">
switch ( $setting_key ) {
if ( version_compare( $wp_version, '5.2.999', '>' ) ) {
esc_html_e( 'As of WordPress 5.3, large image uploads are resized down to a specified max width and height. If you require images larger than 2560px, you can override this setting here.', 'wp-smushit' );
esc_html_e( 'Save a ton of space by not storing over-sized images on your server. Set a maximum height and width for all images uploaded to your site so that any unnecessarily large images are automatically resized before they are added to the media gallery. This setting does not apply to images smushed using Directory Smush feature.', 'wp-smushit' );
esc_html_e( 'By default, WordPress will only optimize the generated attachments when you upload images, not the original ones. Enable this feature to optimize the original images.', 'wp-smushit' );
'Note: This data adds to the size of the image. While this information might be important to photographers, it’s unnecessary for most users and safe to remove.',
$bg_optimization = WP_Smush::get_instance()->core()->mod->bg_optimization;
if ( $bg_optimization->can_use_background() ) {
/* translators: %s: Email address. */
$bg_email_desc = sprintf( __( 'You will receive an email at <strong>%s</strong> when the bulk smush has completed.', 'wp-smushit' ), $bg_optimization->get_mail_recipient() );
$bulk_upgrade_url = $this->get_utm_link(
'utm_campaign' => 'smush_bulk_smush_BO_email_toggle',
$bg_email_desc = sprintf(
/* translators: 1: Open link tag <a>, 2: Close link tag </a> */
esc_html__( 'Get the email notification as part of the Background Optimization feature. You don’t have to keep the bulk smush page open when it is in progress. Be notified when Background Optimization completes. %1$sUnlock now with Pro%2$s', 'wp-smushit' ),
'<a href="' . esc_url( $bulk_upgrade_url ) . '" class="smush-upsell-link" target="_blank">',
echo wp_kses_post( $bg_email_desc );
* Prints notice after auto compress settings.
* @param string $name Setting key.
public function auto_smush( $name = '' ) {
// Add only to auto smush settings.
if ( 'auto' !== $name ) {
<div class="sui-toggle-content">
<div class="sui-notice <?php echo $this->settings->get( 'auto' ) ? '' : ' sui-hidden'; ?>" style="margin-top: 10px">
<div class="sui-notice-content">
<div class="sui-notice-message">
<i class="sui-notice-icon sui-icon-info sui-md" aria-hidden="true"></i>
<p><?php esc_html_e( 'Note: We will only automatically compress the image sizes selected above.', 'wp-smushit' ); ?></p>
* Prints all the registered image sizes, to be selected/unselected for smushing.
* @param string $name Setting key.
public function image_sizes( $name = '' ) {
// Add only to bulk smush settings.
if ( 'bulk' !== $name ) {
// Additional image sizes.
$image_sizes = $this->settings->get_setting( 'wp-smush-image_sizes' );
$sizes = WP_Smush::get_instance()->core()->image_dimensions();
$all_selected = false === $image_sizes || count( $image_sizes ) === count( $sizes );
<?php if ( ! empty( $sizes ) ) : ?>
<div class="sui-side-tabs sui-tabs">
<label for="all-image-sizes" class="sui-tab-item <?php echo $all_selected ? 'active' : ''; ?>">
<input type="radio" name="wp-smush-auto-image-sizes" value="all" id="all-image-sizes" <?php checked( $all_selected ); ?>>
<?php esc_html_e( 'All', 'wp-smushit' ); ?>
<label for="custom-image-sizes" class="sui-tab-item <?php echo $all_selected ? '' : 'active'; ?>">
<input type="radio" name="wp-smush-auto-image-sizes" value="custom" id="custom-image-sizes" <?php checked( $all_selected, false ); ?>>
<?php esc_html_e( 'Custom', 'wp-smushit' ); ?>
</div><!-- end data-tabs -->
<div class="sui-tab-boxed <?php echo $all_selected ? 'active' : ''; ?>" style="display:none"></div>
<div class="sui-tab-boxed <?php echo $all_selected ? '' : 'active'; ?>">
<span class="sui-label"><?php esc_html_e( 'Included image sizes', 'wp-smushit' ); ?></span>
foreach ( $sizes as $size_k => $size ) {
// If image sizes array isn't set, mark all checked ( Default Values ).
if ( false === $image_sizes ) {
// WPMDUDEV hosting support: cast $size_k to string to properly work with object cache.
$checked = is_array( $image_sizes ) && in_array( (string) $size_k, $image_sizes, true );
<label class="sui-checkbox sui-checkbox-stacked sui-checkbox-sm">
<input type="checkbox" <?php checked( $checked, true ); ?>
id="wp-smush-size-<?php echo esc_attr( $size_k ); ?>"
name="wp-smush-image_sizes[]"
value="<?php echo esc_attr( $size_k ); ?>">
<span aria-hidden="true"> </span>
<?php if ( isset( $size['width'], $size['height'] ) ) : ?>
<?php echo esc_html( $size_k . ' (' . $size['width'] . 'x' . $size['height'] . ') ' ); ?>
<?php echo esc_attr( $size_k ); ?>
* Prints Resize, Smush Original, and Backup settings.
* @param string $name Name of the current setting being processed.
public function full_size_options( $name = '' ) {
// Continue only if original image option.
if ( 'original' !== $name ) {
$value = $this->settings->get( 'backup' );
<div class="sui-form-field">
<label for="backup" class="sui-toggle">
aria-labelledby="backup-label"
aria-describedby="backup-desc"
<?php checked( $value, 1 ); ?>
<span class="sui-toggle-slider" aria-hidden="true"></span>
<span id="backup-label" class="sui-toggle-label">
<?php echo esc_html( Settings::get_setting_data( 'backup', 'label' ) ); ?>
<span class="sui-description sui-toggle-description" id="backup-desc">
<?php echo esc_html( Settings::get_setting_data( 'backup', 'desc' ) ); ?>
<div class="sui-toggle-content <?php echo $this->settings->get( 'original' ) ? 'sui-hidden' : ''; ?>" id="backup-notice">
<div class="sui-notice" style="margin-top: 10px">
<div class="sui-notice-content">
<div class="sui-notice-message">
<i class="sui-notice-icon sui-icon-info sui-md" aria-hidden="true"></i>
printf( /* translators: %1$s - <strong>, %2$s - </strong> */
esc_html__( '%1$sOptimize original images%2$s is disabled, which means that enabling %1$sBackup original images%2$s won’t yield additional benefits and will use more storage space. We recommend enabling %1$sBackup original images%2$s only if %1$sOptimize original images%2$s is also enabled.', 'wp-smushit' ),
* Add scale image settings.
* @param string $name Name of the current setting being processed.
public function scale_options( $name = '' ) {
if ( 'resize' !== $name ) {
// Not available on WordPress before 5.3.
if ( version_compare( $wp_version, '5.3', '<' ) ) {
$value = $this->settings->get( 'no_scale' );
<div class="sui-form-field">
<label for="no_scale" class="sui-toggle">