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](#conflict) IF YOU ARE NOT SEEING THE SETTINGS.
11
+
Hide custom menu items based on user roles. PLEASE READ THE FAQ IF YOU ARE NOT SEEING THE SETTINGS.
12
12
13
13
## Description ##
14
14
@@ -31,7 +31,7 @@ In WordPress menu items and pages are completely separate entities. Nav Menu Rol
31
31
32
32
Support is handled in the [WordPress forums](https://wordpress.org/support/plugin/nav-menu-roles). Please note that support is limited and does not cover any custom implementation of the plugin. Before posting, please read the [FAQ](http://wordpress.org/plugins/nav-menu-roles/faq/). Also, please verify the problem with other plugins disabled and while using a default theme.
33
33
34
-
Please report any bugs, errors, warnings, code problems to [Github](https://github.com/helgatheviking/Nav-Menu-Roles/issues)
34
+
Please report any bugs, errors, warnings, code problems to [Github](https://github.com/helgatheviking/nav-menu-roles/issues)
35
35
36
36
## Installation ##
37
37
@@ -44,11 +44,12 @@ Please report any bugs, errors, warnings, code problems to [Github](https://gith
44
44
## Screenshots ##
45
45
46
46
### 1. Show the new options for the menu items in the admin menu customizer ###
47
-

47
+

48
+
48
49
49
50
## Frequently Asked Questions ##
50
51
51
-
###<aid="conflict"></a>I don't see the Nav Menu Roles options in the admin menu items?###
52
+
= <aid="conflict"></a>I don't see the Nav Menu Roles options in the admin menu items? =
52
53
53
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.
54
55
@@ -65,55 +66,51 @@ WordPress does not have sufficient hooks in this area of the admin and until the
65
66
7. Jupiter Theme
66
67
67
68
68
-
###<aid="compatibility"></a>Workaround #1###
69
+
= <aid="compatibility"></a>Workaround #1=
69
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.
70
71
71
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.**
82
83
83
-
###<aid="patch"></a>Patching Your Plugin/Theme###
84
+
= <aid="patch"></a>Patching Your Plugin/Theme =
84
85
85
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!**
86
87
87
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
93
94
}
94
-
```
95
+
`
95
96
96
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:
97
98
98
-
```
99
-
class Walker_Nav_Menu_Edit_Roles extends Walker_Nav_Menu {}
@@ -139,9 +136,9 @@ There are apparently a few membership plugins out there that *don't* use traditi
139
136
140
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.
141
138
142
-
###<aid="new-role"></a>Adding a new "role"###
139
+
= <aid="new-role"></a>Adding a new "role" =
143
140
144
-
```
141
+
`
145
142
/*
146
143
* Add custom roles to Nav Menu Roles menu list
147
144
** * param:** $roles an array of all available roles, by default is global $wp_roles
@@ -152,13 +149,13 @@ function kia_new_roles( $roles ){
152
149
return $roles;
153
150
}
154
151
add_filter( 'nav_menu_roles', 'kia_new_roles' );
155
-
```
152
+
`
156
153
157
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.
158
155
159
156
In case you *do* need to check your visibility status against something very custom, here is how you'd go about it:
160
157
161
-
```
158
+
`
162
159
/*
163
160
* Change visibilty of each menu item
164
161
** * param:** $visible boolean
@@ -177,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).
183
180
@@ -189,9 +186,9 @@ Therefore, if you have no items to display, WordPress will end up displaying ALL
189
186
190
187
If you don't want this, you must set the fallback argument to be a null string.
0 commit comments