Make WordPress Core

Ticket #25515: 25515.4.diff

File 25515.4.diff, 3.3 KB (added by DrewAPicture, 12 years ago)
  • src/wp-includes/class-wp-embed.php

     
    153153                        foreach ( $handlers as $id => $handler ) {
    154154                                if ( preg_match( $handler['regex'], $url, $matches ) && is_callable( $handler['callback'] ) ) {
    155155                                        if ( false !== $return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr ) )
     156                                                /**
     157                                                 * Filter the returned embed handler.
     158                                                 *
     159                                                 * @since 2.9.0
     160                                                 *
     161                                                 * @param mixed  $return The shortcode callback function to call.
     162                                                 * @param string $url    The attempted embed URL.
     163                                                 * @param array  $attr   An array of shortcode attributes.
     164                                                 */
    156165                                                return apply_filters( 'embed_handler_html', $return, $url, $attr );
    157166                                }
    158167                        }
     
    175184                                        return $this->maybe_make_link( $url );
    176185
    177186                                if ( ! empty( $cache ) )
     187                                        /**
     188                                         * Filter the cached oEmbed HTML.
     189                                         *
     190                                         * @since 2.9.0
     191                                         *
     192                                         * @param mixed  $cache   The cached HTML result, stored in post meta.
     193                                         * @param string $url     The attempted embed URL.
     194                                         * @param array  $attr    An array of shortcode attributes.
     195                                         * @param int    $post_ID Post ID.
     196                                         */
    178197                                        return apply_filters( 'embed_oembed_html', $cache, $url, $attr, $post_ID );
    179198                        }
    180199
     200                        /**
     201                         * Filter whether to inspect the given URL for discovery <link> tags.
     202                         *
     203                         * @see WP_oEmbed::discover()
     204                         *
     205                         * @param bool false Whether to enable <link> tag discovery. Default false.
     206                         */
     207                        $attr['discover'] = ( apply_filters( 'embed_oembed_discover', false ) && author_can( $post_ID, 'unfiltered_html' ) );
     208
    181209                        // Use oEmbed to get the HTML
    182                         $attr['discover'] = ( apply_filters('embed_oembed_discover', false) && author_can( $post_ID, 'unfiltered_html' ) );
    183210                        $html = wp_oembed_get( $url, $attr );
    184211
    185212                        // Cache the result
     
    187214                        update_post_meta( $post_ID, $cachekey, $cache );
    188215
    189216                        // If there was a result, return it
    190                         if ( $html )
     217                        if ( $html ) {
     218                                //duplicate_hook
    191219                                return apply_filters( 'embed_oembed_html', $html, $url, $attr, $post_ID );
     220                        }
    192221                }
    193222
    194223                // Still unknown
     
    219248        function cache_oembed( $post_ID ) {
    220249                $post = get_post( $post_ID );
    221250
    222                 if ( empty($post->ID) || !in_array( $post->post_type, apply_filters( 'embed_cache_oembed_types', array( 'post', 'page' ) ) ) )
     251                $post_types = array( 'post', 'page' );
     252                /**
     253                 * Filter array of post types to cache oEmbed results for.
     254                 *
     255                 * @since 2.9.0
     256                 *
     257                 * @param array $post_types Array of post types to cache oEmbed results for. Default 'post', 'page'.
     258                 */
     259                if ( empty($post->ID) || !in_array( $post->post_type, apply_filters( 'embed_cache_oembed_types', $post_types ) ) )
    223260                        return;
    224261
    225262                // Trigger a caching
     
    271308         */
    272309        function maybe_make_link( $url ) {
    273310                $output = ( $this->linkifunknown ) ? '<a href="' . esc_url($url) . '">' . esc_html($url) . '</a>' : $url;
     311
     312                /**
     313                 * Filter the returned, maybe-linked embed URL.
     314                 *
     315                 * @since 2.9.0
     316                 *
     317                 * @param string $output The linked or original URL.
     318                 * @param string $url    The original URL.
     319                 */
    274320                return apply_filters( 'embed_maybe_make_link', $output, $url );
    275321        }
    276322}