[resolved] Do I need to check if User has required capability? (3 posts)

  1. Val Lynn
    Posted 3 years ago #

    #newbie #firstplugin #forgivemeplease

    The plugin I am (trying) writing inserts custom text into the footer of twentyeleven.

    My first question is, do I need to check if a User has the required capability since add_submenu_page takes manage_options as a parameter?

    //  Add this plugin to the Admin Navigation Menu ( register the function )
            add_action('admin_menu', 'register_my_plugin_submenu_page');   
    //  Create a function that contains the admin menu-building code
    //  This adds the plugin to the Admin Navigation Menu
            function register_my_plugin_submenu_page() {
            // Create Plugins submenu item
                            'TnT Custom Text Configuration',
                            'TnT Custom Text',

    And if I do need to check User Capability, is this the "best" way to do it?

    // Create the function the displays the HTML for the plugin submenu in the Admin panel
    		function create_the_admin_html_output() {
    //must check that the user has the required capability
        if (!current_user_can('manage_options'))
          wp_die( __('You do not have sufficient permissions to access this page.') );

    Thank you for any help!

    [No bumping, thank you.]

  2. bcworkz
    Posted 3 years ago #

    You still need to verify capability, your function has to be responsible for it's own security. The sub menu function uses capability only to determine if it should display your menu. Even if there is no way to run your function without the menu displayed, it's just good security practice.

    If your capability check killing the process does what you need, then it's the best way. If you need to continue the process for some reason, it's a terrible way.

  3. Val Lynn
    Posted 3 years ago #

    Thank you! The was the direction I needed to take the next step.

Topic Closed

This topic has been closed to new replies.

About this Topic