BP_Activity_List_Table: prepare_items ()
处理在渲染之前的数据,排序,分页和任何其他数据操作的过滤。
描述
源
文件:bp-activity /类/ class-bp-activity-list-table.php
function prepare_items(){//选项默认值。数组$过滤器= ();美元filter_query = false;美元include_id = false;美元search_term = false;美元类型=“DESC”;垃圾邮件美元=“ham_only”;//设置当前页面。$ = $ this - >页get_pagenum ();//设置每个页面从屏幕选项。 $per_page = $this->get_items_per_page( str_replace( '-', '_', "{$this->screen->id}_per_page" ) ); // Check if we're on the "Spam" view. if ( !empty( $_REQUEST['activity_status'] ) && 'spam' == $_REQUEST['activity_status'] ) { $spam = 'spam_only'; $this->view = 'spam'; } // Sort order. if ( !empty( $_REQUEST['order'] ) && 'desc' != $_REQUEST['order'] ) $sort = 'ASC'; // Order by. /*if ( !empty( $_REQUEST['orderby'] ) ) { }*/ // Filter. if ( ! empty( $_REQUEST['activity_type'] ) ) { $filter = array( 'action' => $_REQUEST['activity_type'] ); /** * Filter here to override the filter with a filter query * * @since BuddyPress 2.5.0 * * @param array $filter */ $has_filter_query = apply_filters( 'bp_activity_list_table_filter_activity_type_items', $filter ); if ( ! empty( $has_filter_query['filter_query'] ) ) { // Reset the filter $filter = array(); // And use the filter query instead $filter_query = $has_filter_query['filter_query']; } } // Are we doing a search? if ( !empty( $_REQUEST['s'] ) ) $search_terms = $_REQUEST['s']; // Check if user has clicked on a specific activity (if so, fetch only that, and any related, activity). if ( !empty( $_REQUEST['aid'] ) ) $include_id = (int) $_REQUEST['aid']; // Get the spam total (ignoring any search query or filter). $spams = bp_activity_get( array( 'display_comments' => 'stream', 'show_hidden' => true, 'spam' => 'spam_only', 'count_total' => 'count_query', ) ); $this->spam_count = $spams['total']; unset( $spams ); // Get the activities from the database. $activities = bp_activity_get( array( 'display_comments' => 'stream', 'filter' => $filter, 'in' => $include_id, 'page' => $page, 'per_page' => $per_page, 'search_terms' => $search_terms, 'filter_query' => $filter_query, 'show_hidden' => true, // 'sort' => $sort, 'spam' => $spam, 'count_total' => 'count_query', ) ); // If we're viewing a specific activity, flatten all activities into a single array. if ( $include_id ) { $activities['activities'] = BP_Activity_List_Table::flatten_activity_array( $activities['activities'] ); $activities['total'] = count( $activities['activities'] ); // Sort the array by the activity object's date_recorded value. usort( $activities['activities'], function( $a, $b ) { return $a->date_recorded > $b->date_recorded; } ); } // The bp_activity_get function returns an array of objects; cast these to arrays for WP_List_Table. $new_activities = array(); foreach ( $activities['activities'] as $activity_item ) { $new_activities[] = (array) $activity_item; // Build an array of activity-to-user ID mappings for better efficiency in the In Response To column. $this->activity_user_id[$activity_item->id] = $activity_item->user_id; } // Set raw data to display. $this->items = $new_activities; // Store information needed for handling table pagination. $this->set_pagination_args( array( 'per_page' => $per_page, 'total_items' => $activities['total'], 'total_pages' => ceil( $activities['total'] / $per_page ) ) ); // Don't truncate activity items; bp_activity_truncate_entry() needs to be used inside a BP_Activity_Template loop. remove_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 ); }
更新日志
版本 | 描述 |
---|---|
BuddyPress 1.6.0 | 介绍了。 |