Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Liam Maclachlan
Liam Maclachlan
22,805 Points

WP_die when setting up custom plugin sub menu. Why?

I'm building a custom plugiin, which is going great... I have hit a snag when trying to add a sub menu item where I keep getting the wp_die message that I do not have sufficient rights, which are the same as the amin page, and that one works. Code below.

<?php
function lsmcustom_options_menu_2() {
    // add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position );
    add_menu_page(
        'Test area',
        'Custom Plugin 2',
        'manage_options',
        'lsmcustom-plugin-2',
        'lsmcustom_options_page_2',
        plugins_url( 'Custom_Plugin_2/images/L-icon.png' )
    );

    // add_submenu_page($parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function);
    add_submenu_page(
        'lsmcustom-plugin-2',
        'Manage',
        'Manage',
        'manage_options',
        'Manage publishers',
        'lsmcustom_manage_page'
    );

}

add_action( 'admin_menu', 'lsmcustom_options_menu_2' );
?>

Any ideas?

Liam Maclachlan
Liam Maclachlan
22,805 Points

I think I have just realised my error, I may have included the function called from within the page set up with the wrong hook. Will let you know.

EDIT... nope. That was not it.

1 Answer

Liam Maclachlan
Liam Maclachlan
22,805 Points

Fixed it... turns out the menu-Slug doesn't allow spaces :)

<?php

function lsmcustom_options_menu_2() {
    // add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position );
    add_menu_page(
        'Test area',
        'Custom Plugin 2',
        'manage_options',
        'lsmcustom-plugin-2',
        'lsmcustom_options_page_2',
        plugins_url( 'Custom_Plugin_2/images/L-icon.png' )
    );

}

function lsmcustom_mange_menu_2() {

    // add_submenu_page($parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function);
    add_submenu_page(
        'lsmcustom-plugin-2',
        'Manage',
        'Manage',
        'manage_options',
        'Manage_publishers', // was 'Manage publishers'.. this was wrong :(
        'lsmcustom_manage_page'
    );

}

add_action( 'admin_menu', 'lsmcustom_options_menu_2' );
add_action( 'admin_menu', 'lsmcustom_mange_menu_2' );

?>