On this page
WP_Posts_List_Table::__construct( array $args = array() )
Constructor.
Description
See also
- WP_List_Table::__construct(): for more information on default arguments.
Parameters
$argsarray Optional-
An associative array of arguments.
Default:
array()
Source
File: wp-admin/includes/class-wp-posts-list-table.php. View all references
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
)
);
}
}
Related
Uses
| Uses | Description |
|---|---|
| WP_List_Table::__construct() wp-admin/includes/class-wp-list-table.php | Constructor. |
| get_post_stati() wp-includes/post.php | Gets a list of post statuses. |
| current_user_can() wp-includes/capabilities.php | Returns whether the current user has the specified capability. |
| get_option() wp-includes/option.php | Retrieves an option value based on an option name. |
| get_current_user_id() wp-includes/user.php | Gets the current user’s ID. |
| get_post_type_object() wp-includes/post.php | Retrieves a post type object by name. |
| wpdb::get_var() wp-includes/class-wpdb.php | Retrieves one variable from the database. |
| wpdb::prepare() wp-includes/class-wpdb.php | Prepares a SQL query for safe execution. |
Changelog
| Version | Description |
|---|---|
| 3.1.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_posts_list_table/__construct