: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
import Fetcher from '../utils/fetcher';
nonceField: document.getElementsByName('wp_smush_options_nonce'),
toggleModuleButton: document.getElementById('smush-toggle-webp-button'),
recheckStatusButton: document.getElementById('smush-webp-recheck'),
recheckStatusLink: document.getElementById('smush-webp-recheck-link'),
showWizardButton: document.getElementById('smush-webp-toggle-wizard'),
switchWebpMethod: document.getElementById('smush-switch-webp-method' ),
this.maybeShowDeleteAllSuccessNotice();
* Handles the "Deactivate" and "Get Started" buttons on the WebP page.
if (this.toggleModuleButton) {
this.toggleModuleButton.addEventListener('click', (e) =>
* Handle "RE-CHECK STATUS' button click on WebP page.
if (this.recheckStatusButton) {
this.recheckStatusButton.addEventListener('click', (e) => {
* Handle "RE-CHECK STATUS' link click on WebP page.
if (this.recheckStatusLink) {
this.recheckStatusLink.addEventListener('click', (e) => {
* Handles the "Delete WebP images" button.
if (document.getElementById('wp-smush-webp-delete-all')) {
.getElementById('wp-smush-webp-delete-all')
.addEventListener('click', (e) => this.deleteAll(e));
if (this.showWizardButton) {
this.showWizardButton.addEventListener(
if ( this.switchWebpMethod ) {
this.switchWebpMethod.addEventListener(
e.target.classList.add('wp-smush-link-in-progress');
this.switchMethod( this.switchWebpMethod.dataset.method );
switchMethod( newMethod ) {
Fetcher.webp.switchMethod( newMethod ).then( ( res ) => {
WP_Smush.helpers.showNotice( res );
window.location.reload();
const button = e.currentTarget,
doEnable = 'enable' === button.dataset.action;
button.classList.add('sui-button-onload');
const xhr = new XMLHttpRequest();
xhr.open('POST', ajaxurl + '?action=smush_webp_toggle', true);
'application/x-www-form-urlencoded'
const res = JSON.parse(xhr.response);
if (200 === xhr.status) {
if ('undefined' !== typeof res.success && res.success) {
const scanPromise = this.runScan();
scanPromise.onload = () => {
window.wp_smush_msgs.localWebpURL;
} else if ('undefined' !== typeof res.data.message) {
this.showNotice(res.data.message);
button.classList.remove('sui-button-onload');
let message = window.wp_smush_msgs.generic_ajax_error;
if (res && 'undefined' !== typeof res.data.message) {
message = res.data.message;
this.showNotice(message);
button.classList.remove('sui-button-onload');
'param=' + doEnable + '&_ajax_nonce=' + this.nonceField[0].value
* re-check server configuration for WebP.
this.recheckStatusButton.classList.add('sui-button-onload');
const xhr = new XMLHttpRequest();
xhr.open('POST', ajaxurl + '?action=smush_webp_get_status', true);
'application/x-www-form-urlencoded'
this.recheckStatusButton.classList.remove('sui-button-onload');
const res = JSON.parse(xhr.response);
if (200 === xhr.status) {
const isConfigured = res.success ? '1' : '0';
this.recheckStatusButton.dataset.isConfigured
// Reload the page when the configuration status changed.
message = window.wp_smush_msgs.generic_ajax_error;
this.showNotice(message);
xhr.send('_ajax_nonce=' + window.wp_smush_msgs.webp_nonce);
const button = e.currentTarget;
button.classList.add('sui-button-onload');
const xhr = new XMLHttpRequest();
xhr.open('POST', ajaxurl + '?action=smush_webp_delete_all', true);
'application/x-www-form-urlencoded'
const res = JSON.parse(xhr.response);
if (200 === xhr.status) {
if ('undefined' !== typeof res.success && res.success) {
const scanPromise = this.runScan();
scanPromise.onload = () => {
location.search + '¬ice=webp-deleted';
message = window.wp_smush_msgs.generic_ajax_error;
message = window.wp_smush_msgs.generic_ajax_error;
if (res && res.data && res.data.message) {
message = res.data.message;
button.classList.remove('sui-button-onload');
const noticeMessage = `<p style="text-align: left;">${message}</p>`;
'wp-smush-webp-delete-all-error-notice',
xhr.send('_ajax_nonce=' + this.nonceField[0].value);
e.currentTarget.classList.add('sui-button-onload');
const xhr = new XMLHttpRequest();
'?action=smush_toggle_webp_wizard&_ajax_nonce=' +
window.wp_smush_msgs.webp_nonce,
xhr.onload = () => location.href = window.wp_smush_msgs.localWebpURL;
* Triggers the scanning of images for updating the images to re-smush.
const xhr = new XMLHttpRequest(),
nonceField = document.getElementsByName(
xhr.open('POST', ajaxurl + '?action=scan_for_resmush', true);
'application/x-www-form-urlencoded'
xhr.send('_ajax_nonce=' + nonceField[0].value);
* @param {string} message
showNotice(message, type) {
if ('undefined' === typeof message) {
const noticeMessage = `<p>${message}</p>`;
label: window.wp_smush_msgs.noticeDismiss,
tooltip: window.wp_smush_msgs.noticeDismissTooltip,
* Show delete all webp success notice.
maybeShowDeleteAllSuccessNotice() {
if (!document.getElementById('wp-smush-webp-delete-all-notice')) {
const noticeMessage = `<p>${
document.getElementById('wp-smush-webp-delete-all-notice')
'wp-smush-webp-delete-all-notice',