<!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>[50230] trunk: Privacy: Rename the `$send_confirmation_email` parameter of `wp_create_user_request()` to `$status`, for clarity.</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/50230">50230</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/50230","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>2021-02-05 15:48:59 +0000 (Fri, 05 Feb 2021)</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: Rename the `$send_confirmation_email` parameter of `wp_create_user_request()` to `$status`, for clarity.
Follow-up to <a href="https://core.trac.wordpress.org/changeset/50159">[50159]</a>, <a href="https://core.trac.wordpress.org/changeset/50165">[50165]</a>.
Props xkon, TimothyBlynJacobs.
Fixes <a href="https://core.trac.wordpress.org/ticket/52430">#52430</a>. See <a href="https://core.trac.wordpress.org/ticket/43890">#43890</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminincludesprivacytoolsphp">trunk/src/wp-admin/includes/privacy-tools.php</a></li>
<li><a href="#trunksrcwpincludesuserphp">trunk/src/wp-includes/user.php</a></li>
<li><a href="#trunktestsphpunittestsprivacywpCreateUserRequestphp">trunk/tests/phpunit/tests/privacy/wpCreateUserRequest.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminincludesprivacytoolsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/privacy-tools.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/privacy-tools.php 2021-02-05 14:42:01 UTC (rev 50229)
+++ trunk/src/wp-admin/includes/privacy-tools.php 2021-02-05 15:48:59 UTC (rev 50230)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -111,10 +111,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $action_type = sanitize_text_field( wp_unslash( $_POST['type_of_action'] ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $username_or_email_address = sanitize_text_field( wp_unslash( $_POST['username_or_email_for_privacy_request'] ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $email_address = '';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $send_confirmation_email = true;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $status = 'pending';
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! isset( $_POST['send_confirmation_email'] ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $send_confirmation_email = false;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $status = 'confirmed';
</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"> if ( ! in_array( $action_type, _wp_privacy_action_request_types(), true ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -146,37 +146,42 @@
</span><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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $request_id = wp_create_user_request( $email_address, $action_type, array(), $send_confirmation_email );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $request_id = wp_create_user_request( $email_address, $action_type, array(), $status );
+ $message = '';
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( is_wp_error( $request_id ) ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $message = $request_id->get_error_message();
+ } elseif ( ! $request_id ) {
+ $message = __( 'Unable to initiate confirmation request.' );
+ }
+
+ if ( $message ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> add_settings_error(
</span><span class="cx" style="display: block; padding: 0 10px"> 'username_or_email_for_privacy_request',
</span><span class="cx" style="display: block; padding: 0 10px"> 'username_or_email_for_privacy_request',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $request_id->get_error_message(),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $message,
</ins><span class="cx" style="display: block; padding: 0 10px"> 'error'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> break;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } elseif ( ! $request_id ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
+
+ if ( 'pending' === $status ) {
+ wp_send_user_request( $request_id );
+
+ $message = __( 'Confirmation request initiated successfully.' );
+ } elseif ( 'confirmed' === $status ) {
+ $message = __( 'Request added successfully.' );
+ }
+
+ if ( $message ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> add_settings_error(
</span><span class="cx" style="display: block; padding: 0 10px"> 'username_or_email_for_privacy_request',
</span><span class="cx" style="display: block; padding: 0 10px"> 'username_or_email_for_privacy_request',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- __( 'Unable to initiate confirmation request.' ),
- 'error'
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $message,
+ 'success'
</ins><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">-
- if ( $send_confirmation_email ) {
- wp_send_user_request( $request_id );
- }
-
- add_settings_error(
- 'username_or_email_for_privacy_request',
- 'username_or_email_for_privacy_request',
- __( 'Confirmation request initiated successfully.' ),
- 'success'
- );
- break;
</del><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></pre></div>
<a id="trunksrcwpincludesuserphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/user.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/user.php 2021-02-05 14:42:01 UTC (rev 50229)
+++ trunk/src/wp-includes/user.php 2021-02-05 15:48:59 UTC (rev 50230)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3936,7 +3936,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * users on the site, or guests without a user account.
</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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 5.7.0 Added the `$send_confirmation_email` parameter.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 5.7.0 Added the `$status` parameter.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $email_address User email address. This can be the address of a registered
</span><span class="cx" style="display: block; padding: 0 10px"> * or non-registered user.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3943,11 +3943,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $action_name Name of the action that is being confirmed. Required.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $request_data Misc data you want to send with the verification request and pass
</span><span class="cx" style="display: block; padding: 0 10px"> * to the actions once the request is confirmed.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param bool $send_confirmation_email Optional. If false, the request status is set to 'Completed' directly.
- * Default true.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $status Optional request status (pending or confirmed). Default 'pending'.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return int|WP_Error Returns the request ID if successful, or a WP_Error object on failure.
</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_create_user_request( $email_address = '', $action_name = '', $request_data = array(), $send_confirmation_email = true ) {
</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(), $status = 'pending' ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $email_address = sanitize_email( $email_address );
</span><span class="cx" style="display: block; padding: 0 10px"> $action_name = sanitize_key( $action_name );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3959,6 +3958,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'invalid_action', __( 'Invalid action name.' ) );
</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">+ if ( ! in_array( $status, array( 'pending', 'confirmed' ), true ) ) {
+ return new WP_Error( 'invalid_status', __( 'Invalid request status.' ) );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $user = get_user_by( 'email', $email_address );
</span><span class="cx" style="display: block; padding: 0 10px"> $user_id = $user && ! is_wp_error( $user ) ? $user->ID : 0;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3980,12 +3983,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'duplicate_request', __( 'An incomplete personal data request for this email address already exists.' ) );
</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 ( false !== $send_confirmation_email ) {
- $status = 'request-pending';
- } else {
- $status = 'request-completed';
- }
-
</del><span class="cx" style="display: block; padding: 0 10px"> $request_id = wp_insert_post(
</span><span class="cx" style="display: block; padding: 0 10px"> array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'post_author' => $user_id,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3992,7 +3989,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'post_name' => $action_name,
</span><span class="cx" style="display: block; padding: 0 10px"> 'post_title' => $email_address,
</span><span class="cx" style="display: block; padding: 0 10px"> 'post_content' => wp_json_encode( $request_data ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'post_status' => $status,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'post_status' => 'request-' . $status,
</ins><span class="cx" style="display: block; padding: 0 10px"> 'post_type' => 'user_request',
</span><span class="cx" style="display: block; padding: 0 10px"> 'post_date' => current_time( 'mysql', false ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'post_date_gmt' => current_time( 'mysql', true ),
</span></span></pre></div>
<a id="trunktestsphpunittestsprivacywpCreateUserRequestphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/privacy/wpCreateUserRequest.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/privacy/wpCreateUserRequest.php 2021-02-05 14:42:01 UTC (rev 50229)
+++ trunk/tests/phpunit/tests/privacy/wpCreateUserRequest.php 2021-02-05 15:48:59 UTC (rev 50230)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -310,11 +310,11 @@
</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">- * Test that the request has a Pending status if a confirmation email is sent.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Test that the request has a Pending status by default.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 43890
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function test_pending_status_with_default_wp_create_user_request_params() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_wp_create_user_request_default_pending_status() {
</ins><span class="cx" style="display: block; padding: 0 10px"> $actual = wp_create_user_request( self::$non_registered_user_email, 'export_personal_data' );
</span><span class="cx" style="display: block; padding: 0 10px"> $post = get_post( $actual );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -322,15 +322,12 @@
</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">- * Test that the request has a Pending status if the $send_confirmation_email param is true.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Test that the request has a Pending status if the $status param is 'pending'.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 43890
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function test_pending_status_with_true_send_confirmation_email() {
- $request_data = array();
- $send_confirmation_email = true;
-
- $actual = wp_create_user_request( self::$non_registered_user_email, 'export_personal_data', $request_data, $send_confirmation_email );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_wp_create_user_request_pending_status() {
+ $actual = wp_create_user_request( self::$non_registered_user_email, 'export_personal_data', array(), 'pending' );
</ins><span class="cx" style="display: block; padding: 0 10px"> $post = get_post( $actual );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame( 'request-pending', $post->post_status );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -337,17 +334,25 @@
</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">- * Test that the request has a Completed status if the $send_confirmation_email param is false.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Test that the request has a Confirmed status if the $status param is 'confirmed'.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 43890
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function test_pending_status_with_false_send_confirmation_email() {
- $request_data = array();
- $send_confirmation_email = false;
-
- $actual = wp_create_user_request( self::$non_registered_user_email, 'export_personal_data', $request_data, $send_confirmation_email );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_wp_create_user_request_confirmed_status() {
+ $actual = wp_create_user_request( self::$non_registered_user_email, 'export_personal_data', array(), 'confirmed' );
</ins><span class="cx" style="display: block; padding: 0 10px"> $post = get_post( $actual );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertSame( 'request-completed', $post->post_status );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertSame( 'request-confirmed', $post->post_status );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * Test that the request returns a WP_Error if $status isn't 'pending' or 'confirmed'.
+ *
+ * @ticket 43890
+ */
+ public function test_wp_create_user_request_wp_error_status() {
+ $actual = wp_create_user_request( self::$non_registered_user_email, 'export_personal_data', array(), 'wrong-status' );
+
+ $this->assertWPError( $actual );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>
</body>
</html>