Make WordPress Core

Changeset 15203


Ignore:
Timestamp:
06/10/2010 09:38:41 PM (13 years ago)
Author:
westi
Message:

Introduce menu_page_url() for plugins to use to get the url for the pages they have added. Fixes #13829 props o'malley for all the cuteness.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/plugin.php

    r15017 r15203  
    818818 */
    819819function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '', $position = NULL ) {
    820     global $menu, $admin_page_hooks, $_registered_pages;
     820    global $menu, $admin_page_hooks, $_registered_pages, $_parent_pages;
    821821
    822822    $menu_slug = plugin_basename( $menu_slug );
     
    843843    $_registered_pages[$hookname] = true;
    844844
     845    // No parent as top level
     846    $_parent_pages[$menu_slug] = false;
     847   
    845848    return $hookname;
    846849}
     
    916919    global $_wp_submenu_nopriv;
    917920    global $_registered_pages;
     921    global $_parent_pages;
    918922
    919923    $menu_slug = plugin_basename( $menu_slug );
     
    950954        $_registered_pages[get_plugin_page_hookname( $menu_slug, 'edit.php')] = true;
    951955
     956    // No parent as top level
     957    $_parent_pages[$menu_slug] = $parent_slug;
     958       
    952959    return $hookname;
    953960}
     
    11631170function add_comments_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' ) {
    11641171    return add_submenu_page( 'edit-comments.php', $page_title, $menu_title, $capability, $menu_slug, $function );
     1172}
     1173
     1174/**
     1175 * Get the url to access a particular menu page based on the slug it was registered with.
     1176 *
     1177 * If the slug hasn't been registered properly no url will be returned
     1178 *
     1179 * @since 3.0
     1180 *
     1181 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
     1182 * @param bool $echo Whether or not to echo the url - default is true
     1183 * @return string the url
     1184 */
     1185function menu_page_url($menu_slug, $echo = true) {
     1186    global $_parent_pages;
     1187       
     1188    if ( isset( $_parent_pages[$menu_slug] ) ) {
     1189        if ( $_parent_pages[$menu_slug] ) {
     1190            $url = admin_url($_parent_pages[$menu_slug] . '?page=' . $menu_slug);
     1191        } else {
     1192            $url = admin_url('admin.php?page=' . $menu_slug);
     1193        }
     1194    } else {
     1195        $url = '';
     1196    }
     1197   
     1198    $url = esc_url($url);
     1199   
     1200    if ( $echo )
     1201        echo $url;
     1202   
     1203    return $url;
    11651204}
    11661205
Note: See TracChangeset for help on using the changeset viewer.