BP_Activity_Template::__construct( array $args )
Constructor method.
Description Description
The arguments passed to this class constructor are of the same format as BP_Activity_Activity::get().
See also See also
- BP_Activity_Activity::get(): for a description of the argument structure, as well as default values.
Parameters Parameters
- $args
-
(Required) Array of arguments. Supports all arguments from BP_Activity_Activity::get(), as well as 'page_arg' and 'include'. Default values for 'per_page' and 'display_comments' differ from the originating function, and are described below.
- 'page_arg'
(string) The string used as a query parameter in pagination links. Default: 'acpage'. - 'include'
(array|bool) Pass an array of activity IDs to retrieve only those items, or false to noop the 'include' parameter. 'include' differs from 'in' in that 'in' forms an IN clause that works in conjunction with other filters passed to the function, while 'include' is interpreted as an exact list of items to retrieve, which skips all other filter-related parameters. Default: false. - 'per_page'
(int|bool) Default: 20. - 'display_comments'
(string|bool) Default: 'threaded'.
- 'page_arg'
Source Source
File: bp-activity/classes/class-bp-activity-template.php
public function __construct( $args ) { $bp = buddypress(); $function_args = func_get_args(); // Backward compatibility with old method of passing arguments. if ( !is_array( $args ) || count( $function_args ) > 1 ) { _deprecated_argument( __METHOD__, '1.6', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) ); $old_args_keys = array( 0 => 'page', 1 => 'per_page', 2 => 'max', 3 => 'include', 4 => 'sort', 5 => 'filter', 6 => 'search_terms', 7 => 'display_comments', 8 => 'show_hidden', 9 => 'exclude', 10 => 'in', 11 => 'spam', 12 => 'page_arg' ); $args = bp_core_parse_args_array( $old_args_keys, $function_args ); } $defaults = array( 'page' => 1, 'per_page' => 20, 'page_arg' => 'acpage', 'max' => false, 'fields' => 'all', 'count_total' => false, 'sort' => false, 'include' => false, 'exclude' => false, 'in' => false, 'filter' => false, 'scope' => false, 'search_terms' => false, 'meta_query' => false, 'date_query' => false, 'filter_query' => false, 'display_comments' => 'threaded', 'show_hidden' => false, 'spam' => 'ham_only', 'update_meta_cache' => true, ); $r = wp_parse_args( $args, $defaults ); extract( $r ); $this->pag_arg = sanitize_key( $r['page_arg'] ); $this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $r['page'] ); $this->pag_num = bp_sanitize_pagination_arg( 'num', $r['per_page'] ); // Check if post/comment replies are disabled. $this->disable_blogforum_replies = (bool) bp_core_get_root_option( 'bp-disable-blogforum-comments' ); // Get an array of the logged in user's favorite activities. $this->my_favs = bp_get_user_meta( bp_loggedin_user_id(), 'bp_favorite_activities', true ); // Fetch specific activity items based on ID's. if ( !empty( $include ) ) { $this->activities = bp_activity_get_specific( array( 'activity_ids' => explode( ',', $include ), 'max' => $max, 'count_total' => $count_total, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'sort' => $sort, 'display_comments' => $display_comments, 'show_hidden' => $show_hidden, 'spam' => $spam, 'update_meta_cache' => $update_meta_cache, ) ); // Fetch all activity items. } else { $this->activities = bp_activity_get( array( 'display_comments' => $display_comments, 'max' => $max, 'count_total' => $count_total, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'sort' => $sort, 'search_terms' => $search_terms, 'meta_query' => $meta_query, 'date_query' => $date_query, 'filter_query' => $filter_query, 'filter' => $filter, 'scope' => $scope, 'show_hidden' => $show_hidden, 'exclude' => $exclude, 'in' => $in, 'spam' => $spam, 'update_meta_cache' => $update_meta_cache, ) ); } // The total_activity_count property will be set only if a // 'count_total' query has taken place. if ( ! is_null( $this->activities['total'] ) ) { if ( ! $max || $max >= (int) $this->activities['total'] ) { $this->total_activity_count = (int) $this->activities['total']; } else { $this->total_activity_count = (int) $max; } } $this->has_more_items = $this->activities['has_more_items']; $this->activities = $this->activities['activities']; if ( $max ) { if ( $max >= count($this->activities) ) { $this->activity_count = count( $this->activities ); } else { $this->activity_count = (int) $max; } } else { $this->activity_count = count( $this->activities ); } $this->full_name = bp_get_displayed_user_fullname(); // Fetch parent content for activity comments so we do not have to query in the loop. foreach ( (array) $this->activities as $activity ) { if ( 'activity_comment' != $activity->type ) { continue; } $parent_ids[] = $activity->item_id; } if ( !empty( $parent_ids ) ) { $activity_parents = bp_activity_get_specific( array( 'activity_ids' => $parent_ids ) ); } if ( !empty( $activity_parents['activities'] ) ) { foreach( $activity_parents['activities'] as $parent ) { $this->activity_parents[$parent->id] = $parent; } unset( $activity_parents ); } if ( (int) $this->total_activity_count && (int) $this->pag_num ) { $this->pag_links = paginate_links( array( 'base' => add_query_arg( $this->pag_arg, '%#%' ), 'format' => '', 'total' => ceil( (int) $this->total_activity_count / (int) $this->pag_num ), 'current' => (int) $this->pag_page, 'prev_text' => _x( '←', 'Activity pagination previous text', 'buddypress' ), 'next_text' => _x( '→', 'Activity pagination next text', 'buddypress' ), 'mid_size' => 1, 'add_args' => array(), ) ); } }
Changelog Changelog
Version | Description |
---|---|
1.5.0 | Introduced. |