<!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>[43083] branches/4.9/src: Privacy: update the method to confirm user requests by email.</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 { white-space: pre-line; 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/43083">43083</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/43083","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>SergeyBiryukov</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2018-05-02 01:00:46 +0000 (Wed, 02 May 2018)</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'>Privacy: update the method to confirm user requests by email. Use a single CPT to store the requests and to allow logging/audit trail.
Props mikejolley.
Merges <a href="https://core.trac.wordpress.org/changeset/43008">[43008]</a> to the 4.9 branch.
See <a href="https://core.trac.wordpress.org/ticket/43443">#43443</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#branches49srcwpadminincludesadminfiltersphp">branches/4.9/src/wp-admin/includes/admin-filters.php</a></li>
<li><a href="#branches49srcwpadminincludesajaxactionsphp">branches/4.9/src/wp-admin/includes/ajax-actions.php</a></li>
<li><a href="#branches49srcwpadminincludesuserphp">branches/4.9/src/wp-admin/includes/user.php</a></li>
<li><a href="#branches49srcwpincludesdefaultfiltersphp">branches/4.9/src/wp-includes/default-filters.php</a></li>
<li><a href="#branches49srcwpincludespostphp">branches/4.9/src/wp-includes/post.php</a></li>
<li><a href="#branches49srcwpincludesuserphp">branches/4.9/src/wp-includes/user.php</a></li>
<li><a href="#branches49srcwploginphp">branches/4.9/src/wp-login.php</a></li>
</ul>
<h3>Property Changed</h3>
<ul>
<li><a href="#branches49">branches/4.9/</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<span class="cx" style="display: block; padding: 0 10px">Index: branches/4.9
</span><span class="cx" style="display: block; padding: 0 10px">===================================================================
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">--- branches/4.9 2018-05-02 00:48:23 UTC (rev 43082)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+++ branches/4.9 2018-05-02 01:00:46 UTC (rev 43083)
</ins><a id="branches49"></a>
<div class="propset"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Property changes: branches/4.9</h4>
<pre class="diff"><span>
</span></pre></div>
<a id="svnmergeinfo"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: svn:mergeinfo</h4></div>
<span class="cx" style="display: block; padding: 0 10px"> /branches/3.1:18031
</span><span class="cx" style="display: block; padding: 0 10px"> /branches/3.3:20543
</span><span class="cx" style="display: block; padding: 0 10px"> /branches/3.4:21757
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-/trunk:18512,42132,42134,42136,42138,42140,42144,42146,42148,42150,42152-42153,42155,42157,42159,42161,42163,42169,42171,42173,42175,42177,42181,42183,42185,42187,42189,42191,42193,42199,42203,42210,42214,42220,42222,42226,42242,42244,42247,42251,42256-42261,42350,42358,42362,42364-42368,42374,42388,42390,42401,42417,42421,42423-42425,42430,42433,42437,42441,42443,42446-42447,42449,42451,42453,42457,42459,42462,42491,42521,42529,42531,42533,42536,42538,42541,42543,42545,42549,42566,42568,42570,42572,42574,42576,42579,42581-42582,42584-42585,42587-42588,42590,42592,42594-42595,42598-42599,42602,42604,42606,42611-42613,42615,42617,42624-42625,42639,42648,42652-42653,42665,42687,42711,42713,42719,42722,42739-42740,42744,42758,42791-42792,42801,42817-42818,42830,42837,42839,42841,42844,42851-42852,42860,42864,42881,42888-42889,42892-42894,42930,42964,42967,42971-42972,42977,42986-42987,42989
,42994,42998,43001,43004,43007,43025,43027,43030,43032,43034,43036,43039,43056,43058,43062-43063,43065,43081
</del><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/trunk:18512,42132,42134,42136,42138,42140,42144,42146,42148,42150,42152-42153,42155,42157,42159,42161,42163,42169,42171,42173,42175,42177,42181,42183,42185,42187,42189,42191,42193,42199,42203,42210,42214,42220,42222,42226,42242,42244,42247,42251,42256-42261,42350,42358,42362,42364-42368,42374,42388,42390,42401,42417,42421,42423-42425,42430,42433,42437,42441,42443,42446-42447,42449,42451,42453,42457,42459,42462,42491,42521,42529,42531,42533,42536,42538,42541,42543,42545,42549,42566,42568,42570,42572,42574,42576,42579,42581-42582,42584-42585,42587-42588,42590,42592,42594-42595,42598-42599,42602,42604,42606,42611-42613,42615,42617,42624-42625,42639,42648,42652-42653,42665,42687,42711,42713,42719,42722,42739-42740,42744,42758,42791-42792,42801,42817-42818,42830,42837,42839,42841,42844,42851-42852,42860,42864,42881,42888-42889,42892-42894,42930,42964,42967,42971-42972,42977,42986-42987,42989
,42994,42998,43001,43004,43007-43008,43025,43027,43030,43032,43034,43036,43039,43056,43058,43062-43063,43065,43081
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="branches49srcwpadminincludesadminfiltersphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/4.9/src/wp-admin/includes/admin-filters.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/4.9/src/wp-admin/includes/admin-filters.php 2018-05-02 00:48:23 UTC (rev 43082)
+++ branches/4.9/src/wp-admin/includes/admin-filters.php 2018-05-02 01:00:46 UTC (rev 43083)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -46,7 +46,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'admin_head', '_ipad_meta' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Privacy tools
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-add_action( 'account_action_failed', '_wp_privacy_account_request_failed' );
</del><span class="cx" style="display: block; padding: 0 10px"> add_action( 'admin_menu', '_wp_privacy_hook_requests_page' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Prerendering.
</span></span></pre></div>
<a id="branches49srcwpadminincludesajaxactionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/4.9/src/wp-admin/includes/ajax-actions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/4.9/src/wp-admin/includes/ajax-actions.php 2018-05-02 00:48:23 UTC (rev 43082)
+++ branches/4.9/src/wp-admin/includes/ajax-actions.php 2018-05-02 01:00:46 UTC (rev 43083)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4155,11 +4155,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Find the request CPT
</span><span class="cx" style="display: block; padding: 0 10px"> $request = get_post( $request_id );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( 'user_remove_request' !== $request->post_type ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( 'remove_personal_data' !== $request->post_title ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_send_json_error( __( 'Error: Invalid request ID.' ) );
</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">- $email_address = get_post_meta( $request_id, '_user_email', true );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $email_address = get_post_meta( $request_id, '_wp_user_request_user_email', true );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! is_email( $email_address ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> wp_send_json_error( __( 'Error: Invalid email address in request.' ) );
</span></span></pre></div>
<a id="branches49srcwpadminincludesuserphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/4.9/src/wp-admin/includes/user.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/4.9/src/wp-admin/includes/user.php 2018-05-02 00:48:23 UTC (rev 43082)
+++ branches/4.9/src/wp-admin/includes/user.php 2018-05-02 01:00:46 UTC (rev 43083)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -540,85 +540,23 @@
</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">- * Get action description from the name.
- *
- * @since 4.9.6
- * @access private
- *
- * @return string
- */
-function _wp_privacy_action_description( $request_type ) {
- switch ( $request_type ) {
- case 'user_export_request':
- return __( 'Export Personal Data' );
- case 'user_remove_request':
- return __( 'Remove Personal Data' );
- }
-}
-
-/**
- * Log a request and send to the user.
- *
- * @since 4.9.6
- * @access private
- *
- * @param string $email_address Email address sending the request to.
- * @param string $action Action being requested.
- * @param string $description Description of request.
- * @return bool|WP_Error depending on success.
- */
-function _wp_privacy_create_request( $email_address, $action, $description ) {
- $user_id = 0;
- $user = get_user_by( 'email', $email_address );
-
- if ( $user ) {
- $user_id = $user->ID;
- }
-
- $privacy_request_id = wp_insert_post( array(
- 'post_author' => $user_id,
- 'post_status' => 'request-pending',
- 'post_type' => $action,
- 'post_date' => current_time( 'mysql', false ),
- 'post_date_gmt' => current_time( 'mysql', true ),
- ), true );
-
- if ( is_wp_error( $privacy_request_id ) ) {
- return $privacy_request_id;
- }
-
- update_post_meta( $privacy_request_id, '_user_email', $email_address );
- update_post_meta( $privacy_request_id, '_action_name', $action );
- update_post_meta( $privacy_request_id, '_confirmed_timestamp', false );
-
- return wp_send_account_verification_key( $email_address, $action, $description, array(
- 'privacy_request_id' => $privacy_request_id,
- ) );
-}
-
-/**
</del><span class="cx" style="display: block; padding: 0 10px"> * Resend an existing request and return the result.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.9.6
</span><span class="cx" style="display: block; padding: 0 10px"> * @access private
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param int $privacy_request_id Request ID.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param int $request_id Request ID.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return bool|WP_Error
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function _wp_privacy_resend_request( $privacy_request_id ) {
- $privacy_request_id = absint( $privacy_request_id );
- $privacy_request = get_post( $privacy_request_id );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function _wp_privacy_resend_request( $request_id ) {
+ $request_id = absint( $request_id );
+ $request = get_post( $request_id );
</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 ( ! $privacy_request || ! in_array( $privacy_request->post_type, _wp_privacy_action_request_types(), true ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $request || 'user_request' !== $request->post_type ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'privacy_request_error', __( 'Invalid request.' ) );
</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">- $email_address = get_post_meta( $privacy_request_id, '_user_email', true );
- $action = get_post_meta( $privacy_request_id, '_action_name', true );
- $description = _wp_privacy_action_description( $action );
- $result = wp_send_account_verification_key( $email_address, $action, $description, array(
- 'privacy_request_id' => $privacy_request_id,
- ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $result = wp_send_user_request( $request_id );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( is_wp_error( $result ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return $result;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -626,13 +564,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'privacy_request_error', __( 'Unable to initiate confirmation request.' ) );
</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_update_post( array(
- 'ID' => $privacy_request_id,
- 'post_status' => 'request-pending',
- 'post_date' => current_time( 'mysql', false ),
- 'post_date_gmt' => current_time( 'mysql', true ),
- ) );
-
</del><span class="cx" style="display: block; padding: 0 10px"> return true;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -642,23 +573,23 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.9.6
</span><span class="cx" style="display: block; padding: 0 10px"> * @access private
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param int $privacy_request_id Request ID.
- * @return bool|WP_Error
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param int $request_id Request ID.
+ * @return int|WP_Error Request ID on succes or WP_Error.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function _wp_privacy_completed_request( $privacy_request_id ) {
- $privacy_request_id = absint( $privacy_request_id );
- $privacy_request = get_post( $privacy_request_id );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function _wp_privacy_completed_request( $request_id ) {
+ $request_id = absint( $request_id );
+ $request_data = wp_get_user_request_data( $request_id );
</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 ( ! $privacy_request || ! in_array( $privacy_request->post_type, _wp_privacy_action_request_types(), true ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $request_data ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'privacy_request_error', __( 'Invalid request.' ) );
</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_update_post( array(
- 'ID' => $privacy_request_id,
- 'post_status' => 'request-completed',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ update_post_meta( $request_id, '_wp_user_request_confirmed_timestamp', time() );
+ $request = wp_update_post( array(
+ 'ID' => $request_data['request_id'],
+ 'post_status' => 'request-confirmed',
</ins><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
- update_post_meta( $privacy_request_id, '_completed_timestamp', time() );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $request;
</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><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -762,32 +693,38 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $email_address = $username_or_email_address;
</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 ( ! empty( $email_address ) ) {
- $result = _wp_privacy_create_request( $email_address, $action_type, _wp_privacy_action_description( $action_type ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( empty( $email_address ) ) {
+ break;
+ }
</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 ( is_wp_error( $result ) ) {
- add_settings_error(
- 'username_or_email_to_export',
- 'username_or_email_to_export',
- $result->get_error_message(),
- 'error'
- );
- } elseif ( ! $result ) {
- add_settings_error(
- 'username_or_email_to_export',
- 'username_or_email_to_export',
- __( 'Unable to initiate confirmation request.' ),
- 'error'
- );
- } else {
- add_settings_error(
- 'username_or_email_to_export',
- 'username_or_email_to_export',
- __( 'Confirmation request initiated successfully.' ),
- 'updated'
- );
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $request_id = wp_create_user_request( $email_address, $action_type );
+
+ if ( is_wp_error( $request_id ) ) {
+ add_settings_error(
+ 'username_or_email_to_export',
+ 'username_or_email_to_export',
+ $request_id->get_error_message(),
+ 'error'
+ );
+ break;
+ } elseif ( ! $request_id ) {
+ add_settings_error(
+ 'username_or_email_to_export',
+ 'username_or_email_to_export',
+ __( 'Unable to initiate confirmation request.' ),
+ 'error'
+ );
+ break;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ wp_send_user_request( $request_id );
+
+ add_settings_error(
+ 'username_or_email_to_export',
+ 'username_or_email_to_export',
+ __( 'Confirmation request initiated successfully.' ),
+ 'updated'
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -830,7 +767,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> </div>
</span><span class="cx" style="display: block; padding: 0 10px"> <?php wp_nonce_field( 'personal-data-request' ); ?>
</span><span class="cx" style="display: block; padding: 0 10px"> <input type="hidden" name="action" value="add_export_personal_data_request" />
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <input type="hidden" name="type_of_action" value="user_export_request" />
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <input type="hidden" name="type_of_action" value="export_personal_data" />
</ins><span class="cx" style="display: block; padding: 0 10px"> </form>
</span><span class="cx" style="display: block; padding: 0 10px"> <hr />
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -896,7 +833,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> </div>
</span><span class="cx" style="display: block; padding: 0 10px"> <?php wp_nonce_field( 'personal-data-request' ); ?>
</span><span class="cx" style="display: block; padding: 0 10px"> <input type="hidden" name="action" value="add_remove_personal_data_request" />
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <input type="hidden" name="type_of_action" value="user_remove_request" />
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <input type="hidden" name="type_of_action" value="remove_personal_data" />
</ins><span class="cx" style="display: block; padding: 0 10px"> </form>
</span><span class="cx" style="display: block; padding: 0 10px"> <hr />
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -970,11 +907,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function get_columns() {
</span><span class="cx" style="display: block; padding: 0 10px"> $columns = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'cb' => '<input type="checkbox" />',
- 'email' => __( 'Requester' ),
- 'status' => __( 'Status' ),
- 'requested' => __( 'Requested' ),
- 'next_steps' => __( 'Next Steps' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'cb' => '<input type="checkbox" />',
+ 'email' => __( 'Requester' ),
+ 'status' => __( 'Status' ),
+ 'requested_timestamp' => __( 'Requested' ),
+ 'next_steps' => __( 'Next Steps' ),
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> return $columns;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1002,6 +939,43 @@
</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><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Count number of requests for each status.
+ *
+ * @since 4.9.6
+ *
+ * @return object Number of posts for each status.
+ */
+ protected function get_request_counts() {
+ global $wpdb;
+
+ $cache_key = $this->post_type . '-' . $this->request_type;
+ $counts = wp_cache_get( $cache_key, 'counts' );
+
+ if ( false !== $counts ) {
+ return $counts;
+ }
+
+ $query = "
+ SELECT post_status, COUNT( * ) AS num_posts
+ FROM {$wpdb->posts}
+ WHERE post_type = %s
+ AND post_title = %s
+ GROUP BY post_status";
+
+ $results = (array) $wpdb->get_results( $wpdb->prepare( $query, $this->post_type, $this->request_type ), ARRAY_A );
+ $counts = array_fill_keys( get_post_stati(), 0 );
+
+ foreach ( $results as $row ) {
+ $counts[ $row['post_status'] ] = $row['num_posts'];
+ }
+
+ $counts = (object) $counts;
+ wp_cache_set( $cache_key, $counts, 'counts' );
+
+ return $counts;
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Get an associative array ( id => link ) with the list
</span><span class="cx" style="display: block; padding: 0 10px"> * of views available on this table.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1014,7 +988,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $statuses = _wp_privacy_statuses();
</span><span class="cx" style="display: block; padding: 0 10px"> $views = array();
</span><span class="cx" style="display: block; padding: 0 10px"> $admin_url = admin_url( 'tools.php?page=' . $this->request_type );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $counts = wp_count_posts( $this->post_type );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $counts = $this->get_request_counts();
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $current_link_attributes = empty( $current_status ) ? ' class="current" aria-current="page"' : '';
</span><span class="cx" style="display: block; padding: 0 10px"> $views['all'] = '<a href="' . esc_url( $admin_url ) . "\" $current_link_attributes>" . esc_html__( 'All' ) . ' (' . absint( array_sum( (array) $counts ) ) . ')</a>';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1049,6 +1023,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public function process_bulk_action() {
</span><span class="cx" style="display: block; padding: 0 10px"> $action = $this->current_action();
</span><span class="cx" style="display: block; padding: 0 10px"> $request_ids = isset( $_REQUEST['request_id'] ) ? wp_parse_id_list( wp_unslash( $_REQUEST['request_id'] ) ) : array(); // WPCS: input var ok, CSRF ok.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $count = 0;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $request_ids ) {
</span><span class="cx" style="display: block; padding: 0 10px"> check_admin_referer( 'bulk-privacy_requests' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1056,8 +1031,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> switch ( $action ) {
</span><span class="cx" style="display: block; padding: 0 10px"> case 'delete':
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $count = 0;
-
</del><span class="cx" style="display: block; padding: 0 10px"> foreach ( $request_ids as $request_id ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( wp_delete_post( $request_id, true ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $count ++;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1072,11 +1045,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> case 'resend':
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $count = 0;
-
</del><span class="cx" style="display: block; padding: 0 10px"> foreach ( $request_ids as $request_id ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( _wp_privacy_resend_request( $request_id ) ) {
- $count ++;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $resend = _wp_privacy_resend_request( $request_id );
+
+ if ( $resend && ! is_wp_error( $resend ) ) {
+ $count++;
</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><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1110,6 +1083,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $posts_per_page = 20;
</span><span class="cx" style="display: block; padding: 0 10px"> $args = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'post_type' => $this->post_type,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'title' => $this->request_type,
</ins><span class="cx" style="display: block; padding: 0 10px"> 'posts_per_page' => $posts_per_page,
</span><span class="cx" style="display: block; padding: 0 10px"> 'offset' => isset( $_REQUEST['paged'] ) ? max( 0, absint( $_REQUEST['paged'] ) - 1 ) * $posts_per_page: 0,
</span><span class="cx" style="display: block; padding: 0 10px"> 'post_status' => 'any',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1125,31 +1099,23 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $name_query,
</span><span class="cx" style="display: block; padding: 0 10px"> 'relation' => 'AND',
</span><span class="cx" style="display: block; padding: 0 10px"> array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'key' => '_user_email',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'key' => '_wp_user_request_user_email',
</ins><span class="cx" style="display: block; padding: 0 10px"> 'value' => isset( $_REQUEST['s'] ) ? sanitize_text_field( $_REQUEST['s'] ): '',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'compare' => 'LIKE'
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'compare' => 'LIKE',
</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><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $privacy_requests_query = new WP_Query( $args );
- $privacy_requests = $privacy_requests_query->posts;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $requests_query = new WP_Query( $args );
+ $requests = $requests_query->posts;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- foreach ( $privacy_requests as $privacy_request ) {
- $this->items[] = array(
- 'request_id' => $privacy_request->ID,
- 'user_id' => $privacy_request->post_author,
- 'email' => get_post_meta( $privacy_request->ID, '_user_email', true ),
- 'action' => get_post_meta( $privacy_request->ID, '_action_name', true ),
- 'requested' => strtotime( $privacy_request->post_date_gmt ),
- 'confirmed' => get_post_meta( $privacy_request->ID, '_confirmed_timestamp', true ),
- 'completed' => get_post_meta( $privacy_request->ID, '_completed_timestamp', true ),
- );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( $requests as $request ) {
+ $this->items[] = wp_get_user_request_data( $request->ID );
</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"> $this->set_pagination_args(
</span><span class="cx" style="display: block; padding: 0 10px"> array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'total_items' => $privacy_requests_query->found_posts,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'total_items' => $requests_query->found_posts,
</ins><span class="cx" style="display: block; padding: 0 10px"> 'per_page' => $posts_per_page,
</span><span class="cx" style="display: block; padding: 0 10px"> )
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1187,10 +1153,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> switch ( $status ) {
</span><span class="cx" style="display: block; padding: 0 10px"> case 'request-confirmed':
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $timestamp = $item['confirmed'];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $timestamp = $item['confirmed_timestamp'];
</ins><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> case 'request-completed':
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $timestamp = $item['completed'];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $timestamp = $item['completed_timestamp'];
</ins><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1238,7 +1204,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public function column_default( $item, $column_name ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $cell_value = $item[ $column_name ];
</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 ( in_array( $column_name, array( 'requested' ), true ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( in_array( $column_name, array( 'requested_timestamp' ), true ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return $this->get_timestamp_as_date( $cell_value );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1311,7 +1277,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @var string $post_type The post type.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- protected $post_type = 'user_export_request';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected $post_type = 'user_request';
</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"> * Actions column.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1396,7 +1362,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @var string $post_type The post type.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- protected $post_type = 'user_remove_request';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ protected $post_type = 'user_request';
</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"> * Actions column.
</span></span></pre></div>
<a id="branches49srcwpincludesdefaultfiltersphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/4.9/src/wp-includes/default-filters.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/4.9/src/wp-includes/default-filters.php 2018-05-02 00:48:23 UTC (rev 43082)
+++ branches/4.9/src/wp-includes/default-filters.php 2018-05-02 01:00:46 UTC (rev 43083)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -301,8 +301,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'do_pings', 'do_all_pings', 10, 1 );
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'do_robots', 'do_robots' );
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'set_comment_cookies', 'wp_set_comment_cookies', 10, 2 );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-add_filter( 'wp_privacy_personal_data_exporters', 'wp_register_comment_personal_data_exporter', 10 );
-add_filter( 'wp_privacy_personal_data_erasers', 'wp_register_comment_personal_data_eraser', 10 );
</del><span class="cx" style="display: block; padding: 0 10px"> add_action( 'sanitize_comment_cookies', 'sanitize_comment_cookies' );
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'admin_print_scripts', 'print_emoji_detection_script' );
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'admin_print_scripts', 'print_head_scripts', 20 );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -322,6 +320,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'admin_init', 'send_frame_options_header', 10, 0 );
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'welcome_panel', 'wp_welcome_panel' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+// Privacy
+add_action( 'user_request_action_confirmed', '_wp_privacy_account_request_confirmed' );
+add_filter( 'user_request_action_confirmed_message', '_wp_privacy_account_request_confirmed_message', 10, 2 );
+add_filter( 'wp_privacy_personal_data_exporters', 'wp_register_comment_personal_data_exporter' );
+add_filter( 'wp_privacy_personal_data_erasers', 'wp_register_comment_personal_data_eraser' );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Cron tasks
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'wp_scheduled_delete', 'wp_scheduled_delete' );
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'wp_scheduled_auto_draft_delete', 'wp_delete_auto_drafts' );
</span></span></pre></div>
<a id="branches49srcwpincludespostphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/4.9/src/wp-includes/post.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/4.9/src/wp-includes/post.php 2018-05-02 00:48:23 UTC (rev 43082)
+++ branches/4.9/src/wp-includes/post.php 2018-05-02 01:00:46 UTC (rev 43083)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -210,10 +210,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'supports' => array(),
</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">- register_post_type( 'user_export_request', array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ register_post_type( 'user_request', array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'labels' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'name' => __( 'Export Personal Data Requests' ),
- 'singular_name' => __( 'Export Personal Data Request' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'name' => __( 'User Requests' ),
+ 'singular_name' => __( 'User Request' ),
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'public' => false,
</span><span class="cx" style="display: block; padding: 0 10px"> '_builtin' => true, /* internal use only. don't use this when registering your own post type. */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -222,22 +222,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'query_var' => false,
</span><span class="cx" style="display: block; padding: 0 10px"> 'can_export' => false,
</span><span class="cx" style="display: block; padding: 0 10px"> 'delete_with_user' => false,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'supports' => array(),
</ins><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">- register_post_type( 'user_remove_request', array(
- 'labels' => array(
- 'name' => __( 'Remove Personal Data Requests' ),
- 'singular_name' => __( 'Remove Personal Data Request' ),
- ),
- 'public' => false,
- '_builtin' => true, /* internal use only. don't use this when registering your own post type. */
- 'hierarchical' => false,
- 'rewrite' => false,
- 'query_var' => false,
- 'can_export' => false,
- 'delete_with_user' => false,
- ) );
-
</del><span class="cx" style="display: block; padding: 0 10px"> register_post_status( 'publish', array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'label' => _x( 'Published', 'post status' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'public' => true,
</span></span></pre></div>
<a id="branches49srcwpincludesuserphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/4.9/src/wp-includes/user.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/4.9/src/wp-includes/user.php 2018-05-02 00:48:23 UTC (rev 43082)
+++ branches/4.9/src/wp-includes/user.php 2018-05-02 01:00:46 UTC (rev 43083)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2735,7 +2735,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Get all user privacy request types.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 5.0.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.9.6
</ins><span class="cx" style="display: block; padding: 0 10px"> * @access private
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2742,8 +2742,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function _wp_privacy_action_request_types() {
</span><span class="cx" style="display: block; padding: 0 10px"> return array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'user_export_request',
- 'user_remove_request',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'export_personal_data',
+ 'remove_personal_data',
</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><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2750,115 +2750,185 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Update log when privacy request is confirmed.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 5.0.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.9.6
</ins><span class="cx" style="display: block; padding: 0 10px"> * @access private
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array $result Result of the request from the user.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param int $request_id ID of the request.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function _wp_privacy_account_request_confirmed( $result ) {
- if ( isset( $result['action'], $result['request_data'], $result['request_data']['privacy_request_id'] ) && in_array( $result['action'], _wp_privacy_action_request_types(), true ) ) {
- $privacy_request_id = absint( $result['request_data']['privacy_request_id'] );
- $privacy_request = get_post( $privacy_request_id );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function _wp_privacy_account_request_confirmed( $request_id ) {
+ $request_data = wp_get_user_request_data( $request_id );
</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 ( ! $privacy_request || ! in_array( $privacy_request->post_type, _wp_privacy_action_request_types(), true ) ) {
- return;
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $request_data ) {
+ return;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- update_post_meta( $privacy_request_id, '_confirmed_timestamp', time() );
- wp_update_post( array(
- 'ID' => $privacy_request_id,
- 'post_status' => 'request-confirmed',
- ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! in_array( $request_data['status'], array( 'request-pending', 'request-failed' ), true ) ) {
+ return;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ update_post_meta( $request_id, '_wp_user_request_confirmed_timestamp', time() );
+ wp_update_post( array(
+ 'ID' => $request_data['request_id'],
+ 'post_status' => 'request-confirmed',
+ ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-add_action( 'account_action_confirmed', '_wp_privacy_account_request_confirmed' );
</del><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">- * Update log when privacy request fails.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Return request confirmation message HTML.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 5.0.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.9.6
</ins><span class="cx" style="display: block; padding: 0 10px"> * @access private
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array $result Result of the request from the user.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return string $message The confirmation message.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function _wp_privacy_account_request_failed( $result ) {
- if ( isset( $result['action'], $result['request_data'], $result['request_data']['privacy_request_id'] ) &&
- in_array( $result['action'], _wp_privacy_action_request_types(), true ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function _wp_privacy_account_request_confirmed_message( $message, $request_id ) {
+ $request = wp_get_user_request_data( $request_id );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $privacy_request_id = absint( $result['request_data']['privacy_request_id'] );
- $privacy_request = get_post( $privacy_request_id );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $request && in_array( $request['action'], _wp_privacy_action_request_types(), true ) ) {
+ $message = '<p class="message">' . __( 'Action has been confirmed.' ) . '</p>';
+ $message .= __( 'The site administrator has been notified and will fulfill your request as soon as possible.' );
+ }
</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 ( ! $privacy_request || ! in_array( $privacy_request->post_type, _wp_privacy_action_request_types(), true ) ) {
- return;
- }
-
- wp_update_post( array(
- 'ID' => $privacy_request_id,
- 'post_status' => 'request-failed',
- ) );
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $message;
</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">- * Send a confirmation request email to confirm an action.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Create and log a user request to perform a specific action.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 5.0.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Requests are stored inside a post type named `user_request` since they can apply to both
+ * users on the site, or guests without a user account.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $email User email address. This can be the address of a registered or non-registered user. Defaults to logged in user email address.
- * @param string $action_name Name of the action that is being confirmed. Defaults to 'confirm_email'.
- * @param string $action_description User facing description of the action they will be confirming. Defaults to "confirm your email address".
- * @param array $request_data Misc data you want to send with the verification request and pass to the actions once the request is confirmed.
- * @return WP_Error|bool Will return true/false based on the success of sending the email, or a WP_Error object.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.9.6
+ *
+ * @param string $email_address User email address. This can be the address of a registered or non-registered user.
+ * @param string $action_name Name of the action that is being confirmed. Required.
+ * @param array $request_data Misc data you want to send with the verification request and pass to the actions once the request is confirmed.
+ * @return int|WP_Error Returns the request ID if successful, or a WP_Error object on failure.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function wp_send_account_verification_key( $email = '', $action_name = '', $action_description = '', $request_data = array() ) {
- if ( ! function_exists( 'wp_get_current_user' ) ) {
- return new WP_Error( 'invalid', __( 'This function cannot be used before init.' ) );
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function wp_create_user_request( $email_address = '', $action_name = '', $request_data = array() ) {
+ $email_address = sanitize_email( $email_address );
+ $action_name = sanitize_key( $action_name );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $action_name = sanitize_key( $action_name );
- $action_description = wp_kses_post( $action_description );
-
- if ( empty( $action_name ) ) {
- $action_name = 'confirm_email';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! is_email( $email_address ) ) {
+ return new WP_Error( 'invalid_email', __( 'Invalid email address' ) );
</ins><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 ( empty( $action_description ) ) {
- $action_description = __( 'Confirm your email address.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $action_name ) {
+ return new WP_Error( 'invalid_action', __( 'Invalid action name' ) );
</ins><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 ( empty( $email ) ) {
- $user = wp_get_current_user();
- $email = $user->ID ? $user->user_email : '';
- } else {
- $user = false;
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $user = get_user_by( 'email', $email_address );
+ $user_id = $user && ! is_wp_error( $user ) ? $user->ID: 0;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $email = sanitize_email( $email );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Check for duplicates.
+ $requests_query = new WP_Query( array(
+ 'post_type' => 'user_request',
+ 'title' => $action_name,
+ 'post_status' => 'any',
+ 'fields' => 'ids',
+ 'meta_query' => array(
+ array(
+ 'key' => '_wp_user_request_user_email',
+ 'value' => $email_address,
+ ),
+ ),
+ ) );
</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 ( ! is_email( $email ) ) {
- return new WP_Error( 'invalid_email', __( 'Invalid email address' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $requests_query->found_posts ) {
+ return new WP_Error( 'duplicate_request', __( 'A request for this email address already exists.' ) );
</ins><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 ( ! $user ) {
- $user = get_user_by( 'email', $email );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $request_id = wp_insert_post( array(
+ 'post_author' => $user_id,
+ 'post_title' => $action_name,
+ 'post_content' => wp_json_encode( $request_data ),
+ 'post_status' => 'request-pending',
+ 'post_type' => 'user_request',
+ 'post_date' => current_time( 'mysql', false ),
+ 'post_date_gmt' => current_time( 'mysql', true ),
+ ), true );
+
+ if ( is_wp_error( $request_id ) ) {
+ return $request_id;
</ins><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">- $confirm_key = wp_get_account_verification_key( $email, $action_name, $request_data );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ update_post_meta( $request_id, '_wp_user_request_user_email', $email_address );
+ update_post_meta( $request_id, '_wp_user_request_confirmed_timestamp', false );
</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 ( is_wp_error( $confirm_key ) ) {
- return $confirm_key;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $request_id;
+}
+
+/**
+ * Get action description from the name and return a string.
+ *
+ * @since 4.9.6
+ *
+ * @param string $action_name Action name of the request.
+ * @return string
+ */
+function wp_user_request_action_description( $action_name ) {
+ switch ( $action_name ) {
+ case 'export_personal_data':
+ $description = __( 'Export Personal Data' );
+ break;
+ case 'remove_personal_data':
+ $description = __( 'Remove Personal Data' );
+ break;
+ default:
+ /* translators: %s: action name */
+ $description = sprintf( __( 'Confirm the "%s" action' ), $action_name );
+ break;
</ins><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">- // We could be dealing with a registered user account, or a visitor.
- $is_registered_user = $user && ! is_wp_error( $user );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Filters the user action description.
+ *
+ * @param string $description The default description.
+ * @param string $action_name The name of the request.
+ */
+ return apply_filters( 'user_request_action_description', $description, $action_name );
+}
</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 ( $is_registered_user ) {
- $uid = $user->ID;
- } else {
- // Generate a UID for this email address so we don't send the actual email in the query string. Hash is not supported on all systems.
- $uid = function_exists( 'hash' ) ? hash( 'sha256', $email ) : sha1( $email );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/**
+ * Send a confirmation request email to confirm an action.
+ *
+ * If the request is not already pending, it will be updated.
+ *
+ * @since 4.9.6
+ *
+ * @param string $request_id ID of the request created via wp_create_user_request().
+ * @return WP_Error|bool Will return true/false based on the success of sending the email, or a WP_Error object.
+ */
+function wp_send_user_request( $request_id ) {
+ $request_id = absint( $request_id );
+ $request = get_post( $request_id );
+
+ if ( ! $request || 'user_request' !== $request->post_type ) {
+ return new WP_Error( 'user_request_error', __( 'Invalid request.' ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( 'request-pending' !== $request->post_status ) {
+ wp_update_post( array(
+ 'ID' => $request_id,
+ 'post_status' => 'request-pending',
+ 'post_date' => current_time( 'mysql', false ),
+ 'post_date_gmt' => current_time( 'mysql', true ),
+ ) );
+ }
+
+ $email_data = array(
+ 'action_name' => $request->post_title,
+ 'email' => get_post_meta( $request->ID, '_wp_user_request_user_email', true ),
+ 'description' => wp_user_request_action_description( $request->post_title ),
+ 'confirm_url' => add_query_arg( array(
+ 'action' => 'confirmaction',
+ 'request_id' => $request_id,
+ 'confirm_key' => wp_generate_user_request_key( $request_id ),
+ ), site_url( 'wp-login.php' ) ),
+ 'sitename' => is_multisite() ? get_site_option( 'site_name' ) : get_option( 'blogname' ),
+ 'siteurl' => network_home_url(),
+ );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /* translators: Do not translate DESCRIPTION, CONFIRM_URL, EMAIL, SITENAME, SITEURL: those are placeholders. */
</span><span class="cx" style="display: block; padding: 0 10px"> $email_text = __(
</span><span class="cx" style="display: block; padding: 0 10px"> 'Howdy,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2880,20 +2950,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ###SITEURL###'
</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">- $email_data = array(
- 'action_name' => $action_name,
- 'email' => $email,
- 'description' => $action_description,
- 'confirm_url' => add_query_arg( array(
- 'action' => 'verifyaccount',
- 'confirm_action' => $action_name,
- 'uid' => $uid,
- 'confirm_key' => $confirm_key,
- ), site_url( 'wp-login.php' ) ),
- 'sitename' => is_multisite() ? get_site_option( 'site_name' ) : get_option( 'blogname' ),
- 'siteurl' => network_home_url(),
- );
-
</del><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Filters the text of the email sent when an account action is attempted.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2905,7 +2961,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * ###SITENAME### The name of the site.
</span><span class="cx" style="display: block; padding: 0 10px"> * ###SITEURL### The URL to the site.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 5.0.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.9.6
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $email_text Text in the email.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $email_data {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2919,7 +2975,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string $siteurl The site URL sending the mail.
</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">- $content = apply_filters( 'account_verification_email_content', $email_text, $email_data );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $content = apply_filters( 'user_request_action_email_content', $email_text, $email_data );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $content = str_replace( '###DESCRIPTION###', $email_data['description'], $content );
</span><span class="cx" style="display: block; padding: 0 10px"> $content = str_replace( '###CONFIRM_URL###', esc_url_raw( $email_data['confirm_url'] ), $content );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2932,124 +2988,71 @@
</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">- * Creates, stores, then returns a confirmation key for an account action.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Returns a confirmation key for a user action and stores the hashed version.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 5.0.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.9.6
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $email User email address. This can be the address of a registered or non-registered user.
- * @param string $action_name Name of the action this key is being generated for.
- * @param array $request_data Misc data you want to send with the verification request and pass to the actions once the request is confirmed.
- * @return string|WP_Error Confirmation key on success. WP_Error on error.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param int $request_id Request ID.
+ * @return string Confirmation key.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function wp_get_account_verification_key( $email, $action_name, $request_data = array() ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function wp_generate_user_request_key( $request_id ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> global $wp_hasher;
</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_email( $email ) ) {
- return new WP_Error( 'invalid_email', __( 'Invalid email address' ) );
- }
-
- if ( empty( $action_name ) ) {
- return new WP_Error( 'invalid_action', __( 'Invalid action' ) );
- }
-
- $user = get_user_by( 'email', $email );
-
- // We could be dealing with a registered user account, or a visitor.
- $is_registered_user = $user && ! is_wp_error( $user );
-
</del><span class="cx" style="display: block; padding: 0 10px"> // Generate something random for a confirmation key.
</span><span class="cx" style="display: block; padding: 0 10px"> $key = wp_generate_password( 20, false );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Now insert the key, hashed, into the DB.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Return the key, hashed.
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $wp_hasher ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> require_once ABSPATH . WPINC . '/class-phpass.php';
</span><span class="cx" style="display: block; padding: 0 10px"> $wp_hasher = new PasswordHash( 8, true );
</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">- $hashed_key = $wp_hasher->HashPassword( $key );
- $value = array(
- 'action' => $action_name,
- 'time' => time(),
- 'hash' => $hashed_key,
- 'email' => $email,
- 'request_data' => $request_data,
- );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ update_post_meta( $request_id, '_wp_user_request_confirm_key', $wp_hasher->HashPassword( $key ) );
+ update_post_meta( $request_id, '_wp_user_request_confirm_key_timestamp', time() );
</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 ( $is_registered_user ) {
- $key_saved = (bool) update_user_meta( $user->ID, '_verify_action_' . $action_name, wp_json_encode( $value ) );
- } else {
- $uid = function_exists( 'hash' ) ? hash( 'sha256', $email ) : sha1( $email );
- $key_saved = (bool) update_site_option( '_verify_action_' . $action_name . '_' . $uid, wp_json_encode( $value ) );
- }
-
- if ( false === $key_saved ) {
- return new WP_Error( 'no_account_verification_key_update', __( 'Could not save confirm account action key to database.' ) );
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> return $key;
</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">- * Checks if a key is valid and handles the action based on this.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Valdate a user request by comparing the key with the request's key.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 5.0.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.9.6
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $key Key to confirm.
- * @param string $uid Email hash or user ID.
- * @param string $action_name Name of the action this key is being generated for.
- * @return array|WP_Error WP_Error on failure, action name and user email address on success.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $request_id ID of the request being confirmed.
+ * @param string $key Provided key to validate.
+ * @return bool|WP_Error WP_Error on failure, true on success.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function wp_check_account_verification_key( $key, $uid, $action_name ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function wp_validate_user_request_key( $request_id, $key ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> global $wp_hasher;
</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( $action_name ) || empty( $key ) || empty( $uid ) ) {
- return new WP_Error( 'invalid_key', __( 'Invalid key' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $request_id = absint( $request_id );
+ $request = wp_get_user_request_data( $request_id );
+
+ if ( ! $request ) {
+ return new WP_Error( 'user_request_error', __( 'Invalid request.' ) );
</ins><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">- $user = false;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! in_array( $request['status'], array( 'request-pending', 'request-failed' ), true ) ) {
+ return __( 'This link has expired.' );
+ }
</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 ( is_numeric( $uid ) ) {
- $user = get_user_by( 'id', absint( $uid ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( empty( $key ) ) {
+ return new WP_Error( 'invalid_key', __( 'Invalid key' ) );
</ins><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">- // We could be dealing with a registered user account, or a visitor.
- $is_registered_user = ( $user && ! is_wp_error( $user ) );
- $key_request_time = '';
- $saved_key = '';
- $email = '';
-
</del><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $wp_hasher ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> require_once ABSPATH . WPINC . '/class-phpass.php';
</span><span class="cx" style="display: block; padding: 0 10px"> $wp_hasher = new PasswordHash( 8, true );
</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">- // Get the saved key from the database.
- if ( $is_registered_user ) {
- $raw_data = get_user_meta( $user->ID, '_verify_action_' . $action_name, true );
- $email = $user->user_email;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $key_request_time = $request['confirm_key_timestamp'];
+ $saved_key = $request['confirm_key'];
</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 ( false !== strpos( $raw_data, ':' ) ) {
- list( $key_request_time, $saved_key ) = explode( ':', $raw_data, 2 );
- }
- } else {
- $raw_data = get_site_option( '_verify_action_' . $action_name . '_' . $uid, '' );
-
- if ( false !== strpos( $raw_data, ':' ) ) {
- list( $key_request_time, $saved_key, $email ) = explode( ':', $raw_data, 3 );
- }
- }
-
- $data = json_decode( $raw_data, true );
- $key_request_time = (int) isset( $data['time'] ) ? $data['time'] : 0;
- $saved_key = isset( $data['hash'] ) ? $data['hash'] : '';
- $email = sanitize_email( isset( $data['email'] ) ? $data['email'] : '' );
- $request_data = isset( $data['request_data'] ) ? $data['request_data'] : array();
-
</del><span class="cx" style="display: block; padding: 0 10px"> if ( ! $saved_key ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'invalid_key', __( 'Invalid key' ) );
</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 ( ! $key_request_time || ! $email ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $key_request_time ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'invalid_key', __( 'Invalid action' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3056,11 +3059,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Filters the expiration time of confirm keys.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 5.0.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.9.6
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param int $expiration The expiration time in seconds.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $expiration_duration = apply_filters( 'account_verification_expiration', DAY_IN_SECONDS );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $expiration_duration = (int) apply_filters( 'user_request_key_expiration', DAY_IN_SECONDS );
</ins><span class="cx" style="display: block; padding: 0 10px"> $expiration_time = $key_request_time + $expiration_duration;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! $wp_hasher->CheckPassword( $key, $saved_key ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3067,22 +3070,40 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'invalid_key', __( 'Invalid key' ) );
</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 ( $expiration_time && time() < $expiration_time ) {
- $return = array(
- 'action' => $action_name,
- 'email' => $email,
- 'request_data' => $request_data,
- );
- } else {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! $expiration_time || time() > $expiration_time ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $return = new WP_Error( 'expired_key', __( 'The confirmation email has expired.' ) );
</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">- // Clean up stored keys.
- if ( $is_registered_user ) {
- delete_user_meta( $user->ID, '_verify_action_' . $action_name );
- } else {
- delete_site_option( '_verify_action_' . $action_name . '_' . $uid );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return true;
+}
+
+/**
+ * Return data about a user request.
+ *
+ * @since 4.9.6
+ *
+ * @param int $request_id Request ID to get data about.
+ * @return array|false
+ */
+function wp_get_user_request_data( $request_id ) {
+ $request_id = absint( $request_id );
+ $request = get_post( $request_id );
+
+ if ( ! $request || 'user_request' !== $request->post_type ) {
+ return false;
</ins><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">- return $return;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return array(
+ 'request_id' => $request->ID,
+ 'user_id' => $request->post_author,
+ 'email' => get_post_meta( $request->ID, '_wp_user_request_user_email', true ),
+ 'action' => $request->post_title,
+ 'requested_timestamp' => strtotime( $request->post_date_gmt ),
+ 'confirmed_timestamp' => get_post_meta( $request->ID, '_wp_user_request_confirmed_timestamp', true ),
+ 'completed_timestamp' => get_post_meta( $request->ID, '_wp_user_request_completed_timestamp', true ),
+ 'request_data' => json_decode( $request->post_content, true ),
+ 'status' => $request->post_status,
+ 'confirm_key' => get_post_meta( $request_id, '_wp_user_request_confirm_key', true ),
+ 'confirm_key_timestamp' => get_post_meta( $request_id, '_wp_user_request_confirm_key_timestamp', true ),
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="branches49srcwploginphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/4.9/src/wp-login.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/4.9/src/wp-login.php 2018-05-02 00:48:23 UTC (rev 43082)
+++ branches/4.9/src/wp-login.php 2018-05-02 01:00:46 UTC (rev 43083)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -413,7 +413,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $action = 'resetpass';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // validate action so as to default to the login screen
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-if ( !in_array( $action, array( 'postpass', 'logout', 'lostpassword', 'retrievepassword', 'resetpass', 'rp', 'register', 'login', 'verifyaccount' ), true ) && false === has_filter( 'login_form_' . $action ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+if ( !in_array( $action, array( 'postpass', 'logout', 'lostpassword', 'retrievepassword', 'resetpass', 'rp', 'register', 'login', 'confirmaction' ), true ) && false === has_filter( 'login_form_' . $action ) )
</ins><span class="cx" style="display: block; padding: 0 10px"> $action = 'login';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> nocache_headers();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -838,26 +838,21 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-case 'verifyaccount' :
- if ( isset( $_GET['confirm_action'], $_GET['confirm_key'], $_GET['uid'] ) ) {
- $key = sanitize_text_field( wp_unslash( $_GET['confirm_key'] ) );
- $uid = sanitize_text_field( wp_unslash( $_GET['uid'] ) );
- $action_name = sanitize_key( wp_unslash( $_GET['confirm_action'] ) );
- $result = wp_check_account_verification_key( $key, $uid, $action_name );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+case 'confirmaction' :
+ if ( ! isset( $_GET['request_id'] ) ) {
+ wp_die( __( 'Invalid request' ) );
+ }
+
+ $request_id = (int) $_GET['request_id'];
+
+ if ( isset( $_GET['confirm_key'] ) ) {
+ $key = sanitize_text_field( wp_unslash( $_GET['confirm_key'] ) );
+ $result = wp_validate_user_request_key( $request_id, $key );
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> $result = new WP_Error( 'invalid_key', __( 'Invalid key' ) );
</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"> if ( is_wp_error( $result ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /**
- * Fires an action hook when the account action was not confirmed.
- *
- * After running this action hook the page will die.
- *
- * @param WP_Error $result Error object.
- */
- do_action( 'account_action_failed', $result );
-
</del><span class="cx" style="display: block; padding: 0 10px"> wp_die( $result );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -867,20 +862,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Using this you can assume the user has agreed to perform the action by
</span><span class="cx" style="display: block; padding: 0 10px"> * clicking on the link in the confirmation email.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * After firing this action hook the page will redirect to wp-login a callback
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * After firing this action hook the page will redirect to wp-login a callback
</ins><span class="cx" style="display: block; padding: 0 10px"> * redirects or exits first.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- *
- * @param array $result {
- * Data about the action which was confirmed.
</del><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @type string $action Name of the action that was confirmed.
- * @type string $email Email of the user who confirmed the action.
- * }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param int $request_id Request ID.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- do_action( 'account_action_confirmed', $result );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ do_action( 'user_request_action_confirmed', $request_id );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $message = '<p class="message">' . __( 'Action has been confirmed.' ) . '</p>';
- login_header( '', $message );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $message = apply_filters( 'user_request_action_confirmed_message', '<p class="message">' . __( 'Action has been confirmed.' ) . '</p>', $request_id );
+
+ login_header( __( 'User action confirmed.' ), $message );
</ins><span class="cx" style="display: block; padding: 0 10px"> login_footer();
</span><span class="cx" style="display: block; padding: 0 10px"> exit;
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre>
</div>
</div>
</body>
</html>