| 1178 | | // Unknown URL format. Let oEmbed have a go. |
| | 1175 | // Let 3rd-party plugins override post ID so they can easily extend the WP_Embed class |
| | 1176 | $post_ID = apply_filters( 'embed_post_id', $post_ID ); |
| | 1177 | |
| | 1178 | // Is oEmbed discovery on? |
| | 1179 | $attr['discover'] = ( apply_filters( 'embed_oembed_discover', false ) && apply_filters( 'embed_oembed_author_can', author_can( $post_ID, 'unfiltered_html' ), $post_ID ) ); |
| | 1180 | |
| | 1181 | // Set up a new WP oEmbed object to check URL with registered oEmbed providers |
| | 1182 | require_once( ABSPATH . WPINC . '/class-oembed.php' ); |
| | 1183 | $oembed_obj = _wp_oembed_get_object(); |
| | 1184 | |
| | 1185 | // If oEmbed discovery is true, skip oEmbed provider check |
| | 1186 | $is_oembed_link = false; |
| | 1187 | if ( !$attr['discover'] ) { |
| | 1188 | foreach ( (array)$oembed_obj->providers as $provider_matchmask => $provider ) { |
| | 1189 | $regex = ( $is_regex = $provider[1] ) ? $provider_matchmask : '#' . str_replace( '___wildcard___', '(.+)', preg_quote( str_replace( '*', '___wildcard___', $provider_matchmask ), '#' ) ) . '#i'; |
| | 1190 | |
| | 1191 | if ( preg_match( $regex, $url ) ) |
| | 1192 | $is_oembed_link = true; |
| | 1193 | } |
| | 1194 | |
| | 1195 | // If url doesn't match a WP oEmbed provider, stop parsing |
| | 1196 | if ( !$is_oembed_link ) |
| | 1197 | return $this->maybe_make_link( $url ); |
| | 1198 | } |
| | 1199 | |
| | 1200 | return $this->parse_oembed( $post_ID, $url, $attr, $rawattr ); |
| | 1201 | } |
| | 1202 | |
| | 1203 | /** |
| | 1204 | * Attempts to convert a URL into embed HTML. Checks cache first. If no cache, ping oEmbed provider and cache the result. |
| | 1205 | * URL is passed to the {@link WP_oEmbed} class via {@link wp_oembed_get()}. |
| | 1206 | * 3rd party plugins not using post types could extend this class and function to grab their own cache. |
| | 1207 | * |
| | 1208 | * @uses wp_oembed_get() |
| | 1209 | * @uses WP_Embed::maybe_make_link() |
| | 1210 | * @uses get_post_meta() |
| | 1211 | * @uses update_post_meta() |
| | 1212 | * @param int $post_id Post ID to do the caching for. |
| | 1213 | * @param string $url The URL attempting to be embedded. |
| | 1214 | * @param array $attr Shortcode attributes. |
| | 1215 | * @param array $rawattr Untouched shortcode attributes. |
| | 1216 | * @return string The embed HTML on success, otherwise the original URL. |
| | 1217 | */ |
| | 1218 | function parse_oembed( $post_ID, $url, $attr, $rawattr ) { |