Nav Menu Roles - Version 1.10.0

Version Description

  • Fix: My hook made it into core for WP5.4!! Can finally stop overriding the admin menu Walker.
Download this release

Release Info

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

Code changes from version 1.9.5 to 1.10.0

Files changed (2) hide show
  1. nav-menu-roles.php +24 -9
  2. readme.txt +5 -2
nav-menu-roles.php CHANGED
@@ -3,13 +3,13 @@
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.5
7
  Author: Kathy Darling
8
  Author URI: http://www.kathyisawesome.com
9
  License: GPL-3.0
10
  Text Domain: nav-menu-roles
11
 
12
- Copyright 2017 Kathy Darling(email: kathy@kathyisawesome.com)
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
@@ -54,7 +54,7 @@ class Nav_Menu_Roles {
54
  * @constant string version number
55
  * @since 1.7.0
56
  */
57
- CONST VERSION = '1.9.5';
58
 
59
  /**
60
  * Main Nav Menu Roles Instance
@@ -108,8 +108,10 @@ class Nav_Menu_Roles {
108
  // Add FAQ and Donate link to plugin.
109
  add_filter( 'plugin_row_meta', array( $this, 'add_action_links' ), 10, 2 );
110
 
111
- // Switch the admin walker.
112
- add_filter( 'wp_edit_nav_menu_walker', array( $this, 'edit_nav_menu_walker' ) );
 
 
113
 
114
  // Add new fields via hook.
115
  add_action( 'wp_nav_menu_item_custom_fields', array( $this, 'custom_fields' ), 10, 4 );
@@ -234,11 +236,11 @@ class Nav_Menu_Roles {
234
  * @since 1.0
235
  */
236
  public function edit_nav_menu_walker( $walker ) {
237
- if( ! class_exists( 'Walker_Nav_Menu_Edit_Roles' ) ){
238
- global $wp_version;
239
- if ( version_compare( $wp_version, '4.7', '>=' ) ){
240
  require_once( plugin_dir_path( __FILE__ ) . 'inc/class.Walker_Nav_Menu_Edit_Roles_4.7.php' );
241
- } else if ( version_compare( $wp_version, '4.5', '>=' ) ){
242
  require_once( plugin_dir_path( __FILE__ ) . 'inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php' );
243
  } else {
244
  require_once( plugin_dir_path( __FILE__ ) . 'inc/class.Walker_Nav_Menu_Edit_Roles.php' );
@@ -517,6 +519,7 @@ class Nav_Menu_Roles {
517
  foreach ( $item->roles as $role ) {
518
  if ( current_user_can( $role ) ) {
519
  $visible = true;
 
520
  }
521
  }
522
  }
@@ -566,6 +569,18 @@ class Nav_Menu_Roles {
566
  }
567
  }
568
 
 
 
 
 
 
 
 
 
 
 
 
 
569
  } // end class
570
 
571
  endif; // class_exists check
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.10.0
7
  Author: Kathy Darling
8
  Author URI: http://www.kathyisawesome.com
9
  License: GPL-3.0
10
  Text Domain: nav-menu-roles
11
 
12
+ Copyright 2020 Kathy Darling
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
54
  * @constant string version number
55
  * @since 1.7.0
56
  */
57
+ CONST VERSION = '1.10.0';
58
 
59
  /**
60
  * Main Nav Menu Roles Instance
108
  // Add FAQ and Donate link to plugin.
109
  add_filter( 'plugin_row_meta', array( $this, 'add_action_links' ), 10, 2 );
110
 
111
+ // Maybe switch the admin walker.
112
+ if( ! self::is_wp_gte( '5.4' ) ) {
113
+ add_filter( 'wp_edit_nav_menu_walker', array( $this, 'edit_nav_menu_walker' ) );
114
+ }
115
 
116
  // Add new fields via hook.
117
  add_action( 'wp_nav_menu_item_custom_fields', array( $this, 'custom_fields' ), 10, 4 );
236
  * @since 1.0
237
  */
238
  public function edit_nav_menu_walker( $walker ) {
239
+ if( ! class_exists( 'Walker_Nav_Menu_Edit_Roles' ) ) {
240
+
241
+ if ( self::is_wp_gte( '4.7' ) ) {
242
  require_once( plugin_dir_path( __FILE__ ) . 'inc/class.Walker_Nav_Menu_Edit_Roles_4.7.php' );
243
+ } else if ( self::is_wp_gte( '4.5' ) ) {
244
  require_once( plugin_dir_path( __FILE__ ) . 'inc/class.Walker_Nav_Menu_Edit_Roles_4.5.php' );
245
  } else {
246
  require_once( plugin_dir_path( __FILE__ ) . 'inc/class.Walker_Nav_Menu_Edit_Roles.php' );
519
  foreach ( $item->roles as $role ) {
520
  if ( current_user_can( $role ) ) {
521
  $visible = true;
522
+ break;
523
  }
524
  }
525
  }
569
  }
570
  }
571
 
572
+ /**
573
+ * Test WordPress version
574
+ *
575
+ * @access public
576
+ * @param string $version - A WordPress version to compare against current version.
577
+ * @return boolean
578
+ */
579
+ public static function is_wp_gte( $version = '5.4' ) {
580
+ global $wp_version;
581
+ return version_compare( strtolower( $wp_version ), strtolower( $version ), '>=' );
582
+ }
583
+
584
  } // end class
585
 
586
  endif; // class_exists check
readme.txt CHANGED
@@ -4,8 +4,8 @@ Contributors: helgatheviking
4
  Donate link: https://www.paypal.com/fundraiser/charity/1451316
5
  Tags: menu, menus, nav menu, nav menus
6
  Requires at least: 4.5.0
7
- Tested up to: 5.3.0
8
- Stable tag: 1.9.5
9
  License: GPLv3
10
 
11
  Hide custom menu items based on user roles. PLEASE READ THE FAQ IF YOU ARE NOT SEEING THE SETTINGS.
@@ -238,6 +238,9 @@ Yes, but manually. WPML developers have informed me that the meta data for nav m
238
 
239
  == Changelog ==
240
 
 
 
 
241
  = 1.9.5 =
242
  * Fix: PHP Notice: Undefined variable $item
243
 
4
  Donate link: https://www.paypal.com/fundraiser/charity/1451316
5
  Tags: menu, menus, nav menu, nav menus
6
  Requires at least: 4.5.0
7
+ Tested up to: 5.4.0
8
+ Stable tag: 1.10.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.
238
 
239
  == Changelog ==
240
 
241
+ = 1.10.0 =
242
+ * Fix: My hook made it into core for WP5.4!! Can finally stop overriding the admin menu Walker.
243
+
244
  = 1.9.5 =
245
  * Fix: PHP Notice: Undefined variable $item
246