If Menu – Visibility control for Menu Items - Version 0.2

Version Description

Update for compatibility with newer versions of WordPress

  • Feature - access to menu item object in condition callback (thanks BramNL)
  • Fix - alert for leaving page even if no changes were made for menus (thanks Denny)
  • Fix - update method in Walker_Nav_Menu_Edit to be compatible with newer version of WP
  • Fix - example in Readme (thanks BramNL)
Download this release

Release Info

Developer andrei.igna
Plugin Icon 128x128 If Menu – Visibility control for Menu Items
Version 0.2
Comparing to
See all releases

Code changes from version 0.1 to 0.2

Files changed (3) hide show
  1. if-menu.js +1 -1
  2. if-menu.php +9 -9
  3. readme.txt +34 -18
if-menu.js CHANGED
@@ -2,6 +2,6 @@ jQuery( function( $ ) {
2
 
3
  $( '.menu-item-if-menu-enable' ).change( function() {
4
  $( this ).closest( '.if-menu-enable' ).next().toggle( $( this ).prop( 'checked' ) );
5
- } ).trigger( 'change' );
6
 
7
  } );
2
 
3
  $( '.menu-item-if-menu-enable' ).change( function() {
4
  $( this ).closest( '.if-menu-enable' ).next().toggle( $( this ).prop( 'checked' ) );
5
+ } );
6
 
7
  } );
if-menu.php CHANGED
@@ -1,15 +1,15 @@
1
  <?php
2
  /*
3
  Plugin Name: If Menu
4
- Plugin URI: http://morewp.net/plugin/if-menu
5
  Description: Show/hide menu items with conditional statements
6
- Version: 0.1
7
- Author: More WordPress
8
- Author URI: http://morewp.net
9
  License: GPL2
10
  */
11
 
12
- /* Copyright 2012 More WordPress (email: hello@morewp.net)
13
 
14
  This program is free software; you can redistribute it and/or modify
15
  it under the terms of the GNU General Public License, version 2, as
@@ -75,7 +75,7 @@ class If_Menu {
75
  $condition_type = get_post_meta( $item->ID, 'if_menu_condition_type', true );
76
  $condition = get_post_meta( $item->ID, 'if_menu_condition', true );
77
 
78
- $condition_result = call_user_func( $conditions[$condition]['condition'] );
79
  if( $condition_type == 'show' ) $condition_result = ! $condition_result;
80
 
81
  if( $condition_result ) {
@@ -110,7 +110,7 @@ class If_Menu {
110
  </label>
111
  </p>
112
 
113
- <p class="if-menu-condition description description-wide">
114
  <select id="edit-menu-item-if-menu-condition-type-<?php echo $item->ID; ?>" name="menu-item-if-menu-condition-type[<?php echo $item->ID; ?>]">
115
  <option <?php selected( 'show', $if_menu_condition_type ) ?> value="show"><?php _e( 'Show', 'if-menu' ) ?></option>
116
  <option <?php selected( 'hide', $if_menu_condition_type ) ?> value="hide"><?php _e( 'Hide', 'if-menu' ) ?></option>
@@ -150,9 +150,9 @@ require_once( ABSPATH . 'wp-admin/includes/nav-menu.php' );
150
 
151
  class If_Menu_Walker_Nav_Menu_Edit extends Walker_Nav_Menu_Edit {
152
 
153
- function start_el(&$output, $item, $depth, $args) {
154
  $desc_snipp = '<div class="menu-item-actions description-wide submitbox">';
155
- parent::start_el($output, $item, $depth, $args);
156
 
157
  $pos = strrpos( $output, $desc_snipp );
158
  if( $pos !== false ) {
1
  <?php
2
  /*
3
  Plugin Name: If Menu
4
+ Plugin URI: http://wordpress.org/plugins/if-menu/
5
  Description: Show/hide menu items with conditional statements
6
+ Version: 0.2
7
+ Author: Andrei Igna
8
+ Author URI: http://rokm.ro
9
  License: GPL2
10
  */
11
 
