: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
maybeShowCDNUpsellForPreSiteOnCompleted() {
const upsellCdn = document.querySelector('.wp-smush-upsell-cdn');
upsellCdn.querySelector('p').innerHTML = wp_smush_msgs.processed_cdn_for_free;
upsellCdn.classList.remove('sui-hidden');
// Show upsell unlimited on completed.
this.maybeShowUnlimitedUpsellNotice();
// Show CDN activation notice for pro users.
this.maybeShowCDNActivationNotice();
// Show CDN upsell for old users.
this.maybeShowCDNUpsellForPreSiteOnCompleted();
this.maybeShowBulkErrorActions();
const callback = this.is_bulk
? () => this.trackBulkSmushCompleted()
this.syncStats().done(callback);
getPercentOptimized(totalImages, totalImagesToSmush) {
if (totalImages === totalImagesToSmush || totalImages <= 0) {
return Math.floor((totalImages - totalImagesToSmush) * 100 / totalImages);
* Prepare error row. Will only allow to hide errors for WP media attachments (not nextgen).
* @param {string} errorMsg Error message.
* @param {string} fileName File name.
* @param {string} thumbnail Thumbnail for image (if available).
* @param {number} id Image ID.
* @param {string} type Smush type: media or netxgen.
* @return {string} Row with error.
static prepareErrorRow( errorMsg, fileName, thumbnail, id, type ) {
'undefined' === typeof thumbnail
? '<i class="sui-icon-photo-picture" aria-hidden="true"></i>'
'undefined' === fileName || 'undefined' === typeof fileName
'<div class="smush-bulk-error-row">' +
'<div class="smush-bulk-image-data">' +
'<span class="smush-image-name">' +
'<span class="smush-image-error">' +
if ( 'media' === type ) {
'<div class="smush-bulk-image-actions">' +
'<button type="button" class="sui-button-icon sui-tooltip sui-tooltip-constrained sui-tooltip-left smush-ignore-image" data-tooltip="' +
window.wp_smush_msgs.error_ignore +
'<i class="sui-icon-eye-hide" aria-hidden="true"></i>' +
tableDiv = tableDiv + '</div>';
trackBulkSmushCompleted() {
} = GlobalStats.getGlobalStats();
const failurePercentage = this.total > 0 ? Math.round( this.errors.length * 100 / this.total ) : 0;
tracker.track( 'Bulk Smush Completed', {
'Total Savings': this.convertToMegabytes( savings_bytes ),
'Total Images': count_images,
'Media Optimization Percentage': parseFloat( percent_optimized ),
'Percentage of Savings': parseFloat( savings_percent ),
'Images Resized': count_resize,
'Resize Savings': this.convertToMegabytes( savings_resize ),
'Total Enqueued Images': this.total,
'Failure Percentage': failurePercentage,
convertToMegabytes( sizeInBytes ) {
const unitMB = Math.pow( 1024, 2 );
const sizeInMegabytes = sizeInBytes / unitMB;
return sizeInMegabytes && parseFloat( sizeInMegabytes.toFixed( 2 ) ) || 0;
* Send ajax request for single and bulk Smushing.
// If bulk and we have a definite number of IDs.
if ( this.is_bulk && this.ids.length > 0 ) {
* Show bulk Smush errors, and disable bulk Smush button on completion.
this.deferred.done( function() {
// self.button.removeAttr( 'continue_smush' );
self.continueSmush = true;
if ( self.errors.length ) {
/** @param {string} wp_smush_msgs.error_in_bulk */
const msg = self.errors.length === self.total ?
window.wp_smush_msgs.all_failed :
window.wp_smush_msgs.error_in_bulk
.replace( '{{errors}}', self.errors.length )
.replace( '{{total}}', self.total )
.replace( '{{smushed}}', self.smushed );
jQuery( '.wp-smush-all-done' )
.addClass( 'sui-notice-warning' )
.removeClass( 'sui-notice-success' )
// Re-enable the buttons.
'.wp-smush-all:not(.wp-smush-finished)'
).prop('disabled', false);
* Handles the cancel button click.
* Update the UI, and enable the bulk Smush button.
// Add a data attribute to the Smush button, to stop sending ajax.
// this.button.attr( 'continue_smush', false );
this.continueSmush = false;
// Sync and update stats.
this.button.removeClass( 'wp-smush-started' );
wp_smushit_data.unsmushed.unshift( this.current_id );
jQuery( '.wp-smush-bulk-wrapper' ).removeClass( 'sui-hidden' );
// Hide the progress bar.
jQuery( '.wp-smush-bulk-progress-bar-wrapper' ).addClass( 'sui-hidden' );
this.hideBulkFreeLimitReachedNotice();
* Remove the current ID from the unSmushed/re-Smush variable.
* @param {number} currentId
static updateSmushIds( currentId ) {
'undefined' !== typeof wp_smushit_data.unsmushed &&
wp_smushit_data.unsmushed.length > 0
const uIndex = wp_smushit_data.unsmushed.indexOf( currentId );
wp_smushit_data.unsmushed.splice( uIndex, 1 );
// Remove from the re-Smush list.
'undefined' !== typeof wp_smushit_data.resmush &&
wp_smushit_data.resmush.length > 0
const index = wp_smushit_data.resmush.indexOf( currentId );
wp_smushit_data.resmush.splice( index, 1 );