Changeset 50230
- Timestamp:
- 02/05/2021 03:48:59 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/privacy-tools.php
r50165 r50230 112 112 $username_or_email_address = sanitize_text_field( wp_unslash( $_POST['username_or_email_for_privacy_request'] ) ); 113 113 $email_address = ''; 114 $s end_confirmation_email = true;114 $status = 'pending'; 115 115 116 116 if ( ! isset( $_POST['send_confirmation_email'] ) ) { 117 $s end_confirmation_email = false;117 $status = 'confirmed'; 118 118 } 119 119 … … 147 147 } 148 148 149 $request_id = wp_create_user_request( $email_address, $action_type, array(), $send_confirmation_email ); 149 $request_id = wp_create_user_request( $email_address, $action_type, array(), $status ); 150 $message = ''; 150 151 151 152 if ( is_wp_error( $request_id ) ) { 153 $message = $request_id->get_error_message(); 154 } elseif ( ! $request_id ) { 155 $message = __( 'Unable to initiate confirmation request.' ); 156 } 157 158 if ( $message ) { 152 159 add_settings_error( 153 160 'username_or_email_for_privacy_request', 154 161 'username_or_email_for_privacy_request', 155 $request_id->get_error_message(), 156 'error' 157 ); 158 break; 159 } elseif ( ! $request_id ) { 160 add_settings_error( 161 'username_or_email_for_privacy_request', 162 'username_or_email_for_privacy_request', 163 __( 'Unable to initiate confirmation request.' ), 162 $message, 164 163 'error' 165 164 ); … … 167 166 } 168 167 169 if ( $send_confirmation_email) {168 if ( 'pending' === $status ) { 170 169 wp_send_user_request( $request_id ); 170 171 $message = __( 'Confirmation request initiated successfully.' ); 172 } elseif ( 'confirmed' === $status ) { 173 $message = __( 'Request added successfully.' ); 171 174 } 172 175 173 add_settings_error( 174 'username_or_email_for_privacy_request', 175 'username_or_email_for_privacy_request', 176 __( 'Confirmation request initiated successfully.' ), 177 'success' 178 ); 179 break; 176 if ( $message ) { 177 add_settings_error( 178 'username_or_email_for_privacy_request', 179 'username_or_email_for_privacy_request', 180 $message, 181 'success' 182 ); 183 break; 184 } 180 185 } 181 186 } -
trunk/src/wp-includes/user.php
r50165 r50230 3937 3937 * 3938 3938 * @since 4.9.6 3939 * @since 5.7.0 Added the `$s end_confirmation_email` parameter.3939 * @since 5.7.0 Added the `$status` parameter. 3940 3940 * 3941 3941 * @param string $email_address User email address. This can be the address of a registered … … 3944 3944 * @param array $request_data Misc data you want to send with the verification request and pass 3945 3945 * to the actions once the request is confirmed. 3946 * @param bool $send_confirmation_email Optional. If false, the request status is set to 'Completed' directly. 3947 * Default true. 3946 * @param string $status Optional request status (pending or confirmed). Default 'pending'. 3948 3947 * @return int|WP_Error Returns the request ID if successful, or a WP_Error object on failure. 3949 3948 */ 3950 function wp_create_user_request( $email_address = '', $action_name = '', $request_data = array(), $s end_confirmation_email = true) {3949 function wp_create_user_request( $email_address = '', $action_name = '', $request_data = array(), $status = 'pending' ) { 3951 3950 $email_address = sanitize_email( $email_address ); 3952 3951 $action_name = sanitize_key( $action_name ); … … 3958 3957 if ( ! in_array( $action_name, _wp_privacy_action_request_types(), true ) ) { 3959 3958 return new WP_Error( 'invalid_action', __( 'Invalid action name.' ) ); 3959 } 3960 3961 if ( ! in_array( $status, array( 'pending', 'confirmed' ), true ) ) { 3962 return new WP_Error( 'invalid_status', __( 'Invalid request status.' ) ); 3960 3963 } 3961 3964 … … 3981 3984 } 3982 3985 3983 if ( false !== $send_confirmation_email ) {3984 $status = 'request-pending';3985 } else {3986 $status = 'request-completed';3987 }3988 3989 3986 $request_id = wp_insert_post( 3990 3987 array( … … 3993 3990 'post_title' => $email_address, 3994 3991 'post_content' => wp_json_encode( $request_data ), 3995 'post_status' => $status,3992 'post_status' => 'request-' . $status, 3996 3993 'post_type' => 'user_request', 3997 3994 'post_date' => current_time( 'mysql', false ), -
trunk/tests/phpunit/tests/privacy/wpCreateUserRequest.php
r50160 r50230 311 311 312 312 /** 313 * Test that the request has a Pending status if a confirmation email is sent.313 * Test that the request has a Pending status by default. 314 314 * 315 315 * @ticket 43890 316 316 */ 317 public function test_ pending_status_with_default_wp_create_user_request_params() {317 public function test_wp_create_user_request_default_pending_status() { 318 318 $actual = wp_create_user_request( self::$non_registered_user_email, 'export_personal_data' ); 319 319 $post = get_post( $actual ); … … 323 323 324 324 /** 325 * Test that the request has a Pending status if the $s end_confirmation_email param is true.325 * Test that the request has a Pending status if the $status param is 'pending'. 326 326 * 327 327 * @ticket 43890 328 328 */ 329 public function test_pending_status_with_true_send_confirmation_email() { 330 $request_data = array(); 331 $send_confirmation_email = true; 332 333 $actual = wp_create_user_request( self::$non_registered_user_email, 'export_personal_data', $request_data, $send_confirmation_email ); 329 public function test_wp_create_user_request_pending_status() { 330 $actual = wp_create_user_request( self::$non_registered_user_email, 'export_personal_data', array(), 'pending' ); 334 331 $post = get_post( $actual ); 335 332 … … 338 335 339 336 /** 340 * Test that the request has a Co mpleted status if the $send_confirmation_email param is false.337 * Test that the request has a Confirmed status if the $status param is 'confirmed'. 341 338 * 342 339 * @ticket 43890 343 340 */ 344 public function test_pending_status_with_false_send_confirmation_email() { 345 $request_data = array(); 346 $send_confirmation_email = false; 347 348 $actual = wp_create_user_request( self::$non_registered_user_email, 'export_personal_data', $request_data, $send_confirmation_email ); 341 public function test_wp_create_user_request_confirmed_status() { 342 $actual = wp_create_user_request( self::$non_registered_user_email, 'export_personal_data', array(), 'confirmed' ); 349 343 $post = get_post( $actual ); 350 344 351 $this->assertSame( 'request-completed', $post->post_status ); 345 $this->assertSame( 'request-confirmed', $post->post_status ); 346 } 347 348 /** 349 * Test that the request returns a WP_Error if $status isn't 'pending' or 'confirmed'. 350 * 351 * @ticket 43890 352 */ 353 public function test_wp_create_user_request_wp_error_status() { 354 $actual = wp_create_user_request( self::$non_registered_user_email, 'export_personal_data', array(), 'wrong-status' ); 355 356 $this->assertWPError( $actual ); 352 357 } 353 358 }
Note: See TracChangeset
for help on using the changeset viewer.