BP_REST_Group_Membership_Endpoint:: update_item_permissions_check (WP_REST_Request美元的请求)
检查给定的请求是否有权限更新组成员。
描述
参数
- 美元的请求
-
(WP_REST_Request)(必需)请求的全部细节。
返回
(WP_Error | bool)
源
文件:bp-groups /类/ class-bp-rest-group-membership-endpoint.php
Public function update_item_permissions_check($request) {$retval = true;如果(!is_user_logged_in()) {$retval = new WP_Error('bp_rest_authorization_required', __('对不起,你需要登录进行更新。', 'buddyboss'), array('status' => rest_authorization_required_code(),));} $user = bp_rest_get_user($request['user_id']);If (true === $retval && !$user instanceof WP_User) {$retval = new WP_Error('bp_rest_group_member_invalid_id', __('无效的组成员ID。', 'buddyboss'), array('status' => 404,));} $group = $this-> group_endpoint ->get_group_object($request['group_id']);If (true === $retval && !$group instanceof bp_group_group) {$retval = new WP_Error('bp_rest_group_invalid_id', __('无效的组ID。', 'buddyboss'), array('status' => 404,));} //站点管理员可以做任何事情。 if ( true === $retval && bp_current_user_can( 'bp_moderate' ) ) { $retval = true; } else { $loggedin_user_id = bp_loggedin_user_id(); if ( true === $retval && in_array( $request['action'], array( 'ban', 'unban', 'promote', 'demote' ), true ) ) { if ( ! groups_is_user_admin( $loggedin_user_id, $group->id ) && ! groups_is_user_mod( $loggedin_user_id, $group->id ) ) { $messages = array( 'ban' => __( 'Sorry, you are not allowed to ban this group member.', 'buddyboss' ), 'unban' => __( 'Sorry, you are not allowed to unban this group member.', 'buddyboss' ), 'promote' => __( 'Sorry, you are not allowed to promote this group member.', 'buddyboss' ), 'demote' => __( 'Sorry, you are not allowed to demote this group member.', 'buddyboss' ), ); $retval = new WP_Error( 'bp_rest_group_member_cannot_' . $request['action'], $messages[ $request['action'] ], array( 'status' => rest_authorization_required_code(), ) ); } else { $retval = true; } } } /** * Filter the group members `update_item` permissions check. * * @param bool|WP_Error $retval Returned value. * @param WP_REST_Request $request The request sent to the API. * * @since 0.1.0 */ return apply_filters( 'bp_rest_group_members_update_item_permissions_check', $retval, $request ); }
更新日志
版本 | 描述 |
---|---|
0.1.0 | 介绍了。 |