Changeset 7350 for sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-main/inc/privacy-functions.php
- Timestamp:
- 06/29/2018 08:57:02 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-main/inc/privacy-functions.php
r7251 r7350 2 2 /** 3 3 * Functions for the Privacy Tools - Exports and Erasures. 4 * 5 * @package WordPressdotorg\MainTheme 4 6 */ 7 8 // phpcs:disable WordPress.VIP.SuperGlobalInputUsage.AccessDetected, WordPress.VIP.ValidatedSanitizedInput 9 5 10 namespace WordPressdotorg\MainTheme; 11 6 12 use WordPressdotorg\GDPR\Main as GDPR_Main; 7 13 14 /** 15 * Processes privacy requests. 16 * 17 * @param string $type Type of request. 18 * 19 * @return array 20 */ 8 21 function privacy_process_request( $type ) { 9 $email = $error_message = $success = false; 10 $nonce_action = 'request_' . $type; 22 $email = false; 23 $error_message = false; 24 $success = false; 25 $nonce_action = 'request_' . $type; 11 26 12 if ( empty( $_POST['email'] ) || ! $type || ! in_array( $type, [ 'erase', 'export' ] ) ) {27 if ( empty( $_POST['email'] ) || ! $type || ! in_array( $type, [ 'erase', 'export' ], true ) ) { 13 28 return compact( 'email', 'error_message', 'success', 'nonce_action' ); 14 29 } 15 30 16 $email = trim( wp_unslash( $_POST['email'] ) ); 17 18 $requesting_user = false; 19 if ( is_user_logged_in() ) { 20 $requesting_user = wp_get_current_user()->user_login; 21 } 31 // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification 32 $email = trim( wp_unslash( $_POST['email'] ) ); 33 $requesting_user = is_user_logged_in() ? wp_get_current_user()->user_login : false; 34 $email_user = get_user_by( 'email', $email ); 22 35 23 36 // Currently only enabled for special accounts. 24 if ( 'export' === $type && ( ! is_user_logged_in() || ! wporg_user_has_restricted_password() ) ) {37 if ( 'export' === $type && ( ! is_user_logged_in() || ! function_exists( 'wporg_user_has_restricted_password' ) || ! wporg_user_has_restricted_password() ) ) { 25 38 $error_message = 'This form is currently unavailable.'; 26 } else 27 28 if ( ! reCAPTCHA\check_status() ) { 39 } elseif ( ! reCAPTCHA\check_status() ) { 29 40 $error_message = esc_html__( 'Your form session has expired. Please try again.', 'wporg' ); 30 41 } elseif ( 31 42 is_user_logged_in() && 32 ! wp_verify_nonce( $_POST['_wpnonce'], $nonce_action )43 ! wp_verify_nonce( wp_unslash( $_POST['_wpnonce'] ), $nonce_action ) 33 44 ) { 34 45 $error_message = esc_html__( 'Your form session has expired. Please try again.', 'wporg' ); 35 36 46 } elseif ( 37 47 // Check if a user account exists for this email before processing. 38 false != ( $email_user = get_user_by( 'email', $email ) ) && 39 $email_user->user_login !== $requesting_user 48 false !== $email_user && $email_user->user_login !== $requesting_user 40 49 ) { 41 50 if ( is_user_logged_in() ) { … … 52 61 ); 53 62 } 54 55 63 } else { 56 if ( 'export' == $type ) {64 if ( 'export' === $type ) { 57 65 $api_method = 'create-data-export-request'; 58 } elseif ( 'erase' == $type ) {66 } elseif ( 'erase' === $type ) { 59 67 $api_method = 'create-account-erasure-request'; 60 68 } … … 73 81 $error_message = $api_request->get_error_message(); 74 82 75 if ( 'duplicate_request' == $api_request->get_error_code() ) {83 if ( 'duplicate_request' === $api_request->get_error_code() ) { 76 84 // TODO This should never have to be displayed to an end user. See API for details. 77 85 $error_message = esc_html__( 'A request for this email address already exists. Please check your spam folder for your confirmation email.', 'wporg' ); 78 86 79 } elseif ( 'invalid_identifier' == $api_request->get_error_code() ) {87 } elseif ( 'invalid_identifier' === $api_request->get_error_code() ) { 80 88 $error_message = esc_html__( 'The provided email was invalid. Please check the address and try again.', 'wporg' ); 81 89 82 90 } 83 } elseif ( ! empty( $api_request['created'] ) ) {91 } elseif ( ! empty( $api_request['created'] ) ) { 84 92 $success = true; 85 93 }
Note: See TracChangeset
for help on using the changeset viewer.