Nav Menu Roles - Version 1.9.0

Version Description

  • Add support for multisite. Props @open-dsi and @fiech.
Download this release

Release Info

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

Code changes from version 1.8.6 to 1.9.0

inc/class.Walker_Nav_Menu_Edit_Roles_4.7.php CHANGED
@@ -1,69 +1,69 @@
1
- <?php
2
- /**
3
- * Custom Walker for Nav Menu Editor
4
- * Add wp_nav_menu_item_custom_fields hook
5
- * Hat tip to @kucrut and Menu Icons for the preg_replace() idea
6
- * means I no longer have to translate core strings
7
- *
8
- * @package Nav Menu Roles
9
- * @since 1.8.6
10
- * @uses Walker_Nav_Menu_Edit
11
- */
12
- class Walker_Nav_Menu_Edit_Roles extends Walker_Nav_Menu_Edit {
13
-
14
- /**
15
- * Start the element output.
16
- *
17
- * @see Walker_Nav_Menu::start_el()
18
- *
19
- * @param string $output Passed by reference. Used to append additional content.
20
- * @param object $item Menu item data object.
21
- * @param int $depth Depth of menu item. Used for padding.
22
- * @param array $args Not used.
23
- * @param int $id Not used.
24
- */
25
- public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
26
- $item_output = '';
27
- $output .= parent::start_el( $item_output, $item, $depth, $args, $id );
28
- $output .= preg_replace(
29
- // NOTE: Check this regex on major WP version updates!
30
- '/(?=<fieldset[^>]+class="[^"]*field-move)/',
31
- $this->get_custom_fields( $item, $depth, $args ),
32
- $item_output
33
- );
34
- }
35
-
36
-
37
- /**
38
- * Get custom fields
39
- *
40
- * @access protected
41
- * @since 0.1.0
42
- * @uses do_action() Calls 'menu_item_custom_fields' hook
43
- *
44
- * @param object $item Menu item data object.
45
- * @param int $depth Depth of menu item. Used for padding.
46
- * @param array $args Menu item args.
47
- * @param int $id Nav menu ID.
48
- *
49
- * @return string Form fields
50
- */
51
- protected function get_custom_fields( $item, $depth, $args = array(), $id = 0 ) {
52
- ob_start();
53
- $item_id = intval( $item->ID );
54
- /**
55
- * Get menu item custom fields from plugins/themes
56
- *
57
- * @since 0.1.0
58
- *
59
- * @param int $item_id post ID of menu
60
- * @param object $item Menu item data object.
61
- * @param int $depth Depth of menu item. Used for padding.
62
- * @param array $args Menu item args.
63
- *
64
- * @return string Custom fields
65
- */
66
- do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args );
67
- return ob_get_clean();
68
- }
69
  } // Walker_Nav_Menu_Edit
1
+ <?php
2
+ /**
3
+ * Custom Walker for Nav Menu Editor
4
+ * Add wp_nav_menu_item_custom_fields hook
5
+ * Hat tip to @kucrut and Menu Icons for the preg_replace() idea
6
+ * means I no longer have to translate core strings
7
+ *
8
+ * @package Nav Menu Roles
9
+ * @since 1.8.6
10
+ * @uses Walker_Nav_Menu_Edit
11
+ */
12
+ class Walker_Nav_Menu_Edit_Roles extends Walker_Nav_Menu_Edit {
13
+
14
+ /**
15
+ * Start the element output.
16
+ *
17
+ * @see Walker_Nav_Menu::start_el()
18
+ *
19
+ * @param string $output Passed by reference. Used to append additional content.
20
+ * @param object $item Menu item data object.
21
+ * @param int $depth Depth of menu item. Used for padding.
22
+ * @param array $args Not used.
23
+ * @param int $id Not used.
24
+ */
25
+ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
26
+ $item_output = '';
27
+ $output .= parent::start_el( $item_output, $item, $depth, $args, $id );
28
+ $output .= preg_replace(
29
+ // NOTE: Check this regex on major WP version updates!
30
+ '/(?=<fieldset[^>]+class="[^"]*field-move)/',
31
+ $this->get_custom_fields( $item, $depth, $args ),
32
+ $item_output
33
+ );
34
+ }
35
+
36
+
37
+ /**
38
+ * Get custom fields
39
+ *
40
+ * @access protected
41
+ * @since 0.1.0
42
+ * @uses do_action() Calls 'menu_item_custom_fields' hook
43
+ *
44
+ * @param object $item Menu item data object.
45
+ * @param int $depth Depth of menu item. Used for padding.
46
+ * @param array $args Menu item args.
47
+ * @param int $id Nav menu ID.
48
+ *
49
+ * @return string Form fields
50
+ */
51
+ protected function get_custom_fields( $item, $depth, $args = array(), $id = 0 ) {
52
+ ob_start();
53
+ $item_id = intval( $item->ID );
54
+ /**
55
+ * Get menu item custom fields from plugins/themes
56
+ *
57
+ * @since 0.1.0
58
+ *
59
+ * @param int $item_id post ID of menu
60
+ * @param object $item Menu item data object.
61
+ * @param int $depth Depth of menu item. Used for padding.
62
+ * @param array $args Menu item args.
63
+ *
64
+ * @return string Custom fields
65
+ */
66
+ do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args );
67
+ return ob_get_clean();
68
+ }
69
  } // Walker_Nav_Menu_Edit
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.6
7
  Author: Kathy Darling
8
  Author URI: http://www.kathyisawesome.com
9
  License: GPL-3.0
