Custom Menu Wizard Widget - Version 2.0.6

Version Description

  • change : modified determination of current item to cope better with multiple occurences (still first-found, but within prioritised groups)

  • change : display of the upgrade notice in the plugins list has been replaced with a simple request to read the changelog before upgrading

Download this release

Release Info

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

Code changes from version 2.0.5 to 2.0.6

Files changed (2) hide show
  1. custom-menu-wizard.php +68 -65
  2. readme.txt +13 -2
custom-menu-wizard.php CHANGED
@@ -3,13 +3,17 @@
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: 2.0.5
7
  * Author: Roger Barrett
8
  * Author URI: http://www.wizzud.com/
9
  * License: GPL2+
10
  */
11
 
12
  /*
 
 
 
 
13
  * v2.0.5 change log:
14
  * - prevent PHP warnings of Undefined index/offset when building $substructure
15
  *
@@ -68,7 +72,7 @@
68
  * - moved the setting of 'disabled' attributes on INPUTs/SELECTs from PHP into javascript
69
  */
70
 
71
- $Custom_Menu_Wizard_Widget_Version = '2.0.5';
72
 
73
  /**
74
  * registers the widget and adds the shortcode
@@ -95,71 +99,33 @@ function custom_menu_wizard_widget_admin_script(){
95
  add_action('admin_print_scripts-widgets.php', 'custom_menu_wizard_widget_admin_script');
96
 
97
  /**
98
- * puts the contents of the Upgrade Notice (from readme.txt) for a new version under the widget's entry in Appearances - Widgets
99
  */
100
  function custom_menu_wizard_update_message($plugin_data, $r){
101
- global $Custom_Menu_Wizard_Widget_Version;
102
- $readme = wp_remote_fopen( 'http://plugins.svn.wordpress.org/custom-menu-wizard/trunk/readme.txt' );
103
- // $readme = file_get_contents( plugins_url( '/readme.txt', __FILE__ ) );
104
- if(!empty($readme)){
105
- //grab the Upgrade Notice section from the readme...
106
- if(preg_match('/== upgrade notice ==(.+)(==|$)/ims', $readme, $match) > 0){
107
- $readme = $match[1];
108
- }else{
109
- $readme = '';
110
- }
111
- }
112
- if(!empty($readme)){
113
- //if there's a heading for the currently installed version, take anything above it...
114
- if(($match = strpos($readme, "= $Custom_Menu_Wizard_Widget_Version =")) !== false){
115
- $readme = substr($readme, 0, $match);
116
- }
117
- //trim it...
118
- $readme = trim(str_replace("\r", '', $readme), " \n");
119
- }
120
- if(!empty($readme)){
121
- $readme = preg_replace(
122
- array(
123
- '/^= (\d+\.\d+\.\d+.*) =/m', // => /P H4 Upgrade Notice ... /H4 P
124
- '/(__|\*\*)!\s?([^*]+!)\1/', // => STRONG red ... /STRONG
125
- '/(__|\*\*)([^*]+)\1/', // => STRONG ... /STRONG
126
- '/\*([^*]+)\*/', // => EM ... /EM
127
- '/`([^`]+)`/', // => CODE ... /CODE
128
- '/\[([^\]]+)\]\(([^\)]+)\)/', // => A ... /A
129
- '/\n\+\s+/', // => SPAN indented bullet
130
- '/\n[ \n]*/', // => BR
131
- //remove breaks that immediately follow/precede a paragraph start/end tag...
132
- '/(<p[^>]*>)<br\s\/>/', // => P
133
- '/<br\s\/>(<\/p>)/' // => /P
134
- ),
135
- array(
136
- '</p><h4 style="margin:0;"><em>' . __("Upgrade Notice") . ' $1</em></h4><p style="margin:0.25em 1em;">',
137
- '<strong style="color:#cc0000;">$2</strong>',
138
- '<strong>$2</strong>',
139
- '<em>$1</em>',
140
- '<code>$1</code>',
141
- '<a href="$2">$1</a>',
142
- "\n" . '&nbsp;<span style="margin:0 0.5em;">&bull;</span>',
143
- '<br />',
144
- '$1',
145
- '$1'
146
- ),
147
- //convert html chars...
148
- esc_html($readme)
149
- );
150
- //remove the *first* P end tag...
151
- $readme = preg_replace('/<\/p>/', '', $readme . '</p>', 1);
152
- }
153
- //show if not empty...
154
- if(!empty($readme)){
155
  ?>
156
- <div style="font-weight:normal;background-color:#fff0c0;border:1px solid #d54e21;border-radius:0.5em;margin:0.1em 0;">
157
- <div style="margin:0.5em 0.5em 0.5em 1em;max-height:12em;overflow:auto;">
158
- <?php echo $readme; ?>
159
- </div>
160
- </div>
161
  <?php
162
- }
163
  }
