: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
import tracker from "../utils/tracker";
* Bulk restore JavaScript code.
modal: document.getElementById('smush-restore-images-dialog'),
contentContainer: document.getElementById('smush-bulk-restore-content'),
slide: 'start', // start, progress or finish.
items: [], // total items, 1 item = 1 step.
success: [], // successful items restored.
errors: [], // failed items.
'smush-restore-images-dialog',
* Update the template, register new listeners.
const template = WP_Smush.onboarding.template('smush-bulk-restore');
const content = template(this.settings);
this.contentContainer.innerHTML = content;
this.modal.style.maxWidth = '460px';
this.modal.querySelector('.sui-box').style.maxWidth = '460px';
* Catch "Finish setup wizard" button click.
const confirmButton = this.modal.querySelector(
'button[id="smush-bulk-restore-button"]'
confirmButton.addEventListener('click', function (e) {
self.settings = { slide: 'progress' };
tracker.track('Bulk Restore Triggered');
* Cancel the bulk restore.
'start' === this.settings.slide ||
'finish' === this.settings.slide
this.updateProgressBar(true);
window.location.reload();
* Update progress bar during directory smush.
* @param {boolean} cancel Cancel status.
updateProgressBar(cancel = false) {
if (0 < this.currentStep) {
Math.round((this.currentStep * 100) / this.totalSteps),
this.modal.querySelector('.sui-progress-text span').innerHTML =
this.modal.querySelector('.sui-progress-bar span').style.width =
const statusDiv = this.modal.querySelector(
'.sui-progress-state-text'
statusDiv.innerHTML = 'Finalizing...';
statusDiv.innerHTML = 'Cancelling...';
* First step in bulk restore - get the bulk attachment count.
const _nonce = document.getElementById('_wpnonce');
const xhr = new XMLHttpRequest();
xhr.open('POST', ajaxurl + '?action=get_image_count', true);
'application/x-www-form-urlencoded'
if (200 === xhr.status) {
const res = JSON.parse(xhr.response);
if ('undefined' !== typeof res.data.items) {
self.items = res.data.items;
self.totalSteps = res.data.items.length;
'Request failed. Returned status of ' + xhr.status
xhr.send('_ajax_nonce=' + _nonce.value);
* Execute a scan step recursively
const _nonce = document.getElementById('_wpnonce');
if (0 < this.items.length) {
const item = this.items.pop();
const xhr = new XMLHttpRequest();
xhr.open('POST', ajaxurl + '?action=restore_step', true);
'application/x-www-form-urlencoded'
if (200 === xhr.status) {
const res = JSON.parse(xhr.response);
const data = ((res || {}).data || {});
src: data.src || "Error",
self.updateProgressBar();
xhr.send('item=' + item + '&_ajax_nonce=' + _nonce.value);
success: this.success.length,
if (0 < this.errors.length) {
this.modal.style.maxWidth = '660px';
this.modal.querySelector('.sui-box').style.maxWidth =
* Template function (underscores based).
WP_Smush.restore.template = _.memoize((id) => {
evaluate: /<#([\s\S]+?)#>/g,
interpolate: /{{{([\s\S]+?)}}}/g,
escape: /{{([^}]+?)}}(?!})/g,
_.templateSettings = options;
compiled || _.template(document.getElementById(id).innerHTML);