<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[15753] trunk/wp-admin/includes/plugin.php: Introduce remove_menu_page()
and remove_submenu_page().</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/15753">15753</a></dd>
<dt>Author</dt> <dd>scribu</dd>
<dt>Date</dt> <dd>2010-10-07 22:35:31 +0000 (Thu, 07 Oct 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Introduce remove_menu_page() and remove_submenu_page(). Fixes <a href="http://trac.wordpress.org/ticket/12718">#12718</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludespluginphp">trunk/wp-admin/includes/plugin.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludespluginphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/plugin.php (15752 => 15753)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/plugin.php        2010-10-07 21:50:32 UTC (rev 15752)
+++ trunk/wp-admin/includes/plugin.php        2010-10-07 22:35:31 UTC (rev 15753)
</span><span class="lines">@@ -852,12 +852,6 @@
</span><span class="cx"> /**
</span><span class="cx"> * Add a top level menu page in the 'objects' section
</span><span class="cx"> *
</span><del>- * This function takes a capability which will be used to determine whether
- * or not a page is included in the menu.
- *
- * The function which is hooked in to handle the output of the page must check
- * that the user has the required capability as well.
- *
</del><span class="cx"> * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
</span><span class="cx"> * @param string $menu_title The text to be used for the menu
</span><span class="cx"> * @param string $capability The capability required for this menu to be displayed to the user.
</span><span class="lines">@@ -876,12 +870,6 @@
</span><span class="cx"> /**
</span><span class="cx"> * Add a top level menu page in the 'utility' section
</span><span class="cx"> *
</span><del>- * This function takes a capability which will be used to determine whether
- * or not a page is included in the menu.
- *
- * The function which is hooked in to handle the output of the page must check
- * that the user has the required capability as well.
- *
</del><span class="cx"> * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
</span><span class="cx"> * @param string $menu_title The text to be used for the menu
</span><span class="cx"> * @param string $capability The capability required for this menu to be displayed to the user.
</span><span class="lines">@@ -900,12 +888,6 @@
</span><span class="cx"> /**
</span><span class="cx"> * Add a sub menu page
</span><span class="cx"> *
</span><del>- * This function takes a capability which will be used to determine whether
- * or not a page is included in the menu.
- *
- * The function which is hooked in to handle the output of the page must check
- * that the user has the required capability as well.
- *
</del><span class="cx"> * @param string $parent_slug The slug name for the parent menu (or the file name of a standard WordPress admin page)
</span><span class="cx"> * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
</span><span class="cx"> * @param string $menu_title The text to be used for the menu
</span><span class="lines">@@ -962,13 +944,7 @@
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Add sub menu page to the tools main menu.
</span><del>-*
- * This function takes a capability which will be used to determine whether
- * or not a page is included in the menu.
</del><span class="cx"> *
</span><del>- * The function which is hooked in to handle the output of the page must check
- * that the user has the required capability as well.
- *
</del><span class="cx"> * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
</span><span class="cx"> * @param string $menu_title The text to be used for the menu
</span><span class="cx"> * @param string $capability The capability required for this menu to be displayed to the user.
</span><span class="lines">@@ -981,13 +957,7 @@
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Add sub menu page to the options main menu.
</span><del>-*
- * This function takes a capability which will be used to determine whether
- * or not a page is included in the menu.
</del><span class="cx"> *
</span><del>- * The function which is hooked in to handle the output of the page must check
- * that the user has the required capability as well.
- *
</del><span class="cx"> * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
</span><span class="cx"> * @param string $menu_title The text to be used for the menu
</span><span class="cx"> * @param string $capability The capability required for this menu to be displayed to the user.
</span><span class="lines">@@ -1000,13 +970,7 @@
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Add sub menu page to the themes main menu.
</span><del>-*
- * This function takes a capability which will be used to determine whether
- * or not a page is included in the menu.
</del><span class="cx"> *
</span><del>- * The function which is hooked in to handle the output of the page must check
- * that the user has the required capability as well.
- *
</del><span class="cx"> * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
</span><span class="cx"> * @param string $menu_title The text to be used for the menu
</span><span class="cx"> * @param string $capability The capability required for this menu to be displayed to the user.
</span><span class="lines">@@ -1019,13 +983,7 @@
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Add sub menu page to the plugins main menu.
</span><del>-*
- * This function takes a capability which will be used to determine whether
- * or not a page is included in the menu.
</del><span class="cx"> *
</span><del>- * The function which is hooked in to handle the output of the page must check
- * that the user has the required capability as well.
- *
</del><span class="cx"> * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
</span><span class="cx"> * @param string $menu_title The text to be used for the menu
</span><span class="cx"> * @param string $capability The capability required for this menu to be displayed to the user.
</span><span class="lines">@@ -1038,13 +996,7 @@
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Add sub menu page to the Users/Profile main menu.
</span><del>-*
- * This function takes a capability which will be used to determine whether
- * or not a page is included in the menu.
</del><span class="cx"> *
</span><del>- * The function which is hooked in to handle the output of the page must check
- * that the user has the required capability as well.
- *
</del><span class="cx"> * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
</span><span class="cx"> * @param string $menu_title The text to be used for the menu
</span><span class="cx"> * @param string $capability The capability required for this menu to be displayed to the user.
</span><span class="lines">@@ -1060,13 +1012,7 @@
</span><span class="cx"> }
</span><span class="cx"> /**
</span><span class="cx"> * Add sub menu page to the Dashboard main menu.
</span><del>-*
- * This function takes a capability which will be used to determine whether
- * or not a page is included in the menu.
</del><span class="cx"> *
</span><del>- * The function which is hooked in to handle the output of the page must check
- * that the user has the required capability as well.
- *
</del><span class="cx"> * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
</span><span class="cx"> * @param string $menu_title The text to be used for the menu
</span><span class="cx"> * @param string $capability The capability required for this menu to be displayed to the user.
</span><span class="lines">@@ -1079,13 +1025,7 @@
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Add sub menu page to the posts main menu.
</span><del>-*
- * This function takes a capability which will be used to determine whether
- * or not a page is included in the menu.
</del><span class="cx"> *
</span><del>- * The function which is hooked in to handle the output of the page must check
- * that the user has the required capability as well.
- *
</del><span class="cx"> * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
</span><span class="cx"> * @param string $menu_title The text to be used for the menu
</span><span class="cx"> * @param string $capability The capability required for this menu to be displayed to the user.
</span><span class="lines">@@ -1098,13 +1038,7 @@
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Add sub menu page to the media main menu.
</span><del>-*
- * This function takes a capability which will be used to determine whether
- * or not a page is included in the menu.
</del><span class="cx"> *
</span><del>- * The function which is hooked in to handle the output of the page must check
- * that the user has the required capability as well.
- *
</del><span class="cx"> * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
</span><span class="cx"> * @param string $menu_title The text to be used for the menu
</span><span class="cx"> * @param string $capability The capability required for this menu to be displayed to the user.
</span><span class="lines">@@ -1117,13 +1051,7 @@
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Add sub menu page to the links main menu.
</span><del>-*
- * This function takes a capability which will be used to determine whether
- * or not a page is included in the menu.
</del><span class="cx"> *
</span><del>- * The function which is hooked in to handle the output of the page must check
- * that the user has the required capability as well.
- *
</del><span class="cx"> * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
</span><span class="cx"> * @param string $menu_title The text to be used for the menu
</span><span class="cx"> * @param string $capability The capability required for this menu to be displayed to the user.
</span><span class="lines">@@ -1136,13 +1064,7 @@
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Add sub menu page to the pages main menu.
</span><del>-*
- * This function takes a capability which will be used to determine whether
- * or not a page is included in the menu.
</del><span class="cx"> *
</span><del>- * The function which is hooked in to handle the output of the page must check
- * that the user has the required capability as well.
- *
</del><span class="cx"> * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
</span><span class="cx"> * @param string $menu_title The text to be used for the menu
</span><span class="cx"> * @param string $capability The capability required for this menu to be displayed to the user.
</span><span class="lines">@@ -1155,13 +1077,7 @@
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Add sub menu page to the comments main menu.
</span><del>-*
- * This function takes a capability which will be used to determine whether
- * or not a page is included in the menu.
</del><span class="cx"> *
</span><del>- * The function which is hooked in to handle the output of the page must check
- * that the user has the required capability as well.
- *
</del><span class="cx"> * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
</span><span class="cx"> * @param string $menu_title The text to be used for the menu
</span><span class="cx"> * @param string $capability The capability required for this menu to be displayed to the user.
</span><span class="lines">@@ -1172,7 +1088,54 @@
</span><span class="cx">         return add_submenu_page( 'edit-comments.php', $page_title, $menu_title, $capability, $menu_slug, $function );
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+
</ins><span class="cx"> /**
</span><ins>+ * Remove a top level admin menu
+ *
+ * @since 3.1.0
+ *
+ * @param string $menu_slug The slug of the menu
+ * @return array|bool The removed menu on success, False if not found
+ */
+function remove_menu_page( $menu_slug ) {
+        global $menu;
+
+        foreach ( $menu as $i => $item ) {
+                if ( $menu_slug == $item[2] ) {
+                        unset( $menu[$i] );
+                        return $item;
+                }
+        }
+
+        return false;
+}
+
+/**
+ * Remove an admin submenu
+ *
+ * @since 3.1.0
+ *
+ * @param string $menu_slug The slug for the parent menu
+ * @param string $submenu_slug The slug of the submenu
+ * @return array|bool The removed submenu on success, False if not found
+ */
+function remove_submenu_page( $menu_slug, $submenu_slug ) {
+        global $submenu;
+
+        if ( !isset( $submenu[$menu_slug] ) )
+                return false;
+
+        foreach ( $submenu[$menu_slug] as $i => $item ) {
+                if ( $submenu_slug == $item[2] ) {
+                        unset( $submenu[$menu_slug][$i] );
+                        return $item;
+                }
+        }
+
+        return false;
+}
+
+/**
</ins><span class="cx"> * Get the url to access a particular menu page based on the slug it was registered with.
</span><span class="cx"> *
</span><span class="cx"> * If the slug hasn't been registered properly no url will be returned
</span></span></pre>
</div>
</div>
</body>
</html>