WordPress.org

Make WordPress Core

Ticket #13829: menu_page_url.diff

File menu_page_url.diff, 2.2 KB (added by westi, 4 years ago)

Kittehs first patch

  • wp-admin/includes/plugin.php

    ### Eclipse Workspace Patch 1.0
    #P trunk.domain
     
    817817 * @param int $position The position in the menu order this one should appear 
    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 ); 
    823823 
     
    842842 
    843843        $_registered_pages[$hookname] = true; 
    844844 
     845        // No parent as top level 
     846        $_parent_pages[$menu_slug] = false; 
     847         
    845848        return $hookname; 
    846849} 
    847850 
     
    915918        global $_wp_real_parent_file; 
    916919        global $_wp_submenu_nopriv; 
    917920        global $_registered_pages; 
     921        global $_parent_pages; 
    918922 
    919923        $menu_slug = plugin_basename( $menu_slug ); 
    920924        $parent_slug = plugin_basename( $parent_slug); 
     
    949953        if ( 'tools.php' == $parent_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} 
    954961 
     
    11641171        return add_submenu_page( 'edit-comments.php', $page_title, $menu_title, $capability, $menu_slug, $function ); 
    11651172} 
    11661173 
     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; 
     1204} 
     1205 
    11671206// 
    11681207// Pluggable Menu Support -- Private 
    11691208//