bp_rest_group_membership_endpoint :: update_item(wp_rest_request.$请求的)
更新组上的用户状态(添加,删除,推广,缩小或禁止)。
描述
参数
- $请求
-
(wp_rest_request.的)(必需的)有关该请求的完整详细信息。
返回
(wp_rest_response)|wp_error.
来源
文件:bp-groups / classes / class-bp-rest-group-membershial-endpoint.php
公共功能update_item($请求){$ user = bp_rest_get_user($请求['user_id']);$ group = $ this-> groups_endpoint-> get_group_object($请求['group_id']);$ action = $请求['行动'];$角色= $请求[''角色];$ group_id = $ group-> ID;$ group_member = new bp_groups_member($ user-> id,$ group_id);/ ** *在推广用户到新状态之前发射。* * @param int $ group_id被录制的组的explate。* @param int $ user_id被推广的用户。* @param string $ status正在推广新状态。* / do_action(“组_ {$ action} _member”,$ group_id,$用户 - > ID,$角色); if ( 'promote' === $action ) { if ( ! $group_member->promote( $role ) ) { return new WP_Error( 'bp_rest_group_member_failed_to_promote', __( 'Could not promote member.', 'buddyboss' ), array( 'status' => 500, ) ); } } elseif ( 'demote' === $action && 'member' !== $role ) { if ( ! $group_member->promote( $role ) ) { return new WP_Error( 'bp_rest_group_member_failed_to_demote', __( 'Could not demote member.', 'buddyboss' ), array( 'status' => 500, ) ); } } elseif ( in_array( $action, array( 'demote', 'ban', 'unban' ), true ) ) { if ( ! $group_member->$action() ) { $messages = array( 'demote' => __( 'Could not demote member from the group.', 'buddyboss' ), 'ban' => __( 'Could not ban member from the group.', 'buddyboss' ), 'unban' => __( 'Could not unban member from the group.', 'buddyboss' ), ); return new WP_Error( 'bp_rest_group_member_failed_to_' . $action, $messages[ $action ], array( 'status' => 500, ) ); } } $after_action = array( 'promote' => 'promoted', 'demote' => 'demoted', 'ban' => 'banned', 'unban' => 'unbanned', ); /** * Fires after a group member has been updated. * * @param int $user_id ID of the user being updated. * @param int $group_id ID of the group. */ do_action( "groups_{$after_action[$action]}_member", $user->ID, $group_id ); // Setting context. $request->set_param( 'context', 'edit' ); $retval = $this->prepare_response_for_collection( $this->prepare_item_for_response( $group_member, $request ) ); $response = rest_ensure_response( $retval ); /** * Fires after a group member is updated via the REST API. * * @param WP_User $user The updated member. * @param BP_Groups_Member $group_member The group member object. * @param BP_Groups_Group $group The group object. * @param WP_REST_Response $response The response data. * @param WP_REST_Request $request The request sent to the API. * * @since 0.1.0 */ do_action( 'bp_rest_group_members_update_item', $user, $group_member, $group, $response, $request ); return $response; }
变更乐
版本 | 描述 |
---|---|
0.1.0. | 介绍。 |