Introducing menu_page_url()

We’ve just added a new api into WordPress 3.0 to make plugin writing that bit easier – #13829

It is now really easy to get the url for a plugin page that you have registered to make it easy to link between different plugin pages. You use the new function like this:

add_options_page('Best Evar Menu', 'Best Evar Menu', 'manage_options', 'best_evar_menu', 'best_evar_options_page');

menu_page_url( 'best_evar_menu' );

The function will by default echo the url out but if you want you can get it returned for processing by setting the second argument to false.

Advertisement

About Peter Westwood
Happiness Gardener, Coder, Cat Herder, Bug Tracker, Cook and Code Dreamer

15 Responses to Introducing menu_page_url()

  1. Pingback: Just added menu_page_url() – http://west… « WordPress Development Updates

  2. demetris says:

    There is a “for” missing between “returned” and “processing” in the last paragraph. :-)

    Cheers!

  3. Rich Pedley says:

    Excellent! that will actually come in handy, I think…

  4. Hikari says:

    Cool!

    Now we don’t need anymore to know which kind of page it is, must the mage tag :D

    Will this work for any page, including themes pages?

  5. Denis says:

    Shouldn’t this be admin_menu_url() rather? menu_page_url() sounds like we’re implementing an API for newly menu items.

    • Not really.

      All the front end menu functions refer to themselves as *nav_menu*

      All the back end menu functions for the admin menus refer to themselves add_*_page

  6. hakre says:

    Is there a counter-part function that will return the $hookname for the URL? That would make it perfect!

  7. Ron says:

    Thanks Peter. I used it tonight. Very handy :)

  8. Just tried to use this in my plugin and I didn’t get it to work.
    My code looks like this:

    add_pages_page( CMS_TPV_NAME, CMS_TPV_NAME, “edit_pages”, “cms-tpv-pages-page”, “cms_tpv_pages_page” );

    echo menu_page_url(“cms-tpv-pages-page”);
    // echoes “http://localhost/wordpress3/wp-admin/edit.php?post_type=page?page=cms-tpv-pages-page”

    See that is outputs a questionmark instead of an ampersand. Don’t know if I did anything wrong here..

Follow

Get every new post delivered to your Inbox.

Join 2,155 other followers