• Resolved Cory.Nickerson

    (@corynickerson)


    I’m having some trouble understanding how to get my admin url’s for my custom pages to display properly. I can successfully add my custom menu into the admin side menu, but the URL’s are acting funky.

    function scholarship_admin_actions()
    {
    	add_menu_page('Scholarship Plugin', 'Scholarship Plugin', 'edit_plugins', 'scholarship/scholarship_admin.php', '',   plugins_url('scholarship/images/education.png'), 27);
    	add_submenu_page('scholarship/scholarship_admin.php', 'Scholarship Plugin: Contact Requests.', 'Contact Requests', 'edit_plugins', 'scholarship/scholarship_admin.php?page=contact_requests', '' );
    }
    
    add_action('admin_menu', 'scholarship_admin_actions');

    the code displays this for a url when viewing my submenu

    wp-admin/admin.php?page=scholarship/scholarship_admin.php?page=contact_requests

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    The menu slug arguments are meant to be more like labels than relative file paths, though obviously the system accepts any string argument. The ability to specify a php file was intended as a shortcut to pages within the normal path search range, not anywhere on your site, and certainly not for passing url parameters as well.

    As you can see, with no $function argument, the slugs are passed to admin.php, and if the slug is a php file, it redirects there. I suggest you do something similar. Specify a $function to call to display the page. That function can in turn redirect to the actual destination page, along with the URL parameter. This way, the menu slug can become just a simple handle again.

    Thread Starter Cory.Nickerson

    (@corynickerson)

    Still not sure on how to do this. Can you show me an example please?

    Thread Starter Cory.Nickerson

    (@corynickerson)

    Would I need to use apply_filters('plugins_url', $url, $path, $plugin) ?

    Thread Starter Cory.Nickerson

    (@corynickerson)

    Figured this out.

    In the add_menu_page and add_submenu_page functions you need to create a function (the field I left blank) and have that function include the .php pages. Then for the menu slug you are free to enter whatever you want.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Trouble with admin url's.’ is closed to new replies.