BBP_Topic_Replies_List_Table::prepare_items( $topic_id )
Prepare the list-table items for display
Description Description
Source Source
File: includes/admin/classes/class-bbp-topic-replies-list-table.php
public function prepare_items( $topic_id = 0 ) {
// Sanitize the topic ID
$topic_id = bbp_get_topic_id( $topic_id );
// Set column headers
$this->_column_headers = array(
$this->get_columns(),
array(),
$this->get_sortable_columns()
);
// Handle bulk actions
$this->process_bulk_action();
// Query parameters
$per_page = 5;
$current_page = $this->get_pagenum();
$orderby = ! empty( $_REQUEST['orderby'] ) ? sanitize_key( $_REQUEST['orderby'] ) : 'date';
$order = ! empty( $_REQUEST['order'] ) ? sanitize_key( $_REQUEST['order'] ) : 'asc';
$statuses = bbp_get_public_reply_statuses();
// Maybe add private statuses to query
if ( current_user_can( 'edit_others_replies' ) ) {
// Default view=all statuses
$statuses = array_keys( bbp_get_topic_statuses() );
// Add support for private status
if ( current_user_can( 'read_private_replies' ) ) {
$statuses[] = bbp_get_private_status_id();
}
}
// Query for replies
$reply_query = new WP_Query( array(
'post_type' => bbp_get_reply_post_type(),
'post_status' => $statuses,
'post_parent' => $topic_id,
'posts_per_page' => $per_page,
'paged' => $current_page,
'orderby' => $orderby,
'order' => ucwords( $order ),
'hierarchical' => false,
'ignore_sticky_posts' => true
) );
// Get the total number of replies, for pagination
$total_items = bbp_get_topic_reply_count( $topic_id );
// Set list table items to queried posts
$this->items = $reply_query->posts;
// Set the pagination arguments
$this->set_pagination_args( array(
'total_items' => $total_items,
'per_page' => $per_page,
'total_pages' => ceil( $total_items / $per_page )
) );
}
Changelog Changelog
| Version | Description |
|---|---|
| 2.6.0 | Introduced. |