* Basically a copy of {@link _oembed_rest_pre_serve_request()}. Unfortunate * that we have to duplicate this just for a URL check. * * @since 2.6.0 * * @param bool $served Whether the request has already been served. * @param WP_HTTP_ResponseInterface $result Result to send to the client. Usually a WP_REST_Response. * @param WP_REST_Request $request Request used to generate the response. * @param WP_REST_Server $server Server instance. * @return bool */ public function oembed_xml_request( $served, $result, $request, $server ) { $params = $request->get_params(); if ( ! isset( $params['format'] ) || 'xml' !== $params['format'] ) { return $served; } // Validate URL against our oEmbed endpoint. If not valid, bail. // This is our mod to _oembed_rest_pre_serve_request(). $query_params = $request->get_query_params(); if ( ! isset( $query_params['url'] ) || false === $this->validate_url_to_item_id( $query_params['url'] ) ) { return $served; } // Embed links inside the request. $data = $server->response_to_data( $result, false ); if ( ! class_exists( 'SimpleXMLElement' ) ) { status_header( 501 ); die( esc_html( get_status_header_desc( 501 ) ) ); } $result = _oembed_create_xml( $data ); // Bail if there's no XML. if ( ! $result ) { status_header( 501 ); return get_status_header_desc( 501 ); } if ( ! headers_sent() ) { $server->send_header( 'Content-Type', 'text/xml; charset=' . get_option( 'blog_charset' ) ); } // phpcs:ignore WordPress.Security.EscapeOutput echo $result; return true; } /** * Pass our BuddyPress activity permalink for embedding. * * @since 2.6.0 * * @see bp_activity_embed_rest_route_callback() * * @param string $retval Current embed URL. * @return string */ public function filter_embed_url( $retval ) { if ( false === isset( buddypress()->{$this->slug_endpoint}->embedurl_in_progress ) && ! $this->is_page() ) { return $retval; } $url = $this->is_page() ? $this->set_permalink() : buddypress()->{$this->slug_endpoint}->embedurl_in_progress; $url = trailingslashit( $url ); // This is for the 'WordPress Embed' block // @see bp_activity_embed_comments_button(). if ( 'the_permalink' !== current_filter() ) { $url = add_query_arg( 'embed', 'true', trailingslashit( $url ) ); // Add custom route args to iframe. if ( isset( buddypress()->{$this->slug_endpoint}->embedargs_in_progress ) && buddypress()->{$this->slug_endpoint}->embedargs_in_progress ) { foreach( buddypress()->{$this->slug_endpoint}->embedargs_in_progress as $key => $value ) { $url = add_query_arg( $key, $value, $url ); } } } return $url; } /** * Filters the embed HTML for our BP oEmbed endpoint. * * @since 2.6.0 * * @param string $retval Current embed HTML. * @return string */ public function filter_embed_html( $retval ) { if ( false === isset( buddypress()->{$this->slug_endpoint}->embedurl_in_progress ) && ! $this->is_page() ) { return $retval; } $url = $this->set_permalink(); $item_id = $this->is_page() ? $this->validate_url_to_item_id( $url ) : buddypress()->{$this->slug_endpoint}->embedid_in_progress; // Change 'Embedded WordPress Post' to custom title. $custom_title = $this->set_iframe_title( $item_id ); if ( ! empty( $custom_title ) ) { $title_pos = strpos( $retval, 'title=' ) + 7; $title_end_pos = strpos( $retval, '"', $title_pos ); $retval = substr_replace( $retval, esc_attr( $custom_title ), $title_pos, $title_end_pos - $title_pos ); } // Add 'max-width' CSS attribute to IFRAME. // This will make our oEmbeds responsive. if ( false === strpos( $retval, 'style="max-width' ) ) { $retval = str_replace( '. $retval = substr( $retval, strpos( $retval, '' ) + 13 ); // Set up new fallback HTML // @todo Maybe use KSES? $fallback_html = $this->set_fallback_html( $item_id ); /** * Dynamic filter to return BP oEmbed HTML. * * @since 2.6.0 * * @var string $retval */ return apply_filters( "bp_{$this->slug_endpoint}_embed_html", $fallback_html . $retval ); } /** * Append our custom slug endpoint to oEmbed endpoint URL. * * Meant to be used as a filter on 'rest_url' before any call to * {@link get_oembed_endpoint_url()} is used. * * @since 2.6.0 * * @see add_oembed_discovery_links() * * @param string $retval Current oEmbed endpoint URL. * @return string */ public function filter_rest_url( $retval = '' ) { return $retval . "/{$this->slug_endpoint}"; } /** * Inject content into the embed template. * * @since 2.6.0 */ public function inject_content() { if ( ! $this->is_page() ) { return; } $this->content(); } }