: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$authenticated = wp_authenticate_application_password( null, $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'] );
if ( $authenticated instanceof WP_User ) {
return $authenticated->ID;
// If it wasn't a user what got returned, just pass on what we had received originally.
* For Multisite blogs, checks if the authenticated user has been marked as a
* spammer, or if the user's primary blog has been marked as spam.
* @param WP_User|WP_Error|null $user WP_User or WP_Error object from a previous callback. Default null.
* @return WP_User|WP_Error WP_User on success, WP_Error if the user is considered a spammer.
function wp_authenticate_spam_check( $user ) {
if ( $user instanceof WP_User && is_multisite() ) {
* Filters whether the user has been marked as a spammer.
* @param bool $spammed Whether the user is considered a spammer.
* @param WP_User $user User to check against.
$spammed = apply_filters( 'check_is_user_spammed', is_user_spammy( $user ), $user );
return new WP_Error( 'spammer_account', __( '<strong>Error:</strong> Your account has been marked as a spammer.' ) );
* Validates the logged-in cookie.
* Checks the logged-in cookie if the previous auth cookie could not be
* This is a callback for the {@see 'determine_current_user'} filter, rather than API.
* @param int|false $user_id The user ID (or false) as received from
* the `determine_current_user` filter.
* @return int|false User ID if validated, false otherwise. If a user ID from
* an earlier filter callback is received, that value is returned.
function wp_validate_logged_in_cookie( $user_id ) {
if ( is_blog_admin() || is_network_admin() || empty( $_COOKIE[ LOGGED_IN_COOKIE ] ) ) {
return wp_validate_auth_cookie( $_COOKIE[ LOGGED_IN_COOKIE ], 'logged_in' );
* Gets the number of posts a user has written.
* @since 4.1.0 Added `$post_type` argument.
* @since 4.3.0 Added `$public_only` argument. Added the ability to pass an array
* of post types to `$post_type`.
* @global wpdb $wpdb WordPress database abstraction object.
* @param int $userid User ID.
* @param array|string $post_type Optional. Single post type or array of post types to count the number of posts for. Default 'post'.
* @param bool $public_only Optional. Whether to only return counts for public posts. Default false.
* @return string Number of posts the user has written in this post type.
function count_user_posts( $userid, $post_type = 'post', $public_only = false ) {
$where = get_posts_by_author_sql( $post_type, true, $userid, $public_only );
$count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
* Filters the number of posts a user has written.
* @since 4.1.0 Added `$post_type` argument.
* @since 4.3.1 Added `$public_only` argument.
* @param int $count The user's post count.
* @param int $userid User ID.
* @param string|array $post_type Single post type or array of post types to count the number of posts for.
* @param bool $public_only Whether to limit counted posts to public posts.
return apply_filters( 'get_usernumposts', $count, $userid, $post_type, $public_only );
* Gets the number of posts written by a list of users.
* @global wpdb $wpdb WordPress database abstraction object.
* @param int[] $users Array of user IDs.
* @param string|string[] $post_type Optional. Single post type or array of post types to check. Defaults to 'post'.
* @param bool $public_only Optional. Only return counts for public posts. Defaults to false.
* @return string[] Amount of posts each user has written, as strings, keyed by user ID.
function count_many_users_posts( $users, $post_type = 'post', $public_only = false ) {
if ( empty( $users ) || ! is_array( $users ) ) {
$userlist = implode( ',', array_map( 'absint', $users ) );
$where = get_posts_by_author_sql( $post_type, true, null, $public_only );
$result = $wpdb->get_results( "SELECT post_author, COUNT(*) FROM $wpdb->posts $where AND post_author IN ($userlist) GROUP BY post_author", ARRAY_N );
foreach ( $result as $row ) {
$count[ $row[0] ] = $row[1];
foreach ( $users as $id ) {
if ( ! isset( $count[ $id ] ) ) {
// User option functions.
* Gets the current user's ID.
* @return int The current user's ID, or 0 if no user is logged in.
function get_current_user_id() {
if ( ! function_exists( 'wp_get_current_user' ) ) {
$user = wp_get_current_user();
return ( isset( $user->ID ) ? (int) $user->ID : 0 );
* Retrieves user option that can be either per Site or per Network.
* If the user ID is not given, then the current user will be used instead. If
* the user ID is given, then the user data will be retrieved. The filter for
* the result, will also pass the original option name and finally the user data
* object as the third parameter.
* The option will first check for the per site name and then the per Network name.
* @global wpdb $wpdb WordPress database abstraction object.
* @param string $option User option name.
* @param int $user Optional. User ID.
* @param string $deprecated Use get_option() to check for an option in the options table.
* @return mixed User option value on success, false on failure.
function get_user_option( $option, $user = 0, $deprecated = '' ) {
if ( ! empty( $deprecated ) ) {
_deprecated_argument( __FUNCTION__, '3.0.0' );
$user = get_current_user_id();
$user = get_userdata( $user );
$prefix = $wpdb->get_blog_prefix();
if ( $user->has_prop( $prefix . $option ) ) { // Blog-specific.
$result = $user->get( $prefix . $option );
} elseif ( $user->has_prop( $option ) ) { // User-specific and cross-blog.
$result = $user->get( $option );
* Filters a specific user option value.
* The dynamic portion of the hook name, `$option`, refers to the user option name.
* @param mixed $result Value for the user's option.
* @param string $option Name of the option being retrieved.
* @param WP_User $user WP_User object of the user whose option is being retrieved.
return apply_filters( "get_user_option_{$option}", $result, $option, $user );
* Updates user option with global blog capability.
* User options are just like user metadata except that they have support for
* global blog options. If the 'is_global' parameter is false, which it is by default,
* it will prepend the WordPress table prefix to the option name.
* Deletes the user option if $newvalue is empty.
* @global wpdb $wpdb WordPress database abstraction object.
* @param int $user_id User ID.
* @param string $option_name User option name.
* @param mixed $newvalue User option value.
* @param bool $is_global Optional. Whether option name is global or blog specific.
* Default false (blog specific).
* @return int|bool User meta ID if the option didn't exist, true on successful update,
function update_user_option( $user_id, $option_name, $newvalue, $is_global = false ) {
$option_name = $wpdb->get_blog_prefix() . $option_name;
return update_user_meta( $user_id, $option_name, $newvalue );
* Deletes user option with global blog capability.
* User options are just like user metadata except that they have support for
* global blog options. If the 'is_global' parameter is false, which it is by default,
* it will prepend the WordPress table prefix to the option name.
* @global wpdb $wpdb WordPress database abstraction object.
* @param int $user_id User ID
* @param string $option_name User option name.
* @param bool $is_global Optional. Whether option name is global or blog specific.
* Default false (blog specific).
* @return bool True on success, false on failure.
function delete_user_option( $user_id, $option_name, $is_global = false ) {
$option_name = $wpdb->get_blog_prefix() . $option_name;
return delete_user_meta( $user_id, $option_name );
* Retrieves list of users matching criteria.
* @param array $args Optional. Arguments to retrieve users. See WP_User_Query::prepare_query()
* for more information on accepted arguments.
* @return array List of users.
function get_users( $args = array() ) {
$args = wp_parse_args( $args );
$args['count_total'] = false;
$user_search = new WP_User_Query( $args );
return (array) $user_search->get_results();
* Lists all the users of the site, with several options available.
* @param string|array $args {
* Optional. Array or string of default arguments.
* @type string $orderby How to sort the users. Accepts 'nicename', 'email', 'url', 'registered',
* 'user_nicename', 'user_email', 'user_url', 'user_registered', 'name',
* 'display_name', 'post_count', 'ID', 'meta_value', 'user_login'. Default 'name'.
* @type string $order Sorting direction for $orderby. Accepts 'ASC', 'DESC'. Default 'ASC'.
* @type int $number Maximum users to return or display. Default empty (all users).
* @type bool $exclude_admin Whether to exclude the 'admin' account, if it exists. Default false.
* @type bool $show_fullname Whether to show the user's full name. Default false.
* @type string $feed If not empty, show a link to the user's feed and use this text as the alt
* parameter of the link. Default empty.
* @type string $feed_image If not empty, show a link to the user's feed and use this image URL as
* clickable anchor. Default empty.
* @type string $feed_type The feed type to link to, such as 'rss2'. Defaults to default feed type.
* @type bool $echo Whether to output the result or instead return it. Default true.
* @type string $style If 'list', each user is wrapped in an `<li>` element, otherwise the users
* will be separated by commas.
* @type bool $html Whether to list the items in HTML form or plaintext. Default true.
* @type string $exclude An array, comma-, or space-separated list of user IDs to exclude. Default empty.
* @type string $include An array, comma-, or space-separated list of user IDs to include. Default empty.
* @return string|null The output if echo is false. Otherwise null.
function wp_list_users( $args = array() ) {
'show_fullname' => false,
$parsed_args = wp_parse_args( $args, $defaults );
$query_args = wp_array_slice_assoc( $parsed_args, array( 'orderby', 'order', 'number', 'exclude', 'include' ) );
$query_args['fields'] = 'ids';
* Filters the query arguments for the list of all users of the site.
* @param array $query_args The query arguments for get_users().
* @param array $parsed_args The arguments passed to wp_list_users() combined with the defaults.
$query_args = apply_filters( 'wp_list_users_args', $query_args, $parsed_args );
$users = get_users( $query_args );
foreach ( $users as $user_id ) {
$user = get_userdata( $user_id );
if ( $parsed_args['exclude_admin'] && 'admin' === $user->display_name ) {
if ( $parsed_args['show_fullname'] && '' !== $user->first_name && '' !== $user->last_name ) {
/* translators: 1: User's first name, 2: Last name. */
_x( '%1$s %2$s', 'Display name based on first name and last name' ),
$name = $user->display_name;
if ( ! $parsed_args['html'] ) {
continue; // No need to go further to process HTML.
if ( 'list' === $parsed_args['style'] ) {
if ( ! empty( $parsed_args['feed_image'] ) || ! empty( $parsed_args['feed'] ) ) {
if ( empty( $parsed_args['feed_image'] ) ) {
$row .= '<a href="' . get_author_feed_link( $user->ID, $parsed_args['feed_type'] ) . '"';
if ( ! empty( $parsed_args['feed'] ) ) {
$alt = ' alt="' . esc_attr( $parsed_args['feed'] ) . '"';
$name = $parsed_args['feed'];
if ( ! empty( $parsed_args['feed_image'] ) ) {
$row .= '<img src="' . esc_url( $parsed_args['feed_image'] ) . '" style="border: none;"' . $alt . ' />';
if ( empty( $parsed_args['feed_image'] ) ) {
$return .= ( 'list' === $parsed_args['style'] ) ? '</li>' : ', ';
$return = rtrim( $return, ', ' );
if ( ! $parsed_args['echo'] ) {
* Gets the sites a user belongs to.
* @since 4.7.0 Converted to use `get_sites()`.
* @global wpdb $wpdb WordPress database abstraction object.
* @param int $user_id User ID
* @param bool $all Whether to retrieve all sites, or only sites that are not
* marked as deleted, archived, or spam.
* @return object[] A list of the user's sites. An empty array if the user doesn't exist
* or belongs to no sites.
function get_blogs_of_user( $user_id, $all = false ) {
$user_id = (int) $user_id;
// Logged out users can't have sites.
if ( empty( $user_id ) ) {
* Filters the list of a user's sites before it is populated.
* Returning a non-null value from the filter will effectively short circuit
* get_blogs_of_user(), returning that value instead.
* @param null|object[] $sites An array of site objects of which the user is a member.
* @param int $user_id User ID.
* @param bool $all Whether the returned array should contain all sites, including
* those marked 'deleted', 'archived', or 'spam'. Default false.
$sites = apply_filters( 'pre_get_blogs_of_user', null, $user_id, $all );
$keys = get_user_meta( $user_id );
if ( ! is_multisite() ) {
$site_id = get_current_blog_id();
$sites = array( $site_id => new stdClass() );
$sites[ $site_id ]->userblog_id = $site_id;
$sites[ $site_id ]->blogname = get_option( 'blogname' );
$sites[ $site_id ]->domain = '';
$sites[ $site_id ]->path = '';
$sites[ $site_id ]->site_id = 1;
$sites[ $site_id ]->siteurl = get_option( 'siteurl' );
$sites[ $site_id ]->archived = 0;
$sites[ $site_id ]->spam = 0;
$sites[ $site_id ]->deleted = 0;
if ( isset( $keys[ $wpdb->base_prefix . 'capabilities' ] ) && defined( 'MULTISITE' ) ) {