Y
Y
Yuri Yanin2018-02-19 14:43:05
WordPress
Yuri Yanin, 2018-02-19 14:43:05

How to organize access rights to Wordpress plugin?

I'm writing a plug-in "Add-in". I need to organize the access rights to the plugin settings page so that if there are not enough rights, this page will not even appear in the left menu of the admin panel. I have never specifically written permissions for plugins. Temporarily made a check of the user's rights with the output of messages for the user about an insufficient level of rights. But how do you remove the settings page from the list altogether?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Syomka Gavrilenko, 2018-02-19
@VPank

The easiest way is to check the user's permissions in a function that adds a settings page to the menu:

function true_options() {
    global $true_page;
    if( current_user_can('manage_options') ){
        add_options_page( 'Параметры', 'Параметры', 'manage_options', $true_page, 'true_option_page');  
    }
}

add_action('admin_menu', 'true_options');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question