BP_REST_Activity_Link_Preview_Endpoint::get_items( WP_REST_Request $request )
Retrieve activity link preview.
Description
Parameters
- $request
-
(Required) Full details about the request.
Return
(WP_REST_Response) | WP_Error
Source
File: bp-activity/classes/class-bp-rest-activity-link-preview-endpoint.php
public function get_items( $request ) { $url = $request->get_param( 'url' ); if ( ! wp_http_validate_url( $url ) ) { return new WP_Error( 'bp_rest_invalid_url', __( 'Sorry, URL is not valid.', 'buddyboss' ), array( 'status' => 400, ) ); } $retval = array( 'title' => '', 'description' => '', 'images' => '', 'error' => '', 'wp_embed' => '', ); // Get URL parsed data. $parse_url_data = ( function_exists( 'bp_core_parse_url' ) ? bp_core_parse_url( $url ) : '' ); // If empty data then send error. if ( empty( $parse_url_data ) ) { return new WP_Error( 'bp_rest_unknown_error', __( 'Sorry! preview is not available right now. Please try again later.', 'buddyboss' ), array( 'status' => 400, ) ); } $retval = array_merge( $retval, $parse_url_data ); $retval = $this->add_additional_fields_to_object( $retval, $request ); $response = rest_ensure_response( $retval ); /** * Fires after the activity link preview is fetched via the REST API. * * @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_activity_link_preview_get_items', $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.