BP_REST_Blogs_Endpoint::get_items( WP_REST_Request $request )
Retrieve Blogs.
Description
Parameters
- $request
-
(Required) Full details about the request.
Return
(WP_REST_Response) | WP_Error
Source
File: bp-blogs/classes/class-bp-rest-blogs-endpoint.php
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | public function get_items( $request ) { $args = array ( 'type' => $request [ 'type' ], 'include_blog_ids' => $request [ 'include' ], 'user_id' => $request [ 'user_id' ], 'search_terms' => $request [ 'search' ], 'page' => $request [ 'page' ], 'per_page' => $request [ 'per_page' ], ); /** * 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_blogs_get_items_query_args' , $args , $request ); // false is the default value for some args. foreach ( $args as $key => $value ) { if ( empty ( $value ) ) { $args [ $key ] = false; } } // Check if user is valid. if ( 0 !== $request [ 'user_id' ] ) { $user = get_user_by( 'id' , $request [ 'user_id' ] ); if ( ! $user instanceof WP_User ) { return new WP_Error( 'bp_rest_blogs_get_items_user_failed' , __( 'There was a problem confirming if user ID provided is a valid one.' , 'buddyboss' ), array ( 'status' => 500, ) ); } } // Actually, query it. $blogs = bp_blogs_get_blogs( $args ); $retval = array (); foreach ( ( array ) $blogs [ 'blogs' ] as $blog ) { $retval [] = $this ->prepare_response_for_collection( $this ->prepare_item_for_response( $blog , $request ) ); } $response = rest_ensure_response( $retval ); $response = bp_rest_response_add_total_headers( $response , $blogs [ 'total' ], $args [ 'per_page' ] ); /** * Fires after blogs are fetched via the REST API. * * @param array $blogs Fetched blogs. * @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_blogs_get_items' , $blogs , $response , $request ); return $response ; } |
Changelog
Version | Description |
---|---|
0.1.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.