get_userdata example

if ( $author ) {
                $this->queried_object_id = $author;
            } elseif ( $author_name ) {
                $user = get_user_by( 'slug', $author_name );

                if ( $user ) {
                    $this->queried_object_id = $user->ID;
                }
            }

            $this->queried_object = get_userdata( $this->queried_object_id );
        }

        return $this->queried_object;
    }

    /** * Retrieves the ID of the currently queried object. * * @since 1.5.0 * * @return int */


            // If the user doesn't already belong to the blog, bail.             if ( is_multisite() && ! is_user_member_of_blog( $id ) ) {
                wp_die(
                    '<h1>' . __( 'Something went wrong.' ) . '</h1>' .
                    '<p>' . __( 'One of the selected users is not a member of this site.' ) . '</p>',
                    403
                );
            }

            $user = get_userdata( $id );
            $user->set_role( $role );
        }

        wp_redirect( add_query_arg( 'update', $update$redirect ) );
        exit;

    case 'dodelete':
        if ( is_multisite() ) {
            wp_die( __( 'User deletion is not allowed from this screen.' ), 400 );
        }

        

function author_can( $post$capability, ...$args ) {
    $post = get_post( $post );
    if ( ! $post ) {
        return false;
    }

    $author = get_userdata( $post->post_author );

    if ( ! $author ) {
        return false;
    }

    return $author->has_cap( $capability, ...$args );
}

/** * Returns whether a particular user has the specified capability. * * This function also accepts an ID of an object to check against if the capability is a meta capability. Meta * capabilities such as `edit_post` and `edit_user` are capabilities used by the `map_meta_cap()` function to * map to primitive capabilities that a user or role has, such as `edit_posts` and `edit_others_posts`. * * Example usage: * * user_can( $user->ID, 'edit_posts' ); * user_can( $user->ID, 'edit_post', $post->ID ); * user_can( $user->ID, 'edit_post_meta', $post->ID, $meta_key ); * * @since 3.1.0 * @since 5.3.0 Formalized the existing and already documented `...$args` parameter * by adding it to the function signature. * * @param int|WP_User $user User ID or object. * @param string $capability Capability name. * @param mixed ...$args Optional further parameters, typically starting with an object ID. * @return bool Whether the user has the given capability. */
function get_user_option( $option$user = 0, $deprecated = '' ) {
    global $wpdb;

    if ( ! empty( $deprecated ) ) {
        _deprecated_argument( __FUNCTION__, '3.0.0' );
    }

    if ( empty( $user ) ) {
        $user = get_current_user_id();
    }

    $user = get_userdata( $user );
    if ( ! $user ) {
        return false;
    }

    $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 );
    } else {
        $result = false;
    }

            if ( empty( $category ) ) {
                $default_category = get_term( get_option( 'default_category' ), 'category' );
                if ( $default_category && ! is_wp_error( $default_category ) ) {
                    $category = $default_category->slug;
                }
            }
        }

        $author = '';
        if ( str_contains( $permalink, '%author%' ) ) {
            $authordata = get_userdata( $post->post_author );
            $author     = $authordata->user_nicename;
        }

        /* * This is not an API call because the permalink is based on the stored post_date value, * which should be parsed as local time regardless of the default PHP timezone. */
        $date = explode( ' ', str_replace( array( '-', ':' ), ' ', $post->post_date ) );

        $rewritereplace = array(
            $date[0],
            
$GLOBALS['query_string'] = $this->query_string;
        $GLOBALS['posts']        = & $wp_query->posts;
        $GLOBALS['post']         = isset( $wp_query->post ) ? $wp_query->post : null;
        $GLOBALS['request']      = $wp_query->request;

        if ( $wp_query->is_single() || $wp_query->is_page() ) {
            $GLOBALS['more']   = 1;
            $GLOBALS['single'] = 1;
        }

        if ( $wp_query->is_author() ) {
            $GLOBALS['authordata'] = get_userdata( get_queried_object_id() );
        }
    }

    /** * Set up the current user. * * @since 2.0.0 */
    public function init() {
        wp_get_current_user();
    }

    
$user_id = (int) $user_id;

                    // If the user doesn't already belong to the blog, bail.                     if ( ! is_user_member_of_blog( $user_id ) ) {
                        wp_die(
                            '<h1>' . __( 'Something went wrong.' ) . '</h1>' .
                            '<p>' . __( 'One of the selected users is not a member of this site.' ) . '</p>',
                            403
                        );
                    }

                    $user = get_userdata( $user_id );
                    $user->set_role( $role );
                }
            } else {
                $update = 'err_promote';
            }
            break;
        default:
            if ( ! isset( $_REQUEST['users'] ) ) {
                break;
            }
            check_admin_referer( 'bulk-users' );
            

