Shihan Khan
Shihan Khan

Reputation: 2188

Permission error while developing Wordpress plugin

I'm new to wordpress plugin development & I want to make a plugin. So far I managed to add Menu in Dashboard. Now I want to add a submenu. Menu works when I click on it but submenu doesn't work. It shows this error, You do not have sufficient permissions to access this page. My code is below,

<?php
add_action( 'admin_menu', 'sms_dashmenu');

function sms_dashmenu() {

    add_menu_page( 'sms_menu_page', 'SMS Demo','manage_options', __FILE__,'sms_plugin',plugins_url( '/Images/logo.png', __FILE__ ) );
    add_submenu_page( __FILE__, 'AdminPanel','Admin', 'manage_options',__FILE__.'/menu1', sms_panel_admin);
}
function sms_plugin(){
    echo 'Welcome to the business!';
}

function sms_panel_admin(){
?>

<h2>Admin Panel Design</h2>

<?php
}
?>

Is there something wrong in my code? I need a solution badly. Your help would be appreciated. Tnx.

Upvotes: 0

Views: 88

Answers (1)

Vidya L
Vidya L

Reputation: 2314

The fourth parameter in add_menu_page is the menu slug of string type use anything unique you want, and the first parameter of add_submenu_page is the parent slug and that is what you entered for add_menu_page menu slug

add_menu_page( 'sms_menu_page', 'SMS Demo','manage_options', 'smsmenu','sms_plugin',plugins_url( '/Images/logo.png', __FILE__ ) );
add_submenu_page( 'smsmenu', 'AdminPanel','Admin', 'manage_options', 'smsadmin', 'sms_panel_admin');

Check add_menu_page and add_submenu_page

Upvotes: 1

Related Questions