BP_Embed::shortcode( array $attr, string $url = '' )
The {@link do_shortcode()} callback function.
Description
Attempts to convert a URL into embed HTML. Starts by checking the URL against the regex of the registered embed handlers. Next, checks the URL against the regex of registered WP_oEmbed providers if oEmbed discovery is false. If none of the regex matches and it’s enabled, then the URL will be passed to BP_Embed::parse_oembed() for oEmbed parsing.
Parameters
- $attr
-
(Required) Shortcode attributes.
- $url
-
(Optional) The URL attempting to be embeded.
Default value: ''
Return
(string) The embed HTML on success, otherwise the original URL.
Source
File: bp-core/classes/class-bp-embed.php
public function shortcode( $attr, $url = '' ) { if ( empty( $url ) ) return ''; $rawattr = $attr; $attr = wp_parse_args( $attr, wp_embed_defaults() ); // Use kses to convert & into & and we need to undo this // See https://core.trac.wordpress.org/ticket/11311. $url = str_replace( '&', '&', $url ); // Look for known internal handlers. ksort( $this->handlers ); foreach ( $this->handlers as $priority => $handlers ) { foreach ( $handlers as $hid => $handler ) { if ( preg_match( $handler['regex'], $url, $matches ) && is_callable( $handler['callback'] ) ) { if ( false !== $return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr ) ) { /** * Filters the oEmbed handler result for the provided URL. * * @since BuddyPress 1.5.0 * * @param string $return Handler callback for the oEmbed. * @param string $url URL attempting to be embedded. * @param array $attr Shortcode attributes. */ return apply_filters( 'embed_handler_html', $return, $url, $attr ); } } } } /** * Filters the embed object ID. * * @since BuddyPress 1.5.0 * * @param int $value Value of zero. */ $id = apply_filters( 'embed_post_id', 0 ); $unfiltered_html = current_user_can( 'unfiltered_html' ); $default_discovery = false; // Since 4.4, WordPress is now an oEmbed provider. if ( function_exists( 'wp_oembed_register_route' ) ) { $unfiltered_html = true; $default_discovery = true; } /** * Filters whether or not oEmbed discovery is on. * * @since BuddyPress 1.5.0 * @since BuddyPress 2.5.0 Default status of oEmbed discovery has been switched * to true to apply changes introduced in WordPress 4.4 * * @param bool $default_discovery Current status of oEmbed discovery. */ $attr['discover'] = ( apply_filters( 'bp_embed_oembed_discover', $default_discovery ) && $unfiltered_html ); // Set up a new WP oEmbed object to check URL with registered oEmbed providers. require_once( ABSPATH . WPINC . '/class-oembed.php' ); $oembed_obj = _wp_oembed_get_object(); // If oEmbed discovery is true, skip oEmbed provider check. $is_oembed_link = false; if ( !$attr['discover'] ) { foreach ( (array) $oembed_obj->providers as $provider_matchmask => $provider ) { $regex = ( $is_regex = $provider[1] ) ? $provider_matchmask : '#' . str_replace( '___wildcard___', '(.+)', preg_quote( str_replace( '*', '___wildcard___', $provider_matchmask ), '#' ) ) . '#i'; if ( preg_match( $regex, $url ) ) $is_oembed_link = true; } // If url doesn't match a WP oEmbed provider, stop parsing. if ( !$is_oembed_link ) return $this->maybe_make_link( $url ); } return $this->parse_oembed( $id, $url, $attr, $rawattr ); }
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.