wp/wp-includes/user.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
   110 	do_action( 'wp_login', $user->user_login, $user );
   110 	do_action( 'wp_login', $user->user_login, $user );
   111 	return $user;
   111 	return $user;
   112 }
   112 }
   113 
   113 
   114 /**
   114 /**
   115  * Authenticate a user, confirming the username and password are valid.
   115  * Authenticates a user, confirming the username and password are valid.
   116  *
   116  *
   117  * @since 2.8.0
   117  * @since 2.8.0
   118  *
   118  *
   119  * @param WP_User|WP_Error|null $user     WP_User or WP_Error object from a previous callback. Default null.
   119  * @param WP_User|WP_Error|null $user     WP_User or WP_Error object from a previous callback. Default null.
   120  * @param string                $username Username for authentication.
   120  * @param string                $username Username for authentication.
   156 			)
   156 			)
   157 		);
   157 		);
   158 	}
   158 	}
   159 
   159 
   160 	/**
   160 	/**
   161 	 * Filters whether the given user can be authenticated with the provided $password.
   161 	 * Filters whether the given user can be authenticated with the provided password.
   162 	 *
   162 	 *
   163 	 * @since 2.5.0
   163 	 * @since 2.5.0
   164 	 *
   164 	 *
   165 	 * @param WP_User|WP_Error $user     WP_User or WP_Error object if a previous
   165 	 * @param WP_User|WP_Error $user     WP_User or WP_Error object if a previous
   166 	 *                                   callback failed authentication.
   166 	 *                                   callback failed authentication.
   259 
   259 
   260 	return $user;
   260 	return $user;
   261 }
   261 }
   262 
   262 
   263 /**
   263 /**
   264  * Authenticate the user using the WordPress auth cookie.
   264  * Authenticates the user using the WordPress auth cookie.
   265  *
   265  *
   266  * @since 2.8.0
   266  * @since 2.8.0
   267  *
   267  *
   268  * @global string $auth_secure_cookie
   268  * @global string $auth_secure_cookie
   269  *
   269  *
   383 
   383 
   384 		return $error;
   384 		return $error;
   385 	}
   385 	}
   386 
   386 
   387 	/*
   387 	/*
   388 	 * Strip out anything non-alphanumeric. This is so passwords can be used with
   388 	 * Strips out anything non-alphanumeric. This is so passwords can be used with
   389 	 * or without spaces to indicate the groupings for readability.
   389 	 * or without spaces to indicate the groupings for readability.
   390 	 *
   390 	 *
   391 	 * Generated application passwords are exclusively alphanumeric.
   391 	 * Generated application passwords are exclusively alphanumeric.
   392 	 */
   392 	 */
   393 	$password = preg_replace( '/[^a-z\d]/i', '', $password );
   393 	$password = preg_replace( '/[^a-z\d]/i', '', $password );
   480 	// If it wasn't a user what got returned, just pass on what we had received originally.
   480 	// If it wasn't a user what got returned, just pass on what we had received originally.
   481 	return $input_user;
   481 	return $input_user;
   482 }
   482 }
   483 
   483 
   484 /**
   484 /**
   485  * For Multisite blogs, check if the authenticated user has been marked as a
   485  * For Multisite blogs, checks if the authenticated user has been marked as a
   486  * spammer, or if the user's primary blog has been marked as spam.
   486  * spammer, or if the user's primary blog has been marked as spam.
   487  *
   487  *
   488  * @since 3.7.0
   488  * @since 3.7.0
   489  *
   489  *
   490  * @param WP_User|WP_Error|null $user WP_User or WP_Error object from a previous callback. Default null.
   490  * @param WP_User|WP_Error|null $user WP_User or WP_Error object from a previous callback. Default null.
   535 
   535 
   536 	return wp_validate_auth_cookie( $_COOKIE[ LOGGED_IN_COOKIE ], 'logged_in' );
   536 	return wp_validate_auth_cookie( $_COOKIE[ LOGGED_IN_COOKIE ], 'logged_in' );
   537 }
   537 }
   538 
   538 
   539 /**
   539 /**
   540  * Number of posts user has written.
   540  * Gets the number of posts a user has written.
   541  *
   541  *
   542  * @since 3.0.0
   542  * @since 3.0.0
   543  * @since 4.1.0 Added `$post_type` argument.
   543  * @since 4.1.0 Added `$post_type` argument.
   544  * @since 4.3.0 Added `$public_only` argument. Added the ability to pass an array
   544  * @since 4.3.0 Added `$public_only` argument. Added the ability to pass an array
   545  *              of post types to `$post_type`.
   545  *              of post types to `$post_type`.
   572 	 */
   572 	 */
   573 	return apply_filters( 'get_usernumposts', $count, $userid, $post_type, $public_only );
   573 	return apply_filters( 'get_usernumposts', $count, $userid, $post_type, $public_only );
   574 }
   574 }
   575 
   575 
   576 /**
   576 /**
   577  * Number of posts written by a list of users.
   577  * Gets the number of posts written by a list of users.
   578  *
   578  *
   579  * @since 3.0.0
   579  * @since 3.0.0
   580  *
   580  *
   581  * @global wpdb $wpdb WordPress database abstraction object.
   581  * @global wpdb $wpdb WordPress database abstraction object.
   582  *
   582  *
   613 //
   613 //
   614 // User option functions.
   614 // User option functions.
   615 //
   615 //
   616 
   616 
   617 /**
   617 /**
   618  * Get the current user's ID
   618  * Gets the current user's ID.
   619  *
   619  *
   620  * @since MU (3.0.0)
   620  * @since MU (3.0.0)
   621  *
   621  *
   622  * @return int The current user's ID, or 0 if no user is logged in.
   622  * @return int The current user's ID, or 0 if no user is logged in.
   623  */
   623  */
   628 	$user = wp_get_current_user();
   628 	$user = wp_get_current_user();
   629 	return ( isset( $user->ID ) ? (int) $user->ID : 0 );
   629 	return ( isset( $user->ID ) ? (int) $user->ID : 0 );
   630 }
   630 }
   631 
   631 
   632 /**
   632 /**
   633  * Retrieve user option that can be either per Site or per Network.
   633  * Retrieves user option that can be either per Site or per Network.
   634  *
   634  *
   635  * If the user ID is not given, then the current user will be used instead. If
   635  * If the user ID is not given, then the current user will be used instead. If
   636  * the user ID is given, then the user data will be retrieved. The filter for
   636  * the user ID is given, then the user data will be retrieved. The filter for
   637  * the result, will also pass the original option name and finally the user data
   637  * the result, will also pass the original option name and finally the user data
   638  * object as the third parameter.
   638  * object as the third parameter.
   686 	 */
   686 	 */
   687 	return apply_filters( "get_user_option_{$option}", $result, $option, $user );
   687 	return apply_filters( "get_user_option_{$option}", $result, $option, $user );
   688 }
   688 }
   689 
   689 
   690 /**
   690 /**
   691  * Update user option with global blog capability.
   691  * Updates user option with global blog capability.
   692  *
   692  *
   693  * User options are just like user metadata except that they have support for
   693  * User options are just like user metadata except that they have support for
   694  * global blog options. If the 'global' parameter is false, which it is by default
   694  * global blog options. If the 'global' parameter is false, which it is by default
   695  * it will prepend the WordPress table prefix to the option name.
   695  * it will prepend the WordPress table prefix to the option name.
   696  *
   696  *
   717 
   717 
   718 	return update_user_meta( $user_id, $option_name, $newvalue );
   718 	return update_user_meta( $user_id, $option_name, $newvalue );
   719 }
   719 }
   720 
   720 
   721 /**
   721 /**
   722  * Delete user option with global blog capability.
   722  * Deletes user option with global blog capability.
   723  *
   723  *
   724  * User options are just like user metadata except that they have support for
   724  * User options are just like user metadata except that they have support for
   725  * global blog options. If the 'global' parameter is false, which it is by default
   725  * global blog options. If the 'global' parameter is false, which it is by default
   726  * it will prepend the WordPress table prefix to the option name.
   726  * it will prepend the WordPress table prefix to the option name.
   727  *
   727  *
   743 	}
   743 	}
   744 	return delete_user_meta( $user_id, $option_name );
   744 	return delete_user_meta( $user_id, $option_name );
   745 }
   745 }
   746 
   746 
   747 /**
   747 /**
   748  * Retrieve list of users matching criteria.
   748  * Retrieves list of users matching criteria.
   749  *
   749  *
   750  * @since 3.1.0
   750  * @since 3.1.0
   751  *
   751  *
   752  * @see WP_User_Query
   752  * @see WP_User_Query
   753  *
   753  *
   764 
   764 
   765 	return (array) $user_search->get_results();
   765 	return (array) $user_search->get_results();
   766 }
   766 }
   767 
   767 
   768 /**
   768 /**
   769  * Get the sites a user belongs to.
   769  * Lists all the users of the site, with several options available.
       
   770  *
       
   771  * @since 5.9.0
       
   772  *
       
   773  * @param string|array $args {
       
   774  *     Optional. Array or string of default arguments.
       
   775  *
       
   776  *     @type string $orderby       How to sort the users. Accepts 'nicename', 'email', 'url', 'registered',
       
   777  *                                 'user_nicename', 'user_email', 'user_url', 'user_registered', 'name',
       
   778  *                                 'display_name', 'post_count', 'ID', 'meta_value', 'user_login'. Default 'name'.
       
   779  *     @type string $order         Sorting direction for $orderby. Accepts 'ASC', 'DESC'. Default 'ASC'.
       
   780  *     @type int    $number        Maximum users to return or display. Default empty (all users).
       
   781  *     @type bool   $exclude_admin Whether to exclude the 'admin' account, if it exists. Default false.
       
   782  *     @type bool   $show_fullname Whether to show the user's full name. Default false.
       
   783  *     @type string $feed          If not empty, show a link to the user's feed and use this text as the alt
       
   784  *                                 parameter of the link. Default empty.
       
   785  *     @type string $feed_image    If not empty, show a link to the user's feed and use this image URL as
       
   786  *                                 clickable anchor. Default empty.
       
   787  *     @type string $feed_type     The feed type to link to, such as 'rss2'. Defaults to default feed type.
       
   788  *     @type bool   $echo          Whether to output the result or instead return it. Default true.
       
   789  *     @type string $style         If 'list', each user is wrapped in an `<li>` element, otherwise the users
       
   790  *                                 will be separated by commas.
       
   791  *     @type bool   $html          Whether to list the items in HTML form or plaintext. Default true.
       
   792  *     @type string $exclude       An array, comma-, or space-separated list of user IDs to exclude. Default empty.
       
   793  *     @type string $include       An array, comma-, or space-separated list of user IDs to include. Default empty.
       
   794  * }
       
   795  * @return string|null The output if echo is false. Otherwise null.
       
   796  */
       
   797 function wp_list_users( $args = array() ) {
       
   798 	$defaults = array(
       
   799 		'orderby'       => 'name',
       
   800 		'order'         => 'ASC',
       
   801 		'number'        => '',
       
   802 		'exclude_admin' => true,
       
   803 		'show_fullname' => false,
       
   804 		'feed'          => '',
       
   805 		'feed_image'    => '',
       
   806 		'feed_type'     => '',
       
   807 		'echo'          => true,
       
   808 		'style'         => 'list',
       
   809 		'html'          => true,
       
   810 		'exclude'       => '',
       
   811 		'include'       => '',
       
   812 	);
       
   813 
       
   814 	$args = wp_parse_args( $args, $defaults );
       
   815 
       
   816 	$return = '';
       
   817 
       
   818 	$query_args           = wp_array_slice_assoc( $args, array( 'orderby', 'order', 'number', 'exclude', 'include' ) );
       
   819 	$query_args['fields'] = 'ids';
       
   820 	$users                = get_users( $query_args );
       
   821 
       
   822 	foreach ( $users as $user_id ) {
       
   823 		$user = get_userdata( $user_id );
       
   824 
       
   825 		if ( $args['exclude_admin'] && 'admin' === $user->display_name ) {
       
   826 			continue;
       
   827 		}
       
   828 
       
   829 		if ( $args['show_fullname'] && '' !== $user->first_name && '' !== $user->last_name ) {
       
   830 			$name = "$user->first_name $user->last_name";
       
   831 		} else {
       
   832 			$name = $user->display_name;
       
   833 		}
       
   834 
       
   835 		if ( ! $args['html'] ) {
       
   836 			$return .= $name . ', ';
       
   837 
       
   838 			continue; // No need to go further to process HTML.
       
   839 		}
       
   840 
       
   841 		if ( 'list' === $args['style'] ) {
       
   842 			$return .= '<li>';
       
   843 		}
       
   844 
       
   845 		$row = $name;
       
   846 
       
   847 		if ( ! empty( $args['feed_image'] ) || ! empty( $args['feed'] ) ) {
       
   848 			$row .= ' ';
       
   849 			if ( empty( $args['feed_image'] ) ) {
       
   850 				$row .= '(';
       
   851 			}
       
   852 
       
   853 			$row .= '<a href="' . get_author_feed_link( $user->ID, $args['feed_type'] ) . '"';
       
   854 
       
   855 			$alt = '';
       
   856 			if ( ! empty( $args['feed'] ) ) {
       
   857 				$alt  = ' alt="' . esc_attr( $args['feed'] ) . '"';
       
   858 				$name = $args['feed'];
       
   859 			}
       
   860 
       
   861 			$row .= '>';
       
   862 
       
   863 			if ( ! empty( $args['feed_image'] ) ) {
       
   864 				$row .= '<img src="' . esc_url( $args['feed_image'] ) . '" style="border: none;"' . $alt . ' />';
       
   865 			} else {
       
   866 				$row .= $name;
       
   867 			}
       
   868 
       
   869 			$row .= '</a>';
       
   870 
       
   871 			if ( empty( $args['feed_image'] ) ) {
       
   872 				$row .= ')';
       
   873 			}
       
   874 		}
       
   875 
       
   876 		$return .= $row;
       
   877 		$return .= ( 'list' === $args['style'] ) ? '</li>' : ', ';
       
   878 	}
       
   879 
       
   880 	$return = rtrim( $return, ', ' );
       
   881 
       
   882 	if ( ! $args['echo'] ) {
       
   883 		return $return;
       
   884 	}
       
   885 	echo $return;
       
   886 }
       
   887 
       
   888 /**
       
   889  * Gets the sites a user belongs to.
   770  *
   890  *
   771  * @since 3.0.0
   891  * @since 3.0.0
   772  * @since 4.7.0 Converted to use `get_sites()`.
   892  * @since 4.7.0 Converted to use `get_sites()`.
   773  *
   893  *
   774  * @global wpdb $wpdb WordPress database abstraction object.
   894  * @global wpdb $wpdb WordPress database abstraction object.
   896 	 */
  1016 	 */
   897 	return apply_filters( 'get_blogs_of_user', $sites, $user_id, $all );
  1017 	return apply_filters( 'get_blogs_of_user', $sites, $user_id, $all );
   898 }
  1018 }
   899 
  1019 
   900 /**
  1020 /**
   901  * Find out whether a user is a member of a given blog.
  1021  * Finds out whether a user is a member of a given blog.
   902  *
  1022  *
   903  * @since MU (3.0.0)
  1023  * @since MU (3.0.0)
   904  *
  1024  *
   905  * @global wpdb $wpdb WordPress database abstraction object.
  1025  * @global wpdb $wpdb WordPress database abstraction object.
   906  *
  1026  *
   978 function add_user_meta( $user_id, $meta_key, $meta_value, $unique = false ) {
  1098 function add_user_meta( $user_id, $meta_key, $meta_value, $unique = false ) {
   979 	return add_metadata( 'user', $user_id, $meta_key, $meta_value, $unique );
  1099 	return add_metadata( 'user', $user_id, $meta_key, $meta_value, $unique );
   980 }
  1100 }
   981 
  1101 
   982 /**
  1102 /**
   983  * Remove metadata matching criteria from a user.
  1103  * Removes metadata matching criteria from a user.
   984  *
  1104  *
   985  * You can match based on the key, or key and value. Removing based on key and
  1105  * You can match based on the key, or key and value. Removing based on key and
   986  * value, will keep from removing duplicate metadata with the same key. It also
  1106  * value, will keep from removing duplicate metadata with the same key. It also
   987  * allows removing all metadata matching key, if needed.
  1107  * allows removing all metadata matching key, if needed.
   988  *
  1108  *
  1000 function delete_user_meta( $user_id, $meta_key, $meta_value = '' ) {
  1120 function delete_user_meta( $user_id, $meta_key, $meta_value = '' ) {
  1001 	return delete_metadata( 'user', $user_id, $meta_key, $meta_value );
  1121 	return delete_metadata( 'user', $user_id, $meta_key, $meta_value );
  1002 }
  1122 }
  1003 
  1123 
  1004 /**
  1124 /**
  1005  * Retrieve user meta field for a user.
  1125  * Retrieves user meta field for a user.
  1006  *
  1126  *
  1007  * @since 3.0.0
  1127  * @since 3.0.0
  1008  *
  1128  *
  1009  * @link https://developer.wordpress.org/reference/functions/get_user_meta/
  1129  * @link https://developer.wordpress.org/reference/functions/get_user_meta/
  1010  *
  1130  *
  1022 function get_user_meta( $user_id, $key = '', $single = false ) {
  1142 function get_user_meta( $user_id, $key = '', $single = false ) {
  1023 	return get_metadata( 'user', $user_id, $key, $single );
  1143 	return get_metadata( 'user', $user_id, $key, $single );
  1024 }
  1144 }
  1025 
  1145 
  1026 /**
  1146 /**
  1027  * Update user meta field based on user ID.
  1147  * Updates user meta field based on user ID.
  1028  *
  1148  *
  1029  * Use the $prev_value parameter to differentiate between meta fields with the
  1149  * Use the $prev_value parameter to differentiate between meta fields with the
  1030  * same key and user ID.
  1150  * same key and user ID.
  1031  *
  1151  *
  1032  * If the meta field for the user does not exist, it will be added.
  1152  * If the meta field for the user does not exist, it will be added.
  1048 function update_user_meta( $user_id, $meta_key, $meta_value, $prev_value = '' ) {
  1168 function update_user_meta( $user_id, $meta_key, $meta_value, $prev_value = '' ) {
  1049 	return update_metadata( 'user', $user_id, $meta_key, $meta_value, $prev_value );
  1169 	return update_metadata( 'user', $user_id, $meta_key, $meta_value, $prev_value );
  1050 }
  1170 }
  1051 
  1171 
  1052 /**
  1172 /**
  1053  * Count number of users who have each of the user roles.
  1173  * Counts number of users who have each of the user roles.
  1054  *
  1174  *
  1055  * Assumes there are neither duplicated nor orphaned capabilities meta_values.
  1175  * Assumes there are neither duplicated nor orphaned capabilities meta_values.
  1056  * Assumes role names are unique phrases. Same assumption made by WP_User_Query::prepare_query()
  1176  * Assumes role names are unique phrases. Same assumption made by WP_User_Query::prepare_query()
  1057  * Using $strategy = 'time' this is CPU-intensive and should handle around 10^7 users.
  1177  * Using $strategy = 'time' this is CPU-intensive and should handle around 10^7 users.
  1058  * Using $strategy = 'memory' this is memory-intensive and should handle around 10^5 users, but see WP Bug #12257.
  1178  * Using $strategy = 'memory' this is memory-intensive and should handle around 10^5 users, but see WP Bug #12257.
  1183 	}
  1303 	}
  1184 
  1304 
  1185 	return $result;
  1305 	return $result;
  1186 }
  1306 }
  1187 
  1307 
       
  1308 /**
       
  1309  * Returns the number of active users in your installation.
       
  1310  *
       
  1311  * Note that on a large site the count may be cached and only updated twice daily.
       
  1312  *
       
  1313  * @since MU (3.0.0)
       
  1314  * @since 4.8.0 The `$network_id` parameter has been added.
       
  1315  * @since 6.0.0 Moved to wp-includes/user.php.
       
  1316  *
       
  1317  * @param int|null $network_id ID of the network. Defaults to the current network.
       
  1318  * @return int Number of active users on the network.
       
  1319  */
       
  1320 function get_user_count( $network_id = null ) {
       
  1321 	if ( ! is_multisite() && null !== $network_id ) {
       
  1322 		_doing_it_wrong(
       
  1323 			__FUNCTION__,
       
  1324 			sprintf(
       
  1325 				/* translators: %s: $network_id */
       
  1326 				__( 'Unable to pass %s if not using multisite.' ),
       
  1327 				'<code>$network_id</code>'
       
  1328 			),
       
  1329 			'6.0.0'
       
  1330 		);
       
  1331 	}
       
  1332 
       
  1333 	return (int) get_network_option( $network_id, 'user_count', -1 );
       
  1334 }
       
  1335 
       
  1336 /**
       
  1337  * Updates the total count of users on the site if live user counting is enabled.
       
  1338  *
       
  1339  * @since 6.0.0
       
  1340  *
       
  1341  * @param int|null $network_id ID of the network. Defaults to the current network.
       
  1342  * @return bool Whether the update was successful.
       
  1343  */
       
  1344 function wp_maybe_update_user_counts( $network_id = null ) {
       
  1345 	if ( ! is_multisite() && null !== $network_id ) {
       
  1346 		_doing_it_wrong(
       
  1347 			__FUNCTION__,
       
  1348 			sprintf(
       
  1349 				/* translators: %s: $network_id */
       
  1350 				__( 'Unable to pass %s if not using multisite.' ),
       
  1351 				'<code>$network_id</code>'
       
  1352 			),
       
  1353 			'6.0.0'
       
  1354 		);
       
  1355 	}
       
  1356 
       
  1357 	$is_small_network = ! wp_is_large_user_count( $network_id );
       
  1358 	/** This filter is documented in wp-includes/ms-functions.php */
       
  1359 	if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'users' ) ) {
       
  1360 		return false;
       
  1361 	}
       
  1362 
       
  1363 	return wp_update_user_counts( $network_id );
       
  1364 }
       
  1365 
       
  1366 /**
       
  1367  * Updates the total count of users on the site.
       
  1368  *
       
  1369  * @global wpdb $wpdb WordPress database abstraction object.
       
  1370  * @since 6.0.0
       
  1371  *
       
  1372  * @param int|null $network_id ID of the network. Defaults to the current network.
       
  1373  * @return bool Whether the update was successful.
       
  1374  */
       
  1375 function wp_update_user_counts( $network_id = null ) {
       
  1376 	global $wpdb;
       
  1377 
       
  1378 	if ( ! is_multisite() && null !== $network_id ) {
       
  1379 		_doing_it_wrong(
       
  1380 			__FUNCTION__,
       
  1381 			sprintf(
       
  1382 				/* translators: %s: $network_id */
       
  1383 				__( 'Unable to pass %s if not using multisite.' ),
       
  1384 				'<code>$network_id</code>'
       
  1385 			),
       
  1386 			'6.0.0'
       
  1387 		);
       
  1388 	}
       
  1389 
       
  1390 	$query = "SELECT COUNT(ID) as c FROM $wpdb->users";
       
  1391 	if ( is_multisite() ) {
       
  1392 		$query .= " WHERE spam = '0' AND deleted = '0'";
       
  1393 	}
       
  1394 
       
  1395 	$count = $wpdb->get_var( $query );
       
  1396 
       
  1397 	return update_network_option( $network_id, 'user_count', $count );
       
  1398 }
       
  1399 
       
  1400 /**
       
  1401  * Schedules a recurring recalculation of the total count of users.
       
  1402  *
       
  1403  * @since 6.0.0
       
  1404  */
       
  1405 function wp_schedule_update_user_counts() {
       
  1406 	if ( ! is_main_site() ) {
       
  1407 		return;
       
  1408 	}
       
  1409 
       
  1410 	if ( ! wp_next_scheduled( 'wp_update_user_counts' ) && ! wp_installing() ) {
       
  1411 		wp_schedule_event( time(), 'twicedaily', 'wp_update_user_counts' );
       
  1412 	}
       
  1413 }
       
  1414 
       
  1415 /**
       
  1416  * Determines whether the site has a large number of users.
       
  1417  *
       
  1418  * The default criteria for a large site is more than 10,000 users.
       
  1419  *
       
  1420  * @since 6.0.0
       
  1421  *
       
  1422  * @param int|null $network_id ID of the network. Defaults to the current network.
       
  1423  * @return bool Whether the site has a large number of users.
       
  1424  */
       
  1425 function wp_is_large_user_count( $network_id = null ) {
       
  1426 	if ( ! is_multisite() && null !== $network_id ) {
       
  1427 		_doing_it_wrong(
       
  1428 			__FUNCTION__,
       
  1429 			sprintf(
       
  1430 				/* translators: %s: $network_id */
       
  1431 				__( 'Unable to pass %s if not using multisite.' ),
       
  1432 				'<code>$network_id</code>'
       
  1433 			),
       
  1434 			'6.0.0'
       
  1435 		);
       
  1436 	}
       
  1437 
       
  1438 	$count = get_user_count( $network_id );
       
  1439 
       
  1440 	/**
       
  1441 	 * Filters whether the site is considered large, based on its number of users.
       
  1442 	 *
       
  1443 	 * @since 6.0.0
       
  1444 	 *
       
  1445 	 * @param bool     $is_large_user_count Whether the site has a large number of users.
       
  1446 	 * @param int      $count               The total number of users.
       
  1447 	 * @param int|null $network_id          ID of the network. `null` represents the current network.
       
  1448 	 */
       
  1449 	return apply_filters( 'wp_is_large_user_count', $count > 10000, $count, $network_id );
       
  1450 }
       
  1451 
  1188 //
  1452 //
  1189 // Private helper functions.
  1453 // Private helper functions.
  1190 //
  1454 //
  1191 
  1455 
  1192 /**
  1456 /**
  1193  * Set up global user vars.
  1457  * Sets up global user vars.
  1194  *
  1458  *
  1195  * Used by wp_set_current_user() for back compat. Might be deprecated in the future.
  1459  * Used by wp_set_current_user() for back compat. Might be deprecated in the future.
  1196  *
  1460  *
  1197  * @since 2.0.4
  1461  * @since 2.0.4
  1198  *
  1462  *
  1233 	$user_url      = $user->user_url;
  1497 	$user_url      = $user->user_url;
  1234 	$user_identity = $user->display_name;
  1498 	$user_identity = $user->display_name;
  1235 }
  1499 }
  1236 
  1500 
  1237 /**
  1501 /**
  1238  * Create dropdown HTML content of users.
  1502  * Creates dropdown HTML content of users.
  1239  *
  1503  *
  1240  * The content can either be displayed, which it is by default or retrieved by
  1504  * The content can either be displayed, which it is by default or retrieved by
  1241  * setting the 'echo' argument. The 'include' and 'exclude' arguments do not
  1505  * setting the 'echo' argument. The 'include' and 'exclude' arguments do not
  1242  * need to be used; all users will be displayed in that case. Only one can be
  1506  * need to be used; all users will be displayed in that case. Only one can be
  1243  * used, either 'include' or 'exclude', but not both.
  1507  * used, either 'include' or 'exclude', but not both.
  1318 		'include_selected'        => false,
  1582 		'include_selected'        => false,
  1319 		'option_none_value'       => -1,
  1583 		'option_none_value'       => -1,
  1320 		'role'                    => '',
  1584 		'role'                    => '',
  1321 		'role__in'                => array(),
  1585 		'role__in'                => array(),
  1322 		'role__not_in'            => array(),
  1586 		'role__not_in'            => array(),
       
  1587 		'capability'              => '',
       
  1588 		'capability__in'          => array(),
       
  1589 		'capability__not_in'      => array(),
  1323 	);
  1590 	);
  1324 
  1591 
  1325 	$defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0;
  1592 	$defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0;
  1326 
  1593 
  1327 	$parsed_args = wp_parse_args( $args, $defaults );
  1594 	$parsed_args = wp_parse_args( $args, $defaults );
  1328 
  1595 
  1329 	$query_args = wp_array_slice_assoc( $parsed_args, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who', 'role', 'role__in', 'role__not_in' ) );
  1596 	$query_args = wp_array_slice_assoc(
       
  1597 		$parsed_args,
       
  1598 		array(
       
  1599 			'blog_id',
       
  1600 			'include',
       
  1601 			'exclude',
       
  1602 			'orderby',
       
  1603 			'order',
       
  1604 			'who',
       
  1605 			'role',
       
  1606 			'role__in',
       
  1607 			'role__not_in',
       
  1608 			'capability',
       
  1609 			'capability__in',
       
  1610 			'capability__not_in',
       
  1611 		)
       
  1612 	);
  1330 
  1613 
  1331 	$fields = array( 'ID', 'user_login' );
  1614 	$fields = array( 'ID', 'user_login' );
  1332 
  1615 
  1333 	$show = ! empty( $parsed_args['show'] ) ? $parsed_args['show'] : 'display_name';
  1616 	$show = ! empty( $parsed_args['show'] ) ? $parsed_args['show'] : 'display_name';
  1334 	if ( 'display_name_with_login' === $show ) {
  1617 	if ( 'display_name_with_login' === $show ) {
  1424 	}
  1707 	}
  1425 	return $html;
  1708 	return $html;
  1426 }
  1709 }
  1427 
  1710 
  1428 /**
  1711 /**
  1429  * Sanitize user field based on context.
  1712  * Sanitizes user field based on context.
  1430  *
  1713  *
  1431  * Possible context values are:  'raw', 'edit', 'db', 'display', 'attribute' and 'js'. The
  1714  * Possible context values are:  'raw', 'edit', 'db', 'display', 'attribute' and 'js'. The
  1432  * 'display' context is used by default. 'attribute' and 'js' contexts are treated like 'display'
  1715  * 'display' context is used by default. 'attribute' and 'js' contexts are treated like 'display'
  1433  * when calling filters.
  1716  * when calling filters.
  1434  *
  1717  *
  1542 
  1825 
  1543 	return $value;
  1826 	return $value;
  1544 }
  1827 }
  1545 
  1828 
  1546 /**
  1829 /**
  1547  * Update all user caches
  1830  * Updates all user caches.
  1548  *
  1831  *
  1549  * @since 3.0.0
  1832  * @since 3.0.0
  1550  *
  1833  *
  1551  * @param object|WP_User $user User object or database row to be cached
  1834  * @param object|WP_User $user User object or database row to be cached
  1552  * @return void|false Void on success, false on failure.
  1835  * @return void|false Void on success, false on failure.
  1565 	wp_cache_add( $user->user_email, $user->ID, 'useremail' );
  1848 	wp_cache_add( $user->user_email, $user->ID, 'useremail' );
  1566 	wp_cache_add( $user->user_nicename, $user->ID, 'userslugs' );
  1849 	wp_cache_add( $user->user_nicename, $user->ID, 'userslugs' );
  1567 }
  1850 }
  1568 
  1851 
  1569 /**
  1852 /**
  1570  * Clean all user caches
  1853  * Cleans all user caches.
  1571  *
  1854  *
  1572  * @since 3.0.0
  1855  * @since 3.0.0
  1573  * @since 4.4.0 'clean_user_cache' action was added.
  1856  * @since 4.4.0 'clean_user_cache' action was added.
  1574  * @since 5.8.0 Refreshes the global user instance if cleaning the user cache for the current user.
  1857  * @since 5.8.0 Refreshes the global user instance if cleaning the user cache for the current user.
  1575  *
  1858  *
  1698 	 */
  1981 	 */
  1699 	return apply_filters( 'validate_username', $valid, $username );
  1982 	return apply_filters( 'validate_username', $valid, $username );
  1700 }
  1983 }
  1701 
  1984 
  1702 /**
  1985 /**
  1703  * Insert a user into the database.
  1986  * Inserts a user into the database.
  1704  *
  1987  *
  1705  * Most of the `$userdata` array fields have filters associated with the values. Exceptions are
  1988  * Most of the `$userdata` array fields have filters associated with the values. Exceptions are
  1706  * 'ID', 'rich_editing', 'syntax_highlighting', 'comment_shortcuts', 'admin_color', 'use_ssl',
  1989  * 'ID', 'rich_editing', 'syntax_highlighting', 'comment_shortcuts', 'admin_color', 'use_ssl',
  1707  * 'user_registered', 'user_activation_key', 'spam', and 'role'. The filters have the prefix
  1990  * 'user_registered', 'user_activation_key', 'spam', and 'role'. The filters have the prefix
  1708  * 'pre_user_' followed by the field name. An example using 'description' would have the filter
  1991  * 'pre_user_' followed by the field name. An example using 'description' would have the filter
  1709  * called 'pre_user_description' that can be hooked into.
  1992  * called 'pre_user_description' that can be hooked into.
  1710  *
  1993  *
  1711  * @since 2.0.0
  1994  * @since 2.0.0
  1712  * @since 3.6.0 The `aim`, `jabber`, and `yim` fields were removed as default user contact
  1995  * @since 3.6.0 The `aim`, `jabber`, and `yim` fields were removed as default user contact
  1713  *              methods for new installations. See wp_get_user_contact_methods().
  1996  *              methods for new installations. See wp_get_user_contact_methods().
  1714  * @since 4.7.0 The user's locale can be passed to `$userdata`.
  1997  * @since 4.7.0 The `locale` field can be passed to `$userdata`.
  1715  * @since 5.3.0 The `user_activation_key` field can be passed to `$userdata`.
  1998  * @since 5.3.0 The `user_activation_key` field can be passed to `$userdata`.
  1716  * @since 5.3.0 The `spam` field can be passed to `$userdata` (Multisite only).
  1999  * @since 5.3.0 The `spam` field can be passed to `$userdata` (Multisite only).
       
  2000  * @since 5.9.0 The `meta_input` field can be passed to `$userdata` to allow addition of user meta data.
  1717  *
  2001  *
  1718  * @global wpdb $wpdb WordPress database abstraction object.
  2002  * @global wpdb $wpdb WordPress database abstraction object.
  1719  *
  2003  *
  1720  * @param array|object|WP_User $userdata {
  2004  * @param array|object|WP_User $userdata {
  1721  *     An array, object, or WP_User object of user data arguments.
  2005  *     An array, object, or WP_User object of user data arguments.
  1747  *                                        shortcuts for the user. Accepts 'true' or 'false'
  2031  *                                        shortcuts for the user. Accepts 'true' or 'false'
  1748  *                                        as a string literal, not boolean. Default 'false'.
  2032  *                                        as a string literal, not boolean. Default 'false'.
  1749  *     @type string $admin_color          Admin color scheme for the user. Default 'fresh'.
  2033  *     @type string $admin_color          Admin color scheme for the user. Default 'fresh'.
  1750  *     @type bool   $use_ssl              Whether the user should always access the admin over
  2034  *     @type bool   $use_ssl              Whether the user should always access the admin over
  1751  *                                        https. Default false.
  2035  *                                        https. Default false.
  1752  *     @type string $user_registered      Date the user registered. Format is 'Y-m-d H:i:s'.
  2036  *     @type string $user_registered      Date the user registered in UTC. Format is 'Y-m-d H:i:s'.
  1753  *     @type string $user_activation_key  Password reset key. Default empty.
  2037  *     @type string $user_activation_key  Password reset key. Default empty.
  1754  *     @type bool   $spam                 Multisite only. Whether the user is marked as spam.
  2038  *     @type bool   $spam                 Multisite only. Whether the user is marked as spam.
  1755  *                                        Default false.
  2039  *                                        Default false.
  1756  *     @type string $show_admin_bar_front Whether to display the Admin Bar for the user
  2040  *     @type string $show_admin_bar_front Whether to display the Admin Bar for the user
  1757  *                                        on the site's front end. Accepts 'true' or 'false'
  2041  *                                        on the site's front end. Accepts 'true' or 'false'
  1758  *                                        as a string literal, not boolean. Default 'true'.
  2042  *                                        as a string literal, not boolean. Default 'true'.
  1759  *     @type string $role                 User's role.
  2043  *     @type string $role                 User's role.
  1760  *     @type string $locale               User's locale. Default empty.
  2044  *     @type string $locale               User's locale. Default empty.
       
  2045  *     @type array  $meta_input           Array of custom user meta values keyed by meta key.
       
  2046  *                                        Default empty.
  1761  * }
  2047  * }
  1762  * @return int|WP_Error The newly created user's ID or a WP_Error object if the user could not
  2048  * @return int|WP_Error The newly created user's ID or a WP_Error object if the user could not
  1763  *                      be created.
  2049  *                      be created.
  1764  */
  2050  */
  1765 function wp_insert_user( $userdata ) {
  2051 function wp_insert_user( $userdata ) {
  1771 		$userdata = $userdata->to_array();
  2057 		$userdata = $userdata->to_array();
  1772 	}
  2058 	}
  1773 
  2059 
  1774 	// Are we updating or creating?
  2060 	// Are we updating or creating?
  1775 	if ( ! empty( $userdata['ID'] ) ) {
  2061 	if ( ! empty( $userdata['ID'] ) ) {
  1776 		$ID            = (int) $userdata['ID'];
  2062 		$user_id       = (int) $userdata['ID'];
  1777 		$update        = true;
  2063 		$update        = true;
  1778 		$old_user_data = get_userdata( $ID );
  2064 		$old_user_data = get_userdata( $user_id );
  1779 
  2065 
  1780 		if ( ! $old_user_data ) {
  2066 		if ( ! $old_user_data ) {
  1781 			return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) );
  2067 			return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) );
  1782 		}
  2068 		}
  1783 
  2069 
  1833 	 * If a nicename is provided, remove unsafe user characters before using it.
  2119 	 * If a nicename is provided, remove unsafe user characters before using it.
  1834 	 * Otherwise build a nicename from the user_login.
  2120 	 * Otherwise build a nicename from the user_login.
  1835 	 */
  2121 	 */
  1836 	if ( ! empty( $userdata['user_nicename'] ) ) {
  2122 	if ( ! empty( $userdata['user_nicename'] ) ) {
  1837 		$user_nicename = sanitize_user( $userdata['user_nicename'], true );
  2123 		$user_nicename = sanitize_user( $userdata['user_nicename'], true );
  1838 		if ( mb_strlen( $user_nicename ) > 50 ) {
       
  1839 			return new WP_Error( 'user_nicename_too_long', __( 'Nicename may not be longer than 50 characters.' ) );
       
  1840 		}
       
  1841 	} else {
  2124 	} else {
  1842 		$user_nicename = mb_substr( $user_login, 0, 50 );
  2125 		$user_nicename = mb_substr( $user_login, 0, 50 );
  1843 	}
  2126 	}
  1844 
  2127 
  1845 	$user_nicename = sanitize_title( $user_nicename );
  2128 	$user_nicename = sanitize_title( $user_nicename );
  1850 	 * @since 2.0.3
  2133 	 * @since 2.0.3
  1851 	 *
  2134 	 *
  1852 	 * @param string $user_nicename The user's nicename.
  2135 	 * @param string $user_nicename The user's nicename.
  1853 	 */
  2136 	 */
  1854 	$user_nicename = apply_filters( 'pre_user_nicename', $user_nicename );
  2137 	$user_nicename = apply_filters( 'pre_user_nicename', $user_nicename );
       
  2138 
       
  2139 	if ( mb_strlen( $user_nicename ) > 50 ) {
       
  2140 		return new WP_Error( 'user_nicename_too_long', __( 'Nicename may not be longer than 50 characters.' ) );
       
  2141 	}
  1855 
  2142 
  1856 	$user_nicename_check = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1", $user_nicename, $user_login ) );
  2143 	$user_nicename_check = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1", $user_nicename, $user_login ) );
  1857 
  2144 
  1858 	if ( $user_nicename_check ) {
  2145 	if ( $user_nicename_check ) {
  1859 		$suffix = 2;
  2146 		$suffix = 2;
  1898 	 * @since 2.0.3
  2185 	 * @since 2.0.3
  1899 	 *
  2186 	 *
  1900 	 * @param string $raw_user_url The user's URL.
  2187 	 * @param string $raw_user_url The user's URL.
  1901 	 */
  2188 	 */
  1902 	$user_url = apply_filters( 'pre_user_url', $raw_user_url );
  2189 	$user_url = apply_filters( 'pre_user_url', $raw_user_url );
       
  2190 
       
  2191 	if ( mb_strlen( $user_url ) > 100 ) {
       
  2192 		return new WP_Error( 'user_url_too_long', __( 'User URL may not be longer than 100 characters.' ) );
       
  2193 	}
  1903 
  2194 
  1904 	$user_registered = empty( $userdata['user_registered'] ) ? gmdate( 'Y-m-d H:i:s' ) : $userdata['user_registered'];
  2195 	$user_registered = empty( $userdata['user_registered'] ) ? gmdate( 'Y-m-d H:i:s' ) : $userdata['user_registered'];
  1905 
  2196 
  1906 	$user_activation_key = empty( $userdata['user_activation_key'] ) ? '' : $userdata['user_activation_key'];
  2197 	$user_activation_key = empty( $userdata['user_activation_key'] ) ? '' : $userdata['user_activation_key'];
  1907 
  2198 
  2014 	 * Filters user data before the record is created or updated.
  2305 	 * Filters user data before the record is created or updated.
  2015 	 *
  2306 	 *
  2016 	 * It only includes data in the users table, not any user metadata.
  2307 	 * It only includes data in the users table, not any user metadata.
  2017 	 *
  2308 	 *
  2018 	 * @since 4.9.0
  2309 	 * @since 4.9.0
  2019 	 * @since 5.8.0 The $userdata parameter was added.
  2310 	 * @since 5.8.0 The `$userdata` parameter was added.
  2020 	 *
  2311 	 *
  2021 	 * @param array    $data {
  2312 	 * @param array    $data {
  2022 	 *     Values and keys for the user.
  2313 	 *     Values and keys for the user.
  2023 	 *
  2314 	 *
  2024 	 *     @type string $user_login      The user's login. Only included if $update == false
  2315 	 *     @type string $user_login      The user's login. Only included if $update == false
  2029 	 *     @type string $display_name    The user's display name.
  2320 	 *     @type string $display_name    The user's display name.
  2030 	 *     @type string $user_registered MySQL timestamp describing the moment when the user registered. Defaults to
  2321 	 *     @type string $user_registered MySQL timestamp describing the moment when the user registered. Defaults to
  2031 	 *                                   the current UTC timestamp.
  2322 	 *                                   the current UTC timestamp.
  2032 	 * }
  2323 	 * }
  2033 	 * @param bool     $update   Whether the user is being updated rather than created.
  2324 	 * @param bool     $update   Whether the user is being updated rather than created.
  2034 	 * @param int|null $id       ID of the user to be updated, or NULL if the user is being created.
  2325 	 * @param int|null $user_id  ID of the user to be updated, or NULL if the user is being created.
  2035 	 * @param array    $userdata The raw array of data passed to wp_insert_user().
  2326 	 * @param array    $userdata The raw array of data passed to wp_insert_user().
  2036 	 */
  2327 	 */
  2037 	$data = apply_filters( 'wp_pre_insert_user_data', $data, $update, ( $update ? (int) $ID : null ), $userdata );
  2328 	$data = apply_filters( 'wp_pre_insert_user_data', $data, $update, ( $update ? $user_id : null ), $userdata );
  2038 
  2329 
  2039 	if ( empty( $data ) || ! is_array( $data ) ) {
  2330 	if ( empty( $data ) || ! is_array( $data ) ) {
  2040 		return new WP_Error( 'empty_data', __( 'Not enough data to create this user.' ) );
  2331 		return new WP_Error( 'empty_data', __( 'Not enough data to create this user.' ) );
  2041 	}
  2332 	}
  2042 
  2333 
  2043 	if ( $update ) {
  2334 	if ( $update ) {
  2044 		if ( $user_email !== $old_user_data->user_email || $user_pass !== $old_user_data->user_pass ) {
  2335 		if ( $user_email !== $old_user_data->user_email || $user_pass !== $old_user_data->user_pass ) {
  2045 			$data['user_activation_key'] = '';
  2336 			$data['user_activation_key'] = '';
  2046 		}
  2337 		}
  2047 		$wpdb->update( $wpdb->users, $data, compact( 'ID' ) );
  2338 		$wpdb->update( $wpdb->users, $data, array( 'ID' => $user_id ) );
  2048 		$user_id = (int) $ID;
       
  2049 	} else {
  2339 	} else {
  2050 		$wpdb->insert( $wpdb->users, $data );
  2340 		$wpdb->insert( $wpdb->users, $data );
  2051 		$user_id = (int) $wpdb->insert_id;
  2341 		$user_id = (int) $wpdb->insert_id;
  2052 	}
  2342 	}
  2053 
  2343 
  2057 	 * Filters a user's meta values and keys immediately after the user is created or updated
  2347 	 * Filters a user's meta values and keys immediately after the user is created or updated
  2058 	 * and before any user meta is inserted or updated.
  2348 	 * and before any user meta is inserted or updated.
  2059 	 *
  2349 	 *
  2060 	 * Does not include contact methods. These are added using `wp_get_user_contact_methods( $user )`.
  2350 	 * Does not include contact methods. These are added using `wp_get_user_contact_methods( $user )`.
  2061 	 *
  2351 	 *
       
  2352 	 * For custom meta fields, see the {@see 'insert_custom_user_meta'} filter.
       
  2353 	 *
  2062 	 * @since 4.4.0
  2354 	 * @since 4.4.0
  2063 	 * @since 5.8.0 The $userdata parameter was added.
  2355 	 * @since 5.8.0 The `$userdata` parameter was added.
  2064 	 *
  2356 	 *
  2065 	 * @param array $meta {
  2357 	 * @param array $meta {
  2066 	 *     Default meta values and keys for the user.
  2358 	 *     Default meta values and keys for the user.
  2067 	 *
  2359 	 *
  2068 	 *     @type string   $nickname             The user's nickname. Default is the user's username.
  2360 	 *     @type string   $nickname             The user's nickname. Default is the user's username.
  2083 	 * @param bool    $update   Whether the user is being updated rather than created.
  2375 	 * @param bool    $update   Whether the user is being updated rather than created.
  2084 	 * @param array   $userdata The raw array of data passed to wp_insert_user().
  2376 	 * @param array   $userdata The raw array of data passed to wp_insert_user().
  2085 	 */
  2377 	 */
  2086 	$meta = apply_filters( 'insert_user_meta', $meta, $user, $update, $userdata );
  2378 	$meta = apply_filters( 'insert_user_meta', $meta, $user, $update, $userdata );
  2087 
  2379 
       
  2380 	$custom_meta = array();
       
  2381 	if ( array_key_exists( 'meta_input', $userdata ) && is_array( $userdata['meta_input'] ) && ! empty( $userdata['meta_input'] ) ) {
       
  2382 		$custom_meta = $userdata['meta_input'];
       
  2383 	}
       
  2384 
       
  2385 	/**
       
  2386 	 * Filters a user's custom meta values and keys immediately after the user is created or updated
       
  2387 	 * and before any user meta is inserted or updated.
       
  2388 	 *
       
  2389 	 * For non-custom meta fields, see the {@see 'insert_user_meta'} filter.
       
  2390 	 *
       
  2391 	 * @since 5.9.0
       
  2392 	 *
       
  2393 	 * @param array   $custom_meta Array of custom user meta values keyed by meta key.
       
  2394 	 * @param WP_User $user        User object.
       
  2395 	 * @param bool    $update      Whether the user is being updated rather than created.
       
  2396 	 * @param array   $userdata    The raw array of data passed to wp_insert_user().
       
  2397 	 */
       
  2398 	$custom_meta = apply_filters( 'insert_custom_user_meta', $custom_meta, $user, $update, $userdata );
       
  2399 
       
  2400 	$meta = array_merge( $meta, $custom_meta );
       
  2401 
  2088 	// Update user meta.
  2402 	// Update user meta.
  2089 	foreach ( $meta as $key => $value ) {
  2403 	foreach ( $meta as $key => $value ) {
  2090 		update_user_meta( $user_id, $key, $value );
  2404 		update_user_meta( $user_id, $key, $value );
  2091 	}
  2405 	}
  2092 
  2406 
  2107 	if ( $update ) {
  2421 	if ( $update ) {
  2108 		/**
  2422 		/**
  2109 		 * Fires immediately after an existing user is updated.
  2423 		 * Fires immediately after an existing user is updated.
  2110 		 *
  2424 		 *
  2111 		 * @since 2.0.0
  2425 		 * @since 2.0.0
  2112 		 * @since 5.8.0 The $userdata parameter was added.
  2426 		 * @since 5.8.0 The `$userdata` parameter was added.
  2113 		 *
  2427 		 *
  2114 		 * @param int     $user_id       User ID.
  2428 		 * @param int     $user_id       User ID.
  2115 		 * @param WP_User $old_user_data Object containing user's data prior to update.
  2429 		 * @param WP_User $old_user_data Object containing user's data prior to update.
  2116 		 * @param array   $userdata      The raw array of data passed to wp_insert_user().
  2430 		 * @param array   $userdata      The raw array of data passed to wp_insert_user().
  2117 		 */
  2431 		 */
  2141 	} else {
  2455 	} else {
  2142 		/**
  2456 		/**
  2143 		 * Fires immediately after a new user is registered.
  2457 		 * Fires immediately after a new user is registered.
  2144 		 *
  2458 		 *
  2145 		 * @since 1.5.0
  2459 		 * @since 1.5.0
  2146 		 * @since 5.8.0 The $userdata parameter was added.
  2460 		 * @since 5.8.0 The `$userdata` parameter was added.
  2147 		 *
  2461 		 *
  2148 		 * @param int   $user_id  User ID.
  2462 		 * @param int   $user_id  User ID.
  2149 		 * @param array $userdata The raw array of data passed to wp_insert_user().
  2463 		 * @param array $userdata The raw array of data passed to wp_insert_user().
  2150 		 */
  2464 		 */
  2151 		do_action( 'user_register', $user_id, $userdata );
  2465 		do_action( 'user_register', $user_id, $userdata );
  2153 
  2467 
  2154 	return $user_id;
  2468 	return $user_id;
  2155 }
  2469 }
  2156 
  2470 
  2157 /**
  2471 /**
  2158  * Update a user in the database.
  2472  * Updates a user in the database.
  2159  *
  2473  *
  2160  * It is possible to update a user's password by specifying the 'user_pass'
  2474  * It is possible to update a user's password by specifying the 'user_pass'
  2161  * value in the $userdata parameter array.
  2475  * value in the $userdata parameter array.
  2162  *
  2476  *
  2163  * If current user's password is being updated, then the cookies will be
  2477  * If current user's password is being updated, then the cookies will be
  2175 		$userdata = get_object_vars( $userdata );
  2489 		$userdata = get_object_vars( $userdata );
  2176 	} elseif ( $userdata instanceof WP_User ) {
  2490 	} elseif ( $userdata instanceof WP_User ) {
  2177 		$userdata = $userdata->to_array();
  2491 		$userdata = $userdata->to_array();
  2178 	}
  2492 	}
  2179 
  2493 
  2180 	$ID = isset( $userdata['ID'] ) ? (int) $userdata['ID'] : 0;
  2494 	$user_id = isset( $userdata['ID'] ) ? (int) $userdata['ID'] : 0;
  2181 	if ( ! $ID ) {
  2495 	if ( ! $user_id ) {
  2182 		return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) );
  2496 		return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) );
  2183 	}
  2497 	}
  2184 
  2498 
  2185 	// First, get all of the original fields.
  2499 	// First, get all of the original fields.
  2186 	$user_obj = get_userdata( $ID );
  2500 	$user_obj = get_userdata( $user_id );
  2187 	if ( ! $user_obj ) {
  2501 	if ( ! $user_obj ) {
  2188 		return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) );
  2502 		return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) );
  2189 	}
  2503 	}
  2190 
  2504 
  2191 	$user = $user_obj->to_array();
  2505 	$user = $user_obj->to_array();
  2192 
  2506 
  2193 	// Add additional custom fields.
  2507 	// Add additional custom fields.
  2194 	foreach ( _get_additional_user_keys( $user_obj ) as $key ) {
  2508 	foreach ( _get_additional_user_keys( $user_obj ) as $key ) {
  2195 		$user[ $key ] = get_user_meta( $ID, $key, true );
  2509 		$user[ $key ] = get_user_meta( $user_id, $key, true );
  2196 	}
  2510 	}
  2197 
  2511 
  2198 	// Escape data pulled from DB.
  2512 	// Escape data pulled from DB.
  2199 	$user = add_magic_quotes( $user );
  2513 	$user = add_magic_quotes( $user );
  2200 
  2514 
  2236 
  2550 
  2237 	// Merge old and new fields with new fields overwriting old ones.
  2551 	// Merge old and new fields with new fields overwriting old ones.
  2238 	$userdata = array_merge( $user, $userdata );
  2552 	$userdata = array_merge( $user, $userdata );
  2239 	$user_id  = wp_insert_user( $userdata );
  2553 	$user_id  = wp_insert_user( $userdata );
  2240 
  2554 
  2241 	if ( ! is_wp_error( $user_id ) ) {
  2555 	if ( is_wp_error( $user_id ) ) {
  2242 
  2556 		return $user_id;
  2243 		$blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
  2557 	}
  2244 
  2558 
  2245 		$switched_locale = false;
  2559 	$blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
  2246 		if ( ! empty( $send_password_change_email ) || ! empty( $send_email_change_email ) ) {
  2560 
  2247 			$switched_locale = switch_to_locale( get_user_locale( $user_id ) );
  2561 	$switched_locale = false;
  2248 		}
  2562 	if ( ! empty( $send_password_change_email ) || ! empty( $send_email_change_email ) ) {
  2249 
  2563 		$switched_locale = switch_to_locale( get_user_locale( $user_id ) );
  2250 		if ( ! empty( $send_password_change_email ) ) {
  2564 	}
  2251 			/* translators: Do not translate USERNAME, ADMIN_EMAIL, EMAIL, SITENAME, SITEURL: those are placeholders. */
  2565 
  2252 			$pass_change_text = __(
  2566 	if ( ! empty( $send_password_change_email ) ) {
  2253 				'Hi ###USERNAME###,
  2567 		/* translators: Do not translate USERNAME, ADMIN_EMAIL, EMAIL, SITENAME, SITEURL: those are placeholders. */
       
  2568 		$pass_change_text = __(
       
  2569 			'Hi ###USERNAME###,
  2254 
  2570 
  2255 This notice confirms that your password was changed on ###SITENAME###.
  2571 This notice confirms that your password was changed on ###SITENAME###.
  2256 
  2572 
  2257 If you did not change your password, please contact the Site Administrator at
  2573 If you did not change your password, please contact the Site Administrator at
  2258 ###ADMIN_EMAIL###
  2574 ###ADMIN_EMAIL###
  2260 This email has been sent to ###EMAIL###
  2576 This email has been sent to ###EMAIL###
  2261 
  2577 
  2262 Regards,
  2578 Regards,
  2263 All at ###SITENAME###
  2579 All at ###SITENAME###
  2264 ###SITEURL###'
  2580 ###SITEURL###'
  2265 			);
  2581 		);
  2266 
  2582 
  2267 			$pass_change_email = array(
  2583 		$pass_change_email = array(
  2268 				'to'      => $user['user_email'],
  2584 			'to'      => $user['user_email'],
  2269 				/* translators: Password change notification email subject. %s: Site title. */
  2585 			/* translators: Password change notification email subject. %s: Site title. */
  2270 				'subject' => __( '[%s] Password Changed' ),
  2586 			'subject' => __( '[%s] Password Changed' ),
  2271 				'message' => $pass_change_text,
  2587 			'message' => $pass_change_text,
  2272 				'headers' => '',
  2588 			'headers' => '',
  2273 			);
  2589 		);
  2274 
  2590 
  2275 			/**
  2591 		/**
  2276 			 * Filters the contents of the email sent when the user's password is changed.
  2592 		 * Filters the contents of the email sent when the user's password is changed.
  2277 			 *
  2593 		 *
  2278 			 * @since 4.3.0
  2594 		 * @since 4.3.0
  2279 			 *
  2595 		 *
  2280 			 * @param array $pass_change_email {
  2596 		 * @param array $pass_change_email {
  2281 			 *     Used to build wp_mail().
  2597 		 *     Used to build wp_mail().
  2282 			 *
  2598 		 *
  2283 			 *     @type string $to      The intended recipients. Add emails in a comma separated string.
  2599 		 *     @type string $to      The intended recipients. Add emails in a comma separated string.
  2284 			 *     @type string $subject The subject of the email.
  2600 		 *     @type string $subject The subject of the email.
  2285 			 *     @type string $message The content of the email.
  2601 		 *     @type string $message The content of the email.
  2286 			 *         The following strings have a special meaning and will get replaced dynamically:
  2602 		 *         The following strings have a special meaning and will get replaced dynamically:
  2287 			 *         - ###USERNAME###    The current user's username.
  2603 		 *         - ###USERNAME###    The current user's username.
  2288 			 *         - ###ADMIN_EMAIL### The admin email in case this was unexpected.
  2604 		 *         - ###ADMIN_EMAIL### The admin email in case this was unexpected.
  2289 			 *         - ###EMAIL###       The user's email address.
  2605 		 *         - ###EMAIL###       The user's email address.
  2290 			 *         - ###SITENAME###    The name of the site.
  2606 		 *         - ###SITENAME###    The name of the site.
  2291 			 *         - ###SITEURL###     The URL to the site.
  2607 		 *         - ###SITEURL###     The URL to the site.
  2292 			 *     @type string $headers Headers. Add headers in a newline (\r\n) separated string.
  2608 		 *     @type string $headers Headers. Add headers in a newline (\r\n) separated string.
  2293 			 * }
  2609 		 * }
  2294 			 * @param array $user     The original user array.
  2610 		 * @param array $user     The original user array.
  2295 			 * @param array $userdata The updated user array.
  2611 		 * @param array $userdata The updated user array.
  2296 			 */
  2612 		 */
  2297 			$pass_change_email = apply_filters( 'password_change_email', $pass_change_email, $user, $userdata );
  2613 		$pass_change_email = apply_filters( 'password_change_email', $pass_change_email, $user, $userdata );
  2298 
  2614 
  2299 			$pass_change_email['message'] = str_replace( '###USERNAME###', $user['user_login'], $pass_change_email['message'] );
  2615 		$pass_change_email['message'] = str_replace( '###USERNAME###', $user['user_login'], $pass_change_email['message'] );
  2300 			$pass_change_email['message'] = str_replace( '###ADMIN_EMAIL###', get_option( 'admin_email' ), $pass_change_email['message'] );
  2616 		$pass_change_email['message'] = str_replace( '###ADMIN_EMAIL###', get_option( 'admin_email' ), $pass_change_email['message'] );
  2301 			$pass_change_email['message'] = str_replace( '###EMAIL###', $user['user_email'], $pass_change_email['message'] );
  2617 		$pass_change_email['message'] = str_replace( '###EMAIL###', $user['user_email'], $pass_change_email['message'] );
  2302 			$pass_change_email['message'] = str_replace( '###SITENAME###', $blog_name, $pass_change_email['message'] );
  2618 		$pass_change_email['message'] = str_replace( '###SITENAME###', $blog_name, $pass_change_email['message'] );
  2303 			$pass_change_email['message'] = str_replace( '###SITEURL###', home_url(), $pass_change_email['message'] );
  2619 		$pass_change_email['message'] = str_replace( '###SITEURL###', home_url(), $pass_change_email['message'] );
  2304 
  2620 
  2305 			wp_mail( $pass_change_email['to'], sprintf( $pass_change_email['subject'], $blog_name ), $pass_change_email['message'], $pass_change_email['headers'] );
  2621 		wp_mail( $pass_change_email['to'], sprintf( $pass_change_email['subject'], $blog_name ), $pass_change_email['message'], $pass_change_email['headers'] );
  2306 		}
  2622 	}
  2307 
  2623 
  2308 		if ( ! empty( $send_email_change_email ) ) {
  2624 	if ( ! empty( $send_email_change_email ) ) {
  2309 			/* translators: Do not translate USERNAME, ADMIN_EMAIL, NEW_EMAIL, EMAIL, SITENAME, SITEURL: those are placeholders. */
  2625 		/* translators: Do not translate USERNAME, ADMIN_EMAIL, NEW_EMAIL, EMAIL, SITENAME, SITEURL: those are placeholders. */
  2310 			$email_change_text = __(
  2626 		$email_change_text = __(
  2311 				'Hi ###USERNAME###,
  2627 			'Hi ###USERNAME###,
  2312 
  2628 
  2313 This notice confirms that your email address on ###SITENAME### was changed to ###NEW_EMAIL###.
  2629 This notice confirms that your email address on ###SITENAME### was changed to ###NEW_EMAIL###.
  2314 
  2630 
  2315 If you did not change your email, please contact the Site Administrator at
  2631 If you did not change your email, please contact the Site Administrator at
  2316 ###ADMIN_EMAIL###
  2632 ###ADMIN_EMAIL###
  2318 This email has been sent to ###EMAIL###
  2634 This email has been sent to ###EMAIL###
  2319 
  2635 
  2320 Regards,
  2636 Regards,
  2321 All at ###SITENAME###
  2637 All at ###SITENAME###
  2322 ###SITEURL###'
  2638 ###SITEURL###'
  2323 			);
  2639 		);
  2324 
  2640 
  2325 			$email_change_email = array(
  2641 		$email_change_email = array(
  2326 				'to'      => $user['user_email'],
  2642 			'to'      => $user['user_email'],
  2327 				/* translators: Email change notification email subject. %s: Site title. */
  2643 			/* translators: Email change notification email subject. %s: Site title. */
  2328 				'subject' => __( '[%s] Email Changed' ),
  2644 			'subject' => __( '[%s] Email Changed' ),
  2329 				'message' => $email_change_text,
  2645 			'message' => $email_change_text,
  2330 				'headers' => '',
  2646 			'headers' => '',
  2331 			);
  2647 		);
  2332 
  2648 
  2333 			/**
  2649 		/**
  2334 			 * Filters the contents of the email sent when the user's email is changed.
  2650 		 * Filters the contents of the email sent when the user's email is changed.
  2335 			 *
  2651 		 *
  2336 			 * @since 4.3.0
  2652 		 * @since 4.3.0
  2337 			 *
  2653 		 *
  2338 			 * @param array $email_change_email {
  2654 		 * @param array $email_change_email {
  2339 			 *     Used to build wp_mail().
  2655 		 *     Used to build wp_mail().
  2340 			 *
  2656 		 *
  2341 			 *     @type string $to      The intended recipients.
  2657 		 *     @type string $to      The intended recipients.
  2342 			 *     @type string $subject The subject of the email.
  2658 		 *     @type string $subject The subject of the email.
  2343 			 *     @type string $message The content of the email.
  2659 		 *     @type string $message The content of the email.
  2344 			 *         The following strings have a special meaning and will get replaced dynamically:
  2660 		 *         The following strings have a special meaning and will get replaced dynamically:
  2345 			 *         - ###USERNAME###    The current user's username.
  2661 		 *         - ###USERNAME###    The current user's username.
  2346 			 *         - ###ADMIN_EMAIL### The admin email in case this was unexpected.
  2662 		 *         - ###ADMIN_EMAIL### The admin email in case this was unexpected.
  2347 			 *         - ###NEW_EMAIL###   The new email address.
  2663 		 *         - ###NEW_EMAIL###   The new email address.
  2348 			 *         - ###EMAIL###       The old email address.
  2664 		 *         - ###EMAIL###       The old email address.
  2349 			 *         - ###SITENAME###    The name of the site.
  2665 		 *         - ###SITENAME###    The name of the site.
  2350 			 *         - ###SITEURL###     The URL to the site.
  2666 		 *         - ###SITEURL###     The URL to the site.
  2351 			 *     @type string $headers Headers.
  2667 		 *     @type string $headers Headers.
  2352 			 * }
  2668 		 * }
  2353 			 * @param array $user     The original user array.
  2669 		 * @param array $user     The original user array.
  2354 			 * @param array $userdata The updated user array.
  2670 		 * @param array $userdata The updated user array.
  2355 			 */
  2671 		 */
  2356 			$email_change_email = apply_filters( 'email_change_email', $email_change_email, $user, $userdata );
  2672 		$email_change_email = apply_filters( 'email_change_email', $email_change_email, $user, $userdata );
  2357 
  2673 
  2358 			$email_change_email['message'] = str_replace( '###USERNAME###', $user['user_login'], $email_change_email['message'] );
  2674 		$email_change_email['message'] = str_replace( '###USERNAME###', $user['user_login'], $email_change_email['message'] );
  2359 			$email_change_email['message'] = str_replace( '###ADMIN_EMAIL###', get_option( 'admin_email' ), $email_change_email['message'] );
  2675 		$email_change_email['message'] = str_replace( '###ADMIN_EMAIL###', get_option( 'admin_email' ), $email_change_email['message'] );
  2360 			$email_change_email['message'] = str_replace( '###NEW_EMAIL###', $userdata['user_email'], $email_change_email['message'] );
  2676 		$email_change_email['message'] = str_replace( '###NEW_EMAIL###', $userdata['user_email'], $email_change_email['message'] );
  2361 			$email_change_email['message'] = str_replace( '###EMAIL###', $user['user_email'], $email_change_email['message'] );
  2677 		$email_change_email['message'] = str_replace( '###EMAIL###', $user['user_email'], $email_change_email['message'] );
  2362 			$email_change_email['message'] = str_replace( '###SITENAME###', $blog_name, $email_change_email['message'] );
  2678 		$email_change_email['message'] = str_replace( '###SITENAME###', $blog_name, $email_change_email['message'] );
  2363 			$email_change_email['message'] = str_replace( '###SITEURL###', home_url(), $email_change_email['message'] );
  2679 		$email_change_email['message'] = str_replace( '###SITEURL###', home_url(), $email_change_email['message'] );
  2364 
  2680 
  2365 			wp_mail( $email_change_email['to'], sprintf( $email_change_email['subject'], $blog_name ), $email_change_email['message'], $email_change_email['headers'] );
  2681 		wp_mail( $email_change_email['to'], sprintf( $email_change_email['subject'], $blog_name ), $email_change_email['message'], $email_change_email['headers'] );
  2366 		}
  2682 	}
  2367 
  2683 
  2368 		if ( $switched_locale ) {
  2684 	if ( $switched_locale ) {
  2369 			restore_previous_locale();
  2685 		restore_previous_locale();
  2370 		}
       
  2371 	}
  2686 	}
  2372 
  2687 
  2373 	// Update the cookies if the password changed.
  2688 	// Update the cookies if the password changed.
  2374 	$current_user = wp_get_current_user();
  2689 	$current_user = wp_get_current_user();
  2375 	if ( $current_user->ID == $ID ) {
  2690 	if ( $current_user->ID == $user_id ) {
  2376 		if ( isset( $plaintext_pass ) ) {
  2691 		if ( isset( $plaintext_pass ) ) {
  2377 			wp_clear_auth_cookie();
  2692 			wp_clear_auth_cookie();
  2378 
  2693 
  2379 			// Here we calculate the expiration length of the current auth cookie and compare it to the default expiration.
  2694 			// Here we calculate the expiration length of the current auth cookie and compare it to the default expiration.
  2380 			// If it's greater than this, then we know the user checked 'Remember Me' when they logged in.
  2695 			// If it's greater than this, then we know the user checked 'Remember Me' when they logged in.
  2381 			$logged_in_cookie = wp_parse_auth_cookie( '', 'logged_in' );
  2696 			$logged_in_cookie = wp_parse_auth_cookie( '', 'logged_in' );
  2382 			/** This filter is documented in wp-includes/pluggable.php */
  2697 			/** This filter is documented in wp-includes/pluggable.php */
  2383 			$default_cookie_life = apply_filters( 'auth_cookie_expiration', ( 2 * DAY_IN_SECONDS ), $ID, false );
  2698 			$default_cookie_life = apply_filters( 'auth_cookie_expiration', ( 2 * DAY_IN_SECONDS ), $user_id, false );
  2384 			$remember            = false;
  2699 			$remember            = false;
  2385 			if ( false !== $logged_in_cookie && ( $logged_in_cookie['expiration'] - time() ) > $default_cookie_life ) {
  2700 			if ( false !== $logged_in_cookie && ( $logged_in_cookie['expiration'] - time() ) > $default_cookie_life ) {
  2386 				$remember = true;
  2701 				$remember = true;
  2387 			}
  2702 			}
  2388 
  2703 
  2389 			wp_set_auth_cookie( $ID, $remember );
  2704 			wp_set_auth_cookie( $user_id, $remember );
  2390 		}
  2705 		}
  2391 	}
  2706 	}
  2392 
  2707 
  2393 	return $user_id;
  2708 	return $user_id;
  2394 }
  2709 }
  2395 
  2710 
  2396 /**
  2711 /**
  2397  * A simpler way of inserting a user into the database.
  2712  * Provides a simpler way of inserting a user into the database.
  2398  *
  2713  *
  2399  * Creates a new user with just the username, password, and email. For more
  2714  * Creates a new user with just the username, password, and email. For more
  2400  * complex user creation use wp_insert_user() to specify more information.
  2715  * complex user creation use wp_insert_user() to specify more information.
  2401  *
  2716  *
  2402  * @since 2.0.0
  2717  * @since 2.0.0
  2434 	$keys = array( 'first_name', 'last_name', 'nickname', 'description', 'rich_editing', 'syntax_highlighting', 'comment_shortcuts', 'admin_color', 'use_ssl', 'show_admin_bar_front', 'locale' );
  2749 	$keys = array( 'first_name', 'last_name', 'nickname', 'description', 'rich_editing', 'syntax_highlighting', 'comment_shortcuts', 'admin_color', 'use_ssl', 'show_admin_bar_front', 'locale' );
  2435 	return array_merge( $keys, array_keys( wp_get_user_contact_methods( $user ) ) );
  2750 	return array_merge( $keys, array_keys( wp_get_user_contact_methods( $user ) ) );
  2436 }
  2751 }
  2437 
  2752 
  2438 /**
  2753 /**
  2439  * Set up the user contact methods.
  2754  * Sets up the user contact methods.
  2440  *
  2755  *
  2441  * Default contact methods were removed in 3.6. A filter dictates contact methods.
  2756  * Default contact methods were removed in 3.6. A filter dictates contact methods.
  2442  *
  2757  *
  2443  * @since 3.7.0
  2758  * @since 3.7.0
  2444  *
  2759  *
  2445  * @param WP_User $user Optional. WP_User object.
  2760  * @param WP_User|null $user Optional. WP_User object.
  2446  * @return string[] Array of contact method labels keyed by contact method.
  2761  * @return string[] Array of contact method labels keyed by contact method.
  2447  */
  2762  */
  2448 function wp_get_user_contact_methods( $user = null ) {
  2763 function wp_get_user_contact_methods( $user = null ) {
  2449 	$methods = array();
  2764 	$methods = array();
  2450 	if ( get_site_option( 'initial_db_version' ) < 23588 ) {
  2765 	if ( get_site_option( 'initial_db_version' ) < 23588 ) {
  2458 	/**
  2773 	/**
  2459 	 * Filters the user contact methods.
  2774 	 * Filters the user contact methods.
  2460 	 *
  2775 	 *
  2461 	 * @since 2.9.0
  2776 	 * @since 2.9.0
  2462 	 *
  2777 	 *
  2463 	 * @param string[] $methods Array of contact method labels keyed by contact method.
  2778 	 * @param string[]     $methods Array of contact method labels keyed by contact method.
  2464 	 * @param WP_User  $user    WP_User object.
  2779 	 * @param WP_User|null $user    WP_User object or null if none was provided.
  2465 	 */
  2780 	 */
  2466 	return apply_filters( 'user_contactmethods', $methods, $user );
  2781 	return apply_filters( 'user_contactmethods', $methods, $user );
  2467 }
  2782 }
  2468 
  2783 
  2469 /**
  2784 /**
  2472  * Use wp_get_user_contact_methods() instead.
  2787  * Use wp_get_user_contact_methods() instead.
  2473  *
  2788  *
  2474  * @since 2.9.0
  2789  * @since 2.9.0
  2475  * @access private
  2790  * @access private
  2476  *
  2791  *
  2477  * @param WP_User $user Optional. WP_User object. Default null.
  2792  * @param WP_User|null $user Optional. WP_User object. Default null.
  2478  * @return string[] Array of contact method labels keyed by contact method.
  2793  * @return string[] Array of contact method labels keyed by contact method.
  2479  */
  2794  */
  2480 function _wp_get_user_contactmethods( $user = null ) {
  2795 function _wp_get_user_contactmethods( $user = null ) {
  2481 	return wp_get_user_contact_methods( $user );
  2796 	return wp_get_user_contact_methods( $user );
  2482 }
  2797 }
  2547 	/**
  2862 	/**
  2548 	 * Filters whether to allow a password to be reset.
  2863 	 * Filters whether to allow a password to be reset.
  2549 	 *
  2864 	 *
  2550 	 * @since 2.7.0
  2865 	 * @since 2.7.0
  2551 	 *
  2866 	 *
  2552 	 * @param bool $allow Whether to allow the password to be reset. Default true.
  2867 	 * @param bool $allow   Whether to allow the password to be reset. Default true.
  2553 	 * @param int  $ID    The ID of the user attempting to reset a password.
  2868 	 * @param int  $user_id The ID of the user attempting to reset a password.
  2554 	 */
  2869 	 */
  2555 	$allow = apply_filters( 'allow_password_reset', $allow, $user->ID );
  2870 	$allow = apply_filters( 'allow_password_reset', $allow, $user->ID );
  2556 
  2871 
  2557 	if ( ! $allow ) {
  2872 	if ( ! $allow ) {
  2558 		return new WP_Error( 'no_password_reset', __( 'Password reset is not allowed for this user' ) );
  2873 		return new WP_Error( 'no_password_reset', __( 'Password reset is not allowed for this user' ) );
  2594 
  2909 
  2595 	return $key;
  2910 	return $key;
  2596 }
  2911 }
  2597 
  2912 
  2598 /**
  2913 /**
  2599  * Retrieves a user row based on password reset key and login
  2914  * Retrieves a user row based on password reset key and login.
  2600  *
  2915  *
  2601  * A key is considered 'expired' if it exactly matches the value of the
  2916  * A key is considered 'expired' if it exactly matches the value of the
  2602  * user_activation_key field, rather than being matched after going through the
  2917  * user_activation_key field, rather than being matched after going through the
  2603  * hashing process. This field is now hashed; old values are no longer accepted
  2918  * hashing process. This field is now hashed; old values are no longer accepted
  2604  * but have a different WP_Error code so good user feedback can be provided.
  2919  * but have a different WP_Error code so good user feedback can be provided.
  2770 	if ( ! $user_data ) {
  3085 	if ( ! $user_data ) {
  2771 		$errors->add( 'invalidcombo', __( '<strong>Error</strong>: There is no account with that username or email address.' ) );
  3086 		$errors->add( 'invalidcombo', __( '<strong>Error</strong>: There is no account with that username or email address.' ) );
  2772 		return $errors;
  3087 		return $errors;
  2773 	}
  3088 	}
  2774 
  3089 
       
  3090 	/**
       
  3091 	 * Filters whether to send the retrieve password email.
       
  3092 	 *
       
  3093 	 * Return false to disable sending the email.
       
  3094 	 *
       
  3095 	 * @since 6.0.0
       
  3096 	 *
       
  3097 	 * @param bool    $send       Whether to send the email.
       
  3098 	 * @param string  $user_login The username for the user.
       
  3099 	 * @param WP_User $user_data  WP_User object.
       
  3100 	 */
       
  3101 	if ( ! apply_filters( 'send_retrieve_password_email', true, $user_login, $user_data ) ) {
       
  3102 		return true;
       
  3103 	}
       
  3104 
  2775 	// Redefining user_login ensures we return the right case in the email.
  3105 	// Redefining user_login ensures we return the right case in the email.
  2776 	$user_login = $user_data->user_login;
  3106 	$user_login = $user_data->user_login;
  2777 	$user_email = $user_data->user_email;
  3107 	$user_email = $user_data->user_email;
  2778 	$key        = get_password_reset_key( $user_data );
  3108 	$key        = get_password_reset_key( $user_data );
  2779 
  3109 
  2844 	 * @param string  $user_login The username for the user.
  3174 	 * @param string  $user_login The username for the user.
  2845 	 * @param WP_User $user_data  WP_User object.
  3175 	 * @param WP_User $user_data  WP_User object.
  2846 	 */
  3176 	 */
  2847 	$message = apply_filters( 'retrieve_password_message', $message, $key, $user_login, $user_data );
  3177 	$message = apply_filters( 'retrieve_password_message', $message, $key, $user_login, $user_data );
  2848 
  3178 
       
  3179 	// Short-circuit on falsey $message value for backwards compatibility.
       
  3180 	if ( ! $message ) {
       
  3181 		return true;
       
  3182 	}
       
  3183 
       
  3184 	/*
       
  3185 	 * Wrap the single notification email arguments in an array
       
  3186 	 * to pass them to the retrieve_password_notification_email filter.
       
  3187 	 */
       
  3188 	$defaults = array(
       
  3189 		'to'      => $user_email,
       
  3190 		'subject' => $title,
       
  3191 		'message' => $message,
       
  3192 		'headers' => '',
       
  3193 	);
       
  3194 
       
  3195 	/**
       
  3196 	 * Filters the contents of the reset password notification email sent to the user.
       
  3197 	 *
       
  3198 	 * @since 6.0.0
       
  3199 	 *
       
  3200 	 * @param array $defaults {
       
  3201 	 *     The default notification email arguments. Used to build wp_mail().
       
  3202 	 *
       
  3203 	 *     @type string $to      The intended recipient - user email address.
       
  3204 	 *     @type string $subject The subject of the email.
       
  3205 	 *     @type string $message The body of the email.
       
  3206 	 *     @type string $headers The headers of the email.
       
  3207 	 * }
       
  3208 	 * @type string  $key        The activation key.
       
  3209 	 * @type string  $user_login The username for the user.
       
  3210 	 * @type WP_User $user_data  WP_User object.
       
  3211 	 */
       
  3212 	$notification_email = apply_filters( 'retrieve_password_notification_email', $defaults, $key, $user_login, $user_data );
       
  3213 
  2849 	if ( $switched_locale ) {
  3214 	if ( $switched_locale ) {
  2850 		restore_previous_locale();
  3215 		restore_previous_locale();
  2851 	}
  3216 	}
  2852 
  3217 
  2853 	if ( $message && ! wp_mail( $user_email, wp_specialchars_decode( $title ), $message ) ) {
  3218 	if ( is_array( $notification_email ) ) {
       
  3219 		// Force key order and merge defaults in case any value is missing in the filtered array.
       
  3220 		$notification_email = array_merge( $defaults, $notification_email );
       
  3221 	} else {
       
  3222 		$notification_email = $defaults;
       
  3223 	}
       
  3224 
       
  3225 	list( $to, $subject, $message, $headers ) = array_values( $notification_email );
       
  3226 
       
  3227 	$subject = wp_specialchars_decode( $subject );
       
  3228 
       
  3229 	if ( ! wp_mail( $to, $subject, $message, $headers ) ) {
  2854 		$errors->add(
  3230 		$errors->add(
  2855 			'retrieve_password_email_failure',
  3231 			'retrieve_password_email_failure',
  2856 			sprintf(
  3232 			sprintf(
  2857 				/* translators: %s: Documentation URL. */
  3233 				/* translators: %s: Documentation URL. */
  2858 				__( '<strong>Error</strong>: The email could not be sent. Your site may not be correctly configured to send emails. <a href="%s">Get support for resetting your password</a>.' ),
  3234 				__( '<strong>Error</strong>: The email could not be sent. Your site may not be correctly configured to send emails. <a href="%s">Get support for resetting your password</a>.' ),
  2939 
  3315 
  2940 	// Check the email address.
  3316 	// Check the email address.
  2941 	if ( '' === $user_email ) {
  3317 	if ( '' === $user_email ) {
  2942 		$errors->add( 'empty_email', __( '<strong>Error</strong>: Please type your email address.' ) );
  3318 		$errors->add( 'empty_email', __( '<strong>Error</strong>: Please type your email address.' ) );
  2943 	} elseif ( ! is_email( $user_email ) ) {
  3319 	} elseif ( ! is_email( $user_email ) ) {
  2944 		$errors->add( 'invalid_email', __( '<strong>Error</strong>: The email address isn&#8217;t correct.' ) );
  3320 		$errors->add( 'invalid_email', __( '<strong>Error</strong>: The email address is not correct.' ) );
  2945 		$user_email = '';
  3321 		$user_email = '';
  2946 	} elseif ( email_exists( $user_email ) ) {
  3322 	} elseif ( email_exists( $user_email ) ) {
  2947 		$errors->add( 'email_exists', __( '<strong>Error</strong>: This email is already registered. Please choose another one.' ) );
  3323 		$errors->add(
       
  3324 			'email_exists',
       
  3325 			sprintf(
       
  3326 				/* translators: %s: Link to the login page. */
       
  3327 				__( '<strong>Error:</strong> This email address is already registered. <a href="%s">Log in</a> with this address or choose another one.' ),
       
  3328 				wp_login_url()
       
  3329 			)
       
  3330 		);
  2948 	}
  3331 	}
  2949 
  3332 
  2950 	/**
  3333 	/**
  2951 	 * Fires when submitting registration form data, before the user is created.
  3334 	 * Fires when submitting registration form data, before the user is created.
  2952 	 *
  3335 	 *
  2987 	if ( ! $user_id || is_wp_error( $user_id ) ) {
  3370 	if ( ! $user_id || is_wp_error( $user_id ) ) {
  2988 		$errors->add(
  3371 		$errors->add(
  2989 			'registerfail',
  3372 			'registerfail',
  2990 			sprintf(
  3373 			sprintf(
  2991 				/* translators: %s: Admin email address. */
  3374 				/* translators: %s: Admin email address. */
  2992 				__( '<strong>Error</strong>: Couldn&#8217;t register you&hellip; please contact the <a href="mailto:%s">site admin</a>!' ),
  3375 				__( '<strong>Error</strong>: Could not register you&hellip; please contact the <a href="mailto:%s">site admin</a>!' ),
  2993 				get_option( 'admin_email' )
  3376 				get_option( 'admin_email' )
  2994 			)
  3377 			)
  2995 		);
  3378 		);
  2996 		return $errors;
  3379 		return $errors;
  2997 	}
  3380 	}
  2998 
  3381 
  2999 	update_user_meta( $user_id, 'default_password_nag', true ); // Set up the password change nag.
  3382 	update_user_meta( $user_id, 'default_password_nag', true ); // Set up the password change nag.
  3000 
  3383 
       
  3384 	if ( ! empty( $_COOKIE['wp_lang'] ) ) {
       
  3385 		$wp_lang = sanitize_text_field( $_COOKIE['wp_lang'] );
       
  3386 		if ( in_array( $wp_lang, get_available_languages(), true ) ) {
       
  3387 			update_user_meta( $user_id, 'locale', $wp_lang ); // Set user locale if defined on registration.
       
  3388 		}
       
  3389 	}
       
  3390 
  3001 	/**
  3391 	/**
  3002 	 * Fires after a new user registration has been recorded.
  3392 	 * Fires after a new user registration has been recorded.
  3003 	 *
  3393 	 *
  3004 	 * @since 4.4.0
  3394 	 * @since 4.4.0
  3005 	 *
  3395 	 *
  3027 function wp_send_new_user_notifications( $user_id, $notify = 'both' ) {
  3417 function wp_send_new_user_notifications( $user_id, $notify = 'both' ) {
  3028 	wp_new_user_notification( $user_id, null, $notify );
  3418 	wp_new_user_notification( $user_id, null, $notify );
  3029 }
  3419 }
  3030 
  3420 
  3031 /**
  3421 /**
  3032  * Retrieve the current session token from the logged_in cookie.
  3422  * Retrieves the current session token from the logged_in cookie.
  3033  *
  3423  *
  3034  * @since 4.0.0
  3424  * @since 4.0.0
  3035  *
  3425  *
  3036  * @return string Token.
  3426  * @return string Token.
  3037  */
  3427  */
  3039 	$cookie = wp_parse_auth_cookie( '', 'logged_in' );
  3429 	$cookie = wp_parse_auth_cookie( '', 'logged_in' );
  3040 	return ! empty( $cookie['token'] ) ? $cookie['token'] : '';
  3430 	return ! empty( $cookie['token'] ) ? $cookie['token'] : '';
  3041 }
  3431 }
  3042 
  3432 
  3043 /**
  3433 /**
  3044  * Retrieve a list of sessions for the current user.
  3434  * Retrieves a list of sessions for the current user.
  3045  *
  3435  *
  3046  * @since 4.0.0
  3436  * @since 4.0.0
  3047  *
  3437  *
  3048  * @return array Array of sessions.
  3438  * @return array Array of sessions.
  3049  */
  3439  */
  3051 	$manager = WP_Session_Tokens::get_instance( get_current_user_id() );
  3441 	$manager = WP_Session_Tokens::get_instance( get_current_user_id() );
  3052 	return $manager->get_all();
  3442 	return $manager->get_all();
  3053 }
  3443 }
  3054 
  3444 
  3055 /**
  3445 /**
  3056  * Remove the current session token from the database.
  3446  * Removes the current session token from the database.
  3057  *
  3447  *
  3058  * @since 4.0.0
  3448  * @since 4.0.0
  3059  */
  3449  */
  3060 function wp_destroy_current_session() {
  3450 function wp_destroy_current_session() {
  3061 	$token = wp_get_session_token();
  3451 	$token = wp_get_session_token();
  3064 		$manager->destroy( $token );
  3454 		$manager->destroy( $token );
  3065 	}
  3455 	}
  3066 }
  3456 }
  3067 
  3457 
  3068 /**
  3458 /**
  3069  * Remove all but the current session token for the current user for the database.
  3459  * Removes all but the current session token for the current user for the database.
  3070  *
  3460  *
  3071  * @since 4.0.0
  3461  * @since 4.0.0
  3072  */
  3462  */
  3073 function wp_destroy_other_sessions() {
  3463 function wp_destroy_other_sessions() {
  3074 	$token = wp_get_session_token();
  3464 	$token = wp_get_session_token();
  3077 		$manager->destroy_others( $token );
  3467 		$manager->destroy_others( $token );
  3078 	}
  3468 	}
  3079 }
  3469 }
  3080 
  3470 
  3081 /**
  3471 /**
  3082  * Remove all session tokens for the current user from the database.
  3472  * Removes all session tokens for the current user from the database.
  3083  *
  3473  *
  3084  * @since 4.0.0
  3474  * @since 4.0.0
  3085  */
  3475  */
  3086 function wp_destroy_all_sessions() {
  3476 function wp_destroy_all_sessions() {
  3087 	$manager = WP_Session_Tokens::get_instance( get_current_user_id() );
  3477 	$manager = WP_Session_Tokens::get_instance( get_current_user_id() );
  3088 	$manager->destroy_all();
  3478 	$manager->destroy_all();
  3089 }
  3479 }
  3090 
  3480 
  3091 /**
  3481 /**
  3092  * Get the user IDs of all users with no role on this site.
  3482  * Gets the user IDs of all users with no role on this site.
  3093  *
  3483  *
  3094  * @since 4.4.0
  3484  * @since 4.4.0
  3095  * @since 4.9.0 The `$site_id` parameter was added to support multisite.
  3485  * @since 4.9.0 The `$site_id` parameter was added to support multisite.
  3096  *
  3486  *
  3097  * @param int|null $site_id Optional. The site ID to get users with no role for. Defaults to the current site.
  3487  * @param int|null $site_id Optional. The site ID to get users with no role for. Defaults to the current site.
  3200 
  3590 
  3201 	return $current_user;
  3591 	return $current_user;
  3202 }
  3592 }
  3203 
  3593 
  3204 /**
  3594 /**
  3205  * Send a confirmation request email when a change of user email address is attempted.
  3595  * Sends a confirmation request email when a change of user email address is attempted.
  3206  *
  3596  *
  3207  * @since 3.0.0
  3597  * @since 3.0.0
  3208  * @since 4.9.0 This function was moved from wp-admin/includes/ms.php so it's no longer Multisite specific.
  3598  * @since 4.9.0 This function was moved from wp-admin/includes/ms.php so it's no longer Multisite specific.
  3209  *
  3599  *
  3210  * @global WP_Error $errors WP_Error object.
  3600  * @global WP_Error $errors WP_Error object.
  3223 
  3613 
  3224 	if ( $current_user->user_email != $_POST['email'] ) {
  3614 	if ( $current_user->user_email != $_POST['email'] ) {
  3225 		if ( ! is_email( $_POST['email'] ) ) {
  3615 		if ( ! is_email( $_POST['email'] ) ) {
  3226 			$errors->add(
  3616 			$errors->add(
  3227 				'user_email',
  3617 				'user_email',
  3228 				__( '<strong>Error</strong>: The email address isn&#8217;t correct.' ),
  3618 				__( '<strong>Error</strong>: The email address is not correct.' ),
  3229 				array(
  3619 				array(
  3230 					'form-field' => 'email',
  3620 					'form-field' => 'email',
  3231 				)
  3621 				)
  3232 			);
  3622 			);
  3233 
  3623 
  3316  * after email address change.
  3706  * after email address change.
  3317  *
  3707  *
  3318  * @since 3.0.0
  3708  * @since 3.0.0
  3319  * @since 4.9.0 This function was moved from wp-admin/includes/ms.php so it's no longer Multisite specific.
  3709  * @since 4.9.0 This function was moved from wp-admin/includes/ms.php so it's no longer Multisite specific.
  3320  *
  3710  *
  3321  * @global string $pagenow
  3711  * @global string $pagenow The filename of the current screen.
  3322  */
  3712  */
  3323 function new_user_email_admin_notice() {
  3713 function new_user_email_admin_notice() {
  3324 	global $pagenow;
  3714 	global $pagenow;
  3325 
  3715 
  3326 	if ( 'profile.php' === $pagenow && isset( $_GET['updated'] ) ) {
  3716 	if ( 'profile.php' === $pagenow && isset( $_GET['updated'] ) ) {
  3331 		}
  3721 		}
  3332 	}
  3722 	}
  3333 }
  3723 }
  3334 
  3724 
  3335 /**
  3725 /**
  3336  * Get all personal data request types.
  3726  * Gets all personal data request types.
  3337  *
  3727  *
  3338  * @since 4.9.6
  3728  * @since 4.9.6
  3339  * @access private
  3729  * @access private
  3340  *
  3730  *
  3341  * @return array List of core privacy action types.
  3731  * @return array List of core privacy action types.
  3437 
  3827 
  3438 	// Get the list of reserved names.
  3828 	// Get the list of reserved names.
  3439 	$reserved_names = array_values( $user_props_to_export );
  3829 	$reserved_names = array_values( $user_props_to_export );
  3440 
  3830 
  3441 	/**
  3831 	/**
  3442 	 * Filter to extend the user's profile data for the privacy exporter.
  3832 	 * Filters the user's profile data for the privacy exporter.
  3443 	 *
  3833 	 *
  3444 	 * @since 5.4.0
  3834 	 * @since 5.4.0
  3445 	 *
  3835 	 *
  3446 	 * @param array    $additional_user_profile_data {
  3836 	 * @param array    $additional_user_profile_data {
  3447 	 *     An array of name-value pairs of additional user data items. Default empty array.
  3837 	 *     An array of name-value pairs of additional user data items. Default empty array.
  3457 
  3847 
  3458 	if ( is_array( $_extra_data ) && ! empty( $_extra_data ) ) {
  3848 	if ( is_array( $_extra_data ) && ! empty( $_extra_data ) ) {
  3459 		// Remove items that use reserved names.
  3849 		// Remove items that use reserved names.
  3460 		$extra_data = array_filter(
  3850 		$extra_data = array_filter(
  3461 			$_extra_data,
  3851 			$_extra_data,
  3462 			function( $item ) use ( $reserved_names ) {
  3852 			static function( $item ) use ( $reserved_names ) {
  3463 				return ! in_array( $item['name'], $reserved_names, true );
  3853 				return ! in_array( $item['name'], $reserved_names, true );
  3464 			}
  3854 			}
  3465 		);
  3855 		);
  3466 
  3856 
  3467 		if ( count( $extra_data ) !== count( $_extra_data ) ) {
  3857 		if ( count( $extra_data ) !== count( $_extra_data ) ) {
  3561 		'done' => true,
  3951 		'done' => true,
  3562 	);
  3952 	);
  3563 }
  3953 }
  3564 
  3954 
  3565 /**
  3955 /**
  3566  * Update log when privacy request is confirmed.
  3956  * Updates log when privacy request is confirmed.
  3567  *
  3957  *
  3568  * @since 4.9.6
  3958  * @since 4.9.6
  3569  * @access private
  3959  * @access private
  3570  *
  3960  *
  3571  * @param int $request_id ID of the request.
  3961  * @param int $request_id ID of the request.
  3589 		)
  3979 		)
  3590 	);
  3980 	);
  3591 }
  3981 }
  3592 
  3982 
  3593 /**
  3983 /**
  3594  * Notify the site administrator via email when a request is confirmed.
  3984  * Notifies the site administrator via email when a request is confirmed.
  3595  *
  3985  *
  3596  * Without this, the admin would have to manually check the site to see if any
  3986  * Without this, the admin would have to manually check the site to see if any
  3597  * action was needed on their part yet.
  3987  * action was needed on their part yet.
  3598  *
  3988  *
  3599  * @since 4.9.6
  3989  * @since 4.9.6
  3802 		update_post_meta( $request_id, '_wp_admin_notified', true );
  4192 		update_post_meta( $request_id, '_wp_admin_notified', true );
  3803 	}
  4193 	}
  3804 }
  4194 }
  3805 
  4195 
  3806 /**
  4196 /**
  3807  * Notify the user when their erasure request is fulfilled.
  4197  * Notifies the user when their erasure request is fulfilled.
  3808  *
  4198  *
  3809  * Without this, the user would never know if their data was actually erased.
  4199  * Without this, the user would never know if their data was actually erased.
  3810  *
  4200  *
  3811  * @since 4.9.6
  4201  * @since 4.9.6
  3812  *
  4202  *
  4075 		update_post_meta( $request_id, '_wp_user_notified', true );
  4465 		update_post_meta( $request_id, '_wp_user_notified', true );
  4076 	}
  4466 	}
  4077 }
  4467 }
  4078 
  4468 
  4079 /**
  4469 /**
  4080  * Return request confirmation message HTML.
  4470  * Returns request confirmation message HTML.
  4081  *
  4471  *
  4082  * @since 4.9.6
  4472  * @since 4.9.6
  4083  * @access private
  4473  * @access private
  4084  *
  4474  *
  4085  * @param int $request_id The request ID being confirmed.
  4475  * @param int $request_id The request ID being confirmed.
  4113 
  4503 
  4114 	return $message;
  4504 	return $message;
  4115 }
  4505 }
  4116 
  4506 
  4117 /**
  4507 /**
  4118  * Create and log a user request to perform a specific action.
  4508  * Creates and logs a user request to perform a specific action.
  4119  *
  4509  *
  4120  * Requests are stored inside a post type named `user_request` since they can apply to both
  4510  * Requests are stored inside a post type named `user_request` since they can apply to both
  4121  * users on the site, or guests without a user account.
  4511  * users on the site, or guests without a user account.
  4122  *
  4512  *
  4123  * @since 4.9.6
  4513  * @since 4.9.6
  4184 
  4574 
  4185 	return $request_id;
  4575 	return $request_id;
  4186 }
  4576 }
  4187 
  4577 
  4188 /**
  4578 /**
  4189  * Get action description from the name and return a string.
  4579  * Gets action description from the name and return a string.
  4190  *
  4580  *
  4191  * @since 4.9.6
  4581  * @since 4.9.6
  4192  *
  4582  *
  4193  * @param string $action_name Action name of the request.
  4583  * @param string $action_name Action name of the request.
  4194  * @return string Human readable action name.
  4584  * @return string Human readable action name.
  4402 
  4792 
  4403 	return $key;
  4793 	return $key;
  4404 }
  4794 }
  4405 
  4795 
  4406 /**
  4796 /**
  4407  * Validate a user request by comparing the key with the request's key.
  4797  * Validates a user request by comparing the key with the request's key.
  4408  *
  4798  *
  4409  * @since 4.9.6
  4799  * @since 4.9.6
  4410  *
  4800  *
  4411  * @param string $request_id ID of the request being confirmed.
  4801  * @param string $request_id ID of the request being confirmed.
  4412  * @param string $key        Provided key to validate.
  4802  * @param string $key        Provided key to validate.
  4457 
  4847 
  4458 	return true;
  4848 	return true;
  4459 }
  4849 }
  4460 
  4850 
  4461 /**
  4851 /**
  4462  * Return the user request object for the specified request ID.
  4852  * Returns the user request object for the specified request ID.
  4463  *
  4853  *
  4464  * @since 4.9.6
  4854  * @since 4.9.6
  4465  *
  4855  *
  4466  * @param int $request_id The ID of the user request.
  4856  * @param int $request_id The ID of the user request.
  4467  * @return WP_User_Request|false
  4857  * @return WP_User_Request|false
  4476 
  4866 
  4477 	return new WP_User_Request( $post );
  4867 	return new WP_User_Request( $post );
  4478 }
  4868 }
  4479 
  4869 
  4480 /**
  4870 /**
       
  4871  * Checks if Application Passwords is supported.
       
  4872  *
       
  4873  * Application Passwords is supported only by sites using SSL or local environments
       
  4874  * but may be made available using the {@see 'wp_is_application_passwords_available'} filter.
       
  4875  *
       
  4876  * @since 5.9.0
       
  4877  *
       
  4878  * @return bool
       
  4879  */
       
  4880 function wp_is_application_passwords_supported() {
       
  4881 	return is_ssl() || 'local' === wp_get_environment_type();
       
  4882 }
       
  4883 
       
  4884 /**
  4481  * Checks if Application Passwords is globally available.
  4885  * Checks if Application Passwords is globally available.
  4482  *
  4886  *
  4483  * By default, Application Passwords is available to all sites using SSL or to local environments.
  4887  * By default, Application Passwords is available to all sites using SSL or to local environments.
  4484  * Use {@see 'wp_is_application_passwords_available'} to adjust its availability.
  4888  * Use the {@see 'wp_is_application_passwords_available'} filter to adjust its availability.
  4485  *
  4889  *
  4486  * @since 5.6.0
  4890  * @since 5.6.0
  4487  *
  4891  *
  4488  * @return bool
  4892  * @return bool
  4489  */
  4893  */
  4490 function wp_is_application_passwords_available() {
  4894 function wp_is_application_passwords_available() {
  4491 	$available = is_ssl() || 'local' === wp_get_environment_type();
       
  4492 
       
  4493 	/**
  4895 	/**
  4494 	 * Filters whether Application Passwords is available.
  4896 	 * Filters whether Application Passwords is available.
  4495 	 *
  4897 	 *
  4496 	 * @since 5.6.0
  4898 	 * @since 5.6.0
  4497 	 *
  4899 	 *
  4498 	 * @param bool $available True if available, false otherwise.
  4900 	 * @param bool $available True if available, false otherwise.
  4499 	 */
  4901 	 */
  4500 	return apply_filters( 'wp_is_application_passwords_available', $available );
  4902 	return apply_filters( 'wp_is_application_passwords_available', wp_is_application_passwords_supported() );
  4501 }
  4903 }
  4502 
  4904 
  4503 /**
  4905 /**
  4504  * Checks if Application Passwords is available for a specific user.
  4906  * Checks if Application Passwords is available for a specific user.
  4505  *
  4907  *