141 |
147 |
142 $errors = new WP_Error(); |
148 $errors = new WP_Error(); |
143 |
149 |
144 /* checking that username has been typed */ |
150 /* checking that username has been typed */ |
145 if ( '' === $user->user_login ) { |
151 if ( '' === $user->user_login ) { |
146 $errors->add( 'user_login', __( '<strong>Error</strong>: Please enter a username.' ) ); |
152 $errors->add( 'user_login', __( '<strong>Error:</strong> Please enter a username.' ) ); |
147 } |
153 } |
148 |
154 |
149 /* checking that nickname has been typed */ |
155 /* checking that nickname has been typed */ |
150 if ( $update && empty( $user->nickname ) ) { |
156 if ( $update && empty( $user->nickname ) ) { |
151 $errors->add( 'nickname', __( '<strong>Error</strong>: Please enter a nickname.' ) ); |
157 $errors->add( 'nickname', __( '<strong>Error:</strong> Please enter a nickname.' ) ); |
152 } |
158 } |
153 |
159 |
154 /** |
160 /** |
155 * Fires before the password and confirm password fields are checked for congruity. |
161 * Fires before the password and confirm password fields are checked for congruity. |
156 * |
162 * |
162 */ |
168 */ |
163 do_action_ref_array( 'check_passwords', array( $user->user_login, &$pass1, &$pass2 ) ); |
169 do_action_ref_array( 'check_passwords', array( $user->user_login, &$pass1, &$pass2 ) ); |
164 |
170 |
165 // Check for blank password when adding a user. |
171 // Check for blank password when adding a user. |
166 if ( ! $update && empty( $pass1 ) ) { |
172 if ( ! $update && empty( $pass1 ) ) { |
167 $errors->add( 'pass', __( '<strong>Error</strong>: Please enter a password.' ), array( 'form-field' => 'pass1' ) ); |
173 $errors->add( 'pass', __( '<strong>Error:</strong> Please enter a password.' ), array( 'form-field' => 'pass1' ) ); |
168 } |
174 } |
169 |
175 |
170 // Check for "\" in password. |
176 // Check for "\" in password. |
171 if ( false !== strpos( wp_unslash( $pass1 ), '\\' ) ) { |
177 if ( str_contains( wp_unslash( $pass1 ), '\\' ) ) { |
172 $errors->add( 'pass', __( '<strong>Error</strong>: Passwords may not contain the character "\\".' ), array( 'form-field' => 'pass1' ) ); |
178 $errors->add( 'pass', __( '<strong>Error:</strong> Passwords may not contain the character "\\".' ), array( 'form-field' => 'pass1' ) ); |
173 } |
179 } |
174 |
180 |
175 // Checking the password has been typed twice the same. |
181 // Checking the password has been typed twice the same. |
176 if ( ( $update || ! empty( $pass1 ) ) && $pass1 != $pass2 ) { |
182 if ( ( $update || ! empty( $pass1 ) ) && $pass1 !== $pass2 ) { |
177 $errors->add( 'pass', __( '<strong>Error</strong>: Passwords do not match. Please enter the same password in both password fields.' ), array( 'form-field' => 'pass1' ) ); |
183 $errors->add( 'pass', __( '<strong>Error:</strong> Passwords do not match. Please enter the same password in both password fields.' ), array( 'form-field' => 'pass1' ) ); |
178 } |
184 } |
179 |
185 |
180 if ( ! empty( $pass1 ) ) { |
186 if ( ! empty( $pass1 ) ) { |
181 $user->user_pass = $pass1; |
187 $user->user_pass = $pass1; |
182 } |
188 } |
183 |
189 |
184 if ( ! $update && isset( $_POST['user_login'] ) && ! validate_username( $_POST['user_login'] ) ) { |
190 if ( ! $update && isset( $_POST['user_login'] ) && ! validate_username( $_POST['user_login'] ) ) { |
185 $errors->add( 'user_login', __( '<strong>Error</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.' ) ); |
191 $errors->add( 'user_login', __( '<strong>Error:</strong> This username is invalid because it uses illegal characters. Please enter a valid username.' ) ); |
186 } |
192 } |
187 |
193 |
188 if ( ! $update && username_exists( $user->user_login ) ) { |
194 if ( ! $update && username_exists( $user->user_login ) ) { |
189 $errors->add( 'user_login', __( '<strong>Error</strong>: This username is already registered. Please choose another one.' ) ); |
195 $errors->add( 'user_login', __( '<strong>Error:</strong> This username is already registered. Please choose another one.' ) ); |
190 } |
196 } |
191 |
197 |
192 /** This filter is documented in wp-includes/user.php */ |
198 /** This filter is documented in wp-includes/user.php */ |
193 $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
199 $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
194 |
200 |
195 if ( in_array( strtolower( $user->user_login ), array_map( 'strtolower', $illegal_logins ), true ) ) { |
201 if ( in_array( strtolower( $user->user_login ), array_map( 'strtolower', $illegal_logins ), true ) ) { |
196 $errors->add( 'invalid_username', __( '<strong>Error</strong>: Sorry, that username is not allowed.' ) ); |
202 $errors->add( 'invalid_username', __( '<strong>Error:</strong> Sorry, that username is not allowed.' ) ); |
197 } |
203 } |
198 |
204 |
199 /* checking email address */ |
205 // Checking email address. |
200 if ( empty( $user->user_email ) ) { |
206 if ( empty( $user->user_email ) ) { |
201 $errors->add( 'empty_email', __( '<strong>Error</strong>: Please enter an email address.' ), array( 'form-field' => 'email' ) ); |
207 $errors->add( 'empty_email', __( '<strong>Error:</strong> Please enter an email address.' ), array( 'form-field' => 'email' ) ); |
202 } elseif ( ! is_email( $user->user_email ) ) { |
208 } elseif ( ! is_email( $user->user_email ) ) { |
203 $errors->add( 'invalid_email', __( '<strong>Error</strong>: The email address is not correct.' ), array( 'form-field' => 'email' ) ); |
209 $errors->add( 'invalid_email', __( '<strong>Error:</strong> The email address is not correct.' ), array( 'form-field' => 'email' ) ); |
204 } else { |
210 } else { |
205 $owner_id = email_exists( $user->user_email ); |
211 $owner_id = email_exists( $user->user_email ); |
206 if ( $owner_id && ( ! $update || ( $owner_id != $user->ID ) ) ) { |
212 if ( $owner_id && ( ! $update || ( $owner_id !== $user->ID ) ) ) { |
207 $errors->add( 'email_exists', __( '<strong>Error</strong>: This email is already registered. Please choose another one.' ), array( 'form-field' => 'email' ) ); |
213 $errors->add( 'email_exists', __( '<strong>Error:</strong> This email is already registered. Please choose another one.' ), array( 'form-field' => 'email' ) ); |
208 } |
214 } |
209 } |
215 } |
210 |
216 |
211 /** |
217 /** |
212 * Fires before user profile update errors are returned. |
218 * Fires before user profile update errors are returned. |
316 $query = apply_filters( 'get_users_drafts', $query ); |
322 $query = apply_filters( 'get_users_drafts', $query ); |
317 return $wpdb->get_results( $query ); |
323 return $wpdb->get_results( $query ); |
318 } |
324 } |
319 |
325 |
320 /** |
326 /** |
321 * Remove user and optionally reassign posts and links to another user. |
327 * Delete user and optionally reassign posts and links to another user. |
322 * |
328 * |
323 * If the $reassign parameter is not assigned to a User ID, then all posts will |
329 * Note that on a Multisite installation the user only gets removed from the site |
324 * be deleted of that user. The action {@see 'delete_user'} that is passed the User ID |
330 * and does not get deleted from the database. |
|
331 * |
|
332 * If the `$reassign` parameter is not assigned to a user ID, then all posts will |
|
333 * be deleted of that user. The action {@see 'delete_user'} that is passed the user ID |
325 * being deleted will be run after the posts are either reassigned or deleted. |
334 * being deleted will be run after the posts are either reassigned or deleted. |
326 * The user meta will also be deleted that are for that User ID. |
335 * The user meta will also be deleted that are for that user ID. |
327 * |
336 * |
328 * @since 2.0.0 |
337 * @since 2.0.0 |
329 * |
338 * |
330 * @global wpdb $wpdb WordPress database abstraction object. |
339 * @global wpdb $wpdb WordPress database abstraction object. |
331 * |
340 * |
332 * @param int $id User ID. |
341 * @param int $id User ID. |
333 * @param int $reassign Optional. Reassign posts and links to new User ID. |
342 * @param int $reassign Optional. Reassign posts and links to new User ID. |
334 * @return bool True when finished. |
343 * @return bool True when finished. |
335 */ |
344 */ |
336 function wp_delete_user( $id, $reassign = null ) { |
345 function wp_delete_user( $id, $reassign = null ) { |
337 global $wpdb; |
346 global $wpdb; |
518 // Short-circuit it. |
534 // Short-circuit it. |
519 if ( 'profile.php' === $pagenow || ! get_user_option( 'default_password_nag' ) ) { |
535 if ( 'profile.php' === $pagenow || ! get_user_option( 'default_password_nag' ) ) { |
520 return; |
536 return; |
521 } |
537 } |
522 |
538 |
523 echo '<div class="error default-password-nag">'; |
539 $default_password_nag_message = sprintf( |
524 echo '<p>'; |
540 '<p><strong>%1$s</strong> %2$s</p>', |
525 echo '<strong>' . __( 'Notice:' ) . '</strong> '; |
541 __( 'Notice:' ), |
526 _e( 'You’re using the auto-generated password for your account. Would you like to change it?' ); |
542 __( 'You are using the auto-generated password for your account. Would you like to change it?' ) |
527 echo '</p><p>'; |
543 ); |
528 printf( '<a href="%s">' . __( 'Yes, take me to my profile page' ) . '</a> | ', get_edit_profile_url() . '#password' ); |
544 $default_password_nag_message .= sprintf( |
529 printf( '<a href="%s" id="default-password-nag-no">' . __( 'No thanks, do not remind me again' ) . '</a>', '?default_password_nag=0' ); |
545 '<p><a href="%1$s">%2$s</a> | ', |
530 echo '</p></div>'; |
546 esc_url( get_edit_profile_url() . '#password' ), |
|
547 __( 'Yes, take me to my profile page' ) |
|
548 ); |
|
549 $default_password_nag_message .= sprintf( |
|
550 '<a href="%1$s" id="default-password-nag-no">%2$s</a></p>', |
|
551 '?default_password_nag=0', |
|
552 __( 'No thanks, do not remind me again' ) |
|
553 ); |
|
554 |
|
555 wp_admin_notice( |
|
556 $default_password_nag_message, |
|
557 array( |
|
558 'additional_classes' => array( 'error', 'default-password-nag' ), |
|
559 'paragraph_wrap' => false, |
|
560 ) |
|
561 ); |
531 } |
562 } |
532 |
563 |
533 /** |
564 /** |
534 * @since 3.5.0 |
565 * @since 3.5.0 |
535 * @access private |
566 * @access private |
619 * @return true|WP_Error True if the request is valid, a WP_Error object contains errors if not. |
652 * @return true|WP_Error True if the request is valid, a WP_Error object contains errors if not. |
620 */ |
653 */ |
621 function wp_is_authorize_application_password_request_valid( $request, $user ) { |
654 function wp_is_authorize_application_password_request_valid( $request, $user ) { |
622 $error = new WP_Error(); |
655 $error = new WP_Error(); |
623 |
656 |
624 if ( ! empty( $request['success_url'] ) ) { |
657 if ( isset( $request['success_url'] ) ) { |
625 $scheme = wp_parse_url( $request['success_url'], PHP_URL_SCHEME ); |
658 $validated_success_url = wp_is_authorize_application_redirect_url_valid( $request['success_url'] ); |
626 |
659 if ( is_wp_error( $validated_success_url ) ) { |
627 if ( 'http' === $scheme ) { |
|
628 $error->add( |
660 $error->add( |
629 'invalid_redirect_scheme', |
661 $validated_success_url->get_error_code(), |
630 __( 'The success URL must be served over a secure connection.' ) |
662 $validated_success_url->get_error_message() |
631 ); |
663 ); |
632 } |
664 } |
633 } |
665 } |
634 |
666 |
635 if ( ! empty( $request['reject_url'] ) ) { |
667 if ( isset( $request['reject_url'] ) ) { |
636 $scheme = wp_parse_url( $request['reject_url'], PHP_URL_SCHEME ); |
668 $validated_reject_url = wp_is_authorize_application_redirect_url_valid( $request['reject_url'] ); |
637 |
669 if ( is_wp_error( $validated_reject_url ) ) { |
638 if ( 'http' === $scheme ) { |
|
639 $error->add( |
670 $error->add( |
640 'invalid_redirect_scheme', |
671 $validated_reject_url->get_error_code(), |
641 __( 'The rejection URL must be served over a secure connection.' ) |
672 $validated_reject_url->get_error_message() |
642 ); |
673 ); |
643 } |
674 } |
644 } |
675 } |
645 |
676 |
646 if ( ! empty( $request['app_id'] ) && ! wp_is_uuid( $request['app_id'] ) ) { |
677 if ( ! empty( $request['app_id'] ) && ! wp_is_uuid( $request['app_id'] ) ) { |
665 return $error; |
696 return $error; |
666 } |
697 } |
667 |
698 |
668 return true; |
699 return true; |
669 } |
700 } |
|
701 |
|
702 /** |
|
703 * Validates the redirect URL protocol scheme. The protocol can be anything except `http` and `javascript`. |
|
704 * |
|
705 * @since 6.3.2 |
|
706 * |
|
707 * @param string $url The redirect URL to be validated. |
|
708 * @return true|WP_Error True if the redirect URL is valid, a WP_Error object otherwise. |
|
709 */ |
|
710 function wp_is_authorize_application_redirect_url_valid( $url ) { |
|
711 $bad_protocols = array( 'javascript', 'data' ); |
|
712 if ( empty( $url ) ) { |
|
713 return true; |
|
714 } |
|
715 |
|
716 // Based on https://www.rfc-editor.org/rfc/rfc2396#section-3.1 |
|
717 $valid_scheme_regex = '/^[a-zA-Z][a-zA-Z0-9+.-]*:/'; |
|
718 if ( ! preg_match( $valid_scheme_regex, $url ) ) { |
|
719 return new WP_Error( |
|
720 'invalid_redirect_url_format', |
|
721 __( 'Invalid URL format.' ) |
|
722 ); |
|
723 } |
|
724 |
|
725 /** |
|
726 * Filters the list of invalid protocols used in applications redirect URLs. |
|
727 * |
|
728 * @since 6.3.2 |
|
729 * |
|
730 * @param string[] $bad_protocols Array of invalid protocols. |
|
731 * @param string $url The redirect URL to be validated. |
|
732 */ |
|
733 $invalid_protocols = apply_filters( 'wp_authorize_application_redirect_url_invalid_protocols', $bad_protocols, $url ); |
|
734 $invalid_protocols = array_map( 'strtolower', $invalid_protocols ); |
|
735 |
|
736 $scheme = wp_parse_url( $url, PHP_URL_SCHEME ); |
|
737 $host = wp_parse_url( $url, PHP_URL_HOST ); |
|
738 $is_local = 'local' === wp_get_environment_type(); |
|
739 |
|
740 // Validates if the proper URI format is applied to the URL. |
|
741 if ( empty( $host ) || empty( $scheme ) || in_array( strtolower( $scheme ), $invalid_protocols, true ) ) { |
|
742 return new WP_Error( |
|
743 'invalid_redirect_url_format', |
|
744 __( 'Invalid URL format.' ) |
|
745 ); |
|
746 } |
|
747 |
|
748 if ( 'http' === $scheme && ! $is_local ) { |
|
749 return new WP_Error( |
|
750 'invalid_redirect_scheme', |
|
751 __( 'The URL must be served over a secure connection.' ) |
|
752 ); |
|
753 } |
|
754 |
|
755 return true; |
|
756 } |