164
  /**
165
  * if the plugin has an update...
@@ -271,6 +237,7 @@ class Custom_Menu_Wizard_Walker extends Walker_Nav_Menu {
271
  );
272
  $allLevels = 9999;
273
  $startWithKidsOf = -1;
 
274
 
275
  foreach( $elements as $i=>$item ){
276
  $itemID = $item->$id_field;
@@ -282,9 +249,38 @@ class Custom_Menu_Wizard_Walker extends Walker_Nav_Menu {
282
  //also note that orphans (in the original menu) are ignored by this widget!
283
  if( isset( $structure[ $parentID ] ) ){
284
  //keep track of current item (as a structure key)...
285
- if( $item->current && empty( $currentItem ) ){
286
- $currentItem = $itemID;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
287
  }
 
288
  //this level...
289
  $thisLevel = $structure[ $parentID ]['level'] + 1;
290
  if( empty( $levels[ $thisLevel ] ) ){
@@ -309,6 +305,13 @@ class Custom_Menu_Wizard_Walker extends Walker_Nav_Menu {
309
  }
310
  } //end foreach
311
 
 
 
 
 
 
 
 
312
  //no point doing much more if we need the current item and we haven't found it, or if we're looking for specific items with none given...
313
  $continue = true;
314
  if( empty( $currentItem ) && ( $find_current_item || $find_current_parent || $find_current_root || $cmw['contains_current'] ) ){
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: 2.0.6
7
  * Author: Roger Barrett
8
  * Author URI: http://www.wizzud.com/
9
  * License: GPL2+
10
  */
11
 
12
  /*
13
+ * v2.0.6 change log:
14
+ * - modified determination of current item to cope better with multiple occurences (still first-found, but within prioritised groups)
15
+ * - replaced display of update information on plugins list with styled request (and link) to read changelog (update info sometimes didn't display, and some considered it "scary" for users)
16
+ *
17
  * v2.0.5 change log:
18
  * - prevent PHP warnings of Undefined index/offset when building $substructure
19
  *
72
  * - moved the setting of 'disabled' attributes on INPUTs/SELECTs from PHP into javascript
73
  */
74
 
75
+ $Custom_Menu_Wizard_Widget_Version = '2.0.6';
76
 
77
  /**
78
  * registers the widget and adds the shortcode
99
  add_action('admin_print_scripts-widgets.php', 'custom_menu_wizard_widget_admin_script');
100
 
101
  /**
102
+ * request read changelog before updating
103
  */
104
  function custom_menu_wizard_update_message($plugin_data, $r){
105
+
106
+ $url = 'http://wordpress.org/plugins/' . $r->slug. '/changelog/';
107
+ $style = implode( ';', array(
108
+ '-webkit-box-sizing:border-box',
109
+ '-moz-box-sizing:border-box',
110
+ 'box-sizing:border-box',
111
+ 'background-color:#D54E21',
112
+ 'border-radius:2px',
113
+ 'color:#FFFFFF',
114
+ 'display:inline-block',
115
+ 'margin:0',
116
+ 'max-width:100%',
117
+ 'overflow:hidden',
118
+ 'padding:0 0.5em',
119
+ 'text-overflow:ellipsis',
120
+ 'text-shadow:0 1px 0 rgba(0, 0, 0, 0.5)',
121
+ 'vertical-align:text-bottom',
122
+ 'white-space:nowrap'
123
+ ) ) . ';';
124
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  ?>
126
+ <p style="<?php echo $style; ?>"><em><?php printf( __('Please <a href="%s" style="color:#FFFFFF;text-decoration:underline;" target="_blank">read the Changelog</a> <strong>before</strong> updating!'), $url ); ?></em></p>
 
 
 
 
127
  <?php
128
+
129
  }
