: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
if ( isPrimaryMenuItem ) {
primaryItems = $( '.menu-item-depth-0' ),
itemPosition = primaryItems.index( menuItem ) + 1,
totalMenuItems = primaryItems.length,
// String together help text for primary menu items.
title = menus.menuFocus.replace( '%1$s', itemName ).replace( '%2$s', menuItemType ).replace( '%3$d', itemPosition ).replace( '%4$d', totalMenuItems );
parentItem = menuItem.prevAll( '.menu-item-depth-' + parseInt( depth - 1, 10 ) ).first(),
parentItemId = parentItem.find( '.menu-item-data-db-id' ).val(),
parentItemName = parentItem.find( '.menu-item-title' ).text(),
subItems = $( '.menu-item .menu-item-data-parent-id[value="' + parentItemId + '"]' ),
totalSubItems = subItems.length,
itemPosition = $( subItems.parents('.menu-item').get().reverse() ).index( menuItem ) + 1;
// String together help text for sub menu items.
title = menus.subMenuFocus.replace( '%1$s', itemName ).replace( '%2$s', menuItemType ).replace( '%3$d', itemPosition ).replace( '%4$d', totalSubItems ).replace( '%5$s', parentItemName );
title = menus.subMenuMoreDepthFocus.replace( '%1$s', itemName ).replace( '%2$s', menuItemType ).replace( '%3$d', itemPosition ).replace( '%4$d', totalSubItems ).replace( '%5$s', parentItemName ).replace( '%6$d', depth );
$this.attr( 'aria-label', title );
// Mark this item's accessibility as refreshed.
$this.data( 'needs_accessibility_refresh', false );
* refreshAdvancedAccessibility
* Hides all advanced accessibility buttons and marks them for refreshing.
refreshAdvancedAccessibility : function() {
// Hide all the move buttons by default.
$( '.menu-item-settings .field-move .menus-move' ).hide();
// Mark all menu items as unprocessed.
$( 'a.item-edit' ).data( 'needs_accessibility_refresh', true );
// All open items have to be refreshed or they will show no links.
$( '.menu-item-edit-active a.item-edit' ).each( function() {
api.refreshAdvancedAccessibilityOfItem( this );
refreshKeyboardAccessibility : function() {
$( 'a.item-edit' ).off( 'focus' ).on( 'focus', function(){
$(this).off( 'keydown' ).on( 'keydown', function(e){
thisItem = $this.parents( 'li.menu-item' ),
thisItemData = thisItem.getItemData();
// Bail if it's not an arrow key.
if ( 37 != e.which && 38 != e.which && 39 != e.which && 40 != e.which )
// Avoid multiple keydown events.
// Bail if there is only one menu item.
if ( 1 === $('#menu-to-edit li').length )
// If RTL, swap left/right arrows.
arrows = { '38': 'up', '40': 'down', '37': 'left', '39': 'right' };
if ( $('body').hasClass('rtl') )
arrows = { '38' : 'up', '40' : 'down', '39' : 'left', '37' : 'right' };
switch ( arrows[e.which] ) {
api.moveMenuItem( $this, 'up' );
api.moveMenuItem( $this, 'down' );
api.moveMenuItem( $this, 'left' );
api.moveMenuItem( $this, 'right' );
// Put focus back on same menu item.
$( '#edit-' + thisItemData['menu-item-db-id'] ).trigger( 'focus' );
initPreviewing : function() {
// Update the item handle title when the navigation label is changed.
$( '#menu-to-edit' ).on( 'change input', '.edit-menu-item-title', function(e) {
var input = $( e.currentTarget ), title, titleEl;
titleEl = input.closest( '.menu-item' ).find( '.menu-item-title' );
// Don't update to empty title.
titleEl.text( title ).removeClass( 'no-title' );
titleEl.text( wp.i18n._x( '(no label)', 'missing menu item navigation label' ) ).addClass( 'no-title' );
initToggles : function() {
postboxes.add_postbox_toggles('nav-menus');
// Adjust columns functions for menus UI.
columns.useCheckboxesForHidden();
columns.checked = function(field) {
$('.field-' + field).removeClass('hidden-field');
columns.unchecked = function(field) {
$('.field-' + field).addClass('hidden-field');
api.menuList.hideAdvancedMenuItemFields();
$('.hide-postbox-tog').on( 'click', function () {
var hidden = $( '.accordion-container li.accordion-section' ).filter(':hidden').map(function() { return this.id; }).get().join(',');
action: 'closed-postboxes',
closedpostboxesnonce: jQuery('#closedpostboxesnonce').val(),
initSortables : function() {
var currentDepth = 0, originalDepth, minDepth, maxDepth,
prev, next, prevBottom, nextThreshold, helperHeight, transport,
menuEdge = api.menuList.offset().left,
body = $('body'), maxChildDepth,
menuMaxDepth = initialMenuMaxDepth();
if( 0 !== $( '#menu-to-edit li' ).length )
$( '.drag-instructions' ).show();
// Use the right edge if RTL.
menuEdge += api.isRTL ? api.menuList.width() : 0;
handle: '.menu-item-handle',
placeholder: 'sortable-placeholder',
items: api.options.sortableItems,
var height, width, parent, children, tempHolder;
// Handle placement for RTL orientation.
ui.item[0].style.right = 'auto';
transport = ui.item.children('.menu-item-transport');
// Set depths. currentDepth must be set before children are located.
originalDepth = ui.item.menuItemDepth();
updateCurrentDepth(ui, originalDepth);
// Attach child elements to parent.
parent = ( ui.item.next()[0] == ui.placeholder[0] ) ? ui.item.next() : ui.item;
children = parent.childMenuItems();
transport.append( children );
// Update the height of the placeholder to match the moving item.
height = transport.outerHeight();
// If there are children, account for distance between top of children and parent.
height += ( height > 0 ) ? (ui.placeholder.css('margin-top').slice(0, -2) * 1) : 0;
height += ui.helper.outerHeight();
height -= 2; // Subtract 2 for borders.
ui.placeholder.height(height);
// Update the width of the placeholder to match the moving item.
maxChildDepth = originalDepth;
children.each(function(){
var depth = $(this).menuItemDepth();
maxChildDepth = (depth > maxChildDepth) ? depth : maxChildDepth;
width = ui.helper.find('.menu-item-handle').outerWidth(); // Get original width.
width += api.depthToPx(maxChildDepth - originalDepth); // Account for children.
width -= 2; // Subtract 2 for borders.
ui.placeholder.width(width);
// Update the list of menu items.
tempHolder = ui.placeholder.next( '.menu-item' );
tempHolder.css( 'margin-top', helperHeight + 'px' ); // Set the margin to absorb the placeholder.
ui.placeholder.detach(); // Detach or jQuery UI will think the placeholder is a menu item.
$(this).sortable( 'refresh' ); // The children aren't sortable. We should let jQuery UI know.
ui.item.after( ui.placeholder ); // Reattach the placeholder.
tempHolder.css('margin-top', 0); // Reset the margin.
// Now that the element is complete, we can update...
var children, subMenuTitle,
depthChange = currentDepth - originalDepth;
// Return child elements to the list.
children = transport.children().insertAfter(ui.item);
// Add "sub menu" description.
subMenuTitle = ui.item.find( '.item-title .is-submenu' );
if ( 0 !== depthChange ) {
ui.item.updateDepthClass( currentDepth );
children.shiftDepthClass( depthChange );
updateMenuMaxDepth( depthChange );
ui.item.updateParentMenuItemDBId();
// Address sortable's incorrectly-calculated top in Opera.
ui.item[0].style.top = 0;
// Handle drop placement for rtl orientation.
ui.item[0].style.left = 'auto';
ui.item[0].style.right = 0;
api.refreshKeyboardAccessibility();
api.refreshAdvancedAccessibility();
api.refreshAdvancedAccessibilityOfItem( ui.item.find( 'a.item-edit' ) );
change: function(e, ui) {
// Make sure the placeholder is inside the menu.
// Otherwise fix it, or we're in trouble.
if( ! ui.placeholder.parent().hasClass('menu') )
(prev.length) ? prev.after( ui.placeholder ) : api.menuList.prepend( ui.placeholder );
var offset = ui.helper.offset(),
edge = api.isRTL ? offset.left + ui.helper.width() : offset.left,
depth = api.negateIfRTL * api.pxToDepth( edge - menuEdge );
* Check and correct if depth is not within range.
* Also, if the dragged element is dragged upwards over an item,
* shift the placeholder to a child position.
if ( depth > maxDepth || offset.top < ( prevBottom - api.options.targetTolerance ) ) {
} else if ( depth < minDepth ) {
if( depth != currentDepth )
updateCurrentDepth(ui, depth);
// If we overlap the next element, manually shift downwards.
if( nextThreshold && offset.top + helperHeight > nextThreshold ) {
next.after( ui.placeholder );
$( this ).sortable( 'refreshPositions' );
function updateSharedVars(ui) {
prev = ui.placeholder.prev( '.menu-item' );
next = ui.placeholder.next( '.menu-item' );
// Make sure we don't select the moving item.
if( prev[0] == ui.item[0] ) prev = prev.prev( '.menu-item' );
if( next[0] == ui.item[0] ) next = next.next( '.menu-item' );
prevBottom = (prev.length) ? prev.offset().top + prev.height() : 0;
nextThreshold = (next.length) ? next.offset().top + next.height() / 3 : 0;
minDepth = (next.length) ? next.menuItemDepth() : 0;
maxDepth = ( (depth = prev.menuItemDepth() + 1) > api.options.globalMaxDepth ) ? api.options.globalMaxDepth : depth;
function updateCurrentDepth(ui, depth) {
ui.placeholder.updateDepthClass( depth, currentDepth );
function initialMenuMaxDepth() {
if( ! body[0].className ) return 0;
var match = body[0].className.match(/menu-max-depth-(\d+)/);
return match && match[1] ? parseInt( match[1], 10 ) : 0;
function updateMenuMaxDepth( depthChange ) {
var depth, newDepth = menuMaxDepth;
if ( depthChange === 0 ) {
} else if ( depthChange > 0 ) {
depth = maxChildDepth + depthChange;
if( depth > menuMaxDepth )
} else if ( depthChange < 0 && maxChildDepth == menuMaxDepth ) {
while( ! $('.menu-item-depth-' + newDepth, api.menuList).length && newDepth > 0 )
// Update the depth class.
body.removeClass( 'menu-max-depth-' + menuMaxDepth ).addClass( 'menu-max-depth-' + newDepth );
initManageLocations : function () {
$('#menu-locations-wrap form').on( 'submit', function(){
window.onbeforeunload = null;
$('.menu-location-menus select').on('change', function () {
var editLink = $(this).closest('tr').find('.locations-edit-menu-link');
if ($(this).find('option:selected').data('orig'))
attachMenuEditListeners : function() {
$('#update-nav-menu').on('click', function(e) {
if ( e.target && e.target.className ) {
if ( -1 != e.target.className.indexOf('item-edit') ) {
return that.eventOnClickEditLink(e.target);
} else if ( -1 != e.target.className.indexOf('menu-save') ) {
return that.eventOnClickMenuSave(e.target);
} else if ( -1 != e.target.className.indexOf('menu-delete') ) {
return that.eventOnClickMenuDelete(e.target);
} else if ( -1 != e.target.className.indexOf('item-delete') ) {
return that.eventOnClickMenuItemDelete(e.target);
} else if ( -1 != e.target.className.indexOf('item-cancel') ) {
return that.eventOnClickCancelLink(e.target);
$( '#menu-name' ).on( 'input', _.debounce( function () {
var menuName = $( document.getElementById( 'menu-name' ) ),
menuNameVal = menuName.val();
if ( ! menuNameVal || ! menuNameVal.replace( /\s+/, '' ) ) {
// Add warning for invalid menu name.
menuName.parent().addClass( 'form-invalid' );
// Remove warning for valid menu name.
menuName.parent().removeClass( 'form-invalid' );
$('#add-custom-links input[type="text"]').on( 'keypress', function(e){
$('#customlinkdiv').removeClass('form-invalid');
if ( e.keyCode === 13 ) {
$( '#submit-customlinkdiv' ).trigger( 'click' );
* Handle toggling bulk selection checkboxes for menu items.
attachBulkSelectButtonListeners : function() {
$( '.bulk-select-switcher' ).on( 'change', function() {
$( '.bulk-select-switcher' ).prop( 'checked', true );
that.enableBulkSelection();
$( '.bulk-select-switcher' ).prop( 'checked', false );
that.disableBulkSelection();
* Enable bulk selection checkboxes for menu items.
enableBulkSelection : function() {
var checkbox = $( '#menu-to-edit .menu-item-checkbox' );
$( '#menu-to-edit' ).addClass( 'bulk-selection' );
$( '#nav-menu-bulk-actions-top' ).addClass( 'bulk-selection' );
$( '#nav-menu-bulk-actions-bottom' ).addClass( 'bulk-selection' );
$.each( checkbox, function() {
$(this).prop( 'disabled', false );
* Disable bulk selection checkboxes for menu items.
disableBulkSelection : function() {
var checkbox = $( '#menu-to-edit .menu-item-checkbox' );
$( '#menu-to-edit' ).removeClass( 'bulk-selection' );
$( '#nav-menu-bulk-actions-top' ).removeClass( 'bulk-selection' );
$( '#nav-menu-bulk-actions-bottom' ).removeClass( 'bulk-selection' );
if ( $( '.menu-items-delete' ).is( '[aria-describedby="pending-menu-items-to-delete"]' ) ) {
$( '.menu-items-delete' ).removeAttr( 'aria-describedby' );
$.each( checkbox, function() {
$(this).prop( 'disabled', true ).prop( 'checked', false );
$( '.menu-items-delete' ).addClass( 'disabled' );
$( '#pending-menu-items-to-delete ul' ).empty();
* Listen for state changes on bulk action checkboxes.
attachMenuCheckBoxListeners : function() {
$( '#menu-to-edit' ).on( 'change', '.menu-item-checkbox', function() {
that.setRemoveSelectedButtonStatus();
* Create delete button to remove menu items from collection.
attachMenuItemDeleteButton : function() {
$( document ).on( 'click', '.menu-items-delete', function( e ) {
var itemsPendingDeletion, itemsPendingDeletionList, deletionSpeech;
if ( ! $(this).hasClass( 'disabled' ) ) {
$.each( $( '.menu-item-checkbox:checked' ), function( index, element ) {
$( element ).parents( 'li' ).find( 'a.item-delete' ).trigger( 'click' );
$( '.menu-items-delete' ).addClass( 'disabled' );
$( '.bulk-select-switcher' ).prop( 'checked', false );
itemsPendingDeletion = '';
itemsPendingDeletionList = $( '#pending-menu-items-to-delete ul li' );
$.each( itemsPendingDeletionList, function( index, element ) {
var itemName = $( element ).find( '.pending-menu-item-name' ).text();
var itemSpeech = menus.menuItemDeletion.replace( '%s', itemName );
itemsPendingDeletion += itemSpeech;
if ( ( index + 1 ) < itemsPendingDeletionList.length ) {
itemsPendingDeletion += ', ';
deletionSpeech = menus.itemsDeleted.replace( '%s', itemsPendingDeletion );
wp.a11y.speak( deletionSpeech, 'polite' );
that.disableBulkSelection();
* List menu items awaiting deletion.
attachPendingMenuItemsListForDeletion : function() {