From 6ba4a6d8554eafa8e5e9ceac8697925c381c3c63 Mon Sep 17 00:00:00 2001 From: WdeVlam Date: Wed, 23 Nov 2022 13:03:45 +0100 Subject: [PATCH] update gh code with current version --- assets/js/ajax.js | 128 +++++++++--------- assets/js/main.js | 114 ++++++++-------- readme.txt | 239 +++++++++++++++++++++++++++++++++- submenu.php | 13 +- walkers/SubmenuWalker.php | 46 ++++++- widgets/SectionMenuWidget.php | 7 +- widgets/SplitMenuWidget.php | 7 +- 7 files changed, 412 insertions(+), 142 deletions(-) diff --git a/assets/js/ajax.js b/assets/js/ajax.js index 981449c..50a0306 100644 --- a/assets/js/ajax.js +++ b/assets/js/ajax.js @@ -1,14 +1,14 @@ /** * Admin Ajax Function */ -(function($){ +(function ($) { - $.fn.jc_edit_menu = function(){ + $.fn.jc_edit_menu = function () { var id = JC_Submenu.get_menu_id($(this).attr('id')); - var _menu_item = $('#menu-item-'+id); - - if(_menu_item.hasClass('menu-item-edit-inactive') && !_menu_item.hasClass('jc-submenu-populated')){ + var _menu_item = $('#menu-item-' + id); + + if (_menu_item.hasClass('menu-item-edit-inactive') && !_menu_item.hasClass('jc-submenu-populated')) { var id = JC_Submenu.get_menu_id(_menu_item.attr('id')); var data = { @@ -19,7 +19,7 @@ // show loading $("
JC Submenu... Loading
").insertBefore(_menu_item.find('.menu-item-actions')); - jQuery.post(ajax_object.ajax_url, data, function(response) { + jQuery.post(ajax_object.ajax_url, data, function (response) { _menu_item.find("#jc-submenu-loading").remove(); @@ -29,50 +29,50 @@ * Display Active Menu Population Options * @since 0.6 */ - _menu_item.find('.jc-accord-heading').each(function(){ + _menu_item.find('.jc-accord-heading').each(function () { var accord_heading = $(this); var id = JC_Submenu.get_menu_id(accord_heading.attr('id')); var btn_handle = $('input', accord_heading); var btn_label = $('label', accord_heading); - btn_handle.live('change', function(){ + btn_handle.on('change', function () { - $('.jc-accord-heading', $('#menu-item-'+id)).removeClass('active'); - $('.item-edit-panel', $('#menu-item-'+id)).hide(); + $('.jc-accord-heading', $('#menu-item-' + id)).removeClass('active'); + $('.item-edit-panel', $('#menu-item-' + id)).hide(); - if($(this).attr('checked') == 'checked'){ - $( '.show-'+$(this).val() , $('#menu-item-'+id) ).show(); + if ($(this).is(':checked')) { + $('.show-' + $(this).val(), $('#menu-item-' + id)).show(); accord_heading.addClass('active'); } }); - btn_label.click(function(event){ - $('.jc-accord-heading input:checked', $('#menu-item-'+id)).attr('checked', false); - btn_handle.attr('checked', 'checked').trigger('change'); + btn_label.click(function (event) { + $('.jc-accord-heading input:checked', $('#menu-item-' + id)).prop('checked', false); + btn_handle.prop('checked', true).trigger('change'); event.preventDefault(); }); btn_handle.filter(":checked").trigger('change'); }); - + /** * Display JC Submenu Options * @since 0.6 */ - _menu_item.find('input.jc-submenu-autopopulate').each(function(index){ + _menu_item.find('input.jc-submenu-autopopulate').each(function (index) { var options_handle = $(this); var id = JC_Submenu.get_menu_id(options_handle.attr('id')); - options_handle.live('change', function(){ - if($(this).attr('checked') == 'checked'){ - $( '#jc-submenu-populate-block-'+id).show(); - $('.jc-submenu-active').show(); - }else{ - $( '#jc-submenu-populate-block-'+id).hide(); - $('.jc-submenu-active').hide(); - } + options_handle.on('change', function () { + if ($(this).is(':checked')) { + $('#jc-submenu-populate-block-' + id).show(); + $('.jc-submenu-active').show(); + } else { + $('#jc-submenu-populate-block-' + id).hide(); + $('.jc-submenu-active').hide(); + } }); options_handle.filter(':checked').trigger('change'); @@ -82,37 +82,37 @@ * Filter Taxonomy via selected Post Type * @since 0.6 */ - _menu_item.find('select[id^="edit-jc-submenu-populate-post"]').each(function(){ + _menu_item.find('select[id^="edit-jc-submenu-populate-post"]').each(function () { var post_select = $(this); var id = JC_Submenu.get_menu_id(post_select.attr('id')); - var tax_select = $('select[id^="edit-jc-submenu-post-tax"]', $('#menu-item-'+id)); - var term_select = $('select[id^="edit-jc-submenu-post-term"]', $('#menu-item-'+id)); + var tax_select = $('select[id^="edit-jc-submenu-post-tax"]', $('#menu-item-' + id)); + var term_select = $('select[id^="edit-jc-submenu-post-term"]', $('#menu-item-' + id)); var taxs = tax_select.clone(); - post_select.live('change', function(){ + post_select.on('change', function () { var show_taxs = post_select.find(':selected').data('taxs').split(' '); var selected = tax_select.find(':selected').val(); // tax_select = taxs.clone(); tax_select.empty(); - $('option', taxs).each(function(index){ - + $('option', taxs).each(function (index) { + var val = $(this).val(); - if($.inArray(val, show_taxs) != -1 || val == 0){ + if ($.inArray(val, show_taxs) != -1 || val == 0) { var clone_option = $(this).clone().attr('selected', false); - if(val == selected){ + if (val == selected) { tax_select.append(clone_option.attr('selected', 'selected')); - }else{ - tax_select.append(clone_option); + } else { + tax_select.append(clone_option); } - }else{ - tax_select.find('option[value='+val+']').remove(); + } else { + tax_select.find('option[value=' + val + ']').remove(); } }); @@ -129,37 +129,37 @@ post_select.trigger('change'); }); - + /** * Filter Terms depending on chosen taxonomy * @since 0.6 */ - _menu_item.find('select[id^="edit-jc-submenu-post-tax"]').each(function(){ + _menu_item.find('select[id^="edit-jc-submenu-post-tax"]').each(function () { var tax_select = $(this); var id = JC_Submenu.get_menu_id(tax_select.attr('id')); - var term_select = $('select[id^="edit-jc-submenu-post-term"]', $('#menu-item-'+id)); + var term_select = $('select[id^="edit-jc-submenu-post-term"]', $('#menu-item-' + id)); var terms = term_select.clone(); - tax_select.live('change', function(){ + tax_select.on('change', function () { var tax = tax_select.find(':selected').val(); var selected = term_select.find(':selected').val(); term_select.empty(); - $('option', terms).each(function(index){ + $('option', terms).each(function (index) { var val = $(this).val(); - if(tax == $(this).data('tax')){ + if (tax == $(this).data('tax')) { var clone_option = $(this).clone().attr('selected', false); - if(val == selected){ + if (val == selected) { term_select.append(clone_option.attr('selected', 'selected')); - }else{ - term_select.append(clone_option); + } else { + term_select.append(clone_option); } - }else{ - term_select.find('option[value='+val+']').remove(); + } else { + term_select.find('option[value=' + val + ']').remove(); } }); @@ -178,32 +178,32 @@ * Filter Taxonomy Terms depending on chosen taxonomy * @since 0.6 */ - _menu_item.find('select[id^="edit-jc-submenu-populate-tax"]').each(function(){ + _menu_item.find('select[id^="edit-jc-submenu-populate-tax"]').each(function () { var tax_select = $(this); var id = JC_Submenu.get_menu_id(tax_select.attr('id')); - var term_select = $('select[id^="edit-jc-submenu-tax-term"]', $('#menu-item-'+id)); + var term_select = $('select[id^="edit-jc-submenu-tax-term"]', $('#menu-item-' + id)); var terms = term_select.clone(); - tax_select.live('change', function(){ + tax_select.on('change', function () { var tax = tax_select.find(':selected').val(); var selected = term_select.find(':selected').val(); term_select.empty(); - $('option', terms).each(function(index){ + $('option', terms).each(function (index) { var val = $(this).val(); - if(tax == $(this).data('tax') || $(this).data('tax') == 0){ + if (tax == $(this).data('tax') || $(this).data('tax') == 0) { var clone_option = $(this).clone().attr('selected', false); - if(val == selected){ + if (val == selected) { term_select.append(clone_option.attr('selected', 'selected')); - }else{ - term_select.append(clone_option); + } else { + term_select.append(clone_option); } - }else{ - term_select.find('option[value='+val+']').remove(); + } else { + term_select.find('option[value=' + val + ']').remove(); } }); @@ -228,13 +228,13 @@ * * add before .menu-item-actions */ - $(document).ready(function(){ + $(document).ready(function () { + + $('#menu-to-edit').on('click', 'a.item-edit', function () { + $(this).jc_edit_menu(); + }); - $('#menu-to-edit').on('click', 'a.item-edit', function(){ - $(this).jc_edit_menu(); - }); - - }); + }); })(jQuery); \ No newline at end of file diff --git a/assets/js/main.js b/assets/js/main.js index 9e43396..09d7253 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -4,65 +4,65 @@ var JC_Submenu = { - get_menu_id: function (id){ - id= id.split("-"); - id = id[id.length-1]; + get_menu_id: function (id) { + id = id.split("-"); + id = id[id.length - 1]; return id; } }; -(function($){ +(function ($) { /** * Display Active Menu Population Options * @since 0.2 */ - $('.jc-accord-heading').each(function(){ + $('.jc-accord-heading').each(function () { var accord_heading = $(this); var id = JC_Submenu.get_menu_id(accord_heading.attr('id')); var btn_handle = $('input', accord_heading); var btn_label = $('label', accord_heading); - btn_handle.live('change', function(){ + btn_handle.on('change', function () { - $('.jc-accord-heading', $('#menu-item-'+id)).removeClass('active'); - $('.item-edit-panel', $('#menu-item-'+id)).hide(); + $('.jc-accord-heading', $('#menu-item-' + id)).removeClass('active'); + $('.item-edit-panel', $('#menu-item-' + id)).hide(); - if($(this).attr('checked') == 'checked'){ - $( '.show-'+$(this).val() , $('#menu-item-'+id) ).show(); + if ($(this).is(':checked')) { + $('.show-' + $(this).val(), $('#menu-item-' + id)).show(); accord_heading.addClass('active'); } }); - btn_label.click(function(event){ - $('.jc-accord-heading input:checked', $('#menu-item-'+id)).attr('checked', false); - btn_handle.attr('checked', 'checked').trigger('change'); + btn_label.click(function (event) { + $('.jc-accord-heading input:checked', $('#menu-item-' + id)).prop('checked', false); + btn_handle.prop('checked', true).trigger('change'); event.preventDefault(); }); btn_handle.filter(":checked").trigger('change'); }); - + /** * Display JC Submenu Options * @since 0.2 */ - $('input.jc-submenu-autopopulate').each(function(index){ + $('input.jc-submenu-autopopulate').each(function (index) { var options_handle = $(this); var id = JC_Submenu.get_menu_id(options_handle.attr('id')); - options_handle.live('change', function(){ - if($(this).attr('checked') == 'checked'){ - $( '#jc-submenu-populate-block-'+id).show(); - $('.jc-submenu-active').show(); - }else{ - $( '#jc-submenu-populate-block-'+id).hide(); - $('.jc-submenu-active').hide(); - } + options_handle.on('change', function () { + if ($(this).is(':checked')) { + $('#jc-submenu-populate-block-' + id).show(); + $('.jc-submenu-active').show(); + } else { + $('#jc-submenu-populate-block-' + id).hide(); + $('.jc-submenu-active').hide(); + } }); options_handle.filter(':checked').trigger('change'); @@ -72,37 +72,37 @@ var JC_Submenu = { * Filter Taxonomy via selected Post Type * @since 0.2 */ - $('select[id^="edit-jc-submenu-populate-post"]').each(function(){ + $('select[id^="edit-jc-submenu-populate-post"]').each(function () { var post_select = $(this); var id = JC_Submenu.get_menu_id(post_select.attr('id')); - var tax_select = $('select[id^="edit-jc-submenu-post-tax"]', $('#menu-item-'+id)); - var term_select = $('select[id^="edit-jc-submenu-post-term"]', $('#menu-item-'+id)); + var tax_select = $('select[id^="edit-jc-submenu-post-tax"]', $('#menu-item-' + id)); + var term_select = $('select[id^="edit-jc-submenu-post-term"]', $('#menu-item-' + id)); var taxs = tax_select.clone(); - post_select.live('change', function(){ + post_select.on('change', function () { var show_taxs = post_select.find(':selected').data('taxs').split(' '); var selected = tax_select.find(':selected').val(); // tax_select = taxs.clone(); tax_select.empty(); - $('option', taxs).each(function(index){ - + $('option', taxs).each(function (index) { + var val = $(this).val(); - if($.inArray(val, show_taxs) != -1 || val == 0){ + if ($.inArray(val, show_taxs) != -1 || val == 0) { var clone_option = $(this).clone().attr('selected', false); - if(val == selected){ + if (val == selected) { tax_select.append(clone_option.attr('selected', 'selected')); - }else{ - tax_select.append(clone_option); + } else { + tax_select.append(clone_option); } - }else{ - tax_select.find('option[value='+val+']').remove(); + } else { + tax_select.find('option[value=' + val + ']').remove(); } }); @@ -119,37 +119,37 @@ var JC_Submenu = { post_select.trigger('change'); }); - + /** * Filter Terms depending on chosen taxonomy * @since 0.2 */ - $('select[id^="edit-jc-submenu-post-tax"]').each(function(){ + $('select[id^="edit-jc-submenu-post-tax"]').each(function () { var tax_select = $(this); var id = JC_Submenu.get_menu_id(tax_select.attr('id')); - var term_select = $('select[id^="edit-jc-submenu-post-term"]', $('#menu-item-'+id)); + var term_select = $('select[id^="edit-jc-submenu-post-term"]', $('#menu-item-' + id)); var terms = term_select.clone(); - tax_select.live('change', function(){ + tax_select.on('change', function () { var tax = tax_select.find(':selected').val(); var selected = term_select.find(':selected').val(); term_select.empty(); - $('option', terms).each(function(index){ + $('option', terms).each(function (index) { var val = $(this).val(); - if(tax == $(this).data('tax')){ + if (tax == $(this).data('tax')) { var clone_option = $(this).clone().attr('selected', false); - if(val == selected){ + if (val == selected) { term_select.append(clone_option.attr('selected', 'selected')); - }else{ - term_select.append(clone_option); + } else { + term_select.append(clone_option); } - }else{ - term_select.find('option[value='+val+']').remove(); + } else { + term_select.find('option[value=' + val + ']').remove(); } }); @@ -168,32 +168,32 @@ var JC_Submenu = { * Filter Taxonomy Terms depending on chosen taxonomy * @since 0.5.4 */ - $('select[id^="edit-jc-submenu-populate-tax"]').each(function(){ + $('select[id^="edit-jc-submenu-populate-tax"]').each(function () { var tax_select = $(this); var id = JC_Submenu.get_menu_id(tax_select.attr('id')); - var term_select = $('select[id^="edit-jc-submenu-tax-term"]', $('#menu-item-'+id)); + var term_select = $('select[id^="edit-jc-submenu-tax-term"]', $('#menu-item-' + id)); var terms = term_select.clone(); - tax_select.live('change', function(){ + tax_select.on('change', function () { var tax = tax_select.find(':selected').val(); var selected = term_select.find(':selected').val(); term_select.empty(); - $('option', terms).each(function(index){ + $('option', terms).each(function (index) { var val = $(this).val(); - if(tax == $(this).data('tax') || $(this).data('tax') == 0){ + if (tax == $(this).data('tax') || $(this).data('tax') == 0) { var clone_option = $(this).clone().attr('selected', false); - if(val == selected){ + if (val == selected) { term_select.append(clone_option.attr('selected', 'selected')); - }else{ - term_select.append(clone_option); + } else { + term_select.append(clone_option); } - }else{ - term_select.find('option[value='+val+']').remove(); + } else { + term_select.find('option[value=' + val + ']').remove(); } }); @@ -212,7 +212,7 @@ var JC_Submenu = { /** * Document Ready */ - $(document).ready(function(){ + $(document).ready(function () { $('.item-edit-panel').hide(); }); diff --git a/readme.txt b/readme.txt index 7b88525..5df4e91 100644 --- a/readme.txt +++ b/readme.txt @@ -3,8 +3,8 @@ Contributors: jcollings Donate link: Tags: submenu, menu, dynamic, custom post type, taxonomy, child pages Requires at least: 3.0.1 -Tested up to: 4 -Stable tag: 0.8.4 +Tested up to: 5.5 +Stable tag: 0.9.1 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -29,23 +29,232 @@ For further documentation on installing and using JC Submneu features can be fou = How do i use the split menu functionality = -The documentation for using the split menu functionality (widget, shortcode, action) can be found [here](http://jamescollings.co.uk/jc-submenu/resources/output-split-menu-section/) +** What is a WordPress Split Menu ** + +A WordPress Split Menu is the process of creating a multi level menu, and displaying a menu section relative to the currently viewed object/page. For Example if a site has the following menu and pages: + +``` +Page 1 + - Page 1.1 + - Page 1.2 +Page 2 + - Page 1.3 +``` + +Creating a split menu section for this example, you would set the start depth of 1, this means that when you are viewing any page or child page of Page 1 the split menu would output related items only: + +``` +Page 1 + - Page 1.1 + - Page 1.2 +``` + +and if you were viewing any page or child page of Page 2 the split menu section would be: + +``` +Page 2 + - Page 1.3 +``` + +** Wordpress Split Menu Widget ** + +JC Submenu plugin comes with a widget titled “Split Menu Widget” which allows you to output your split menu within a wordpress sidebar. + +It is located under Appearance > Widgets in your wordpress administration area. + +Widget Settings: + +* Choose Split Menu widget from the list of avaliable widgets +* Select Menu – Choose the menu you wish to split +* Start Level – Choose the starting depth to display +* Menu Depth – Choose how many levels you wish to display +* Show Parent – Choose to display the split menu’s parent item +* Show Hierarcy – Choose to display a flat or nested list +* Trigger Depth – Choose how many levels of children you would like to display in relation to the activate page, 0 = show all. (Added in v 0.62) + +** Split Menu Action ** + +JC Submenu plugin comes with a built in wordpress action to easily output a split menu anywhere within your theme. + +``` + +``` + +* hierarchy – Whether to display a flat list instead +* start – Menu depth you wish to split from +* depth – Amount of levels you wish to display +* show_parent – Whether to display the parent item +* trigger_depth – how many levels of children you would like to display in relation to the activate page, 0 = show all. (Added in v 0.62) +* menu_class – Set the class of the menu element +* menu_id – Set the id of the menu element +* container – what to wrap the ul in +* container_id – Set the id of the container element +* container_class – Set the class of the container element = How do i output a section of menu = -The documentation for displaying a section of menu (widget, shortcode, action) can be found [here](http://jamescollings.co.uk/jc-submenu/resources/how-to-output-a-section-of-a-wordpress-menu/) +** Menu Section Widget ** + +JC Submenu plugins comes with a widget titled "Section Menu Widget" which allows you to output a section of your wordpress menu within a sidebar. +It is located under Appearance > Widgets in your wordpress administration area. + +Widget Settings: + +* Choose Section Menu widget from the list of avaliable widgets +* Select Menu Part – Choose the menu section you wish display +* Menu Depth – Set how many levels of the menu you wish to display +* Show Parent – Choose whether to display the parent item + +** Menu Section Action ** + +JC Submenu plugin comes with a built in wordpress action to easily output a section of a menu anywhere within your theme. + +``` + +``` + +* hierarchy – Whether to display a flat list instead +* start – Menu item you wish to display from +* depth – Amount of levels you wish to display +* show_parent – Whether to display the parent item +* menu_class – Set the class of the menu element +* menu_id – Set the id of the menu element +* container – what to wrap the ul in +* container_id – Set the id of the container element +* container_class – Set the class of the container element + +** Menu Section Shortcode ** + +Display a section of your wordpress menu within your visual editor using wordpress shortcodes. + +``` +[jcs_menu_section menu="" hierarchy="1" start="1" depth="5" show_parent="0" /] + +``` + +* menu – Choose the menu you wish to display +* hierarchy – Whether to display a flat list instead +* start – ID Menu item you wish to display from (can be found by hovering over the menu item within the wordpress menu admin page) +* depth – Amount of levels you wish to display +* show_parent – Whether to display the parent item = How do i automatically populate menu items = -The documentation for automatically populating menu items can be found [here](http://jamescollings.co.uk/jc-submenu/resources/how-to-automatically-populate-wordpress-submenus/) +JC Submenu WordPress plugin takes the hassle out of creating menus, by removing the manual addition of items and allowing you to automatically populate menu items from posts, categories, tags, custom post types, and taxonomies. + +Each with many customisable options allowing you to refine your final menu. + +** Enabling Automatic Menu Population ** + +Once you have the JC Submenu installed, from the menus section + +* Add a menu item that you wish to have posts as a submenu and click on save menu. +* When the page reloads, click on the arrow on the right hand side of the menu item to display the advanced options.Tick the checkbox labelled JC Submenu – Automatically populate submenu to show an accordion of population options. + +** Populate WordPress Menus with Posts ** + +1. Click on the section labelled Populate from post type. +* Post Type – Make sure Post is selected from from the drop down labelled Post Type +* Taxonomy – If you wish to only show posts from a certain category/taxonomy choose the appropriate taxonomy from the drop down labelled Taxonomy (otherwise choose All), If you wish to filter it down further by choosing a term within that taxonomy choose the appropriate term from the drop down labelled Terms. +* Order – Choose which field you want to order and how you’d like it ordered Ascending or Descending. +* Post Limit – Setting the number of posts to display, Set to 0 if you wish not to have a limit. + +** Populate WordPress Menus with Taxonomies ** + +1. Click on the section labelled Populate from taxonomy. +* Taxonomies – Choose the taxonomy from the drop down you wish to populate from. +* Order – Choose which field you want to order and how you’d like it ordered Ascending or Descending. +* Hide Empty Terms – Hide terms that do not have any posts / custom posts. + +** Populate WordPress Menus with Child Pages ** + +1. Click on the section labelled Populate from pages. +* Parent Page – Choose the parent page to fetch the child pages. +* Order – Choose which field you want to order and how you’d like it ordered Ascending or Descending. + = What Actions and filters are avaliable in this plugin = -A list of all actions and filters can be found [here](http://jamescollings.co.uk/jc-submenu/sections/actions-filters/) +** jcs/menu_item_args ** + +jcs/menu_item_args filter is used to edit wp_nav_menu options on a per menu item basis allowing a truely customizeable menu output. + +Example – Display Menu Item Image + +This example shows how to add an image before a menu item depending on that items object type. + +``` +add_filter( 'jcs/menu_item_args', 'jcs_menu_item_args', 10, 2); +function jcs_menu_item_args($args, $item){ + + switch($item->object){ + case 'page': + // add blue 10 pixel image before the menu item name + $args->link_before = ''; + break; + case 'term': + // add green 10 pixel image before the menu item name + $args->link_before = ''; + break; + case 'post': + // add red 10 pixel image before the menu item name + $args->link_before = ''; + break; + } + return $args; +} +``` + +** jcs/item_classes ** + +Add extra classes to menu items containing their item type. + +``` +add_action( 'jcs/item_classes', 'jc_edit_item_classes', 10, 3 ); +function jc_edit_item_classes($classes, $item_id, $item_type){ + + $classes[] = "item-$item_type"; + return $classes; +} +``` + +** jcs/item_title ** + +Display the dynamic menu type at the end of the item title. + +``` +add_filter('jcs/item_title', 'jc_edit_item_title', 10, 3); +function jc_edit_item_title($title, $item_id, $item_type){ + + if($item_type == 'term'){ + $title .= ' (term)'; + }elseif($item_type == 'page'){ + $title .= ' (page)'; + }else{ + $title .= " ($item_type)"; + } + + return $title; +} +``` = How do i use JC Submenu when my theme uses a custom menu walker = -The documentation to disable JC_Submenu_Nav_Walker and use your own can be found [here](http://jamescollings.co.uk/docs/v1/jc-submenu/how-tos/enable-menu-walker-compatability/) +JC Submenu allows you to disable its custom menu walker making it compatible with themes which uses there own menu walkers. + +To enable compatability with other menu walkers add the following code into your themes functions.php file. + +``` +// enable compatibility with theme custom menu walkers +add_filter('jcs/enable_public_walker', 'jc_disable_public_walker'); +function jc_disable_public_walker($default){ + return false; +} +``` == Screenshots == @@ -57,6 +266,22 @@ The documentation to disable JC_Submenu_Nav_Walker and use your own can be found == Changelog == +**0.9.1** + +* FIX - compatability issues with new jQuery version, .live -> .on .attr('checked) -> .prop('checked') + +**0.9.0** + +* Add menu-item-has-children to account for populated menu items + +**0.8.6** + +* Fix compatability with WP 5.3 - Walker::walk ($elements, $max_depth, … $args) + +**0.8.5** + +* Fix menu deprecated function create_function() + **0.8.4** * Fix menu highlighting when not using JC_Submenu_Nav_Walker diff --git a/submenu.php b/submenu.php index ec36779..e88e879 100644 --- a/submenu.php +++ b/submenu.php @@ -1,11 +1,11 @@ - * @version 0.8.4 + * @version 0.9.1 */ class JCSubmenu{ - var $version = '0.8.4'; - var $version_check = 70; + var $version = '0.9.1'; + var $version_check = 71; var $plugin_dir = false; var $plugin_url = false; var $prefix = 'jc-submenu'; @@ -276,4 +276,3 @@ function output_split_menu($menu, $args = array()){ } $GLOBALS['jcsubmenu'] = new JCSubmenu(); -?> \ No newline at end of file diff --git a/walkers/SubmenuWalker.php b/walkers/SubmenuWalker.php index 1177433..819ff87 100644 --- a/walkers/SubmenuWalker.php +++ b/walkers/SubmenuWalker.php @@ -102,9 +102,9 @@ function end_lvl( &$output, $depth = 0, $args = array() ) { * @param int $max_depth * @return string */ - function walk( $elements, $max_depth) { + function walk( $elements, $max_depth, ...$args) { - $args = array_slice(func_get_args(), 2); + //$args = array_slice(func_get_args(), 2); $output = ''; if ($max_depth < -1) //invalid parameter @@ -271,6 +271,9 @@ public function _process_menu($elements = array()){ // Set Menu Item Depth $elements = $this->set_elements_depth($elements, 0, true); + + // Set Menu Classes + $elements = $this->_set_element_classes($elements); if($this->section_menu || $this->split_menu){ @@ -601,6 +604,43 @@ public function _set_elements_state($elements){ return $elements; } + /** + * Find all elements with children and add parent classes + * + * @param array $elements + */ + public function _set_element_classes($elements){ + + $parent_ids = array(); + $id_field = $this->db_fields['id']; + $parent_field = $this->db_fields['parent']; + + foreach($elements as $element){ + + $parent_id = $element->$parent_field; + if($parent_id <= 0){ + continue; + } + + if(!in_array($parent_id, $parent_ids)){ + $parent_ids[] = $parent_id; + } + + } + + foreach($elements as $i => $element){ + if(!in_array($element->$id_field, $parent_ids)){ + continue; + } + + if (!in_array('menu-item-has-children', $element->classes)) { + $elements[$i]->classes[] = 'menu-item-has-children'; + } + } + + return $elements; + } + /** * Generate Elements from page items * @param stdObj $menu_item Current Menu Item Being Populated @@ -839,7 +879,7 @@ public function _populate_tax_items($menu_item, $taxonomy, $replace_parent = fal $t->title = apply_filters( 'jcs/term_item_title', $t->title, $t->ID ); $t->url = apply_filters( 'jcs/item_url', get_term_link( $t, $taxonomy ), $t->ID , 'term'); - $t->url = apply_filters( 'jcs/term_item_url', $t->url, $t->ID, $taxonomy ); + $t->url = apply_filters( 'jcs/term_item_url', $t->url, $t->ID ); $t->classes = array(); diff --git a/widgets/SectionMenuWidget.php b/widgets/SectionMenuWidget.php index 23ca15b..dabe3b0 100644 --- a/widgets/SectionMenuWidget.php +++ b/widgets/SectionMenuWidget.php @@ -212,5 +212,8 @@ public function update( $new_instance, $old_instance ) { } } - -add_action( 'widgets_init', create_function( '', 'register_widget( "JC_Section_Menu_Widget" );' ) ); \ No newline at end of file + +function register_jc_section_menu_widget(){ + register_widget( "JC_Section_Menu_Widget" ); +} +add_action( 'widgets_init', 'register_jc_section_menu_widget' ); \ No newline at end of file diff --git a/widgets/SplitMenuWidget.php b/widgets/SplitMenuWidget.php index 2e292df..97cb998 100644 --- a/widgets/SplitMenuWidget.php +++ b/widgets/SplitMenuWidget.php @@ -185,5 +185,8 @@ public function update( $new_instance, $old_instance ) { } } - -add_action( 'widgets_init', create_function( '', 'register_widget( "JC_Split_Menu_Widget" );' ) ); \ No newline at end of file + +function register_jc_split_menu_widget(){ + register_widget( "JC_Split_Menu_Widget" ); +} +add_action( 'widgets_init', 'register_jc_split_menu_widget' ); \ No newline at end of file