12
+ /* Copyright 2012 More WordPress (email: andrei@rokm.ro)
13
 
14
  This program is free software; you can redistribute it and/or modify
15
  it under the terms of the GNU General Public License, version 2, as
75
  $condition_type = get_post_meta( $item->ID, 'if_menu_condition_type', true );
76
  $condition = get_post_meta( $item->ID, 'if_menu_condition', true );
77
 
78
+ $condition_result = call_user_func( $conditions[$condition]['condition'], $item );
79
  if( $condition_type == 'show' ) $condition_result = ! $condition_result;
80
 
81
  if( $condition_result ) {
110
  </label>
111
  </p>
112
 
113
+ <p class="if-menu-condition description description-wide" style="display: <?php echo $if_menu_enable ? 'block' : 'none' ?>">
114
  <select id="edit-menu-item-if-menu-condition-type-<?php echo $item->ID; ?>" name="menu-item-if-menu-condition-type[<?php echo $item->ID; ?>]">
115
  <option <?php selected( 'show', $if_menu_condition_type ) ?> value="show"><?php _e( 'Show', 'if-menu' ) ?></option>
116
  <option <?php selected( 'hide', $if_menu_condition_type ) ?> value="hide"><?php _e( 'Hide', 'if-menu' ) ?></option>
150
 
151
  class If_Menu_Walker_Nav_Menu_Edit extends Walker_Nav_Menu_Edit {
152
 
153
+ function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
154
  $desc_snipp = '<div class="menu-item-actions description-wide submitbox">';
155
+ parent::start_el( $output, $item, $depth, $args, $id );
156
 
157
  $pos = strrpos( $output, $desc_snipp );
158
  if( $pos !== false ) {
readme.txt CHANGED
@@ -1,8 +1,8 @@
1
- === Plugin Name ===
2
  Contributors: andrei.igna
3
  Tags: menu, if, conditional, statements, hide, show, dispaly
4
- Requires at least: 3.0.0
5
- Tested up to: 3.4
6
  Stable tag: trunk
7
  License: GPL2
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -13,9 +13,9 @@ Show/hide menu items with conditional statements
13
 
14
  Simple plugin that adds extra functionality to Menu Items. The plugin will allow to show or hide menu items based on condition statements (Is single page, User is Logged In, etc).
15
 
16
- The management is very easy, each menu item will have a "Enable Conditional Logic" check, that will allow to select a conditional statement (Example in Screenshots)
17
 
18
- Basic conditional statements are included in the plugin, other will be included in future releases or can be added nu another plugin or theme.
19
 
20
  Example of adding a new conditional statement is described in the FAQ section
21
 
@@ -29,24 +29,31 @@ To install the plugin, follow the steps below
29
 
30
  == Frequently Asked Questions ==
31
 
32
- = How can I add a conditinal statement =
33
 
34
- New conditional statements can be added by any other plugin or theme.
35
 
36
- Example of adding a new conditional statement
37
 
38
- ``
 
39
  add_filter( 'if_menu_conditions', 'my_new_menu_conditions' );
40
 
41
- function my_new_menu_conditions( $conditions ) {
42
- $conditions[] = array(
43
- 'name' => 'If single custom-post-type', // name of the condition
44
- 'condition' => function() { // callback - must return TRUE or FALSE
45
- return is_singular( 'my-custom-post-type' );
46
- }
47
- );
 
 
48
  }
49
- ``
 
 
 
 
50
 
51
  == Screenshots ==
52
 
@@ -54,5 +61,14 @@ function my_new_menu_conditions( $conditions ) {
54
 
55
  == Changelog ==
56
 
 
 
 
 
 
 
 
 
 
57
  = 0.1 =
58
- Plugin release. Included basic menu conditional statements
1
+ === If Menu ===
2
  Contributors: andrei.igna
3
  Tags: menu, if, conditional, statements, hide, show, dispaly
4
+ Requires at least: 3.7
5
+ Tested up to: 3.9.1
6
  Stable tag: trunk
7
  License: GPL2
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
13
 
14
  Simple plugin that adds extra functionality to Menu Items. The plugin will allow to show or hide menu items based on condition statements (Is single page, User is Logged In, etc).
15
 
16
+ The management is very easy, each menu item will have a "Enable Conditional Logic" check that will allow to select a conditional statement (Example in Screenshots)
17
 
18
+ Basic conditional statements are included in the plugin, other will be included in future releases or can be added by another plugins or themes.
19
 
20
  Example of adding a new conditional statement is described in the FAQ section
21
 
29
 
30
  == Frequently Asked Questions ==
31
 
32
+ = How can I add a conditinal statement for menu items? =
33
 
34
+ New conditional statements can be added by any other plugins or themes.
35
 
36
+ Example of adding a new conditional statement for disaplying/hiding a menu item when current page is a custom-post-type.
37
 
38
+ `
39
+ // theme's functions.php or plugin file
40
  add_filter( 'if_menu_conditions', 'my_new_menu_conditions' );
41
 
42
+ function my_new_menu_conditions( $conditions ) {
43
+ $conditions[] = array(
44
+ 'name' => 'If single custom-post-type', // name of the condition
45
+ 'condition' => function($item) { // callback - must return TRUE or FALSE
46
+ return is_singular( 'my-custom-post-type' );
47
+ }
48
+ );
49
+
50
+ return $conditions;
51
  }
52
+ `
53
+
54
+ = Where do I find conditional functions? =
55
+
56
+ WordPress provides [a lot of functions](http://codex.wordpress.org/Conditional_Tags) which can be used to create conditional statements for almost any combination that a theme/plugin developer can think of.
57
 
58
  == Screenshots ==
59
 
61
 
62
  == Changelog ==
63
 
64
+ = 0.2 =
65
+
66
+ Update for compatibility with newer versions of WordPress
67
+
68
+ * [Feature](http://wordpress.org/support/topic/new-feature-power-to-the-conditions) - access to menu item object in condition callback (thanks [BramNL](http://wordpress.org/support/profile/bramnl))
69
+ * [Fix](http://wordpress.org/support/topic/save-is-requested-before-leaving-menu-page) - alert for leaving page even if no changes were made for menus (thanks [Denny](http://wordpress.org/support/profile/ddahly))
70
+ * Fix - update method in `Walker_Nav_Menu_Edit` to be compatible with newer version of WP
71
+ * [Fix](http://wordpress.org/support/topic/bugfix-for-readmetxt) - example in Readme (thanks [BramNL](http://wordpress.org/support/profile/bramnl))
72
+
73
  = 0.1 =
74
+ * Plugin release. Included basic menu conditional statements