: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
/* global wp_smush_msgs */
$( 'form#smush-bulk-form' ).on( 'submit', function( e ) {
$( '#save-settings-button' ).addClass( 'sui-button-onload' );
saveSettings( $( this ).serialize(), 'bulk' );
$( 'form#smush-lazy-load-form' ).on( 'submit', function( e ) {
$( '#save-settings-button' ).addClass( 'sui-button-onload-text' );
saveSettings( $( this ).serialize(), 'lazy-load' );
$( 'form#smush-cdn-form' ).on( 'submit', function( e ) {
$( '#save-settings-button' ).addClass( 'sui-button-onload-text' );
saveSettings( $( this ).serialize(), 'cdn' );
$( 'form#smush-webp-form' ).on( 'submit', function( e ) {
$( '#save-settings-button' ).addClass( 'sui-button-onload-text' );
saveSettings( $( this ).serialize(), 'webp' );
$( 'form#smush-integrations-form' ).on( 'submit', function( e ) {
$( '#save-settings-button' ).addClass( 'sui-button-onload-text' );
saveSettings( $( this ).serialize(), 'integrations' );
$( 'form#smush-settings-form' ).on( 'submit', function( e ) {
$( '#save-settings-button' ).addClass( 'sui-button-onload-text' );
saveSettings( $( this ).serialize(), 'settings' );
* @param {string} settings JSON string of settings.
* @param {string} page Settings page.
function saveSettings( settings, page ) {
const xhr = new XMLHttpRequest();
xhr.open( 'POST', ajaxurl + '?action=smush_save_settings', true );
'application/x-www-form-urlencoded'
$( '#save-settings-button' ).removeClass(
'sui-button-onload-text sui-button-onload'
if ( 200 === xhr.status ) {
const res = JSON.parse( xhr.response );
if ( 'undefined' !== typeof res.success && res.success ) {
showSuccessNotice( wp_smush_msgs.settingsUpdated );
triggerSavedSmushSettingsEvent( res.data );
} else if ( res.data && res.data.message ) {
WP_Smush.helpers.showErrorNotice( res.data.message );
WP_Smush.helpers.showErrorNotice( 'Request failed.' );
WP_Smush.helpers.showErrorNotice( 'Request failed. Returned status of ' + xhr.status );
xhr.send( 'page=' + page + '&' + settings + '&_ajax_nonce=' + wp_smush_msgs.nonce );
function triggerSavedSmushSettingsEvent( status ) {
new CustomEvent( 'onSavedSmushSettings', {
* Show successful update notice.
* @param {string} msg Notice message.
function showSuccessNotice( msg ) {
const noticeMessage = `<p>${ msg }</p>`,
SUI.openNotice( 'wp-smush-ajax-notice', noticeMessage, noticeOptions );
const loadingButton = document.querySelector( '.sui-button-onload' );
loadingButton.classList.remove( 'sui-button-onload' );
* Re-check images from bulk smush and integrations pages.
$( '#save-settings-button' ).addClass( 'sui-button-onload' );
action: 'scan_for_resmush',
wp_smush_options_nonce: $( '#wp_smush_options_nonce' ).val(),
// Send ajax, Update Settings, And Check For resmush.
$.post( ajaxurl, $.param( param ) ).done( function() {
$( '#save-settings-button' ).removeClass( 'sui-button-onload' );
* Parse remove data change.
$( 'input[name=keep_data]' ).on( 'change', function( e ) {
'keep_data-true' === e.target.id
e.target.parentNode.classList.add( 'active' );
.getElementById( otherClass )
.parentNode.classList.remove( 'active' );
* Handle auto-detect checkbox toggle, to show/hide highlighting notice.
$( 'input#detection' ).on( 'click', function() {
const noticeDiv = $( '.smush-highlighting-notice' );
const warningDiv = $( '.smush-highlighting-warning' );
if ( $( this ).is( ':checked' ) ) {
// Highlighting is already active and setting not saved.
if ( noticeDiv.length > 0 ) {