<!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" />
<title>[21687] trunk: Introduce WP_Screen::in_admin() for determining which admin the screen is in.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { 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 #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#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>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/21687">21687</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2012-08-31 17:16:46 +0000 (Fri, 31 Aug 2012)</dd>
</dl>

<h3>Log Message</h3>
<pre>Introduce WP_Screen::in_admin() for determining which admin the screen is in.
Change is_*_admin() to reference in_admin() with fallback to the WP_*_ADMIN constants during early bootstrap. This allows unit tests and ajax handlers to set the admin context.

fixes <a href="http://core.trac.wordpress.org/ticket/21742">#21742</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesscreenphp">trunk/wp-admin/includes/screen.php</a></li>
<li><a href="#trunkwpincludesloadphp">trunk/wp-includes/load.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesscreenphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/screen.php (21686 => 21687)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/screen.php        2012-08-31 17:05:18 UTC (rev 21686)
+++ trunk/wp-admin/includes/screen.php        2012-08-31 17:16:46 UTC (rev 21687)
</span><span class="lines">@@ -244,9 +244,21 @@
</span><span class="cx">         public $id;
</span><span class="cx"> 
</span><span class="cx">         /**
</span><ins>+         * Which admin the screen is in. network | user | site | false
+         *
+         * @since 3.5.0
+         * @var string
+         * @access protected
+         */
+        protected $in_admin;
+
+        /**
</ins><span class="cx">          * Whether the screen is in the network admin.
</span><span class="cx">          *
</span><ins>+         * Deprecated. Use in_admin() instead.
+         *
</ins><span class="cx">          * @since 3.3.0
</span><ins>+         * @deprecated 3.5.0
</ins><span class="cx">          * @var bool
</span><span class="cx">          * @access public
</span><span class="cx">          */
</span><span class="lines">@@ -255,7 +267,10 @@
</span><span class="cx">         /**
</span><span class="cx">          * Whether the screen is in the user admin.
</span><span class="cx">          *
</span><ins>+         * Deprecated. Use in_admin() instead.
+         *
</ins><span class="cx">          * @since 3.3.0
</span><ins>+         * @deprecated 3.5.0
</ins><span class="cx">          * @var bool
</span><span class="cx">          * @access public
</span><span class="cx">          */
</span><span class="lines">@@ -377,7 +392,7 @@
</span><span class="cx">                         return $hook_name;
</span><span class="cx"> 
</span><span class="cx">                 $post_type = $taxonomy = null;
</span><del>-                $is_network = $is_user = false;
</del><ins>+                $in_admin = false;
</ins><span class="cx">                 $action = '';
</span><span class="cx"> 
</span><span class="cx">                 if ( $hook_name )
</span><span class="lines">@@ -402,10 +417,10 @@
</span><span class="cx">                 if ( ! $post_type &amp;&amp; $hook_name ) {
</span><span class="cx">                         if ( '-network' == substr( $id, -8 ) ) {
</span><span class="cx">                                 $id = substr( $id, 0, -8 );
</span><del>-                                $is_network = true;
</del><ins>+                                $in_admin = 'network';
</ins><span class="cx">                         } elseif ( '-user' == substr( $id, -5 ) ) {
</span><span class="cx">                                 $id = substr( $id, 0, -5 );
</span><del>-                                $is_user = true;
</del><ins>+                                $in_admin = 'user';
</ins><span class="cx">                         }
</span><span class="cx"> 
</span><span class="cx">                         $id = sanitize_key( $id );
</span><span class="lines">@@ -419,13 +434,22 @@
</span><span class="cx">                                         $post_type = $maybe;
</span><span class="cx">                                 }
</span><span class="cx">                          }
</span><ins>+
+                        if ( ! $in_admin )
+                                $in_admin = 'site';
</ins><span class="cx">                 } else {
</span><del>-                        $is_network = is_network_admin();
-                        $is_user = is_user_admin();
</del><ins>+                        if ( defined( 'WP_NETWORK_ADMIN' ) &amp;&amp; WP_NETWORK_ADMIN )
+                                $in_admin = 'network';
+                        elseif ( defined( 'WP_USER_ADMIN' ) &amp;&amp; WP_USER_ADMIN )
+                                $in_admin = 'user';
+                        else
+                                $in_admin = 'site';
</ins><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 if ( 'index' == $id )
</span><span class="cx">                         $id = 'dashboard';
</span><ins>+                elseif ( 'front' == $id )
+                        $in_admin = false;
</ins><span class="cx"> 
</span><span class="cx">                 $base = $id;
</span><span class="cx"> 
</span><span class="lines">@@ -476,10 +500,10 @@
</span><span class="cx">                                 break;
</span><span class="cx">                 }
</span><span class="cx"> 
</span><del>-                if ( $is_network ) {
</del><ins>+                if ( 'network' == $in_admin ) {
</ins><span class="cx">                         $id   .= '-network';
</span><span class="cx">                         $base .= '-network';
</span><del>-                } elseif ( $is_user ) {
</del><ins>+                } elseif ( 'user' == $in_admin ) {
</ins><span class="cx">                         $id   .= '-user';
</span><span class="cx">                         $base .= '-user';
</span><span class="cx">                  }
</span><span class="lines">@@ -497,8 +521,9 @@
</span><span class="cx">                 $screen-&gt;action     = $action;
</span><span class="cx">                 $screen-&gt;post_type  = (string) $post_type;
</span><span class="cx">                 $screen-&gt;taxonomy   = (string) $taxonomy;
</span><del>-                $screen-&gt;is_user    = $is_user;
-                $screen-&gt;is_network = $is_network;
</del><ins>+                $screen-&gt;is_user    = ( 'user' == $in_admin );
+                $screen-&gt;is_network = ( 'network' == $in_admin );
+                $screen-&gt;in_admin   = $in_admin;
</ins><span class="cx"> 
</span><span class="cx">                 self::$_registry[ $id ] = $screen;
</span><span class="cx"> 
</span><span class="lines">@@ -528,6 +553,23 @@
</span><span class="cx">         private function __construct() {}
</span><span class="cx"> 
</span><span class="cx">         /**
</span><ins>+         * Indicates whether the screen is in a particular admin
+         *
+         * @since 3.5.0
+         *
+         * @param string $admin The admin to check against (network | user | site).
+         * If empty any of the three admins will result in true.
+         * @return boolean True if the screen is in the indicated admin, false otherwise.
+         *
+         */
+        public function in_admin( $admin = null ) {
+                if ( empty( $admin ) )
+                        return (bool) $this-&gt;in_admin;
+
+                return ( $admin == $this-&gt;in_admin );
+        }
+
+        /**
</ins><span class="cx">          * Sets the old string-based contextual help for the screen.
</span><span class="cx">          *
</span><span class="cx">          * For backwards compatibility.
</span></span></pre></div>
<a id="trunkwpincludesloadphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/load.php (21686 => 21687)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/load.php        2012-08-31 17:05:18 UTC (rev 21686)
+++ trunk/wp-includes/load.php        2012-08-31 17:16:46 UTC (rev 21687)
</span><span class="lines">@@ -583,8 +583,11 @@
</span><span class="cx">  * @return bool True if inside WordPress administration pages.
</span><span class="cx">  */
</span><span class="cx"> function is_admin() {
</span><del>-        if ( defined( 'WP_ADMIN' ) )
</del><ins>+        if ( isset( $GLOBALS['current_screen'] ) )
+                return $GLOBALS['current_screen']-&gt;in_admin();
+        elseif ( defined( 'WP_ADMIN' ) )
</ins><span class="cx">                 return WP_ADMIN;
</span><ins>+
</ins><span class="cx">         return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -599,8 +602,11 @@
</span><span class="cx">  * @return bool True if inside WordPress network administration pages.
</span><span class="cx">  */
</span><span class="cx"> function is_blog_admin() {
</span><del>-        if ( defined( 'WP_BLOG_ADMIN' ) )
</del><ins>+        if ( isset( $GLOBALS['current_screen'] ) )
+                return $GLOBALS['current_screen']-&gt;in_admin( 'blog' );
+        elseif ( defined( 'WP_BLOG_ADMIN' ) )
</ins><span class="cx">                 return WP_BLOG_ADMIN;
</span><ins>+
</ins><span class="cx">         return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -615,8 +621,11 @@
</span><span class="cx">  * @return bool True if inside WordPress network administration pages.
</span><span class="cx">  */
</span><span class="cx"> function is_network_admin() {
</span><del>-        if ( defined( 'WP_NETWORK_ADMIN' ) )
</del><ins>+        if ( isset( $GLOBALS['current_screen'] ) )
+                return $GLOBALS['current_screen']-&gt;in_admin( 'network' );
+        elseif ( defined( 'WP_NETWORK_ADMIN' ) )
</ins><span class="cx">                 return WP_NETWORK_ADMIN;
</span><ins>+
</ins><span class="cx">         return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -631,8 +640,11 @@
</span><span class="cx">  * @return bool True if inside WordPress user administration pages.
</span><span class="cx">  */
</span><span class="cx"> function is_user_admin() {
</span><del>-        if ( defined( 'WP_USER_ADMIN' ) )
</del><ins>+        if ( isset( $GLOBALS['current_screen'] ) )
+                return $GLOBALS['current_screen']-&gt;in_admin( 'user' );
+        elseif ( defined( 'WP_USER_ADMIN' ) )
</ins><span class="cx">                 return WP_USER_ADMIN;
</span><ins>+
</ins><span class="cx">         return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>