: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$('div.widgets-sortables').each( function() {
if ( $(this).sortable ) {
data['sidebars[' + $(this).attr('id') + ']'] = $(this).sortable('toArray').join(',');
$.post( ajaxurl, data, function() {
$( '#inactive-widgets-control-remove' ).prop( 'disabled' , ! $( '#wp_inactive_widgets .widget' ).length );
$( '.spinner' ).removeClass( 'is-active' );
save : function( widget, del, animate, order ) {
var self = this, data, a,
sidebarId = widget.closest( 'div.widgets-sortables' ).attr( 'id' ),
form = widget.find( 'form' ),
isAdd = widget.find( 'input.add_new' ).val();
if ( ! del && ! isAdd && form.prop( 'checkValidity' ) && ! form[0].checkValidity() ) {
$( '.spinner', widget ).addClass( 'is-active' );
savewidgets: $('#_wpnonce_widgets').val(),
data += '&' + $.param(a);
$.post( ajaxurl, data, function(r) {
var id = $('input.widget-id', widget).val();
if ( ! $('input.widget_number', widget).val() ) {
$('#available-widgets').find('input.widget-id').each(function(){
if ( $(this).val() === id ) {
$(this).closest('div.widget').show();
widget.slideUp( 'fast', function() {
delete self.dirtyWidgets[ id ];
delete self.dirtyWidgets[ id ];
if ( sidebarId === 'wp_inactive_widgets' ) {
$( '#inactive-widgets-control-remove' ).prop( 'disabled' , ! $( '#wp_inactive_widgets .widget' ).length );
$( '.spinner' ).removeClass( 'is-active' );
if ( r && r.length > 2 ) {
$( 'div.widget-content', widget ).html( r );
wpWidgets.appendTitle( widget );
// Re-disable the save button.
widget.find( '.widget-control-save' ).prop( 'disabled', true ).val( wp.i18n.__( 'Saved' ) );
widget.removeClass( 'widget-dirty' );
// Clear the dirty flag from the widget.
delete self.dirtyWidgets[ id ];
$document.trigger( 'widget-updated', [ widget ] );
if ( sidebarId === 'wp_inactive_widgets' ) {
$( '#inactive-widgets-control-remove' ).prop( 'disabled' , ! $( '#wp_inactive_widgets .widget' ).length );
removeInactiveWidgets : function() {
var $element = $( '.remove-inactive-widgets' ), self = this, a, data;
$( '.spinner', $element ).addClass( 'is-active' );
action : 'delete-inactive-widgets',
removeinactivewidgets : $( '#_wpnonce_remove_inactive_widgets' ).val()
$.post( ajaxurl, data, function() {
$( '#wp_inactive_widgets .widget' ).each(function() {
delete self.dirtyWidgets[ $widget.find( 'input.widget-id' ).val() ];
$( '#inactive-widgets-control-remove' ).prop( 'disabled', true );
$( '.spinner', $element ).removeClass( 'is-active' );
appendTitle : function(widget) {
var title = $('input[id*="-title"]', widget).val() || '';
title = ': ' + title.replace(/<[^<>]+>/g, '').replace(/</g, '<').replace(/>/g, '>');
$(widget).children('.widget-top').children('.widget-title').children()
.children('.in-widget-title').html(title);
close : function(widget) {
widget.children('.widget-inside').slideUp('fast', function() {
widget.attr( 'style', '' )
.find( '.widget-top button.widget-action' )
.attr( 'aria-expanded', 'false' )
addWidget: function( chooser ) {
var widget, widgetId, add, n, viewportTop, viewportBottom, sidebarBounds,
sidebarId = chooser.find( '.widgets-chooser-selected' ).data('sidebarId'),
sidebar = $( '#' + sidebarId );
widget = $('#available-widgets').find('.widget-in-question').clone();
widgetId = widget.attr('id');
add = widget.find( 'input.add_new' ).val();
n = widget.find( 'input.multi_number' ).val();
// Remove the cloned chooser from the widget.
widget.find('.widgets-chooser').remove();
widget.html().replace( /<[^<>]+>/g, function(m) {
return m.replace( /__i__|%i%/g, n );
widget.attr( 'id', widgetId.replace( '__i__', n ) );
$( '#' + widgetId ).find('input.multi_number').val(n);
} else if ( 'single' === add ) {
widget.attr( 'id', 'new-' + widgetId );
$( '#' + widgetId ).hide();
// Open the widgets container.
sidebar.closest( '.widgets-holder-wrap' )
.find( '.handlediv' ).attr( 'aria-expanded', 'true' );
sidebar.append( widget );
sidebar.sortable('refresh');
wpWidgets.save( widget, 0, 0, 1 );
// No longer "new" widget.
widget.find( 'input.add_new' ).val('');
$document.trigger( 'widget-added', [ widget ] );
* Check if any part of the sidebar is visible in the viewport. If it is, don't scroll.
* Otherwise, scroll up to so the sidebar is in view.
* We do this by comparing the top and bottom, of the sidebar so see if they are within
* the bounds of the viewport.
viewportTop = $(window).scrollTop();
viewportBottom = viewportTop + $(window).height();
sidebarBounds = sidebar.offset();
sidebarBounds.bottom = sidebarBounds.top + sidebar.outerHeight();
if ( viewportTop > sidebarBounds.bottom || viewportBottom < sidebarBounds.top ) {
$( 'html, body' ).animate({
scrollTop: sidebarBounds.top - 130
window.setTimeout( function() {
// Cannot use a callback in the animation above as it fires twice,
// have to queue this "by hand".
widget.find( '.widget-title' ).trigger('click');
// At the end of the animation, announce the widget has been added.
window.wp.a11y.speak( wp.i18n.__( 'Widget has been added to the selected sidebar' ), 'assertive' );
closeChooser: function() {
widgetInQuestion = $( '#available-widgets .widget-in-question' );
$( '.widgets-chooser' ).slideUp( 200, function() {
$( '#wpbody-content' ).append( this );
self.clearWidgetSelection();
// Move focus back to the toggle button.
widgetInQuestion.find( '.widget-action' ).attr( 'aria-expanded', 'false' ).focus();
clearWidgetSelection: function() {
$( '#widgets-left' ).removeClass( 'chooser' );
$( '.widget-in-question' ).removeClass( 'widget-in-question' );
* Closes a Sidebar that was previously closed, but opened by dragging a Widget over it.
* Used when a Widget gets dragged in/out of the Sidebar and never dropped.
* @param {Object} event jQuery event object.
closeSidebar: function( event ) {
.find( '.handlediv' ).attr( 'aria-expanded', 'false' );
$( event.target ).css( 'min-height', '' );
this.hoveredSidebar = null;
$( function(){ wpWidgets.init(); } );
* Removed in 5.5.0, needed for back-compatibility.
wpWidgets.l10n = wpWidgets.l10n || {
wpWidgets.l10n = window.wp.deprecateL10nObject( 'wpWidgets.l10n', wpWidgets.l10n, '5.5.0' );