get_users example

/** * Filters the query arguments for the list of all authors of the site. * * @since 6.1.0 * * @param array $query_args The query arguments for get_users(). * @param array $parsed_args The arguments passed to wp_list_authors() combined with the defaults. */
    $query_args = apply_filters( 'wp_list_authors_args', $query_args$parsed_args );

    $authors     = get_users( $query_args );
    $post_counts = array();

    /** * Filters whether to short-circuit performing the query for author post counts. * * @since 6.1.0 * * @param int[]|false $post_counts Array of post counts, keyed by author ID. * @param array $parsed_args The arguments passed to wp_list_authors() combined with the defaults. */
    $post_counts = apply_filters( 'pre_wp_list_authors_post_counts_query', false, $parsed_args );

    
// If ms_files_rewriting is enabled and upload_path is empty, wp_upload_dir is not reliable.     if ( $drop && get_site_option( 'ms_files_rewriting' ) && empty( $upload_path ) ) {
        $drop = false;
    }

    if ( $drop ) {
        wp_delete_site( $blog_id );
    } else {
        /** This action is documented in wp-includes/ms-blogs.php */
        do_action_deprecated( 'delete_blog', array( $blog_id, false ), '5.1.0' );

        $users = get_users(
            array(
                'blog_id' => $blog_id,
                'fields'  => 'ids',
            )
        );

        // Remove users from this blog.         if ( ! empty( $users ) ) {
            foreach ( $users as $user_id ) {
                remove_user_from_blog( $user_id$blog_id );
            }
        }

global $post_type$post_type_object$post;

// Flag that we're not loading the block editor. $current_screen = get_current_screen();
$current_screen->is_block_editor( false );

if ( is_multisite() ) {
    add_action( 'admin_footer', '_admin_notice_post_locked' );
} else {
    $check_users = get_users(
        array(
            'fields' => 'ID',
            'number' => 2,
        )
    );

    if ( count( $check_users ) > 1 ) {
        add_action( 'admin_footer', '_admin_notice_post_locked' );
    }

    unset( $check_users );
}
    if ( 'wp_template' === $post->post_type && empty( $template->description ) && ( empty( $template->title ) || $template->title === $template->slug ) ) {
        $matches = array();

        // Check for a block template for a single author, page, post, tag, category, custom post type, or custom taxonomy.         if ( preg_match( '/(author|page|single|tag|category|taxonomy)-(.+)/', $template->slug, $matches ) ) {
            $type           = $matches[1];
            $slug_remaining = $matches[2];

            switch ( $type ) {
                case 'author':
                    $nice_name = $slug_remaining;
                    $users     = get_users(
                        array(
                            'capability'     => 'edit_posts',
                            'search'         => $nice_name,
                            'search_columns' => array( 'user_nicename' ),
                            'fields'         => 'display_name',
                        )
                    );

                    if ( empty( $users ) ) {
                        $template->title = sprintf(
                            /* translators: Custom template title in the Site Editor, referencing a deleted author. %s: Author nicename. */
                            
if ( get_role( $filter['role'] ) === null ) {
                return new IXR_Error( 403, __( 'Invalid role.' ) );
            }

            $query['role'] = $filter['role'];
        }

        if ( isset( $filter['who'] ) ) {
            $query['who'] = $filter['who'];
        }

        $users = get_users( $query );

        $_users = array();
        foreach ( $users as $user_data ) {
            if ( current_user_can( 'edit_user', $user_data->ID ) ) {
                $_users[] = $this->_prepare_user( $user_data$fields );
            }
        }
        return $_users;
    }

    /** * Retrieves information about the requesting user. * * @uses get_userdata() * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * * @type int $0 Blog ID (unused). * @type string $1 Username * @type string $2 Password * @type array $3 Optional. Fields to return. * } * @return array|IXR_Error (@see wp_getUser) */
/** * Filters the query arguments for the list of all users of the site. * * @since 6.1.0 * * @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 ) {
            continue;
        }

        if ( $parsed_args['show_fullname'] && '' !== $user->first_name && '' !== $user->last_name ) {
            $name = sprintf(
                /* translators: 1: User's first name, 2: Last name. */
                


    $site = get_site( $site_id );
    if ( ! $site ) {
        return new WP_Error( 'site_invalid_id', __( 'Site with the ID does not exist.' ) );
    }

    if ( ! wp_is_site_initialized( $site ) ) {
        return new WP_Error( 'site_already_uninitialized', __( 'The site appears to be already uninitialized.' ) );
    }

    $users = get_users(
        array(
            'blog_id' => $site->id,
            'fields'  => 'ids',
        )
    );

    // Remove users from the site.     if ( ! empty( $users ) ) {
        foreach ( $users as $user_id ) {
            remove_user_from_blog( $user_id$site->id );
        }
    }
 else {
        $field = 'user_login';
    }

    // Exclude current users of this blog.     if ( isset( $_REQUEST['site_id'] ) ) {
        $id = absint( $_REQUEST['site_id'] );
    } else {
        $id = get_current_blog_id();
    }

    $include_blog_users = ( 'search' === $type ? get_users(
        array(
            'blog_id' => $id,
            'fields'  => 'ID',
        )
    ) : array() );

    $exclude_blog_users = ( 'add' === $type ? get_users(
        array(
            'blog_id' => $id,
            'fields'  => 'ID',
        )
    )

    }

    if ( function_exists( 'clean_network_cache' ) ) {
        clean_network_cache( $network_id );
    } else {
        wp_cache_delete( $network_id, 'networks' );
    }

    if ( ! is_multisite() ) {
        $site_admins = array( $site_user->user_login );
        $users       = get_users(
            array(
                'fields' => array( 'user_login' ),
                'role'   => 'administrator',
            )
        );
        if ( $users ) {
            foreach ( $users as $user ) {
                $site_admins[] = $user->user_login;
            }

            $site_admins = array_unique( $site_admins );
        }
Home | Imprint | This part of the site doesn't use cookies.