BP_REST_Activity_Endpoint:: prepare_item_for_response (BP_Activity_Activity美元的活动WP_REST_Request美元的请求

准备活动数据作为对象返回。

描述

参数

美元的活动

BP_Activity_Activity(必需)活动数据。

美元的请求

WP_REST_Request(必需)请求的全部细节。

返回

(WP_REST_Response)

文件:bp-activity /类/ class-bp-rest-activity-endpoint.php

Public function prepare_item_for_response($activity, $request) {$top_level_parent_id = 'activity_comment' === $activity->type ?活动- > item_id: 0;全球activities_template美元;$ actives_template = new \stdClass();$activities_template->disable_blogforum_replies = (bool) bp_core_get_root_option('bp-disable-blogforum-comments');= $ $ activities_template - >活动活动;$ data =数组(“user_id”= >活动- > user_id美元,'名字' = > bp_core_get_user_displayname(活动——> user_id美元),“组件”活动——美元= > >组件,“内容”= >数组('生' = >活动- >内容,“呈现”= > $ this - > render_item(活动)美元),“日期”= > bp_rest_prepare_date_response($活动——> date_recorded),“id”活动——美元= > > id,'link' => bp_activity_get_permalink($activity->id), 'primary_item_id' => $activity->item_id, 'secondary_item_id' => $activity->secondary_item_id, 'status' => $activity->is_spam ?'spam': 'published', 'title' => $activity->action, 'type' => $activity->type, 'favorited' => in_array($activity->id, $this->get_user_favorites(), true), //扩展响应。$this->get_activity_favorite_count($activity->id), 'can_comment' => ('activity_comment' === $activity->type) ? bp_activity_can_comment_reply( $activity ) : bp_activity_can_comment(), 'can_delete' => bp_activity_user_can_delete( $activity ), 'content_stripped' => html_entity_decode( wp_strip_all_tags( $activity->content ) ), 'privacy' => ( isset( $activity->privacy ) ? $activity->privacy : false ), ); // Get item schema. $schema = $this->get_item_schema(); // Get comments (count). if ( ! empty( $activity->children ) ) { $comment_count = wp_filter_object_list( $activity->children, array( 'type' => 'activity_comment' ), 'AND', 'id' ); $data['comment_count'] = ! empty( $comment_count ) ? count( $comment_count ) : 0; if ( ! empty( $schema['properties']['comments'] ) && 'threaded' === $request['display_comments'] ) { $data['comments'] = $this->prepare_activity_comments( $activity->children, $request ); } } else { $activities = BP_Activity_Activity::get_activity_comments( $activity->id, $activity->mptt_left, $activity->mptt_right, $request['status'], $top_level_parent_id ); $data['comment_count'] = ! empty( $activities ) ? count( $activities ) : 0; } if ( ! empty( $schema['properties']['user_avatar'] ) ) { $data['user_avatar'] = array( 'full' => bp_core_fetch_avatar( array( 'item_id' => $activity->user_id, 'html' => false, 'type' => 'full', ) ), 'thumb' => bp_core_fetch_avatar( array( 'item_id' => $activity->user_id, 'html' => false, ) ), ); } $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; $data = $this->add_additional_fields_to_object( $data, $request ); $data = $this->filter_response_by_context( $data, $context ); $response = rest_ensure_response( $data ); $response->add_links( $this->prepare_links( $activity ) ); /** * Filter an activity value returned from the API. * * @param WP_REST_Response $response The response data. * @param WP_REST_Request $request Request used to generate the response. * @param BP_Activity_Activity $activity The activity object. * * @since 0.1.0 */ return apply_filters( 'bp_rest_activity_prepare_value', $response, $request, $activity ); }

更新日志

更新日志
版本 描述
0.1.0 介绍了。

问题吗?

我们总是很乐意帮助您解决代码或其他问题!搜索我们的开发人员文档联络支持,或与我们联系销售团队