Ticket #13829: menu_page_url.diff

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

Kittehs first patch

Line 
1### Eclipse Workspace Patch 1.0
2#P trunk.domain
3Index: wp-admin/includes/plugin.php
4===================================================================
5--- wp-admin/includes/plugin.php        (revision 15197)
6+++ wp-admin/includes/plugin.php        (working copy)
7@@ -817,7 +817,7 @@
8  * @param int $position The position in the menu order this one should appear
9  */
10 function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '', $position = NULL ) {
11-       global $menu, $admin_page_hooks, $_registered_pages;
12+       global $menu, $admin_page_hooks, $_registered_pages, $_parent_pages;
13 
14        $menu_slug = plugin_basename( $menu_slug );
15 
16@@ -842,6 +842,9 @@
17 
18        $_registered_pages[$hookname] = true;
19 
20+       // No parent as top level
21+       $_parent_pages[$menu_slug] = false;
22+       
23        return $hookname;
24 }
25 
26@@ -915,6 +918,7 @@
27        global $_wp_real_parent_file;
28        global $_wp_submenu_nopriv;
29        global $_registered_pages;
30+       global $_parent_pages;
31 
32        $menu_slug = plugin_basename( $menu_slug );
33        $parent_slug = plugin_basename( $parent_slug);
34@@ -949,6 +953,9 @@
35        if ( 'tools.php' == $parent_slug )
36                $_registered_pages[get_plugin_page_hookname( $menu_slug, 'edit.php')] = true;
37 
38+       // No parent as top level
39+       $_parent_pages[$menu_slug] = $parent_slug;
40+               
41        return $hookname;
42 }
43 
44@@ -1164,6 +1171,38 @@
45        return add_submenu_page( 'edit-comments.php', $page_title, $menu_title, $capability, $menu_slug, $function );
46 }
47 
48+/**
49+ * Get the url to access a particular menu page based on the slug it was registered with.
50+ *
51+ * If the slug hasn't been registered properly no url will be returned
52+ *
53+ * @since 3.0
54+ *
55+ * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
56+ * @param bool $echo Whether or not to echo the url - default is true
57+ * @return string the url
58+ */
59+function menu_page_url($menu_slug, $echo = true) {
60+       global $_parent_pages;
61+               
62+       if ( isset( $_parent_pages[$menu_slug] ) ) {
63+               if ( $_parent_pages[$menu_slug] ) {
64+                       $url = admin_url($_parent_pages[$menu_slug] . '?page=' . $menu_slug);
65+               } else {
66+                       $url = admin_url('admin.php?page=' . $menu_slug);
67+               }
68+       } else {
69+               $url = '';
70+       }
71+       
72+       $url = esc_url($url);
73+       
74+       if ( $echo )
75+               echo $url;
76+       
77+       return $url;
78+}
79+
80 //
81 // Pluggable Menu Support -- Private
82 //