Custom Menu Wizard Widget - Version 3.0.1

Version Description

  • bugfix : changed the determination of pre-existing legacy widgets versus brand new widget instances, to get round problems encountered when other plugins utilise the widget_form_callback filter to inject fields into a widget
  • addition : added a couple of filters
Download this release

Release Info

Developer wizzud
Plugin Icon 128x128 Custom Menu Wizard Widget
Version 3.0.1
Comparing to
See all releases

Code changes from version 3.0.0 to 3.0.1

Files changed (3) hide show
  1. custom-menu-wizard.php +7 -2
  2. include/class.widget.php +44 -7
  3. readme.txt +9 -1
custom-menu-wizard.php CHANGED
@@ -3,13 +3,18 @@
3
  * Plugin Name: Custom Menu Wizard
4
  * Plugin URI: http://wordpress.org/plugins/custom-menu-wizard/
5
  * Description: Show any part of a custom menu in a Widget, or in content using a Shortcode. Customise the output with extra classes or html; filter by current menu item or a specific item; set a depth, show the parent(s), change the list style, etc. Use the included emulator to assist with the filter settings.
6
- * Version: 3.0.0
7
  * Author: Roger Barrett
8
  * Author URI: http://www.wizzud.com/
9
  * License: GPL2+
10
  */
11
  defined( 'ABSPATH' ) or exit();
12
  /*
 
 
 
 
 
13
  * v3.0.0 change log
14
  * - Major rethink/rewrite : the Children Of filter is now a Branch filter, and the selected menu item becomes the key focus point rather
15
  * than its children. The Levels available for a Branch filter now include relative levels as well as absolute levels, and there are more
@@ -112,7 +117,7 @@ if( !class_exists( 'Custom_Menu_Wizard_Plugin' ) ){
112
  //declare the main plugin class...
113
  class Custom_Menu_Wizard_Plugin {
114
 
115
- public static $version = '3.0.0';
116
  protected static $instance;
117
 
118
  /**
3
  * Plugin Name: Custom Menu Wizard
4
  * Plugin URI: http://wordpress.org/plugins/custom-menu-wizard/
5
  * Description: Show any part of a custom menu in a Widget, or in content using a Shortcode. Customise the output with extra classes or html; filter by current menu item or a specific item; set a depth, show the parent(s), change the list style, etc. Use the included emulator to assist with the filter settings.
6
+ * Version: 3.0.1
7
  * Author: Roger Barrett
8
  * Author URI: http://www.wizzud.com/
9
  * License: GPL2+
10
  */
11
  defined( 'ABSPATH' ) or exit();
12
  /*
13
+ * v3.0.1 change log
14
+ * - fixed bug in determination of pre-existing legacy widgets versus brand new widget instances
15
+ * - replaced widget property _cmw_allow_legacy_update with a filter, custom_menu_wizard_prevent_legacy_updates : return TRUE to prevent updates of legacy widgets
16
+ * - added new filter, custom_menu_wizard_wipe_on_update : return TRUE to cleanse an instance of old settings
17
+ *
18
  * v3.0.0 change log
19
  * - Major rethink/rewrite : the Children Of filter is now a Branch filter, and the selected menu item becomes the key focus point rather
20
  * than its children. The Levels available for a Branch filter now include relative levels as well as absolute levels, and there are more
117
  //declare the main plugin class...
118
  class Custom_Menu_Wizard_Plugin {
119
 
120
+ public static $version = '3.0.1';
121
  protected static $instance;
122
 
123
  /**
include/class.widget.php CHANGED
@@ -20,7 +20,6 @@ class Custom_Menu_Wizard_Widget extends WP_Widget {
20
  'customizer_support' => true
21
  )
22
  );
23
- $this->_cmw_allow_legacy_update = true;
24
  $this->_cmw_legacy_warnreadmore = 'http://wordpress.org/plugins/' . $this->id_base . '/changelog/';
25
  //accessibility mode doesn't necessarily mean that javascript is disabled, but if javascript *is* disabled
26
  //then accessibility mode *will* be on...
@@ -36,8 +35,25 @@ class Custom_Menu_Wizard_Widget extends WP_Widget {
36
  */
