BP_REST_Group_Membership_Endpoint:: prepare_item_for_response (BP_Groups_Membergroup_member美元WP_REST_Request美元的请求

准备作为对象返回的组成员数据。

描述

参数

group_member美元

BP_Groups_Member(必需)小组成员对象。

美元的请求

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

返回

(WP_REST_Response)

文件:bp-groups /类/ class-bp-rest-group-membership-endpoint.php

Public function prepare_item_for_response($group_member, $request) {$user = bp_rest_get_user($group_member->user_id);$上下文= !空($request['context']) ?美元请求(“上下文”):“视图”;$member_data = $this->members_endpoint->user_data($user, $context);//合并两个信息。(data = array_merge美元member_data,阵列(' is_mod ' = > (bool) group_member美元- > is_mod, ' is_admin ' = > (bool) group_member美元- > is_admin, ' is_banned ' = > (bool) group_member美元- > is_banned, ' is_confirmed ' = > (bool) group_member美元- > is_confirmed, ' date_modified ' = > bp_rest_prepare_date_response (group_member美元- > date_modified),”作用 ' => '', ' plural_role ' = >”,));// BuddyBoss平台支持。If (function_exists('bp_get_user_group_role_title') && ! empty( $request['group_id'] ) ) { $data['role'] = bp_get_user_group_role_title( $group_member->user_id, $request['group_id'] ); // BuddyPress support. } elseif ( function_exists( 'bp_groups_get_group_roles' ) && ! empty( $request['group_id'] ) ) { $group_role = bp_groups_get_group_roles(); if ( groups_is_user_admin( $group_member->user_id, $request['group_id'] ) ) { $data['role'] = $group_role['admin']->name; } elseif ( groups_is_user_mod( $group_member->user_id, $request['group_id'] ) ) { $data['role'] = $group_role['mod']->name; } elseif ( groups_is_user_member( $group_member->user_id, $request['group_id'] ) ) { $data['role'] = $group_role['member']->name; } } if ( function_exists( 'get_group_role_label' ) && ! empty( $request['group_id'] ) ) { $data['plural_role'] = $this->groups_endpoint->bp_get_group_member_section_title( (int) $request['group_id'], (int) $group_member->user_id ); if ( empty( $data['plural_role'] ) ) { $data['plural_role'] = $data['role']; } } else { $data['plural_role'] = $data['role']; } $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( $user, $request ) ); /** * Filter a group member 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_Groups_Member $group_member Group member object. * * @since 0.1.0 */ return apply_filters( 'bp_rest_group_members_prepare_value', $response, $request, $group_member ); }

更新日志

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

问题吗?

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