0

Im fairly new to PHP so bare with me. So i have a sub menu in the backoffice settings and i need to grant an exception for this sub menu for specific users, but i have no ideia how to do that. This is the sub menu:

private function setup() {

        fm_register_submenu_page( 'app-items', 'options-page', 'Definições das Apps', 'Definições das Apps', 'edit_theme_options' );
        add_action( 'fm_submenu_app-items', array( $this, 'submenu_apps_init' ) );

    }


public function submenu_apps_init() {

            $news_push = new Fieldmanager_TextField( 'Prefixo do push das notícias', array(
            'input_type'  => 'text',
            'description' => 'O prefixo escolhido será utilizado no push das notícias para a app',
            'attributes'  => array(
                'maxlength' => 40,
            )
        ));

        $fm = new Fieldmanager_Group( array(
            'name'     => 'app-items',
            'children' => array(
                'news_push'     => $news_push,
            )
        ) );
        $fm->activate_submenu_page();
    }

I need to add an exception for a specific role i have, that by default doesn't have the privileges to access this submenus.

0

You can see here a list of roles and capabilities, if you want to check if the user has a certain role, you can:

$the_user = wp_get_current_user();//we get the current user
if ( in_array( 'the_name_of_your_role', (array) $the_user->roles ) ) {
    //the user has the rol, add the submenu here
}

you can use current_user_can if you want to check if the user has a specific capability, like this:

if( current_user_can( 'publish_pages' ) ){
    //the user has the capability do something here
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.