There are cases when you might want to show the floating menu to some users and hide it from others. To allow you to do this, the plugin implements filter cfm_show_menu that can prevent the menu from being displayed altogether.

Filter cfm_show_menu callback function should return true if the menu is to be displayed or false to hide the menu.

All code below can be placed into your WordPress theme functions.php file. As a note, we advise that you create a child theme when doing customizations on a WordPress theme.

Hide menu from users not logged in

To hide the menu from WordPress visitors that are not logged in, we will use function is_user_logged_in().

/**
 * Remove CodeFlavors menu for not logged in users
 * @param boolean $show - show (true) or hide (false) the menu
 * @return boolean
 */
function remove_menu_logged_in( $show ){
    if( !is_user_logged_in() ){
        return false;
    }    
    return $show;
}
add_filter( 'cfm_show_menu', 'remove_menu_logged_in' );

Hide menu unless user is admin

If you want to show the menu only for certain WordPress roles, in our case administrators, we can use function current_user_can():

/**
 * Show CodeFlavors menu for logged in admins
 * @param boolean $show - show (true) or hide (false) the menu
 * @return boolean
 */
function show_menu_admin_logged_in( $show ){
    if( !current_user_can( 'manage_options' ) ){
        return false;
    }
    return $show;
}
add_filter( 'cfm_show_menu', 'show_menu_admin_logged_in' );

If you want to show the menu to other user roles as well, replace “manage_optionscapability with another one appropriate for the user role that you want to grant access to.