37
  function form( $instance ) {
38
 
39
- //only call the legacy form method if the widget already exists and doesn't have a version number (old format)...
40
- if( !empty( $instance ) && empty( $instance['cmwv'] ) ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  $this->cmw_legacy_form( $instance );
42
  return;
43
  }
@@ -603,6 +619,8 @@ class Custom_Menu_Wizard_Widget extends WP_Widget {
603
  /**
604
  * sanitizes/updates the widget settings sent from the backend admin
605
  *
 
 
606
  * @param array $new_instance New widget settings
607
  * @param array $old_instance Old widget settings
608
  * @return array Sanitized widget settings
@@ -614,7 +632,12 @@ class Custom_Menu_Wizard_Widget extends WP_Widget {
614
  return $this->cmw_legacy_update( $new_instance, $old_instance );
615
  }
616
 
617
- return $this->cmw_settings( $new_instance, $old_instance, __FUNCTION__ );
 
 
 
 
 
618
 
619
  } //end update()
620
 
@@ -1430,6 +1453,8 @@ class Custom_Menu_Wizard_Widget extends WP_Widget {
1430
  /**
1431
  * produces the legacy version of the backend admin form(s)
1432
  *
 
 
1433
  * @param array $instance Widget settings
1434
  */
1435
  function cmw_legacy_form( $instance ) {
@@ -1476,7 +1501,9 @@ class Custom_Menu_Wizard_Widget extends WP_Widget {
1476
  <a class="widget-<?php echo $this->id_base; ?>-legacy-close cmw-legacy-close" title="<?php _e('Dismiss'); ?>" href="#">X</a>
1477
  <em><?php _e('This is an old version of the widget!'); ?>
1478
  <?php
1479
- if( !$this->_cmw_allow_legacy_update ){
 
 
1480
  ?>
1481
  <br /><?php _e('Any changes you make will NOT be Saved!'); ?>
1482
  <?php
@@ -1952,14 +1979,24 @@ class Custom_Menu_Wizard_Widget extends WP_Widget {
1952
  /**
1953
  * updates the widget settings sent from the legacy backend admin
1954
  *
 
 
 
1955
  * @param array $new_instance New widget settings
1956
  * @param array $old_instance Old widget settings
1957
  * @return array Sanitized widget settings
1958
  */
1959
  function cmw_legacy_update( $new_instance, $old_instance ){
1960
 
1961
- if( $this->_cmw_allow_legacy_update ){
1962
- return $this->cmw_legacy_settings( $new_instance, $old_instance, 'update' );
 
 
 
 
 
 
 
1963
  }else{
1964
  //prevent the save!...
1965
  return false;
20
  'customizer_support' => true
21
  )
22
  );
 
23
  $this->_cmw_legacy_warnreadmore = 'http://wordpress.org/plugins/' . $this->id_base . '/changelog/';
24
  //accessibility mode doesn't necessarily mean that javascript is disabled, but if javascript *is* disabled
25
  //then accessibility mode *will* be on...
35
  */
36
  function form( $instance ) {
37
 
38
+ //raised June 2014 : problem...
39
+ //using the widget_form_callback filter (as Widget Title Links plugin does, which raised the issue) it is perfectly
40
+ //possible for $instance to be non-empty - with any number of properties - for a new widget! The widget_form_callback
41
+ //filter allows any other plugin to add fields to $instance *before* the actual widget itself gets a chance to (and
42
+ //returning false from that filter will prevent the widget ever being called, but not relevant here).
43
+ //(ref: WP_Widget::form_callback() in wp-includes/widgets.php)
44
+ //this means that I can't rely on a !empty($instance) test being indicative of an existing widget (because it could be
45
+ //a new widget but filtered with widget_form_callback).
46
+ //So, I have changed the "legacy" test from
47
+ // if( !empty( $instance ) && empty( $instance['cmwv'] ) ){
48
+ //to
49
+ // if( is_numeric( $this->number ) && $this->number > 0 && empty( $instance['cmwv'] ) ){
50
+ //(checking for $this->number > 0 is probably overkill but it doesn't hurt)
51
+ //Note that this could still be circumvented by some other plugin using the widget_form_callback filter to set 'cmwv',
52
+ //but I can't do anything about that!
53
+
54
+ //only call the legacy form method if the widget has a number (ie. this instance has been saved, could be either active
55
+ // or inactive) and it does *not* have a version number ('cmwv') set in $instance...
56
+ if( is_numeric( $this->number ) && $this->number > 0 && empty( $instance['cmwv'] ) ){
57
  $this->cmw_legacy_form( $instance );
58
  return;
59
  }
619
  /**
620
  * sanitizes/updates the widget settings sent from the backend admin
621
  *
622
+ * @filters : custom_menu_wizard_wipe_on_update false
623
+ *
624
  * @param array $new_instance New widget settings
625
  * @param array $old_instance Old widget settings
626
  * @return array Sanitized widget settings
632
  return $this->cmw_legacy_update( $new_instance, $old_instance );
633
  }
634
 
635
+ return $this->cmw_settings(
636
+ $new_instance,
637
+ //allow a filter to return true, whereby any previous settings (now possibly unused) will be wiped instead of being allowed to remain...
638
+ //eg. add_filter( 'custom_menu_wizard_wipe_on_update', [filter_function], 10, 1 ) => true
639
+ apply_filters( 'custom_menu_wizard_wipe_on_update', false ) ? array() : $old_instance,
640
+ __FUNCTION__ );
641
 
642
  } //end update()
643
 
1453
  /**
1454
  * produces the legacy version of the backend admin form(s)
1455
  *
1456
+ * @filters : custom_menu_wizard_prevent_legacy_updates false
1457
+ *
1458
  * @param array $instance Widget settings
1459
  */
1460
  function cmw_legacy_form( $instance ) {
1501
  <a class="widget-<?php echo $this->id_base; ?>-legacy-close cmw-legacy-close" title="<?php _e('Dismiss'); ?>" href="#">X</a>
1502
  <em><?php _e('This is an old version of the widget!'); ?>
1503
  <?php
1504
+ //allow a filter to return true, whereby updates to legacy widgets are disallowed...
1505
+ //eg. apply_filter( 'custom_menu_wizard_prevent_legacy_updates', [filter function], 10, 1 ) => true
1506
+ if( apply_filters( 'custom_menu_wizard_prevent_legacy_updates', false ) ){
1507
  ?>
1508
  <br /><?php _e('Any changes you make will NOT be Saved!'); ?>
1509
  <?php
1979
  /**
1980
  * updates the widget settings sent from the legacy backend admin
1981
  *
1982
+ * @filters : custom_menu_wizard_prevent_legacy_updates false
1983
+ * @filters : custom_menu_wizard_wipe_on_update false
1984
+ *
1985
  * @param array $new_instance New widget settings
1986
  * @param array $old_instance Old widget settings
1987
  * @return array Sanitized widget settings
1988
  */
1989
  function cmw_legacy_update( $new_instance, $old_instance ){
1990
 
1991
+ //allow a filter to return true, whereby updates to legacy widgets are disallowed...
1992
+ //eg. apply_filter( 'custom_menu_wizard_prevent_legacy_updates', [filter function], 10, 1 ) => true
1993
+ if( !apply_filters( 'custom_menu_wizard_prevent_legacy_updates', false ) ){
1994
+ return $this->cmw_legacy_settings(
1995
+ $new_instance,
1996
+ //allow a filter to return true, whereby any previous settings (now possibly unused) will be wiped instead of being allowed to remain...
1997
+ //eg. add_filter( 'custom_menu_wizard_wipe_on_update', [filter_function], 10, 1 ) => true
1998
+ apply_filters( 'custom_menu_wizard_wipe_on_update', false ) ? array() : $old_instance,
1999
+ 'update' );
2000
  }else{
2001
  //prevent the save!...
2002
  return false;
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: menu,widget,widgets,navigation,nav,custom menus,custom menu,partial menu,current item,current page,menu level,menu branch,menu shortcode,menu widget,advanced,enhanced
5
  Requires at least: 3.6
6
  Tested up to: 3.9
7
- Stable tag: 3.0.0
8
  License: GPLv2 or Later
9
 
10
  Show branches or levels of your menu in a widget, or in content using a shortcode, with full customisation.
@@ -659,6 +659,10 @@ Note that output from this shortcode extension is restricted to users with edit_
659
 
660
  == Changelog ==
661
 
 
 
 
 
662
  = 3.0.0 =
663
  * **! Rewrite, and Change of Approach !** The widget has had a major rewrite! The `Children of` filter has been replaced with a `Branch` filter, with a subsequent shift in focus for the secondary filter parameters, from the children's level (0, 1 or more items) up to the branch level (a single item!). This should provide a more intuitive interface, and is definitely easier to code for. **However**, it only affects *new instances* of the widget; v2 instances are still ***fully supported***.
664
 
@@ -758,6 +762,10 @@ Note that output from this shortcode extension is restricted to users with edit_
758
 
759
  == Upgrade Notice ==
760
 
 
 
 
 
761
  = 3.0.0 =
762
  **Rewrite, and change of approach** : __! Important !__ : existing (version 2) widgets and shortcodes *__are fully supported__*. Please [read the Changelog](http://wordpress.org/plugins/custom-menu-wizard/changelog/) *before* upgrading!
763
  Version 3 swaps the *Children-Of* filter for a *Branch* filter, with secondary filters to then refine the branch items. It has better filter capabilities - relative and absolute start level, presence of a current menu item at different stages - and adds exclusion of items by id and/or level. A new shortcode - *[cmwizard]* - has been added to support the v3 functionality.
4
  Tags: menu,widget,widgets,navigation,nav,custom menus,custom menu,partial menu,current item,current page,menu level,menu branch,menu shortcode,menu widget,advanced,enhanced
5
  Requires at least: 3.6
6
  Tested up to: 3.9
7
+ Stable tag: 3.0.1
8
  License: GPLv2 or Later
9
 
10
  Show branches or levels of your menu in a widget, or in content using a shortcode, with full customisation.
659
 
660
  == Changelog ==
661
 
662
+ = 3.0.1 =
663
+ * bugfix : changed the determination of pre-existing legacy widgets versus brand new widget instances, to get round problems encountered when other plugins utilise the widget_form_callback filter to inject fields into a widget
664
+ * addition : added a couple of filters
665
+
666
  = 3.0.0 =
667
  * **! Rewrite, and Change of Approach !** The widget has had a major rewrite! The `Children of` filter has been replaced with a `Branch` filter, with a subsequent shift in focus for the secondary filter parameters, from the children's level (0, 1 or more items) up to the branch level (a single item!). This should provide a more intuitive interface, and is definitely easier to code for. **However**, it only affects *new instances* of the widget; v2 instances are still ***fully supported***.
668
 
762
 
763
  == Upgrade Notice ==
764
 
765
+ = 3.0.1 =
766
+ Fixed a bug that created new widget instances as legacy version rather than latest; only encountered when other installed plugins inject their own fields into widgets
767
+ Also added a couple of filters.
768
+
769
  = 3.0.0 =
770
  **Rewrite, and change of approach** : __! Important !__ : existing (version 2) widgets and shortcodes *__are fully supported__*. Please [read the Changelog](http://wordpress.org/plugins/custom-menu-wizard/changelog/) *before* upgrading!
771
  Version 3 swaps the *Children-Of* filter for a *Branch* filter, with secondary filters to then refine the branch items. It has better filter capabilities - relative and absolute start level, presence of a current menu item at different stages - and adds exclusion of items by id and/or level. A new shortcode - *[cmwizard]* - has been added to support the v3 functionality.