You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hide custom menu items based on user roles. PLEASE READ THE FAQ IF YOU ARE NOT SEEING THE SETTINGS.
11
+
Hide custom menu items based on user roles. PLEASE READ THE [FAQ](#frequently-asked-questions) IF YOU ARE NOT SEEING THE SETTINGS.
12
12
13
13
## Description ##
14
14
15
15
This plugin lets you hide custom menu items based on user roles. So if you have a link in the menu that you only want to show to logged in users, certain types of users, or even only to logged out users, this plugin is for you.
16
16
17
-
Nav Menu Roles is very flexible. In addition to standard user roles, you can customize the functionality by adding your own check boxes with custom labels using the `nav_menu_roles` filter and then using the `nav_menu_roles_item_visibility` filter to check against whatever criteria you need. You can check against any user meta values (like capabilities) and any custom attributes added by other plugins. See the [FAQ](http://wordpress.org/plugins/nav-menu-roles/faq/#new-role).
17
+
Nav Menu Roles is very flexible. In addition to standard user roles, you can customize the functionality by adding your own check boxes with custom labels using the `nav_menu_roles` filter and then using the `nav_menu_roles_item_visibility` filter to check against whatever criteria you need. You can check against any user meta values (like capabilities) and any custom attributes added by other plugins. See the [FAQ](#im-using-xyz-membership-plugin-and-i-dont-see-its-levels).
18
18
19
19
### IMPORTANT NOTE ###
20
20
@@ -49,7 +49,7 @@ Please report any bugs, errors, warnings, code problems to [Github](https://gith
49
49
50
50
## Frequently Asked Questions ##
51
51
52
-
= <aid="conflict"></a>I don't see the Nav Menu Roles options in the admin menu items? =
52
+
# I don't see the Nav Menu Roles options in the admin menu items?#
53
53
54
54
This is because you have another plugin (or theme) that is also trying to alter the same code that creates the Menu section in the admin.
55
55
@@ -66,33 +66,33 @@ WordPress does not have sufficient hooks in this area of the admin and until the
66
66
7. Jupiter Theme
67
67
68
68
69
-
= <aid="compatibility"></a>Workaround #1=
69
+
# Workaround #1#
70
70
[Shazdeh](https://profiles.wordpress.org/shazdeh/) had the genius idea to not wait for a core hook and simply add the hook ourselves. If all plugin and theme authors use the same hook, we can make our plugins play together.
71
71
72
72
Therefore, as of version 1.6 I am modifying my admin nav menu Walker to *only* adding the following lines (right after the description input):
**Ask your conflicting plugin/theme's author to add this code to his plugin or theme and our plugins will become compatible.**
83
83
84
-
= <aid="patch"></a>Patching Your Plugin/Theme =
84
+
# Patching Your Plugin/Theme#
85
85
86
86
**Should you wish to attempt this patch yourself, you can modify your conflicting plugin/theme's admin menu Walker class. **Reminder:** I do not provide support for fixing your plugin/theme. If you aren't comfortable with the following instructions, contact the developer of the conflicting plugin/theme!**
87
87
88
88
1. Find the class that extends the `Walker_Nav_Menu`. As a hint, it is filtering `wp_edit_nav_menu_walker` and you might even be getting a warning about it from Nav Menu Roles. Example:
return 'Walker_Nav_Menu_Edit_Roles'; // this is the class name
94
94
}
95
-
`
95
+
```
96
96
97
97
2. Find the file for the extending class. In my plugin this is in a file located at `inc/class.Walker_Nav_Menu_Edit_Roles.php`. I can't know *where* this file is in your plugin/theme. Please don't ask me, but here's what the beginning of that class will look like:
98
98
@@ -110,7 +110,7 @@ In that file you will eventually see a class method that looks like:
110
110
111
111
In Nav Menu Roles, I have placed the hook directly after the description, ex:
@@ -136,9 +136,9 @@ There are apparently a few membership plugins out there that *don't* use traditi
136
136
137
137
Here's an example where I've added a new pseudo role, creatively called "new-role". The first function adds it to the menu item admin screen. The second function is pretty generic and won't actually do anything because you need to supply your own logic based on the plugin you are using. Nav Menu Roles will save the new "role" info and add it to the item in an array to the `$item->roles` variable.
138
138
139
-
= <aid="new-role"></a>Adding a new "role" =
139
+
# Adding a new "role"#
140
140
141
-
`
141
+
```
142
142
/*
143
143
* Add custom roles to Nav Menu Roles menu list
144
144
** * param:** $roles an array of all available roles, by default is global $wp_roles
@@ -149,13 +149,13 @@ function kia_new_roles( $roles ){
149
149
return $roles;
150
150
}
151
151
add_filter( 'nav_menu_roles', 'kia_new_roles' );
152
-
`
152
+
```
153
153
154
154
Note, if you want to add a WordPress capability the above is literally all you need. Because Nav Menu Roles checks whether a role has permission to view the menu item using `current_user_can($role) you do not need to right a custom callback for the `nav_menu_roles_item_visibility` filter.
155
155
156
156
In case you *do* need to check your visibility status against something very custom, here is how you'd go about it:
157
157
158
-
`
158
+
```
159
159
/*
160
160
* Change visibilty of each menu item
161
161
** * param:** $visible boolean
@@ -174,7 +174,7 @@ function kia_item_visibility( $visible, $item ){
Note that you have to generate your own if/then logic. I can't provide free support for custom integration with another plugin. You may [contact me](http://kathyisawesome.com/contact) to discuss hiring me, or I would suggest using a plugin that supports WordPress' roles, such as Justin Tadlock's [Members](http://wordpress.org/plugins/members).
180
180
@@ -186,9 +186,9 @@ Therefore, if you have no items to display, WordPress will end up displaying ALL
186
186
187
187
If you don't want this, you must set the fallback argument to be a null string.
### What happened to my menu roles on import/export? ###
194
194
@@ -204,100 +204,3 @@ However, the Import plugin only imports certain post meta for menu items. As of
204
204
1. Use the same .xml file and perform a second import
205
205
1. No duplicate posts will be created but all menu post meta (including your Nav Menu Roles info) will be imported
206
206
207
-
## Changelog ##
208
-
209
-
### 1.7.6 ###
210
-
* tweak CSS to initially hide checkboxes on newly added menu items (defaults to "Everyone" so roles should not appear)
211
-
212
-
### 1.7.5 ###
213
-
* Update Walker_Nav_Menu_Edit_Roles to mimic Walker_Nav_Menu in WordPress 4.4
214
-
215
-
### 1.7.4 ###
216
-
* Change language in metabox to try to explain min caps versus strict role checking
217
-
* keep tweaking the FAQ
218
-
219
-
### 1.7.3 ###
220
-
* update readme, update error notice, add more links to the FAQ
221
-
222
-
### 1.7.2 ###
223
-
* add Italian language. props @sododesign
224
-
225
-
### 1.7.1 ###
226
-
* Updated FAQ with patch instructions for conflicting plugins/themes
227
-
* add Portugeuse language. props @brunobarros
228
-
229
-
### 1.7.0 ###
230
-
* adjust admin UI to be more user-friendly. Options are now: show to everyone, show to logged out users, and show to logged in users (optionally, logged in users by specific role)
231
-
232
-
### 1.6.5 ###
233
-
* add Guajarati language. props @rohilmistry93
234
-
235
-
### 1.6.4 ###
236
-
* more language issues -> sync svn+git version numbers
237
-
238
-
### 1.6.3 ###
239
-
* Try again to add languages. Where'd they all go?
240
-
241
-
### 1.6.2 ###
242
-
* Add French translation. Props @Philippe Gilles
243
-
244
-
### 1.6.1 ###
245
-
* Update list of conflits
246
-
* Don't display radio buttons if no roles - allows for granular permissions control
247
-
248
-
### 1.6.0 ###
249
-
* Feature: Hiding a parent menu item will automatically hide all its children
250
-
* Feature: Add compatibility with Menu Item Visibility Control plugin and any plugin/theme that is willing to add its inputs via the `wp_nav_menu_item_custom_fields` hook. See the [FAQ](http://wordpress.org/plugins/nav-menu-roles/faq/#compatibility) to make our plugins compatible.
Should you wish to attempt this patch yourself, you can modify your conflicting plugin/theme's admin menu Walker class. **Reminder: I do not provide support for fixing your plugin/theme. If you aren't comfortable with the following instructions, contact the developer of the conflicting plugin/theme!**
84
+
Should you wish to attempt this patch yourself, you can modify your conflicting plugin/theme's admin menu Walker class.
85
+
86
+
**Reminder: I do not provide support for fixing your plugin/theme. If you aren't comfortable with the following instructions, contact the developer of the conflicting plugin/theme!**
85
87
86
88
1. Find the class that extends the `Walker_Nav_Menu`. As a hint, it is filtering `wp_edit_nav_menu_walker` and you might even be getting a warning about it from Nav Menu Roles. Example:
87
89
@@ -134,7 +136,7 @@ There are apparently a few membership plugins out there that *don't* use traditi
134
136
135
137
Here's an example where I've added a new pseudo role, creatively called "new-role". The first function adds it to the menu item admin screen. The second function is pretty generic and won't actually do anything because you need to supply your own logic based on the plugin you are using. Nav Menu Roles will save the new "role" info and add it to the item in an array to the `$item->roles` variable.
136
138
137
-
= <a id="new-role"></a>Adding a new "role" =
139
+
= <a id="new-role"></a>Adding a new "role" =
138
140
139
141
`
140
142
/*
@@ -204,6 +206,12 @@ However, the Import plugin only imports certain post meta for menu items. As of
204
206
205
207
== Changelog ==
206
208
209
+
= 1.7.8 =
210
+
* remove all admin notices
211
+
212
+
= 1.7.7 =
213
+
* add fancy debug messages
214
+
207
215
= 1.7.6 =
208
216
* tweak CSS to initially hide checkboxes on newly added menu items (defaults to "Everyone" so roles should not appear)
0 commit comments