Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #193657

    I have several custom defined user roles that I’d live to be able to use in conjuction with enfold’s conditional menu functionality. I’ve enable the conditional menu feature, but the only user roles that I’m being given as options are the stock WordPress user roles. Is there anything that can be done to allow custom defined user roles to be displayed as an option via mega menu? There are several plugins that allow for this but the hard coded conditional menu functionality in enfold creates a conflict that prevents them from working.

    #194722

    Hey!

    Yes, you can add a custom user role check to the conditional menu function.

    First you need to add a function to your child theme functions.php file which checks if the current user has the user role or not. You can use following code

    
    if(!function_exists('avia_condition_customrole'))
    {
        function avia_condition_customrole()
        {
            global $current_user;
            if( is_user_logged_in() ) foreach( array( 'customrole' ) as $role ) if( in_array( $role, $current_user->roles ) ) return true;
            return false;
        }
    }
    

    but instead of “customrole” insert your user role slug (by default wordpress uses following user roles: ‘administrator’, ‘editor’, ‘author’, ‘contributor’, ‘subscriber’). Make sure that you replace all occurrences of “customrole” in the code above with your user role slug – otherwise the function won’t work.

    Then add following code into the functions.php child theme:

    
    add_filter('avf_avia_menu_conditions','avia_add_conditional_options', 10,1);
    function avia_add_conditional_options($options){
    $options['avia_condition_customrole'] = array('title' =>__('My Custom User Role', 'avia_framework')),
    return $options;
    }
    

    and (again) you need to replace “customrole” with your user role slug. The text “My Custom User Role” is used for the dropdown option label (text you see when you select the conditional). You can insert any other text instead. Afterwards go to the menu editor page and select the new option and save the menu.

    Cheers!
    Peter

Viewing 2 posts - 1 through 2 (of 2 total)
  • The topic ‘Using conditional menus with custom defined user roles’ is closed to new replies.