WP_Posts_List_Table::__construct() WordPress Method

The WP_Posts_List_Table::__construct() method is used to setup the display of the posts list table. It takes care of the display of the table headers, footers, and other data.

WP_Posts_List_Table::__construct( array $args = array() ) #

Constructor.


Description

Top ↑

See also


Top ↑

Parameters

$args

(array)(Optional)An associative array of arguments.

Default value: array()


Top ↑

Source

File: wp-admin/includes/class-wp-posts-list-table.php

74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
public function __construct( $args = array() ) {
    global $post_type_object, $wpdb;
 
    parent::__construct(
        array(
            'plural' => 'posts',
            'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
        )
    );
 
    $post_type        = $this->screen->post_type;
    $post_type_object = get_post_type_object( $post_type );
 
    $exclude_states = get_post_stati(
        array(
            'show_in_admin_all_list' => false,
        )
    );
 
    $this->user_posts_count = (int) $wpdb->get_var(
        $wpdb->prepare(
            "SELECT COUNT( 1 )
            FROM $wpdb->posts
            WHERE post_type = %s
            AND post_status NOT IN ( '" . implode( "','", $exclude_states ) . "' )
            AND post_author = %d",
            $post_type,
            get_current_user_id()
        )
    );
 
    if ( $this->user_posts_count
        && ! current_user_can( $post_type_object->cap->edit_others_posts )
        && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] )
        && empty( $_REQUEST['author'] ) && empty( $_REQUEST['show_sticky'] )
    ) {
        $_GET['author'] = get_current_user_id();
    }
 
    $sticky_posts = get_option( 'sticky_posts' );
 
    if ( 'post' === $post_type && $sticky_posts ) {
        $sticky_posts = implode( ', ', array_map( 'absint', (array) $sticky_posts ) );
 
        $this->sticky_posts_count = (int) $wpdb->get_var(
            $wpdb->prepare(
                "SELECT COUNT( 1 )
                FROM $wpdb->posts
                WHERE post_type = %s
                AND post_status NOT IN ('trash', 'auto-draft')
                AND ID IN ($sticky_posts)",
                $post_type
            )
        );
    }
}


Top ↑

Changelog

Changelog
VersionDescription
3.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by the Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.