diff --git a/src/js/_enqueues/lib/nav-menu.js b/src/js/_enqueues/lib/nav-menu.js index 79917c8447f1a..127976de02dda 100644 --- a/src/js/_enqueues/lib/nav-menu.js +++ b/src/js/_enqueues/lib/nav-menu.js @@ -1116,6 +1116,18 @@ } }); + $( '#custom-menu-item-placeholder' ).on( 'change', function() { + if ( $( this ).is( ':checked' ) ) { + $( '#menu-item-url-wrap' ).hide().removeClass( 'has-error' ); + $( '#custom-menu-item-type' ).val( 'placeholder' ); + $( '#custom-menu-item-url' ).removeClass( 'form-invalid' ).removeAttr( 'aria-invalid' ).removeAttr( 'aria-describedby' ); + $( '#custom-url-error' ).hide(); + } else { + $( '#menu-item-url-wrap' ).show(); + $( '#custom-menu-item-type' ).val( 'custom' ); + } + }); + $( '#submit-customlinkdiv' ).on( 'click', function (e) { var urlInput = $( '#custom-menu-item-url' ), url = urlInput.val().trim(), @@ -1127,6 +1139,11 @@ errorMessage.hide(); urlWrap.removeClass( 'has-error' ); + // Placeholder items intentionally have no URL; skip validation. + if ( $( '#custom-menu-item-placeholder' ).is( ':checked' ) ) { + return; + } + /* * Allow URLs including: * - http://example.com/ @@ -1458,6 +1475,22 @@ processMethod = processMethod || api.addMenuItemToBottom; + // Placeholder items skip URL validation and use an empty URL. + if ( $( '#custom-menu-item-placeholder' ).is( ':checked' ) ) { + $( '.customlinkdiv .spinner' ).addClass( 'is-active' ); + api.addItemToMenu( + {'-1': {'menu-item-type': 'placeholder', 'menu-item-url': '', 'menu-item-title': label, 'menu-item-db-id': 0, 'menu-item-object': 'custom', 'menu-item-parent-id': 0}}, + processMethod, + function() { + $( '.customlinkdiv .spinner' ).removeClass( 'is-active' ); + $('#custom-menu-item-name').val('').trigger( 'blur' ); + $( '#custom-menu-item-url' ).val( '' ).attr( 'placeholder', 'https://' ); + $( '#custom-menu-item-placeholder' ).prop( 'checked', false ).trigger( 'change' ); + } + ); + return; + } + /* * Allow URLs including: * - http://example.com/ diff --git a/src/wp-admin/includes/nav-menu.php b/src/wp-admin/includes/nav-menu.php index 70263a2034807..b18740d8e5c85 100644 --- a/src/wp-admin/includes/nav-menu.php +++ b/src/wp-admin/includes/nav-menu.php @@ -361,7 +361,13 @@ function wp_nav_menu_item_link_meta_box() { ?>