Make WordPress Core

Changeset 63065


Ignore:
Timestamp:
08/06/2026 03:38:58 PM (2 months ago)
Author:
johnbillion
Message:

Users: Ensure a proper email address is used before sending email confirmations.

Props xknown, westonruter, jeremyfelt, peterwilsoncc, paulkevan, lucasbustamante, jorbin, desrosj.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/user.php

    r62688 r63065  
    4545        }
    4646
     47        $errors = new WP_Error();
     48
    4749        $pass1 = '';
    4850        $pass2 = '';
    … …  
    7981
    8082        if ( isset( $_POST['email'] ) ) {
    81                 $user->user_email = sanitize_text_field( wp_unslash( $_POST['email'] ) );
     83                $maybe_email = wp_unslash( $_POST['email'] );
     84                if ( is_string( $maybe_email ) && is_email( $maybe_email ) ) {
     85                        $user->user_email = $maybe_email;
     86                } else {
     87                        $errors->add( 'invalid_email', __( '<strong>Error:</strong> The email address is not correct.' ), array( 'form-field' => 'email' ) );
     88                }
    8289        }
    8390        if ( isset( $_POST['url'] ) ) {
    … …  
    146153                $user->use_ssl = 1;
    147154        }
    148 
    149         $errors = new WP_Error();
    150155
    151156        /* checking that username has been typed */
  • trunk/src/wp-includes/user.php

    r62654 r63065  
    38593859 * @since 3.0.0
    38603860 * @since 4.9.0 This function was moved from wp-admin/includes/ms.php so it's no longer Multisite specific.
     3861 * @since 7.0.3 Added the `$user_id` parameter, which is sent with the `personal_options_update` action.
     3862 *
     3863 * @param int $user_id Optional. The ID of the user whose email is being changed. Defaults to `$_POST['user_id']` if set, otherwise 0.
    38613864 *
    38623865 * @global WP_Error $errors WP_Error object.
    38633866 */
    3864 function send_confirmation_on_profile_email() {
     3867function send_confirmation_on_profile_email( $user_id = 0 ) {
    38653868        global $errors;
     3869
     3870        // Maintain backward compatibility for those relying on a check based on $_POST['user_id'].
     3871        if ( ! $user_id && isset( $_POST['user_id'] ) ) {
     3872                $user_id = absint( $_POST['user_id'] );
     3873        }
    38663874
    38673875        $current_user = wp_get_current_user();
    … …  
    38703878        }
    38713879
    3872         if ( $current_user->ID !== (int) $_POST['user_id'] ) {
     3880        if ( 0 === $current_user->ID || $current_user->ID !== (int) $user_id ) {
    38733881                return false;
    38743882        }
    … …  
    38843892                        );
    38853893
     3894                        $_POST['email'] = addslashes( $current_user->user_email );
    38863895                        return;
    38873896                }
    … …  
    38973906                        delete_user_meta( $current_user->ID, '_new_email' );
    38983907
     3908                        $_POST['email'] = addslashes( $current_user->user_email );
    38993909                        return;
    39003910                }
Note: See TracChangeset for help on using the changeset viewer.