diff --git a/CHANGELOG.md b/CHANGELOG.md
index ff030286..e17ebbf7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,12 @@
# Changelog
+## Unreleased
+
+- Restrict utility menu output to the parent level, fixes #61.
+- Prevent child menu items from being added to the Utility menu, fixes #61.
+- Reset nested Utility menu items to the top/parent level on save, fixes #61.
+- Add admin notice stating the utility nav restrictions, fixes #61.
+
## 2.5.2
- Add alternate-footbar class to alternate-footbar fixes#5.
diff --git a/admin/admin.php b/admin/admin.php
index 4c9558b6..3132511c 100755
--- a/admin/admin.php
+++ b/admin/admin.php
@@ -129,3 +129,12 @@ function responsive_maybe_save_layout_setting() {
set_transient( 'responsive_layout_setting_check', '', WEEK_IN_SECONDS );
}
add_action( 'admin_init', 'responsive_maybe_save_layout_setting' );
+
+/**
+ * Enqueue Custom Admin Menu Scripts.
+ */
+function responsive_enqueue_admin_scripts() {
+ wp_enqueue_script( 'custom-menu-js', get_template_directory_uri() . '/admin/menu.js', array(), RESPONSIVE_FRAMEWORK_VERSION, true );
+
+}
+add_action( 'admin_enqueue_scripts', 'responsive_enqueue_admin_scripts', 20 );
diff --git a/admin/menu.js b/admin/menu.js
new file mode 100644
index 00000000..6c80dad7
--- /dev/null
+++ b/admin/menu.js
@@ -0,0 +1,43 @@
+jQuery( document ).ready(function($) {
+ function verifyNav() {
+ let lis = jQuery('#update-nav-menu #post-body ul.menu li');
+ lis.each(function () {
+ // First Check if active in sort and don't act on the placeholder span.
+ if ( !$(this).hasClass('ui-sortable-helper') && !$(this).hasClass('sortable-placeholder')) {
+ // If not active and not at 0 depth reset to 0 depth and alert user.
+ if ( !$(this).hasClass('menu-item-depth-0') ) {
+ let itemID = $(this).attr('id');
+ let item = document.getElementById( itemID );
+ let itemClasses = item.className;
+ itemClasses = itemClasses.split( ' ' );
+ itemClasses.forEach((element, index) => {
+ if ( -1 !== element.toString().indexOf('menu-item-depth') ) {
+ let currentDepthClass = itemClasses[index];
+ $(this).removeClass(currentDepthClass);
+ $(this).addClass('menu-item-depth-0');
+ $(this).find( '.is-submenu').hide();
+ window.alert( 'Nested menu items not allowed on Utility Menu. Menu item Reset to top level.');
+ }
+ } );
+ }
+ }
+ });
+ }
+
+ // Setup Observer only on Utility Menu.
+ let selectedMenu = jQuery('.manage-menus select').find(':selected').text();
+
+ if( 'Utility Menu (Utility Navigation)' === selectedMenu.trim() ) {
+ // Select the node that will be observed for mutations.
+ const targetNode = document.getElementById('update-nav-menu');
+
+ // Options for the observer (which mutations to observe).
+ const config = {attributes: true, childList: true, subtree: true};
+
+ // Create an observer instance linked to the callback function.
+ const observer = new MutationObserver(verifyNav);
+
+ // Start observing the target node for configured mutations
+ observer.observe(targetNode, config);
+ }
+});
diff --git a/inc/template-tags.php b/inc/template-tags.php
index d9bc1e3c..b8389ee1 100755
--- a/inc/template-tags.php
+++ b/inc/template-tags.php
@@ -434,6 +434,7 @@ function responsive_get_utility_nav( $args = array() ) {
'menu_class' => 'utility-nav-menu',
'container' => false,
'echo' => false,
+ 'depth' => 1,
)
);
}
@@ -1210,3 +1211,71 @@ function responsive_get_the_excerpt( $post_id = null, $length = 55 ) {
}
return $excerpt;
}
+
+
+/**
+ * Add Admin notice describing limitations of the Utility menu.
+ */
+function responsive_utility_menu_notice() {
+
+ // Display only on nav-menus screen.
+ $screen = get_current_screen();
+ if ( 'nav-menus' !== $screen->base ) {
+ return;
+ }
+
+ // Get Current menu id from the global namespace and compare to the utility-menu id.
+ global $nav_menu_selected_id;
+ $utility_menu = wp_get_nav_menu_object( 'utility-menu' );
+
+ if ( $nav_menu_selected_id === $utility_menu->term_id ) {
+ $notice = __( 'The Utility Menu only displays the top level items.', 'responsive-framework' );
+ $notice .= '
';
+ $notice .= __( 'Nested items are prevented and/or reset to the top level on save.', 'responsive-framework' );
+ echo '