function edit_user( $user_id = 0 ) {
    $wp_roles = wp_roles();
    $user     = new stdClass();
    $user_id  = (int) $user_id;
    if ( $user_id ) {
        $update           = true;
        $user->ID         = $user_id;
        $userdata         = get_userdata( $user_id );
        $user->user_login = wp_slash( $userdata->user_login );
    } else {
        $update = false;
    }

    if ( ! $update && isset( $_POST['user_login'] ) ) {
        $user->user_login = sanitize_user( wp_unslash( $_POST['user_login'] ), true );
    }

    $pass1 = '';
    $pass2 = '';
    
wp_die( 0 );
    } elseif ( is_wp_error( $user_id ) ) {
        $x = new WP_Ajax_Response(
            array(
                'what' => 'user',
                'id'   => $user_id,
            )
        );
        $x->send();
    }

    $user_object   = get_userdata( $user_id );
    $wp_list_table = _get_list_table( 'WP_Users_List_Table' );

    $role = current( $user_object->roles );

    $x = new WP_Ajax_Response(
        array(
            'what'         => 'user',
            'id'           => $user_id,
            'data'         => $wp_list_table->single_row( $user_object, '', $role ),
            'supplemental' => array(
                'show-link' => sprintf(
                    

            }

            $user = wp_get_current_user();
        } else {
            $id = (int) $id;

            if ( $id <= 0 ) {
                return $error;
            }

            $user = get_userdata( $id );
        }

        if ( empty( $user ) || ! $user->exists() ) {
            return $error;
        }

        if ( is_multisite() && ! user_can( $user->ID, 'manage_sites' ) && ! is_user_member_of_blog( $user->ID ) ) {
            return $error;
        }

        if ( ! wp_is_application_passwords_available_for_user( $user ) ) {
            
if ( ! empty( $post_ids ) ) {
            $post_ids = array_map( 'absint', $post_ids );
            $and      = 'AND ID IN ( ' . implode( ', ', $post_ids ) . ')';
        } else {
            $and = '';
        }

        $authors = array();
        $results = $wpdb->get_results( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_status != 'auto-draft' $and);
        foreach ( (array) $results as $result ) {
            $authors[] = get_userdata( $result->post_author );
        }

        $authors = array_filter( $authors );

        foreach ( $authors as $author ) {
            echo "\t<wp:author>";
            echo '<wp:author_id>' . (int) $author->ID . '</wp:author_id>';
            echo '<wp:author_login>' . wxr_cdata( $author->user_login ) . '</wp:author_login>';
            echo '<wp:author_email>' . wxr_cdata( $author->user_email ) . '</wp:author_email>';
            echo '<wp:author_display_name>' . wxr_cdata( $author->display_name ) . '</wp:author_display_name>';
            echo '<wp:author_first_name>' . wxr_cdata( $author->first_name ) . '</wp:author_first_name>';
            

function get_comment_author( $comment_id = 0 ) {
    $comment = get_comment( $comment_id );

    $comment_id = ! empty( $comment->comment_ID ) ? $comment->comment_ID : $comment_id;

    if ( empty( $comment->comment_author ) ) {
        $user = ! empty( $comment->user_id ) ? get_userdata( $comment->user_id ) : false;
        if ( $user ) {
            $comment_author = $user->display_name;
        } else {
            $comment_author = __( 'Anonymous' );
        }
    } else {
        $comment_author = $comment->comment_author;
    }

    /** * Filters the returned comment author name. * * @since 1.5.0 * @since 4.1.0 The `$comment_id` and `$comment` parameters were added. * * @param string $comment_author The comment author's username. * @param string $comment_id The comment ID as a numeric string. * @param WP_Comment $comment The comment object. */
/** * Retrieves the author who last edited the current post. * * @since 2.8.0 * * @return string|void The author's display name, empty string if unknown. */
function get_the_modified_author() {
    $last_id = get_post_meta( get_post()->ID, '_edit_last', true );

    if ( $last_id ) {
        $last_user = get_userdata( $last_id );

        /** * Filters the display name of the author who last edited the current post. * * @since 2.8.0 * * @param string $display_name The author's display name, empty string if unknown. */
        return apply_filters( 'the_modified_author', $last_user ? $last_user->display_name : '' );
    }
}


            echo '</p>';
        } elseif ( null === $result || is_wp_error( $result ) ) {
            ?> <h2><?php _e( 'An error occurred during the activation' ); ?></h2> <?php if ( is_wp_error( $result ) ) : ?> <p><?php echo $result->get_error_message(); ?></p> <?php endif; ?> <?php         } else {
            $url  = isset( $result['blog_id'] ) ? get_home_url( (int) $result['blog_id'] ) : '';
            $user = get_userdata( (int) $result['user_id'] );
            ?> <h2><?php _e( 'Your account is now active!' ); ?></h2> <div id="signup-welcome"> <p><span class="h3"><?php _e( 'Username:' ); ?></span> <?php echo $user->user_login; ?></p> <p><span class="h3"><?php _e( 'Password:' ); ?></span> <?php echo $result['password']; ?></p> </div> <?php             if ( $url && network_home_url( '', 'http' ) !== $url ) :
                switch_to_blog( (int) $result['blog_id'] );
                
$page_date_gmt = $this->_convert_date_gmt( $page->post_date_gmt, $page->post_date );

        // Pull the categories info together.         $categories = array();
        if ( is_object_in_taxonomy( 'page', 'category' ) ) {
            foreach ( wp_get_post_categories( $page->ID ) as $cat_id ) {
                $categories[] = get_cat_name( $cat_id );
            }
        }

        // Get the author info.         $author = get_userdata( $page->post_author );

        $page_template = get_page_template_slug( $page->ID );
        if ( empty( $page_template ) ) {
            $page_template = 'default';
        }

        $_page = array(
            'dateCreated'            => $page_date,
            'userid'                 => $page->post_author,
            'page_id'                => $page->ID,
            'page_status'            => $page->post_status,
            
Home | Imprint | This part of the site doesn't use cookies.