: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* When 'All' is selected for the Image Sizes setting, select all available sizes.
$('#all-image-sizes').on('change', function () {
$('input[name^="wp-smush-image_sizes"]').prop('checked', true);
* Handles the tabs navigation on mobile.
$('.sui-mobile-nav').on('change', (e) => {
window.location.assign($(e.currentTarget).val());
* Handle re-check api status button click (Settings)
$('#update-api-status').on('click', function (e) {
//$(this).prop('disabled', true);
$(this).addClass('sui-button-onload');
$.post(ajaxurl, { action: 'recheck_api_status' }, function () {
/** Handle smush button click **/
'.wp-smush-send:not(.wp-smush-resmush)',
// prevent the default action
new Smush($(this), false);
* Handle show in bulk smush button click.
$( 'body' ).on( 'click', '.wp-smush-remove-skipped', function( e ) {
// Send ajax request to remove the image from the skip list.
action: 'remove_from_skip_list',
id: self.attr( 'data-id' ),
_ajax_nonce: self.attr( 'data-nonce' ),
} ).done( ( response ) => {
if ( response.success && 'undefined' !== typeof response.data.html ) {
self.parent().parent().html( response.data.html );
/** Restore: Media Library **/
$('body').on('click', '.wp-smush-action.wp-smush-restore', function (e) {
const current_button = $(this);
/** Resmush: Media Library **/
$('body').on('click', '.wp-smush-action.wp-smush-resmush', function (e) {
process_smush_action(e, $(this), 'smush_resmush_image', 'smushing');
/** Restore: NextGen Gallery **/
'.wp-smush-action.wp-smush-nextgen-restore',
'smush_restore_nextgen_image',
/** Resmush: NextGen Gallery **/
'.wp-smush-action.wp-smush-nextgen-resmush',
'smush_resmush_nextgen_image',
//Scan For resmushing images
$('.wp-smush-scan').on('click', function (e) {
if ( $(this).hasClass('wp-smush-background-scan') ) {
$('body').on('click', '.wp-smush-notice .icon-fi-close', function (e) {
const $el = $(this).parent();
// Enable super smush on clicking link from stats area.
$('a.wp-smush-lossy-enable').on('click', function (e) {
// Scroll down to settings area.
goToByScroll('#column-lossy');
// Enable resize on clicking link from stats area.
$('.wp-smush-resize-enable').on('click', function (e) {
// Scroll down to settings area.
goToByScroll('#column-resize');
// If settings string is found in url, enable and scroll.
if ( window.location.hash ) {
const setting_hash = window.location.hash.substring( 1 );
switch ( setting_hash ) {
scrollTo = '#column-resize';
scrollTo = '#column-lossy';
goToByScroll( scrollTo );
document.getElementById( scrollTo.replace( '#', '' ) ).focus();
$('body').on('click', '.wp-smush-trigger-bulk', function (e) {
//Induce Setting button save click
'undefined' !== typeof e.target.dataset.type &&
'nextgen' === e.target.dataset.type
$('.wp-smush-nextgen-bulk').trigger('click');
$('.wp-smush-all').trigger('click');
$('span.sui-notice-dismiss').trigger('click');
$('body').on('click', '#bulk-smush-top-notice-close', function (e) {
$(this).parent().parent().slideUp('slow');
//Allow the checkboxes to be Keyboard Accessible
$('.wp-smush-setting-row .toggle-checkbox').on('focus', function () {
$(this).keypress(function (e) {
$(this).find('.toggle-checkbox').trigger('click');
// Re-Validate Resize Width And Height.
$('body').on('blur', '.wp-smush-resize-input', function () {
const wrapper_div = self.parents().eq(4);
validate_resize_settings(wrapper_div, false, false); // run the validation.
// Handle Resize Checkbox toggle, to show/hide width, height settings.
$('body').on('click', '#resize', function () {
const settings_wrap = $('#smush-resize-settings-wrap');
if (self.is(':checked')) {
//Handle Re-check button functionality
$('#wp-smush-revalidate-member').on('click', function (e) {
action: 'smush_show_warning',
_ajax_nonce: window.wp_smush_msgs.nonce,
const parent = link.parents().eq(1);
parent.addClass('loading-notice');
$.get(ajaxurl, params, function (r) {
parent.removeClass('loading-notice').addClass('loaded-notice');
parent.attr('data-message', wp_smush_msgs.membership_valid);
remove_element(parent, 1000);
parent.attr('data-message', wp_smush_msgs.membership_invalid);
setTimeout(function remove_loader() {
parent.removeClass('loaded-notice');
if ($('li.smush-dir-savings').length > 0) {
// Update Directory Smush, as soon as the page loads.
action: 'get_dir_smush_stats',
_ajax_nonce: window.wp_smush_msgs.nonce,
$.get(ajaxurl, stats_param, function (r) {
$('li.smush-dir-savings .sui-icon-loader').hide();
//If there are no errors, and we have a message to display
if (!r.success && 'undefined' !== typeof r.data.message) {
$('div.wp-smush-scan-result div.content').prepend(
//If there is no value in r
'undefined' === typeof r.data ||
'undefined' === typeof r.data.dir_smush
$('li.smush-dir-savings span.wp-smush-stats').append(
$('li.smush-dir-savings span.wp-smush-stats span').hide();
update_cummulative_stats(r.data);
// Display dialogs that show up with no user action.
if ( $( '#smush-updated-dialog' ).length ) {
// Displays the modal with the release's higlights if it exists.
const modalId = 'smush-updated-dialog',
focusAfterClosed = 'wpbody-content',
focusWhenOpen = undefined,
* Toggle backup notice based on "Optimize original images" setting.
$( 'input#original' ).on( 'change', function() {
$( '#backup-notice' ).toggleClass( 'sui-hidden', $( this ).is(':checked') );
* Bulk compression level notice.
const handleCompressionLevelNotice = () => {
const compressionLevelNotice = document.querySelector( '.wp-smush-compression-type' );
if ( ! compressionLevelNotice ) {
const compressionNoticeContent = compressionLevelNotice.querySelector( '.wp-smush-compression-type_note p' );
if ( ! compressionNoticeContent ) {
compressionLevelNotice.querySelector('.wp-smush-compression-type_slider').addEventListener('change', (e) => {
if ( 'INPUT' !== e?.target?.nodeName ) {
const note = e.target.dataset?.note;
compressionNoticeContent.innerHTML = note.trim();
handleCompressionLevelNotice();
* Close modal and redirect to the href link.
$('.wp-smush-modal-link-close').on( 'click', function( e ) {
const href = $(this).attr('href');
let openNewTab = '_blank' === $(this).attr('target');
window.open( href, '_blank' );
window.location.href = href;
// Update Smush mode on lossy level change.
const updateLossyLevelInSummaryBox = () => {
const lossyLevelSummaryBox = document.querySelector('.wp-smush-current-compression-level');
const currentLossyLevelTab = document.querySelector( '.wp-smush-lossy-level-tabs button.active' );
if ( ! lossyLevelSummaryBox || ! currentLossyLevelTab ) {
lossyLevelSummaryBox.innerText = currentLossyLevelTab.innerText.trim();
// Toggle Ultra notice/upsell link.
const upsellLink = lossyLevelSummaryBox.nextElementSibling;
if ( currentLossyLevelTab.id.includes('ultra') ) {
upsellLink.classList.add( 'sui-hidden' );
upsellLink.classList.remove( 'sui-hidden' );
document.addEventListener( 'onSavedSmushSettings', function( e ) {
if ( ! e?.detail?.is_outdated_stats ) {
updateLossyLevelInSummaryBox();