130
  /**
131
  * if the plugin has an update...
237
  );
238
  $allLevels = 9999;
239
  $startWithKidsOf = -1;
240
+ $currentItem = array();
241
 
242
  foreach( $elements as $i=>$item ){
243
  $itemID = $item->$id_field;
249
  //also note that orphans (in the original menu) are ignored by this widget!
250
  if( isset( $structure[ $parentID ] ) ){
251
  //keep track of current item (as a structure key)...
252
+ //v2.0.6 change...
253
+ if( $item->current ){
254
+ //should(!) never get either parent and/or ancestor on an item marked as "current", but unfortunately it does occur (grrr!).
255
+ //so this has to cope, not only with more than 1 "current" item, but also with "current" items that are incorrectly marked
256
+ //as (their own?!) parent and/or ancestor.
257
+ //we're going to look for correctly (solely) marked "current" items and take the first one found;
258
+ //failing that, look for a "current" item that is also marked as parent, and, again, use the first one found;
259
+ //failing that, look for a "current" item that is also marked as an ancestor, and, again, use the first one found.
260
+ //
261
+ //array keys, priority order : just current -> parent, not ancestor -> parent and ancestor -> ancestor
262
+ // first found...
263
+ // - a001 : just current
264
+ // - b001 : current & parent (not ancestor)
265
+ // - c001 : current & parent & ancestor
266
+ // - d001 : current & ancestor (not parent)
267
+ // next found...
268
+ // - a002 : just current
269
+ // - b002 : current & parent (not ancestor)
270
+ // - c002 : current & parent & ancestor
271
+ // - d002 : current & ancestor (not parent)
272
+ // etc
273
+ //example :
274
+ // - 1st found : current & ancestor = d001
275
+ // - 2nd found : current & parent & ancestor = c002
276
+ // - 3rd found : just current = a003
277
+ // - 4th found : just current & parent = b004
278
+ // - 5th found : just current = a005
279
+ //reverse sort keys alphabetically and a003 comes out on bottom, so third found gets used! (copes with 999 "current" items; should be enough!)
280
+ $j = $item->current_item_ancestor ? ( $item->current_item_parent ? 'c' : 'd') : ( $item->current_item_parent ? 'b' : 'a' );
281
+ $currentItem[ $j . sprintf( '%03d' , count( $currentItem ) + 1 ) ] = $itemID;
282
  }
283
+
284
  //this level...
285
  $thisLevel = $structure[ $parentID ]['level'] + 1;
286
  if( empty( $levels[ $thisLevel ] ) ){
305
  }
306
  } //end foreach
307
 
308
+ if( empty( $currentItem ) ){
309
+ $currentItem = false;
310
+ }else{
311
+ krsort( $currentItem );
312
+ $currentItem = array_pop( $currentItem );
313
+ }
314
+
315
  //no point doing much more if we need the current item and we haven't found it, or if we're looking for specific items with none given...
316
  $continue = true;
317
  if( empty( $currentItem ) && ( $find_current_item || $find_current_parent || $find_current_root || $cmw['contains_current'] ) ){
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: wizzud
3
  Tags: menu,widget,widgets,navigation,nav,custom menus,custom menu,partial menu,menu level,menu branch
4
  Requires at least: 3.0.1
5
  Tested up to: 3.8
6
- Stable tag: 2.0.5
7
  License: GPLv2 or Later
8
 
9
  Show branches or levels of your menu in a widget, or in content using a shortcode, with full customisation.
@@ -70,7 +70,7 @@ open by default; all sections below that start off collapsed.
70
  and "Current Parent Item" (v1.1.0) option, followed by all the available items from the menu chosen in `Select Menu`.
71
  The widget will output the *children* of the selected item, always assuming that they lie within the bounds of any other parameters set.
72
 
73
- * "Current Item" is the menu item that WordPress recognises as being currently on display (current menu item)
74
 
75
  * "Current Parent Item" (v1.1.0) is the *immediate* ancestor (within `Select Menu`) of the current menu item
76
 
@@ -489,6 +489,12 @@ It was a close call, but since the Output options can extend the final list - an
489
 
490
  == Changelog ==
491
 
 
 
 
 
 
 
492
  = 2.0.5 =
493
 
494
  * bugfix : prevent PHP warnings of Undefined index/offset
@@ -593,6 +599,11 @@ Initial release
593
 
594
  == Upgrade Notice ==
595
 
 
 
 
 
 
596
  = 2.0.5 =
597
 
598
  Fixed a bug to prevent PHP warnings of Undefined index/offset being output.
3
  Tags: menu,widget,widgets,navigation,nav,custom menus,custom menu,partial menu,menu level,menu branch
4
  Requires at least: 3.0.1
5
  Tested up to: 3.8
6
+ Stable tag: 2.0.6
7
  License: GPLv2 or Later
8
 
9
  Show branches or levels of your menu in a widget, or in content using a shortcode, with full customisation.
70
  and "Current Parent Item" (v1.1.0) option, followed by all the available items from the menu chosen in `Select Menu`.
71
  The widget will output the *children* of the selected item, always assuming that they lie within the bounds of any other parameters set.
72
 
73
+ * "Current Item" is the menu item that WordPress has marked as being currently on display (current menu item)
74
 
75
  * "Current Parent Item" (v1.1.0) is the *immediate* ancestor (within `Select Menu`) of the current menu item
76
 
489
 
490
  == Changelog ==
491
 
492
+ = 2.0.6 =
493
+
494
+ * change : modified determination of current item to cope better with multiple occurences (still first-found, but within prioritised groups)
495
+
496
+ * change : display of the upgrade notice in the plugins list has been replaced with a simple request to read the changelog before upgrading
497
+
498
  = 2.0.5 =
499
 
500
  * bugfix : prevent PHP warnings of Undefined index/offset
599
 
600
  == Upgrade Notice ==
601
 
602
+ = 2.0.6 =
603
+
604
+ Determination of the current menu item has been slightly modified to cope a bit better with occasions where multiple items have been set as "current".
605
+ The display of the upgrade notice in the plugins list has been replaced with a simple request to read the changelog before upgrading.
606
+
607
  = 2.0.5 =
608
 
609
  Fixed a bug to prevent PHP warnings of Undefined index/offset being output.