: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
cdnEnableButton: document.getElementById( 'smush-enable-cdn' ),
cdnDisableButton: document.getElementById( 'smush-cancel-cdn' ),
cdnStatsBox: document.querySelector( '.smush-cdn-stats' ),
* Handle "Get Started" button click on disabled CDN page.
if ( this.cdnEnableButton ) {
this.cdnEnableButton.addEventListener( 'click', ( e ) => {
e.currentTarget.classList.add( 'sui-button-onload' );
* Handle "Deactivate' button click on CDN page.
if ( this.cdnDisableButton ) {
this.cdnDisableButton.addEventListener( 'click', ( e ) => {
e.currentTarget.classList.add( 'sui-button-onload' );
this.toggle_cdn( false );
* @param {boolean} enable
const nonceField = document.getElementsByName(
const xhr = new XMLHttpRequest();
xhr.open( 'POST', ajaxurl + '?action=smush_toggle_cdn', true );
'application/x-www-form-urlencoded'
if ( 200 === xhr.status ) {
const res = JSON.parse( xhr.response );
if ( 'undefined' !== typeof res.success && res.success ) {
WP_Smush.helpers.redirectToPage( 'cdn' );
} else if ( 'undefined' !== typeof res.data.message ) {
WP_Smush.helpers.showErrorNotice( res.data.message );
WP_Smush.helpers.showErrorNotice( 'Request failed. Returned status of ' + xhr.status );
'param=' + enable + '&_ajax_nonce=' + nonceField[ 0 ].value
* Update the CDN stats box in summary meta box. Only fetch new data when on CDN page.
'undefined' === typeof this.cdnStatsBox ||
// Only fetch the new stats, when user is on CDN page.
if ( ! window.location.search.includes( 'page=smush-cdn' ) ) {
const xhr = new XMLHttpRequest();
xhr.open( 'POST', ajaxurl + '?action=get_cdn_stats', true );
if ( 200 === xhr.status ) {
const res = JSON.parse( xhr.response );
if ( 'undefined' !== typeof res.success && res.success ) {
} else if ( 'undefined' !== typeof res.data.message ) {
WP_Smush.helpers.showErrorNotice( res.data.message );
WP_Smush.helpers.showErrorNotice( 'Request failed. Returned status of ' + xhr.status );
* Show/hide elements during status update in the updateStatsBox()
* @since 3.1 Moved out from updateStatsBox()
const spinner = this.cdnStatsBox.querySelector(
const elements = this.cdnStatsBox.querySelectorAll(
'.wp-smush-stats > :not(.sui-icon-loader)'
for ( let i = 0; i < elements.length; i++ ) {
elements[ i ].classList.toggle( 'sui-hidden' );
spinner.classList.toggle( 'sui-hidden' );