<!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>[30888] trunk/src: Updates to the 'Log out everywhere' implementation.</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" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/30888">30888</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/30888","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>nacin</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2014-12-16 09:15:01 +0000 (Tue, 16 Dec 2014)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Updates to the 'Log out everywhere' implementation.
* Include a message and a disabled button when you're only logged in at one location.
* Avoid leaking the session token in HTML.
* Simplify, simplify, simplify.
see <a href="https://core.trac.wordpress.org/ticket/30264">#30264</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadmincsscommoncss">trunk/src/wp-admin/css/common.css</a></li>
<li><a href="#trunksrcwpadminincludesajaxactionsphp">trunk/src/wp-admin/includes/ajax-actions.php</a></li>
<li><a href="#trunksrcwpadminjsuserprofilejs">trunk/src/wp-admin/js/user-profile.js</a></li>
<li><a href="#trunksrcwpadminusereditphp">trunk/src/wp-admin/user-edit.php</a></li>
<li><a href="#trunksrcwpincludesscriptloaderphp">trunk/src/wp-includes/script-loader.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadmincsscommoncss"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/css/common.css</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/css/common.css 2014-12-16 08:57:11 UTC (rev 30887)
+++ trunk/src/wp-admin/css/common.css 2014-12-16 09:15:01 UTC (rev 30888)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1265,7 +1265,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> .notice p,
</span><span class="cx" style="display: block; padding: 0 10px"> div.updated p,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-div.error p {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+div.error p,
+.form-table td .notice p {
</ins><span class="cx" style="display: block; padding: 0 10px"> margin: 0.5em 0;
</span><span class="cx" style="display: block; padding: 0 10px"> padding: 2px;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunksrcwpadminincludesajaxactionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/ajax-actions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/ajax-actions.php 2014-12-16 08:57:11 UTC (rev 30887)
+++ trunk/src/wp-admin/includes/ajax-actions.php 2014-12-16 09:15:01 UTC (rev 30888)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2771,42 +2771,25 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function wp_ajax_destroy_sessions() {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( empty( $_POST['user_id'] ) ) {
- $user = new WP_Error();
- } else {
- $user = new WP_User( absint( $_POST['user_id'] ) );
-
- if ( ! $user->exists() ) {
- $user = new WP_Error();
- } elseif ( ! current_user_can( 'edit_user', $user->ID ) ) {
- $user = new WP_Error();
- } elseif ( ! check_ajax_referer( sprintf( 'destroy_sessions_%d', $user->ID ), false, false ) ) {
- $user = new WP_Error();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $user = get_userdata( (int) $_POST['user_id'] );
+ if ( $user ) {
+ if ( ! current_user_can( 'edit_user', $user->ID ) ) {
+ $user = false;
+ } elseif ( ! wp_verify_nonce( $_POST['nonce'], 'update-user_' . $user->ID ) ) {
+ $user = false;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( is_wp_error( $user ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $user ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_send_json_error( array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'message' => __( 'Could not log out user sessions. Please try again.' ),
</span><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // 'token' is only set if the initiating user is viewing their own profile-editing screen.
- if ( isset( $_POST['token'] ) ) {
- $keep = wp_unslash( $_POST['token'] );
- } else {
- $keep = null;
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> $sessions = WP_Session_Tokens::get_instance( $user->ID );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /*
- * If $keep is a string, then the current user is destroying all of their own sessions
- * except the current one. If $keep is not a string, the current user is destroying all
- * of another user's sessions with no exceptions.
- */
- if ( is_string( $keep ) ) {
- $sessions->destroy_others( $keep );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $user->ID === get_current_user_id() ) {
+ $sessions->destroy_others( wp_get_session_token() );
</ins><span class="cx" style="display: block; padding: 0 10px"> $message = __( 'You are now logged out everywhere else.' );
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> $sessions->destroy_all();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2814,8 +2797,5 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $message = sprintf( __( '%s has been logged out.' ), $user->display_name );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_send_json_success( array(
- 'message' => $message
- ) );
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_send_json_success( array( 'message' => $message ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunksrcwpadminjsuserprofilejs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/js/user-profile.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/js/user-profile.js 2014-12-16 08:57:11 UTC (rev 30887)
+++ trunk/src/wp-admin/js/user-profile.js 2014-12-16 09:15:01 UTC (rev 30888)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,4 +1,4 @@
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-/* global ajaxurl, pwsL10n, _wpSessionMangager */
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/* global ajaxurl, pwsL10n */
</ins><span class="cx" style="display: block; padding: 0 10px"> (function($){
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> function check_pass_strength() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -125,26 +125,20 @@
</span><span class="cx" style="display: block; padding: 0 10px"> });
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $( '#destroy-sessions' ).on( 'click', function( e ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> var $this = $(this);
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- var data = {
- action : 'destroy-sessions',
- _ajax_nonce : _wpSessionMangager.nonce,
- user_id : _wpSessionMangager.user_id,
- token : $(this).data('token')
- };
</del><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $.post( ajaxurl, data, function( response ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp.ajax.post( 'destroy-sessions', {
+ nonce: $( '#_wpnonce' ).val(),
+ user_id: $( '#user_id' ).val()
+ }).done( function( response ) {
+ $this.prop( 'disabled', true );
+ $this.siblings( '.notice' ).remove();
+ $this.before( '<div class="notice notice-success inline"><p>' + response.message + '</p></div>' );
+ }).fail( function( response ) {
+ $this.siblings( '.notice' ).remove();
+ $this.before( '<div class="notice notice-error inline"><p>' + response.message + '</p></div>' );
+ });
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( response.success ) {
- $this.prop( 'disabled', true );
- $this.before( '<div class="updated inline"><p>' + response.data.message + '</p></div>' );
- } else {
- $this.before( '<div class="error inline"><p>' + response.data.message + '</p></div>' );
- }
-
- }, 'json' );
-
</del><span class="cx" style="display: block; padding: 0 10px"> e.preventDefault();
</span><span class="cx" style="display: block; padding: 0 10px"> });
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunksrcwpadminusereditphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/user-edit.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/user-edit.php 2014-12-16 08:57:11 UTC (rev 30887)
+++ trunk/src/wp-admin/user-edit.php 2014-12-16 09:15:01 UTC (rev 30888)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -25,15 +25,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> wp_enqueue_script('user-profile');
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-wp_localize_script(
- 'user-profile',
- '_wpSessionMangager',
- array(
- 'user_id' => $user_id,
- 'nonce' => wp_create_nonce( sprintf( 'destroy_sessions_%d', $user_id ) ),
- )
-);
-
</del><span class="cx" style="display: block; padding: 0 10px"> $title = IS_PROFILE_PAGE ? __('Profile') : __('Edit User');
</span><span class="cx" style="display: block; padding: 0 10px"> if ( current_user_can('edit_users') && !IS_PROFILE_PAGE )
</span><span class="cx" style="display: block; padding: 0 10px"> $submenu_file = 'users.php';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -493,17 +484,28 @@
</span><span class="cx" style="display: block; padding: 0 10px"> </tr>
</span><span class="cx" style="display: block; padding: 0 10px"> <?php endif; ?>
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php if ( IS_PROFILE_PAGE && ( count( $sessions->get_all() ) > 1 ) ) { ?>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+if ( IS_PROFILE_PAGE && count( $sessions->get_all() ) === 1 ) : ?>
</ins><span class="cx" style="display: block; padding: 0 10px"> <tr class="user-sessions-wrap hide-if-no-js">
</span><span class="cx" style="display: block; padding: 0 10px"> <th> </th>
</span><span class="cx" style="display: block; padding: 0 10px"> <td aria-live="assertive">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <div class="destroy-sessions"><button class="button button-secondary" id="destroy-sessions" data-token="<?php echo esc_attr( wp_get_session_token() ); ?>"><?php _e( 'Log Out of All Other Sessions' ); ?></button></div>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <div class="destroy-sessions"><button disabled class="button button-secondary"><?php _e( 'Log Out of All Other Sessions' ); ?></button></div>
</ins><span class="cx" style="display: block; padding: 0 10px"> <p class="description">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <?php _e( 'You are only logged in at this location.' ); ?>
+ </p>
+ </td>
+ </tr>
+<?php elseif ( IS_PROFILE_PAGE && count( $sessions->get_all() ) > 1 ) : ?>
+ <tr class="user-sessions-wrap hide-if-no-js">
+ <th> </th>
+ <td aria-live="assertive">
+ <div class="destroy-sessions"><button class="button button-secondary" id="destroy-sessions"><?php _e( 'Log Out of All Other Sessions' ); ?></button></div>
+ <p class="description">
</ins><span class="cx" style="display: block; padding: 0 10px"> <?php _e( 'Left your account logged in at a public computer? Lost your phone? This will log you out everywhere except your current browser.' ); ?>
</span><span class="cx" style="display: block; padding: 0 10px"> </p>
</span><span class="cx" style="display: block; padding: 0 10px"> </td>
</span><span class="cx" style="display: block; padding: 0 10px"> </tr>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php } else if ( ! IS_PROFILE_PAGE && ( count( $sessions->get_all() ) > 0 ) ) { ?>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php elseif ( ! IS_PROFILE_PAGE && $sessions->get_all() ) : ?>
</ins><span class="cx" style="display: block; padding: 0 10px"> <tr class="user-sessions-wrap hide-if-no-js">
</span><span class="cx" style="display: block; padding: 0 10px"> <th> </th>
</span><span class="cx" style="display: block; padding: 0 10px"> <td>
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -516,7 +518,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> </p>
</span><span class="cx" style="display: block; padding: 0 10px"> </td>
</span><span class="cx" style="display: block; padding: 0 10px"> </tr>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php } ?>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php endif; ?>
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> </table>
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunksrcwpincludesscriptloaderphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/script-loader.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/script-loader.php 2014-12-16 08:57:11 UTC (rev 30887)
+++ trunk/src/wp-includes/script-loader.php 2014-12-16 09:15:01 UTC (rev 30888)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -349,7 +349,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'mismatch' => __('Mismatch')
</span><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $scripts->add( 'user-profile', "/wp-admin/js/user-profile$suffix.js", array( 'jquery', 'password-strength-meter' ), false, 1 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $scripts->add( 'user-profile', "/wp-admin/js/user-profile$suffix.js", array( 'jquery', 'password-strength-meter', 'wp-util' ), false, 1 );
</ins><span class="cx" style="display: block; padding: 0 10px"> $scripts->add( 'language-chooser', "/wp-admin/js/language-chooser$suffix.js", array( 'jquery' ), false, 1 );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $scripts->add( 'user-suggest', "/wp-admin/js/user-suggest$suffix.js", array( 'jquery-ui-autocomplete' ), false, 1 );
</span></span></pre>
</div>
</div>
</body>
</html>