BP_REST_Groups_Endpoint:: get_item (WP_REST_Request美元的请求)
检索组。
描述
参数
- 美元的请求
-
(WP_REST_Request)(必需)请求的全部细节。
返回
(WP_REST_Response)| WP_Error组对象数据列表。
源
文件:bp-groups /类/ class-bp-rest-groups-endpoint.php
Public function get_items($request) {$args = array('type' => $request['type'], 'order' => $request['order'], 'fields' => $request['fields'], 'orderby' => $request['orderby'], 'user_id' => $request['user_id'], 'include' => $request['include'], 'parent_id' => $request['parent_id'], 'exclude' => $request['exclude'],' search_term ' = > $请求['搜索'],' meta_query ' = >请求(“元”),美元/ / phpcs:忽略“group_type”= > $请求(“group_type”),“show_hidden”= > $请求(“show_hidden”),“per_page”= > $请求(“per_page”),“地位”= > $请求“状态”,“页面”= >请求(“页”),美元);如果($request['parent_id']) {$args['parent_id'] = null;} //查看用户是否可以看到隐藏的组。If (isset($request['show_hidden']) && true === (bool) $request['show_hidden'] && !$this->can_see_hidden_groups($request) {$args['show_hidden'] = false;}如果(收取($请求(“范围”))){如果(“个人”= = = $请求(“范围”)){$ args [' user_id '] = (!($request['user_id']) ?(int)请求(“user_id”):美元get_current_user_id ());}} if ((empty($request['scope']) || (isset($request['scope']) && 'all' === $request['scope'])) && function_exists(' bp_group_get_excluded_group_ids_by_type ') && ! empty( bp_groups_get_excluded_group_ids_by_type() ) ) { $args['exclude'] = array_unique( bp_groups_get_excluded_group_ids_by_type() ); } /** * 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_groups_get_items_query_args', $args, $request ); // Actually, query it. $groups = groups_get_groups( $args ); // Users need (at least, should we be more restrictive ?) to be logged in to use the edit context. if ( 'edit' === $request->get_param( 'context' ) && ! is_user_logged_in() ) { $request->set_param( 'context', 'view' ); } $retval = array(); foreach ( $groups['groups'] as $group ) { $retval[] = $this->prepare_response_for_collection( $this->prepare_item_for_response( $group, $request ) ); } $response = rest_ensure_response( $retval ); $response = bp_rest_response_add_total_headers( $response, $groups['total'], $args['per_page'] ); /** * Fires after a list of groups is fetched via the REST API. * * @param array $groups Fetched groups. * @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_groups_get_items', $groups, $response, $request ); return $response; }
更新日志
版本 | 描述 |
---|---|
0.1.0 | 介绍了。 |