BP_Activity_Activity:: get_activity_data (数组activity_id美元=数组())
将活动id转换为活动对象,如模板循环中预期的那样。
描述
参数
- activity_id美元
-
(数组)(可选)活动id数组。
默认值:数组()
返回
(数组)
源
文件:bp-activity /类/ class-bp-activity-activity.php
Protected static function get_activity_data($activity_ids = array()) {global $wpdb;//如果没有活动ID通过,则退出。If (empty($activity_ids)){返回数组();} //获取BuddyPress。英国石油美元= buddypress ();$ =活动数组();$uncached_ids = bp_get_non_cached_ids($activity_ids, 'bp_activity');//主要缓存。如果(!empty($uncached_ids)){//下面查询中使用的活动ID的格式。 $uncached_ids_sql = implode( ',', wp_parse_id_list( $uncached_ids ) ); // Fetch data from activity table, preserving order. $queried_adata = $wpdb->get_results( "SELECT * FROM {$bp->activity->table_name} WHERE id IN ({$uncached_ids_sql})"); // Put that data into the placeholders created earlier, // and add it to the cache. foreach ( (array) $queried_adata as $adata ) { wp_cache_set( $adata->id, $adata, 'bp_activity' ); } } // Now fetch data from the cache. foreach ( $activity_ids as $activity_id ) { // Integer casting. $activity = wp_cache_get( $activity_id, 'bp_activity' ); if ( ! empty( $activity ) ) { $activity->id = (int) $activity->id; $activity->user_id = (int) $activity->user_id; $activity->item_id = (int) $activity->item_id; $activity->secondary_item_id = (int) $activity->secondary_item_id; $activity->hide_sitewide = (int) $activity->hide_sitewide; $activity->mptt_left = (int) $activity->mptt_left; $activity->mptt_right = (int) $activity->mptt_right; $activity->is_spam = (int) $activity->is_spam; } $activities[] = $activity; } // Then fetch user data. $user_query = new BP_User_Query( array( 'user_ids' => wp_list_pluck( $activities, 'user_id' ), 'populate_extras' => false, ) ); // Associated located user data with activity items. foreach ( $activities as $a_index => $a_item ) { $a_user_id = intval( $a_item->user_id ); $a_user = isset( $user_query->results[ $a_user_id ] ) ? $user_query->results[ $a_user_id ] : ''; if ( !empty( $a_user ) ) { $activities[ $a_index ]->user_email = $a_user->user_email; $activities[ $a_index ]->user_nicename = $a_user->user_nicename; $activities[ $a_index ]->user_login = $a_user->user_login; $activities[ $a_index ]->display_name = $a_user->display_name; } } return $activities; }
更新日志
版本 | 描述 |
---|---|
BuddyPress 2.0.0 | 介绍了。 |