diff --git a/src/js/_enqueues/lib/nav-menu.js b/src/js/_enqueues/lib/nav-menu.js
index 9877f78217..077e106e57 100644
a
|
b
|
|
589 | 589 | }, |
590 | 590 | |
591 | 591 | initPreviewing : function() { |
| 592 | |
| 593 | const menuToEdit = $( '#menu-to-edit' ); |
| 594 | |
592 | 595 | // Update the item handle title when the navigation label is changed. |
593 | | $( '#menu-to-edit' ).on( 'change input', '.edit-menu-item-title', function(e) { |
| 596 | menuToEdit.on( 'change input', '.edit-menu-item-title', function(e) { |
594 | 597 | var input = $( e.currentTarget ), title, titleEl; |
595 | 598 | title = input.val(); |
596 | 599 | titleEl = input.closest( '.menu-item' ).find( '.menu-item-title' ); |
… |
… |
|
601 | 604 | titleEl.text( wp.i18n._x( '(no label)', 'missing menu item navigation label' ) ).addClass( 'no-title' ); |
602 | 605 | } |
603 | 606 | } ); |
| 607 | |
| 608 | // Show warning when url is empty/invalid in custom menu item type. |
| 609 | menuToEdit.on( 'change input', '.edit-menu-item-url', function( e ) { |
| 610 | |
| 611 | const input = $( e.currentTarget ); |
| 612 | const url = input.val(); |
| 613 | const urlEl = input.closest( '.menu-item' ).find( '.field-url' ); |
| 614 | |
| 615 | if ( '' === url || 'https://' === url || 'http://' === url ) { |
| 616 | |
| 617 | urlEl.addClass( 'form-invalid' ); |
| 618 | urlEl.attr( 'placeholder', 'https://' ); |
| 619 | |
| 620 | } else { |
| 621 | |
| 622 | urlEl.removeClass( 'form-invalid' ); |
| 623 | urlEl.attr( 'placeholder', '' ); |
| 624 | |
| 625 | } |
| 626 | } ); |
604 | 627 | }, |
605 | 628 | |
606 | 629 | initToggles : function() { |
… |
… |
|
1063 | 1086 | }, |
1064 | 1087 | |
1065 | 1088 | attachMenuSaveSubmitListeners : function() { |
| 1089 | const updateNavMenuEl = $( '#update-nav-menu' ); |
| 1090 | |
1066 | 1091 | /* |
1067 | 1092 | * When a navigation menu is saved, store a JSON representation of all form data |
1068 | 1093 | * in a single input to avoid PHP `max_input_vars` limitations. See #14134. |
1069 | 1094 | */ |
1070 | | $( '#update-nav-menu' ).on( 'submit', function() { |
1071 | | var navMenuData = $( '#update-nav-menu' ).serializeArray(); |
| 1095 | updateNavMenuEl.on( 'submit', function() { |
| 1096 | |
| 1097 | // Stop saving of menu if it has invalid field. |
| 1098 | if ( updateNavMenuEl.has( '.form-invalid' ).length > 0 ) { |
| 1099 | |
| 1100 | updateNavMenuEl.find( '.form-invalid' ).each( function () { |
| 1101 | |
| 1102 | const menuItem = $( this ).closest( '.menu-item' ); |
| 1103 | |
| 1104 | // Open all the menu items containing invalid fields. |
| 1105 | if( menuItem.hasClass( 'menu-item-edit-inactive' ) ) { |
| 1106 | |
| 1107 | menuItem.find( '.menu-item-settings' ).slideDown( 'fast' ); |
| 1108 | menuItem.removeClass('menu-item-edit-inactive') |
| 1109 | .addClass('menu-item-edit-active'); |
| 1110 | |
| 1111 | } |
| 1112 | } ); |
| 1113 | |
| 1114 | return false; |
| 1115 | } |
| 1116 | |
| 1117 | var navMenuData = updateNavMenuEl.serializeArray(); |
1072 | 1118 | $( '[name="nav-menu-data"]' ).val( JSON.stringify( navMenuData ) ); |
1073 | 1119 | }); |
1074 | 1120 | }, |
diff --git a/src/wp-admin/includes/class-walker-nav-menu-edit.php b/src/wp-admin/includes/class-walker-nav-menu-edit.php
index 7cc7052cdb..1e67d7458a 100644
a
|
b
|
class Walker_Nav_Menu_Edit extends Walker_Nav_Menu { |
196 | 196 | <p class="field-url description description-wide"> |
197 | 197 | <label for="edit-menu-item-url-<?php echo $item_id; ?>"> |
198 | 198 | <?php _e( 'URL' ); ?><br /> |
199 | | <input type="text" id="edit-menu-item-url-<?php echo $item_id; ?>" class="widefat code edit-menu-item-url" name="menu-item-url[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->url ); ?>" /> |
| 199 | <input type="text" id="edit-menu-item-url-<?php echo $item_id; ?>" class="widefat code form-required edit-menu-item-url" name="menu-item-url[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $menu_item->url ); ?>" placeholder="https://" /> |
200 | 200 | </label> |
201 | 201 | </p> |
202 | 202 | <?php endif; ?> |
diff --git a/src/wp-admin/includes/nav-menu.php b/src/wp-admin/includes/nav-menu.php
index 8f18057c23..cb70eb5c8d 100644
a
|
b
|
function wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selecte |
1425 | 1425 | continue; |
1426 | 1426 | } |
1427 | 1427 | |
| 1428 | // Menu item URL can't be blank. |
| 1429 | if ( isset( $_POST['menu-item-type'][ $_key ] ) && 'custom' === $_POST['menu-item-type'][ $_key ] && '' === $_POST['menu-item-url'][ $_key ] ) { |
| 1430 | continue; |
| 1431 | } |
| 1432 | |
1428 | 1433 | $args = array(); |
1429 | 1434 | foreach ( $post_fields as $field ) { |
1430 | 1435 | $args[ $field ] = isset( $_POST[ $field ][ $_key ] ) ? $_POST[ $field ][ $_key ] : ''; |