Nav Menu Roles - Version 1.8.1

Version Description

  • Switch input names to use a counter [nav-menu-role][100][1]. For some reason [nav-menu-role][100][] doesn't post an array and hypenated names [nav-menu-role][100][gold-plan] wreak havoc on the save routine. Shouldn't impact anyone not using hyphenated role names.
Download this release

Release Info

Developer helgatheviking
Plugin Icon 128x128 Nav Menu Roles
Version 1.8.1
Comparing to
See all releases

Code changes from version 1.8.0 to 1.8.1

Files changed (3) hide show
  1. assets/screenshot-1.jpg +0 -0
  2. nav-menu-roles.php +19 -9
  3. readme.txt +8 -5
assets/screenshot-1.jpg ADDED
Binary file
nav-menu-roles.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Nav Menu Roles
4
  Plugin URI: http://www.kathyisawesome.com/449/nav-menu-roles/
5
  Description: Hide custom menu items based on user roles.
6
- Version: 1.8.0
7
  Author: Kathy Darling
8
  Author URI: http://www.kathyisawesome.com
9
  License: GPL2
@@ -54,7 +54,7 @@ class Nav_Menu_Roles {
54
  * @constant string version number
55
  * @since 1.7.1
56
  */
57
- CONST VERSION = '1.8.0';
58
 
59
  /**
60
  * Main Nav Menu Roles Instance
@@ -327,6 +327,8 @@ class Nav_Menu_Roles {
327
  <br />
328
 
329
  <?php
 
 
330
 
331
  /* Loop through each of the available roles. */
332
  foreach ( $display_roles as $role => $name ) {
@@ -337,9 +339,10 @@ class Nav_Menu_Roles {
337
  ?>
338
 
339
  <div class="role-input-holder" style="float: left; width: 33.3%; margin: 2px 0;">
340
- <input type="checkbox" name="nav-menu-role[<?php echo $item->ID ;?>][<?php echo $role; ?>]" id="nav_menu_role-<?php echo $role; ?>-for-<?php echo $item->ID ;?>" <?php echo $checked; ?> value="<?php echo $role; ?>" />
341
  <label for="nav_menu_role-<?php echo $role; ?>-for-<?php echo $item->ID ;?>">
342
  <?php echo esc_html( $name ); ?>
 
343
  </label>
344
  </div>
345
 
@@ -375,19 +378,26 @@ class Nav_Menu_Roles {
375
  $allowed_roles = apply_filters( 'nav_menu_roles', $wp_roles->role_names );
376
 
377
  // verify this came from our screen and with proper authorization.
378
- if ( ! isset( $_POST['nav-menu-role-nonce'] ) || ! wp_verify_nonce( $_POST['nav-menu-role-nonce'], 'nav-menu-nonce-name' ) )
379
  return;
380
-
 
381
  $saved_data = false;
382
 
383
  if ( isset( $_POST['nav-menu-logged-in-out'][$menu_item_db_id] ) && $_POST['nav-menu-logged-in-out'][$menu_item_db_id] == 'in' && ! empty ( $_POST['nav-menu-role'][$menu_item_db_id] ) ) {
 
384
  $custom_roles = array();
 
385
  // only save allowed roles
386
- foreach( $_POST['nav-menu-role'][$menu_item_db_id] as $role ) {
387
- if ( array_key_exists ( $role, $allowed_roles ) ) $custom_roles[] = $role;
 
 
 
 
 
388
  }
389
- if ( ! empty ( $custom_roles ) ) $saved_data = $custom_roles;
390
- } else if ( isset( $_POST['nav-menu-logged-in-out'][$menu_item_db_id] ) && in_array( $_POST['nav-menu-logged-in-out'][$menu_item_db_id], array( 'in', 'out' ) ) ) {
391
  $saved_data = $_POST['nav-menu-logged-in-out'][$menu_item_db_id];
392
  }
393
 
3
  Plugin Name: Nav Menu Roles
4
  Plugin URI: http://www.kathyisawesome.com/449/nav-menu-roles/
5
  Description: Hide custom menu items based on user roles.
6
+ Version: 1.8.1
7
  Author: Kathy Darling
8
  Author URI: http://www.kathyisawesome.com
9
  License: GPL2
54
  * @constant string version number
55
  * @since 1.7.1
56
  */
57
+ CONST VERSION = '1.8.1';
58
 
59
  /**
60
  * Main Nav Menu Roles Instance
327
  <br />
328
 
329
  <?php
330
+
331
+ $i = 1;
332
 
333
  /* Loop through each of the available roles. */
334
  foreach ( $display_roles as $role => $name ) {
339
  ?>
340
 
341
  <div class="role-input-holder" style="float: left; width: 33.3%; margin: 2px 0;">
342
+ <input type="checkbox" name="nav-menu-role[<?php echo $item->ID ;?>][<?php echo $i; ?>]" id="nav_menu_role-<?php echo $role; ?>-for-<?php echo $item->ID ;?>" <?php echo $checked; ?> value="<?php echo $role; ?>" />
343
  <label for="nav_menu_role-<?php echo $role; ?>-for-<?php echo $item->ID ;?>">
344
  <?php echo esc_html( $name ); ?>
345
+ <?php $i++; ?>
346
  </label>
347
  </div>
348
 
378
  $allowed_roles = apply_filters( 'nav_menu_roles', $wp_roles->role_names );
379
 
380
  // verify this came from our screen and with proper authorization.
381
+ if ( ! isset( $_POST['nav-menu-role-nonce'] ) || ! wp_verify_nonce( $_POST['nav-menu-role-nonce'], 'nav-menu-nonce-name' ) ){
382
  return;
383
+ }
384
+
385
  $saved_data = false;
386
 
387
  if ( isset( $_POST['nav-menu-logged-in-out'][$menu_item_db_id] ) && $_POST['nav-menu-logged-in-out'][$menu_item_db_id] == 'in' && ! empty ( $_POST['nav-menu-role'][$menu_item_db_id] ) ) {
388
+
389
  $custom_roles = array();
390
+
391
  // only save allowed roles
392
+ foreach( (array) $_POST['nav-menu-role'][$menu_item_db_id] as $role ) {
393
+ if ( array_key_exists ( $role, $allowed_roles ) ) {
394
+ $custom_roles[] = $role;
395
+ }
396
+ }
397
+ if ( ! empty ( $custom_roles ) ) {
398
+ $saved_data = $custom_roles;
399
  }
400
+ } else if ( isset( $_POST['nav-menu-logged-in-out'][$menu_item_db_id] ) && in_array( $_POST['nav-menu-logged-in-out'][$menu_item_db_id], array( 'in', 'out' ) ) ) {
 
401
  $saved_data = $_POST['nav-menu-logged-in-out'][$menu_item_db_id];
402
  }
403
 
readme.txt CHANGED
@@ -5,7 +5,7 @@ Donate link: https://www.paypal.me/helgatheviking
5
  Tags: menu, menus, nav menu, nav menus
6
  Requires at least: 4.5.0
7
  Tested up to: 4.5.1
8
- Stable tag: 1.8.0
9
  License: GPLv3
10
 
11
  Hide custom menu items based on user roles. PLEASE READ THE FAQ IF YOU ARE NOT SEEING THE SETTINGS.
@@ -23,9 +23,8 @@ In WordPress menu items and pages are completely separate entities. Nav Menu Rol
23
  = Usage =
24
 
25
  1. Go to Appearance > Menus
26
- 1. Edit the menu items accordingly. First select whether you'd like to display the item to all logged in users, all logged out users or to customize by role.
27
- 1. If you chose customize by role, keep in mind that the role doesn't limit the item strictly to that role, but to everyone who has that role's capability. For example: an item set to "Subscriber" will be visible by Subscribers *and* by admins. Think of this more as a minimum role required to see an item.
28
- 1. If you choose 'By Role' and don't check any boxes, the item will be visible to everyone like normal.
29
 
30
  = Support =
31
 
@@ -62,7 +61,8 @@ WordPress does not have sufficient hooks in this area of the admin and until the
62
  5. BeTheme
63
  6. Yith Menu
64
  7. Jupiter Theme
65
- 8. iMedica
 
66
 
67
 
68
  = <a id="compatibility"></a>Workaround #1 =
@@ -199,6 +199,9 @@ However, the Import plugin only imports certain post meta for menu items. As of
199
 
200
  == Changelog ==
201
 
 
 
 
202
  = 1.8.0 =
203
  * Fix style issue in WordPress 4.5
204
 
5
  Tags: menu, menus, nav menu, nav menus
6
  Requires at least: 4.5.0
7
  Tested up to: 4.5.1
8
+ Stable tag: 1.8.1
9
  License: GPLv3
10
 
11
  Hide custom menu items based on user roles. PLEASE READ THE FAQ IF YOU ARE NOT SEEING THE SETTINGS.
23
  = Usage =
24
 
25
  1. Go to Appearance > Menus
26
+ 1. Set the "Display Mode" to either "logged in users", "logged out users", or "everyone". "Everyone" is the default.
27
+ 1. If you wish to customize by role, set the "Display Mode" to "Logged In Users" and under "Restrict menu item to a minimum role" check the boxes next to the desired roles. **Keep in mind that the role doesn't limit the item strictly to that role, but to everyone who has that role's capability.** For example: an item set to "Subscriber" will be visible by Subscribers *and* by admins. Think of this more as a minimum role required to see an item.
 
28
 
29
  = Support =
30
 
61
  5. BeTheme
62
  6. Yith Menu
63
  7. Jupiter Theme
64
+ 8. iMedica theme
65
+ 9. Prostyler EVO theme
66
 
67
 
68
  = <a id="compatibility"></a>Workaround #1 =
199
 
200
  == Changelog ==
201
 
202
+ = 1.8.1 =
203
+ * Switch input names to use a counter [nav-menu-role][100][1]. For some reason [nav-menu-role][100][] doesn't post an array and hypenated names [nav-menu-role][100][gold-plan] wreak havoc on the save routine. Shouldn't impact anyone not using hyphenated role names.
204
+
205
  = 1.8.0 =
206
  * Fix style issue in WordPress 4.5
207