wp/wp-admin/includes/user.php
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
    45 	}
    45 	}
    46 
    46 
    47 	$pass1 = '';
    47 	$pass1 = '';
    48 	$pass2 = '';
    48 	$pass2 = '';
    49 	if ( isset( $_POST['pass1'] ) ) {
    49 	if ( isset( $_POST['pass1'] ) ) {
    50 		$pass1 = $_POST['pass1'];
    50 		$pass1 = trim( $_POST['pass1'] );
    51 	}
    51 	}
    52 	if ( isset( $_POST['pass2'] ) ) {
    52 	if ( isset( $_POST['pass2'] ) ) {
    53 		$pass2 = $_POST['pass2'];
    53 		$pass2 = trim( $_POST['pass2'] );
    54 	}
    54 	}
    55 
    55 
    56 	if ( isset( $_POST['role'] ) && current_user_can( 'promote_users' ) && ( ! $user_id || current_user_can( 'promote_user', $user_id ) ) ) {
    56 	if ( isset( $_POST['role'] ) && current_user_can( 'promote_users' ) && ( ! $user_id || current_user_can( 'promote_user', $user_id ) ) ) {
    57 		$new_role = sanitize_text_field( $_POST['role'] );
    57 		$new_role = sanitize_text_field( $_POST['role'] );
    58 
    58 
   278  * Retrieve user data and filter it.
   278  * Retrieve user data and filter it.
   279  *
   279  *
   280  * @since 2.0.5
   280  * @since 2.0.5
   281  *
   281  *
   282  * @param int $user_id User ID.
   282  * @param int $user_id User ID.
   283  * @return WP_User|bool WP_User object on success, false on failure.
   283  * @return WP_User|false WP_User object on success, false on failure.
   284  */
   284  */
   285 function get_user_to_edit( $user_id ) {
   285 function get_user_to_edit( $user_id ) {
   286 	$user = get_userdata( $user_id );
   286 	$user = get_userdata( $user_id );
   287 
   287 
   288 	if ( $user ) {
   288 	if ( $user ) {
   480 	// get_user_setting() = JS-saved UI setting. Else no-js-fallback code.
   480 	// get_user_setting() = JS-saved UI setting. Else no-js-fallback code.
   481 	if ( 'hide' === get_user_setting( 'default_password_nag' )
   481 	if ( 'hide' === get_user_setting( 'default_password_nag' )
   482 		|| isset( $_GET['default_password_nag'] ) && '0' == $_GET['default_password_nag']
   482 		|| isset( $_GET['default_password_nag'] ) && '0' == $_GET['default_password_nag']
   483 	) {
   483 	) {
   484 		delete_user_setting( 'default_password_nag' );
   484 		delete_user_setting( 'default_password_nag' );
   485 		update_user_option( $user_ID, 'default_password_nag', false, true );
   485 		update_user_meta( $user_ID, 'default_password_nag', false );
   486 	}
   486 	}
   487 }
   487 }
   488 
   488 
   489 /**
   489 /**
   490  * @since 2.8.0
   490  * @since 2.8.0
   491  *
   491  *
   492  * @param int    $user_ID
   492  * @param int     $user_ID
   493  * @param object $old_data
   493  * @param WP_User $old_data
   494  */
   494  */
   495 function default_password_nag_edit_user( $user_ID, $old_data ) {
   495 function default_password_nag_edit_user( $user_ID, $old_data ) {
   496 	// Short-circuit it.
   496 	// Short-circuit it.
   497 	if ( ! get_user_option( 'default_password_nag', $user_ID ) ) {
   497 	if ( ! get_user_option( 'default_password_nag', $user_ID ) ) {
   498 		return;
   498 		return;
   501 	$new_data = get_userdata( $user_ID );
   501 	$new_data = get_userdata( $user_ID );
   502 
   502 
   503 	// Remove the nag if the password has been changed.
   503 	// Remove the nag if the password has been changed.
   504 	if ( $new_data->user_pass != $old_data->user_pass ) {
   504 	if ( $new_data->user_pass != $old_data->user_pass ) {
   505 		delete_user_setting( 'default_password_nag' );
   505 		delete_user_setting( 'default_password_nag' );
   506 		update_user_option( $user_ID, 'default_password_nag', false, true );
   506 		update_user_meta( $user_ID, 'default_password_nag', false );
   507 	}
   507 	}
   508 }
   508 }
   509 
   509 
   510 /**
   510 /**
   511  * @since 2.8.0
   511  * @since 2.8.0
   592 		wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ),
   592 		wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ),
   593 		home_url(),
   593 		home_url(),
   594 		wp_specialchars_decode( translate_user_role( $role['name'] ) )
   594 		wp_specialchars_decode( translate_user_role( $role['name'] ) )
   595 	);
   595 	);
   596 }
   596 }
       
   597 
       
   598 /**
       
   599  * Checks if the Authorize Application Password request is valid.
       
   600  *
       
   601  * @since 5.6.0
       
   602  *
       
   603  * @param array   $request {
       
   604  *     The array of request data. All arguments are optional and may be empty.
       
   605  *
       
   606  *     @type string $app_name    The suggested name of the application.
       
   607  *     @type string $app_id      A uuid provided by the application to uniquely identify it.
       
   608  *     @type string $success_url The url the user will be redirected to after approving the application.
       
   609  *     @type string $reject_url  The url the user will be redirected to after rejecting the application.
       
   610  * }
       
   611  * @param WP_User $user The user authorizing the application.
       
   612  * @return true|WP_Error True if the request is valid, a WP_Error object contains errors if not.
       
   613  */
       
   614 function wp_is_authorize_application_password_request_valid( $request, $user ) {
       
   615 	$error = new WP_Error();
       
   616 
       
   617 	if ( ! empty( $request['success_url'] ) ) {
       
   618 		$scheme = wp_parse_url( $request['success_url'], PHP_URL_SCHEME );
       
   619 
       
   620 		if ( 'http' === $scheme ) {
       
   621 			$error->add(
       
   622 				'invalid_redirect_scheme',
       
   623 				__( 'The success url must be served over a secure connection.' )
       
   624 			);
       
   625 		}
       
   626 	}
       
   627 
       
   628 	if ( ! empty( $request['reject_url'] ) ) {
       
   629 		$scheme = wp_parse_url( $request['reject_url'], PHP_URL_SCHEME );
       
   630 
       
   631 		if ( 'http' === $scheme ) {
       
   632 			$error->add(
       
   633 				'invalid_redirect_scheme',
       
   634 				__( 'The rejection url must be served over a secure connection.' )
       
   635 			);
       
   636 		}
       
   637 	}
       
   638 
       
   639 	if ( ! empty( $request['app_id'] ) && ! wp_is_uuid( $request['app_id'] ) ) {
       
   640 		$error->add(
       
   641 			'invalid_app_id',
       
   642 			__( 'The app id must be a uuid.' )
       
   643 		);
       
   644 	}
       
   645 
       
   646 	/**
       
   647 	 * Fires before application password errors are returned.
       
   648 	 *
       
   649 	 * @since 5.6.0
       
   650 	 *
       
   651 	 * @param WP_Error $error   The error object.
       
   652 	 * @param array    $request The array of request data.
       
   653 	 * @param WP_User  $user    The user authorizing the application.
       
   654 	 */
       
   655 	do_action( 'wp_authorize_application_password_request_errors', $error, $request, $user );
       
   656 
       
   657 	if ( $error->has_errors() ) {
       
   658 		return $error;
       
   659 	}
       
   660 
       
   661 	return true;
       
   662 }