Make WordPress Core

Ticket #17857: 17857.001.patch

File 17857.001.patch, 4.1 KB (added by r-a-y, 14 years ago)
  • wp-includes/media.php

     
    11301130         * The {@link do_shortcode()} callback function.
    11311131         *
    11321132         * Attempts to convert a URL into embed HTML. Starts by checking the URL against the regex of the registered embed handlers.
    1133          * If none of the regex matches and it's enabled, then the URL will be given to the {@link WP_oEmbed} class.
     1133         * Next, checks the URL against the regex of registered {@link WP_oEmbed} providers if oEmbed discovery is false.
     1134         * If none of the regex matches and it's enabled, then the URL will be passed to {@link WP_Embed::parse_oembed()} for oEmbed parsing.
    11341135         *
    1135          * @uses wp_oembed_get()
    11361136         * @uses wp_parse_args()
    11371137         * @uses wp_embed_defaults()
     1138         * @uses author_can()
     1139         * @uses _wp_oembed_get_object()
    11381140         * @uses WP_Embed::maybe_make_link()
    1139          * @uses get_option()
    1140          * @uses current_user_can()
    1141          * @uses wp_cache_get()
    1142          * @uses wp_cache_set()
    1143          * @uses get_post_meta()
    1144          * @uses update_post_meta()
    11451141         *
    11461142         * @param array $attr Shortcode attributes.
    11471143         * @param string $url The URL attempting to be embeded.
     
    11711167                        }
    11721168                }
    11731169
     1170                // Get post ID
    11741171                $post_ID = ( !empty($post->ID) ) ? $post->ID : null;
    1175                 if ( !empty($this->post_ID) ) // Potentially set by WP_Embed::cache_oembed()
     1172                if ( !empty( $this->post_ID ) ) // Potentially set by WP_Embed::cache_oembed()
    11761173                        $post_ID = $this->post_ID;
    11771174
    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 ) {
    11791219                if ( $post_ID ) {
    11801220
    11811221                        // Check for a cached result (stored in the post meta)
     
    11871227                                if ( '{{unknown}}' === $cache )
    11881228                                        return $this->maybe_make_link( $url );
    11891229
    1190                                 if ( !empty($cache) )
     1230                                if ( !empty( $cache ) )
    11911231                                        return apply_filters( 'embed_oembed_html', $cache, $url, $attr, $post_ID );
    11921232                        }
    11931233
    11941234                        // Use oEmbed to get the HTML
    1195                         $attr['discover'] = ( apply_filters('embed_oembed_discover', false) && author_can( $post_ID, 'unfiltered_html' ) );
    11961235                        $html = wp_oembed_get( $url, $attr );
    11971236
    11981237                        // Cache the result