Skip to content

Commit

Permalink
update readme.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
helgatheviking committed Jul 26, 2024
1 parent 27f8d31 commit b0c540b
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ If your membership plugin is not listed here, you may be able to use the above b
The roles in NMR are filterable distinct from the global `$wp_roles`. This allows for compatibility to be added between plugins that don't use the core roles to determine access, like some membership plugins.

`
/*
/**
* Add custom roles to Nav Menu Roles menu list
* param: $roles an array of all available roles, by default is global $wp_roles
* return: array
*/
function kia_new_roles( $roles ){
function kia_new_roles( $roles ) {
$roles['new-role-key'] = 'new-role';
return $roles;
}
Expand All @@ -173,16 +173,17 @@ Note, if you want to add a WordPress capability the above is literally all you n
In case you *do* need to check your visibility status against something very custom, here is how you'd go about it:

`
/*
* Change visibility of each menu item
* param: $visible boolean
* param: $item object, the complete menu object. Nav Menu Roles adds its info to $item->roles
* $item->roles can be "in" (all logged in), "out" (all logged out) or an array of specific roles
* return boolean
*/
function kia_item_visibility( $visible, $item ){
if( isset( $item->roles ) && is_array( $item->roles ) && in_array( 'new-role-key', $item->roles ) ){
/* if ( // your own custom check on the current user versus 'new-role' status ){
/**
* Change visibility of each menu item
* @param bool $visible
* @param obj $item The complete menu object. Nav Menu Roles adds its info to the following keys {
* roles - Possible value: "in" (all logged in) | "out" (all logged out) | an array of specific roles, ex: [ "administrator", "editor" ]
* display_mode - Possible values: "show" (show if conditions met) | "hide" (hide if conditions met)
* return boolean
*/
function kia_item_visibility( $visible, $item ) {
if ( isset( $item->roles ) && is_array( $item->roles ) && in_array( 'new-role-key', $item->roles ) ) {
/* if ( // your own custom check on the current user versus 'new-role' status ) {
$visible = true;
} else {
$visible = false;
Expand All @@ -205,8 +206,8 @@ Add the following snippet to your theme's `functions.php` file:
* @param: $roles an array of all available roles with ID=>Name
* @return: array
*/
function kia_sort_roles( $roles ){
if( is_admin() ) {
function kia_sort_roles( $roles ) {
if ( is_admin() ) {
$array_lowercase = array_map( 'strtolower', $roles );
array_multisort( $array_lowercase, SORT_ASC, SORT_STRING, $roles );
return $roles;
Expand Down

0 comments on commit b0c540b

Please sign in to comment.