BP_REST_Members_Endpoint:: get_item (WP_REST_Request美元的请求

检索用户。

描述

参数

美元的请求

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

返回

(WP_REST_Response)| WP_Error

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

公共函数get_item(请求){$ args =阵列(“类型”= > $请求(“类型”),“user_id”= > $请求(“user_id”),“user_id”= > $请求(“user_id”),“xprofile_query”= > $请求(“xprofile”),“包括”= > $请求“包括”,“排除”= > $请求(“排除”),“member_type”= > $请求(“member_type”),“search_term”= > $请求(“搜索”),“per_page”= > $请求(“per_page”),“页面”= > $请求(“页面”));如果($request['user_ids']) {$args['user_ids'] = false;} if(空($request['exclude'])) {$args['exclude'] = false;} if(空($request['include'])) {$args['include'] = false;} if(空($request['xprofile']) {$args['xprofile_query'] = false;}如果[' member_type(空($请求 '] ) ) { $ args [' member_type '] = ";} if (!空($请求(“范围”))& &“所有”! = = $请求(“范围”)){如果('后' = = = $请求(“范围”)){$ user_id = (!($request['user_id']) ? (int) $request['user_id'] : get_current_user_id() ); $following_ids = $this->rest_bp_get_following_ids( array( 'user_id' => $user_id ) ); if ( ! empty( $following_ids ) ) { $args['include'] = $following_ids; unset( $args['user_id'] ); } else { $response = rest_ensure_response( array() ); return bp_rest_response_add_total_headers( $response, 0, $args['per_page'] ); } } if ( 'followers' === $request['scope'] ) { $user_id = ( ! empty( $request['user_id'] ) ? (int) $request['user_id'] : get_current_user_id() ); $followers_ids = $this->rest_bp_get_follower_ids( array( 'user_id' => $user_id ) ); if ( ! empty( $followers_ids ) ) { $args['include'] = $followers_ids; unset( $args['user_id'] ); } else { $response = rest_ensure_response( array() ); return bp_rest_response_add_total_headers( $response, 0, $args['per_page'] ); } } if ( 'personal' === $request['scope'] ) { $args['user_id'] = ( ! empty( $request['user_id'] ) ? (int) $request['user_id'] : get_current_user_id() ); } } if ( ! empty( $request['bp_ps_search'] ) ) { $results = $this->rest_bp_ps_search( $request['bp_ps_search'] ); if ( $results['validated'] ) { $users = $results['users']; if ( isset( $args['include'] ) && ! empty( $args['include'] ) ) { $included = explode( ',', $args['include'] ); $users = array_intersect( $users, $included ); if ( count( $users ) === 0 ) { $users = array( 0 ); } } $users = apply_filters( 'bp_ps_search_results', $users ); $args['include'] = implode( ',', $users ); } } if ( ( empty( $request['scope'] ) || ( isset( $request['scope'] ) && 'all' === $request['scope'] ) || empty( $request['bp_ps_search'] ) ) && function_exists( 'bp_get_users_of_removed_member_types' ) && ! empty( bp_get_users_of_removed_member_types() ) ) { $args['exclude'] = bp_get_users_of_removed_member_types(); } /** * Filter the query arguments for the request. * * @param array $args Key value array of query var to query value. * @param WP_REST_Request $request The request sent to the API. * * @since 0.1.0 */ $args = apply_filters( 'bp_rest_members_get_items_query_args', $args, $request ); // Actually, query it. $member_query = new BP_User_Query( $args ); $members = array_values( $member_query->results ); $retval = array(); foreach ( $members as $member ) { $retval[] = $this->prepare_response_for_collection( $this->prepare_item_for_response( $member, $request ) ); } $response = rest_ensure_response( $retval ); $response = bp_rest_response_add_total_headers( $response, $member_query->total_users, $args['per_page'] ); /** * Fires after a list of members is fetched via the REST API. * * @param array $members Fetched members. * @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_members_get_items', $members, $response, $request ); return $response; }

更新日志

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

问题吗?

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