<!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>[24738] trunk/wp-includes: Fire wp_auth_check_load() from admin_enqueue_scripts instead of admin_init so that it can access the current screen object.</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 { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { 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/24738">24738</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2013-07-18 19:06:35 +0000 (Thu, 18 Jul 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Fire wp_auth_check_load() from admin_enqueue_scripts instead of admin_init so that it can access the current screen object.

Black list the update and upgrade screens.

Allow plugins to white/black list screens via the wp_auth_check_load filter.

Props nacin

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

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesdefaultfiltersphp">trunk/wp-includes/default-filters.php</a></li>
<li><a href="#trunkwpincludesfunctionsphp">trunk/wp-includes/functions.php</a></li>
<li><a href="#trunkwpincludesjswpauthcheckjs">trunk/wp-includes/js/wp-auth-check.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesdefaultfiltersphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/default-filters.php (24737 => 24738)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/default-filters.php    2013-07-18 18:58:49 UTC (rev 24737)
+++ trunk/wp-includes/default-filters.php       2013-07-18 19:06:35 UTC (rev 24738)
</span><span class="lines">@@ -295,6 +295,8 @@
</span><span class="cx"> add_filter( 'heartbeat_settings', 'wp_heartbeat_settings' );
</span><span class="cx"> 
</span><span class="cx"> // Check if the user is logged out
</span><del>-add_action( 'admin_init', 'wp_auth_check_load' );
</del><ins>+add_action( 'admin_enqueue_scripts',     'wp_auth_check_load'   );
+add_filter( 'heartbeat_received',        'wp_auth_check', 10, 2 );
+add_filter( 'heartbeat_nopriv_received', 'wp_auth_check', 10, 2 );
</ins><span class="cx"> 
</span><span class="cx"> unset($filter, $action);
</span></span></pre></div>
<a id="trunkwpincludesfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/functions.php (24737 => 24738)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/functions.php  2013-07-18 18:58:49 UTC (rev 24737)
+++ trunk/wp-includes/functions.php     2013-07-18 19:06:35 UTC (rev 24738)
</span><span class="lines">@@ -3916,37 +3916,39 @@
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="cx">  * Load the auth check for monitoring whether the user is still logged in.
</span><del>- * Can be disabled with remove_action( 'admin_init', 'wp_auth_check_load' );
</del><span class="cx">  *
</span><ins>+ * Can be disabled with remove_action( 'admin_enqueue_scripts', 'wp_auth_check_load' );
+ *
+ * This is disabled for certain screens where a login screen could cause an
+ * inconvenient interruption. A filter called wp_auth_check_load can be used
+ * for fine-grained control.
+ *
</ins><span class="cx">  * @since 3.6.0
</span><del>- *
- * @return void
</del><span class="cx">  */
</span><span class="cx"> function wp_auth_check_load() {
</span><del>-       global $pagenow;
</del><ins>+        if ( ! is_admin() && ! is_user_logged_in() )
+               return;
</ins><span class="cx"> 
</span><del>-       // Don't load for these types of requests
-       if ( defined('XMLRPC_REQUEST') || defined('IFRAME_REQUEST') || 'wp-login.php' == $pagenow )
</del><ins>+        if ( defined( 'IFRAME_REQUEST' ) )
</ins><span class="cx">           return;
</span><span class="cx"> 
</span><del>-       if ( is_admin() || is_user_logged_in() ) {
-               if ( defined('DOING_AJAX') ) {
-                       add_filter( 'heartbeat_received', 'wp_auth_check', 10, 2 );
-                       add_filter( 'heartbeat_nopriv_received', 'wp_auth_check', 10, 2 );
-               } else {
-                       wp_enqueue_style( 'wp-auth-check' );
-                       wp_enqueue_script( 'wp-auth-check' );
</del><ins>+        $screen = get_current_screen();
+       $hidden = array( 'update', 'update-network', 'update-core', 'update-core-network', 'upgrade', 'upgrade-network', 'network' );
+       $show = ! in_array( $screen->id, $hidden );
</ins><span class="cx"> 
</span><del>-                       if ( is_admin() )
-                               add_action( 'admin_print_footer_scripts', 'wp_auth_check_html', 5 );
-                       else
-                               add_action( 'wp_print_footer_scripts', 'wp_auth_check_html', 5 );
-               }
</del><ins>+        if ( apply_filters( 'wp_auth_check_load', $show, $screen ) ) {
+               wp_enqueue_style( 'wp-auth-check' );
+               wp_enqueue_script( 'wp-auth-check' );
+
+               add_action( 'admin_print_footer_scripts', 'wp_auth_check_html', 5 );
+               add_action( 'wp_print_footer_scripts', 'wp_auth_check_html', 5 );
</ins><span class="cx">   }
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- * Output the HTML that shows the wp-login dialog when the user is no longer logged in
</del><ins>+ * Output the HTML that shows the wp-login dialog when the user is no longer logged in.
+ *
+ * @since 3.6.0
</ins><span class="cx">  */
</span><span class="cx"> function wp_auth_check_html() {
</span><span class="cx">  $login_url = wp_login_url();
</span><span class="lines">@@ -3985,19 +3987,16 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- * Check whether a user is still logged in, and act accordingly if not.
</del><ins>+ * Check whether a user is still logged in, for the heartbeat.
</ins><span class="cx">  *
</span><ins>+ * Send a result that shows a log-in box if the user is no longer logged in,
+ * or if their cookie is within the grace period.
+ *
</ins><span class="cx">  * @since 3.6.0
</span><span class="cx">  */
</span><span class="cx"> function wp_auth_check( $response, $data ) {
</span><del>-       if ( ! isset( $data['wp-auth-check'] ) )
-               return $response;
-
-       // If the user is logged in and we are outside the login grace period, bail.
-       if ( is_user_logged_in() && empty( $GLOBALS['login_grace_period'] ) )
-               return array_merge( $response, array( 'wp-auth-check' => '1' ) );
-
-       return array_merge( $response, array( 'wp-auth-check' => 'show' ) );
</del><ins>+        $response['wp-auth-check'] = is_user_logged_in() && empty( $GLOBALS['login_grace_period'] );
+       return $response;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span></span></pre></div>
<a id="trunkwpincludesjswpauthcheckjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/wp-auth-check.js (24737 => 24738)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/wp-auth-check.js    2013-07-18 18:58:49 UTC (rev 24737)
+++ trunk/wp-includes/js/wp-auth-check.js       2013-07-18 19:06:35 UTC (rev 24738)
</span><span class="lines">@@ -85,17 +85,16 @@
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="cx">  $( document ).on( 'heartbeat-tick.wp-auth-check', function( e, data ) {
</span><del>-               if ( data['wp-auth-check'] ) {
</del><ins>+                if ( 'wp-auth-check' in data ) {
</ins><span class="cx">                   schedule();
</span><del>-
-                       if ( data['wp-auth-check'] == 'show' && wrap.hasClass('hidden') )
</del><ins>+                        if ( ! data['wp-auth-check'] && wrap.hasClass('hidden') )
</ins><span class="cx">                           show();
</span><del>-                       else if ( data['wp-auth-check'] != 'show' && ! wrap.hasClass('hidden') )
</del><ins>+                        else if ( data['wp-auth-check'] && ! wrap.hasClass('hidden') )
</ins><span class="cx">                           hide();
</span><span class="cx">          }
</span><span class="cx">  }).on( 'heartbeat-send.wp-auth-check', function( e, data ) {
</span><span class="cx">          if ( ( new Date() ).getTime() > next )
</span><del>-                       data['wp-auth-check'] = 1;
</del><ins>+                        data['wp-auth-check'] = true;
</ins><span class="cx">   }).ready( function() {
</span><span class="cx">          schedule();
</span><span class="cx">          wrap = $('#wp-auth-check-wrap');
</span></span></pre>
</div>
</div>

</body>
</html>