wp/wp-admin/includes/user.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
    23  * Used on user-edit.php and profile.php to manage and process user options, passwords etc.
    23  * Used on user-edit.php and profile.php to manage and process user options, passwords etc.
    24  *
    24  *
    25  * @since 2.0.0
    25  * @since 2.0.0
    26  *
    26  *
    27  * @param int $user_id Optional. User ID.
    27  * @param int $user_id Optional. User ID.
    28  * @return int|WP_Error User ID of the updated user.
    28  * @return int|WP_Error User ID of the updated user or WP_Error on failure.
    29  */
    29  */
    30 function edit_user( $user_id = 0 ) {
    30 function edit_user( $user_id = 0 ) {
    31 	$wp_roles = wp_roles();
    31 	$wp_roles = wp_roles();
    32 	$user     = new stdClass;
    32 	$user     = new stdClass;
    33 	$user_id  = (int) $user_id;
    33 	$user_id  = (int) $user_id;
   172 		$errors->add( 'pass', __( '<strong>Error</strong>: Passwords may not contain the character "\\".' ), array( 'form-field' => 'pass1' ) );
   172 		$errors->add( 'pass', __( '<strong>Error</strong>: Passwords may not contain the character "\\".' ), array( 'form-field' => 'pass1' ) );
   173 	}
   173 	}
   174 
   174 
   175 	// Checking the password has been typed twice the same.
   175 	// Checking the password has been typed twice the same.
   176 	if ( ( $update || ! empty( $pass1 ) ) && $pass1 != $pass2 ) {
   176 	if ( ( $update || ! empty( $pass1 ) ) && $pass1 != $pass2 ) {
   177 		$errors->add( 'pass', __( '<strong>Error</strong>: Passwords don&#8217;t match. Please enter the same password in both password fields.' ), array( 'form-field' => 'pass1' ) );
   177 		$errors->add( 'pass', __( '<strong>Error</strong>: Passwords do not match. Please enter the same password in both password fields.' ), array( 'form-field' => 'pass1' ) );
   178 	}
   178 	}
   179 
   179 
   180 	if ( ! empty( $pass1 ) ) {
   180 	if ( ! empty( $pass1 ) ) {
   181 		$user->user_pass = $pass1;
   181 		$user->user_pass = $pass1;
   182 	}
   182 	}
   198 
   198 
   199 	/* checking email address */
   199 	/* checking email address */
   200 	if ( empty( $user->user_email ) ) {
   200 	if ( empty( $user->user_email ) ) {
   201 		$errors->add( 'empty_email', __( '<strong>Error</strong>: Please enter an email address.' ), array( 'form-field' => 'email' ) );
   201 		$errors->add( 'empty_email', __( '<strong>Error</strong>: Please enter an email address.' ), array( 'form-field' => 'email' ) );
   202 	} elseif ( ! is_email( $user->user_email ) ) {
   202 	} elseif ( ! is_email( $user->user_email ) ) {
   203 		$errors->add( 'invalid_email', __( '<strong>Error</strong>: The email address isn&#8217;t correct.' ), array( 'form-field' => 'email' ) );
   203 		$errors->add( 'invalid_email', __( '<strong>Error</strong>: The email address is not correct.' ), array( 'form-field' => 'email' ) );
   204 	} else {
   204 	} else {
   205 		$owner_id = email_exists( $user->user_email );
   205 		$owner_id = email_exists( $user->user_email );
   206 		if ( $owner_id && ( ! $update || ( $owner_id != $user->ID ) ) ) {
   206 		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' ) );
   207 			$errors->add( 'email_exists', __( '<strong>Error</strong>: This email is already registered. Please choose another one.' ), array( 'form-field' => 'email' ) );
   208 		}
   208 		}
   232 		/**
   232 		/**
   233 		 * Fires after a new user has been created.
   233 		 * Fires after a new user has been created.
   234 		 *
   234 		 *
   235 		 * @since 4.4.0
   235 		 * @since 4.4.0
   236 		 *
   236 		 *
   237 		 * @param int    $user_id ID of the newly created user.
   237 		 * @param int|WP_Error $user_id ID of the newly created user or WP_Error on failure.
   238 		 * @param string $notify  Type of notification that should happen. See wp_send_new_user_notifications()
   238 		 * @param string       $notify  Type of notification that should happen. See
   239 		 *                        for more information on possible values.
   239 		 *                              wp_send_new_user_notifications() for more information.
   240 		 */
   240 		 */
   241 		do_action( 'edit_user_created_user', $user_id, $notify );
   241 		do_action( 'edit_user_created_user', $user_id, $notify );
   242 	}
   242 	}
   243 	return $user_id;
   243 	return $user_id;
   244 }
   244 }
   508 }
   508 }
   509 
   509 
   510 /**
   510 /**
   511  * @since 2.8.0
   511  * @since 2.8.0
   512  *
   512  *
   513  * @global string $pagenow
   513  * @global string $pagenow The filename of the current screen.
   514  */
   514  */
   515 function default_password_nag() {
   515 function default_password_nag() {
   516 	global $pagenow;
   516 	global $pagenow;
       
   517 
   517 	// Short-circuit it.
   518 	// Short-circuit it.
   518 	if ( 'profile.php' === $pagenow || ! get_user_option( 'default_password_nag' ) ) {
   519 	if ( 'profile.php' === $pagenow || ! get_user_option( 'default_password_nag' ) ) {
   519 		return;
   520 		return;
   520 	}
   521 	}
   521 
   522 
   534  * @access private
   535  * @access private
   535  */
   536  */
   536 function delete_users_add_js() {
   537 function delete_users_add_js() {
   537 	?>
   538 	?>
   538 <script>
   539 <script>
   539 jQuery(document).ready( function($) {
   540 jQuery( function($) {
   540 	var submit = $('#submit').prop('disabled', true);
   541 	var submit = $('#submit').prop('disabled', true);
   541 	$('input[name="delete_option"]').one('change', function() {
   542 	$('input[name="delete_option"]').one('change', function() {
   542 		submit.prop('disabled', false);
   543 		submit.prop('disabled', false);
   543 	});
   544 	});
   544 	$('#reassign_user').focus( function() {
   545 	$('#reassign_user').focus( function() {
   545 		$('#delete_option1').prop('checked', true).trigger('change');
   546 		$('#delete_option1').prop('checked', true).trigger('change');
   546 	});
   547 	});
   547 });
   548 } );
   548 </script>
   549 </script>
   549 	<?php
   550 	<?php
   550 }
   551 }
   551 
   552 
   552 /**
   553 /**
   574  * @return string
   575  * @return string
   575  */
   576  */
   576 function admin_created_user_email( $text ) {
   577 function admin_created_user_email( $text ) {
   577 	$roles = get_editable_roles();
   578 	$roles = get_editable_roles();
   578 	$role  = $roles[ $_REQUEST['role'] ];
   579 	$role  = $roles[ $_REQUEST['role'] ];
       
   580 
       
   581 	if ( '' !== get_bloginfo( 'name' ) ) {
       
   582 		$site_title = wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES );
       
   583 	} else {
       
   584 		$site_title = parse_url( home_url(), PHP_URL_HOST );
       
   585 	}
   579 
   586 
   580 	return sprintf(
   587 	return sprintf(
   581 		/* translators: 1: Site title, 2: Site URL, 3: User role. */
   588 		/* translators: 1: Site title, 2: Site URL, 3: User role. */
   582 		__(
   589 		__(
   583 			'Hi,
   590 			'Hi,
   587 this email. This invitation will expire in a few days.
   594 this email. This invitation will expire in a few days.
   588 
   595 
   589 Please click the following link to activate your user account:
   596 Please click the following link to activate your user account:
   590 %%s'
   597 %%s'
   591 		),
   598 		),
   592 		wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ),
   599 		$site_title,
   593 		home_url(),
   600 		home_url(),
   594 		wp_specialchars_decode( translate_user_role( $role['name'] ) )
   601 		wp_specialchars_decode( translate_user_role( $role['name'] ) )
   595 	);
   602 	);
   596 }
   603 }
   597 
   604 
   602  *
   609  *
   603  * @param array   $request {
   610  * @param array   $request {
   604  *     The array of request data. All arguments are optional and may be empty.
   611  *     The array of request data. All arguments are optional and may be empty.
   605  *
   612  *
   606  *     @type string $app_name    The suggested name of the application.
   613  *     @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.
   614  *     @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.
   615  *     @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.
   616  *     @type string $reject_url  The URL the user will be redirected to after rejecting the application.
   610  * }
   617  * }
   611  * @param WP_User $user The user authorizing the application.
   618  * @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.
   619  * @return true|WP_Error True if the request is valid, a WP_Error object contains errors if not.
   613  */
   620  */
   614 function wp_is_authorize_application_password_request_valid( $request, $user ) {
   621 function wp_is_authorize_application_password_request_valid( $request, $user ) {
   618 		$scheme = wp_parse_url( $request['success_url'], PHP_URL_SCHEME );
   625 		$scheme = wp_parse_url( $request['success_url'], PHP_URL_SCHEME );
   619 
   626 
   620 		if ( 'http' === $scheme ) {
   627 		if ( 'http' === $scheme ) {
   621 			$error->add(
   628 			$error->add(
   622 				'invalid_redirect_scheme',
   629 				'invalid_redirect_scheme',
   623 				__( 'The success url must be served over a secure connection.' )
   630 				__( 'The success URL must be served over a secure connection.' )
   624 			);
   631 			);
   625 		}
   632 		}
   626 	}
   633 	}
   627 
   634 
   628 	if ( ! empty( $request['reject_url'] ) ) {
   635 	if ( ! empty( $request['reject_url'] ) ) {
   629 		$scheme = wp_parse_url( $request['reject_url'], PHP_URL_SCHEME );
   636 		$scheme = wp_parse_url( $request['reject_url'], PHP_URL_SCHEME );
   630 
   637 
   631 		if ( 'http' === $scheme ) {
   638 		if ( 'http' === $scheme ) {
   632 			$error->add(
   639 			$error->add(
   633 				'invalid_redirect_scheme',
   640 				'invalid_redirect_scheme',
   634 				__( 'The rejection url must be served over a secure connection.' )
   641 				__( 'The rejection URL must be served over a secure connection.' )
   635 			);
   642 			);
   636 		}
   643 		}
   637 	}
   644 	}
   638 
   645 
   639 	if ( ! empty( $request['app_id'] ) && ! wp_is_uuid( $request['app_id'] ) ) {
   646 	if ( ! empty( $request['app_id'] ) && ! wp_is_uuid( $request['app_id'] ) ) {
   640 		$error->add(
   647 		$error->add(
   641 			'invalid_app_id',
   648 			'invalid_app_id',
   642 			__( 'The app id must be a uuid.' )
   649 			__( 'The application ID must be a UUID.' )
   643 		);
   650 		);
   644 	}
   651 	}
   645 
   652 
   646 	/**
   653 	/**
   647 	 * Fires before application password errors are returned.
   654 	 * Fires before application password errors are returned.