Skip to content

Commit

Permalink
update readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
helgatheviking committed Jul 26, 2024
1 parent b0c540b commit 125c0c1
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ The roles in NMR are filterable distinct from the global `$wp_roles`. This allow
* 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 @@ -174,16 +174,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
* @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 ){
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 @@ -201,13 +202,13 @@ Note that you have to generate your own if/then logic. I can't provide free supp
Add the following snippet to your theme's `functions.php` file:


/*
/**
* Sort the NMR roles
* @param: $roles an array of all available roles with ID=>Name
* @return: array
* @param array $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 125c0c1

Please sign in to comment.