@@ -48,13 +48,13 @@ class Nav_Menu_Roles {
48
  * @constant string donate url
49
  * @since 1.5
50
  */
51
- CONST DONATE_URL = "https://inspirepay.com/pay/helgatheviking/10";
52
 
53
  /**
54
  * @constant string version number
55
  * @since 1.7.1
56
  */
57
- CONST VERSION = '1.8.6';
58
 
59
  /**
60
  * Main Nav Menu Roles Instance
@@ -329,7 +329,7 @@ class Nav_Menu_Roles {
329
  <br />
330
 
331
  <?php
332
-
333
  $i = 1;
334
 
335
  /* Loop through each of the available roles. */
@@ -426,11 +426,15 @@ class Nav_Menu_Roles {
426
  }
427
 
428
  /**
429
- * Exclude menu items via wp_get_nav_menu_items filter
430
- * this fixes plugin's incompatibility with theme's that use their own custom Walker
431
- * Thanks to Evan Stein @vanpop http://vanpop.com/
432
- * @since 1.2
433
- */
 
 
 
 
434
  public function exclude_menu_items( $items ) {
435
 
436
  $hide_children_of = array();
@@ -452,10 +456,26 @@ class Nav_Menu_Roles {
452
  // check all logged in, all logged out, or role
453
  switch( $item->roles ) {
454
  case 'in' :
455
- $visible = is_user_logged_in() ? true : false;
 
 
 
 
 
 
 
456
  break;
457
  case 'out' :
458
- $visible = ! is_user_logged_in() ? true : false;
 
 
 
 
 
 
 
 
 
459
  break;
460
  default:
461
  $visible = false;
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.9.0
7
  Author: Kathy Darling
8
  Author URI: http://www.kathyisawesome.com
9
  License: GPL-3.0
48
  * @constant string donate url
49
  * @since 1.5
50
  */
51
+ CONST DONATE_URL = "https://paypal.me/helgatheviking/20";
52
 
53
  /**
54
  * @constant string version number
55
  * @since 1.7.1
56
  */
57
+ CONST VERSION = '1.9.0';
58
 
59
  /**
60
  * Main Nav Menu Roles Instance
329
  <br />
330
 
331
  <?php
332
+
333
  $i = 1;
334
 
335
  /* Loop through each of the available roles. */
426
  }
427
 
428
  /**
429
+ * Exclude menu items via wp_get_nav_menu_items filter
430
+ * this fixes plugin's incompatibility with theme's that use their own custom Walker
431
+ * Thanks to Evan Stein @vanpop http://vanpop.com/
432
+ *
433
+ * @since 1.2
434
+ *
435
+ * Multisite compatibility added in 1.9.0
436
+ * by @open-dsi https://www.open-dsi.fr/ with props to @fiech
437
+ */
438
  public function exclude_menu_items( $items ) {
439
 
440
  $hide_children_of = array();
456
  // check all logged in, all logged out, or role
457
  switch( $item->roles ) {
458
  case 'in' :
459
+ /**
460
+ * Multisite compatibility.
461
+ *
462
+ * For the logged in condition to work,
463
+ * the user has to be a logged in member of the current blog
464
+ * or be a logged in super user.
465
+ */
466
+ $visible = is_user_member_of_blog() || is_super_admin() ? true : false;
467
  break;
468
  case 'out' :
469
+ /**
470
+ * Multisite compatibility.
471
+ *
472
+ * For the logged out condition to work,
473
+ * the user has to be either logged out
474
+ * or not be a member of the current blog.
475
+ * But they also may not be a super admin,
476
+ * because logged in super admins should see the internal stuff, not the external.
477
+ */
478
+ $visible = ! is_user_member_of_blog() && ! is_super_admin() ? true : false;
479
  break;
480
  default:
481
  $visible = false;
readme.txt CHANGED
@@ -1,11 +1,11 @@
1
  === Nav Menu Roles ===
2
 
3
  Contributors: helgatheviking
4
- 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.7.0
8
- Stable tag: 1.8.6
9
  License: GPLv3
10
 
11
  Hide custom menu items based on user roles. PLEASE READ THE FAQ IF YOU ARE NOT SEEING THE SETTINGS.
@@ -202,8 +202,15 @@ However, the Import plugin only imports certain post meta for menu items. As of
202
  1. Use the same .xml file and perform a second import
203
  1. No duplicate posts will be created but all menu post meta (including your Nav Menu Roles info) will be imported
204
 
 
 
 
 
205
  == Changelog ==
206
 
 
 
 
207
  = 1.8.5 =
208
  * Use new Walker for WP4.7
209
 
1
  === Nav Menu Roles ===
2
 
3
  Contributors: helgatheviking
4
+ Donate link: https://www.paypal.me/helgatheviking/20
5
  Tags: menu, menus, nav menu, nav menus
6
  Requires at least: 4.5.0
7
+ Tested up to: 4.8.3
8
+ Stable tag: 1.9.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.
202
  1. Use the same .xml file and perform a second import
203
  1. No duplicate posts will be created but all menu post meta (including your Nav Menu Roles info) will be imported
204
 
205
+ = Is Nav Menu Roles compatible with WPML ? =
206
+
207
+ Yes, but manually. WPML developers have informed me that the meta data for nav menu items is **not** synced by WPML, meaning that menus copied into a new language will not bring their custom Nav Menu Roles settings. However, if you manually reconfigure the settings, the new language menu will work as expected.
208
+
209
  == Changelog ==
210
 
211
+ = 1.9.0 =
212
+ * Add support for multisite. Props @open-dsi and @fiech.
213
+
214
  = 1.8.5 =
215
  * Use new Walker for WP4.7
216