Make WordPress Core


Ignore:
Timestamp:
06/23/2020 06:06:11 AM (4 years ago)
Author:
whyisjake
Message:

Embeds: Ensure that classic embed support works in the block editor.

See https://github.com/WordPress/gutenberg/pull/6345

Fixes #45447.

Props swisspidy, pento, audrasjb, aduth, jrchamp, thrijith, TimothyBlynJacobs, whyisjake.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-embed.php

    r47808 r48135  
    127127
    128128    /**
    129      * The do_shortcode() callback function.
    130      *
    131      * Attempts to convert a URL into embed HTML. Starts by checking the URL against the regex of
    132      * the registered embed handlers. If none of the regex matches and it's enabled, then the URL
    133      * will be given to the WP_oEmbed class.
     129     * Returns embed HTML for a given URL from embed handlers.
     130     *
     131     * Attempts to convert a URL into embed HTML by checking the URL
     132     * against the regex of the registered embed handlers.
     133     *
     134     * @since 5.5.0
    134135     *
    135136     * @param array $attr {
     
    140141     * }
    141142     * @param string $url The URL attempting to be embedded.
    142      * @return string|false The embed HTML on success, otherwise the original URL.
    143      *                      `->maybe_make_link()` can return false on failure.
    144      */
    145     public function shortcode( $attr, $url = '' ) {
    146         $post = get_post();
    147 
    148         if ( empty( $url ) && ! empty( $attr['src'] ) ) {
    149             $url = $attr['src'];
    150         }
    151 
    152         $this->last_url = $url;
    153 
    154         if ( empty( $url ) ) {
    155             $this->last_attr = $attr;
    156             return '';
    157         }
    158 
     143     * @return string|false The embed HTML on success, false otherwise.
     144     */
     145    public function get_embed_handler_html( $attr, $url ) {
    159146        $rawattr = $attr;
    160147        $attr    = wp_parse_args( $attr, wp_embed_defaults( $url ) );
    161148
    162         $this->last_attr = $attr;
    163 
    164         // KSES converts & into & and we need to undo this.
    165         // See https://core.trac.wordpress.org/ticket/11311
    166         $url = str_replace( '&', '&', $url );
    167 
    168         // Look for known internal handlers.
    169149        ksort( $this->handlers );
    170150        foreach ( $this->handlers as $priority => $handlers ) {
     
    188168                }
    189169            }
     170        }
     171
     172        return false;
     173    }
     174
     175    /**
     176     * The do_shortcode() callback function.
     177     *
     178     * Attempts to convert a URL into embed HTML. Starts by checking the URL against the regex of
     179     * the registered embed handlers. If none of the regex matches and it's enabled, then the URL
     180     * will be given to the WP_oEmbed class.
     181     *
     182     * @param array $attr {
     183     *     Shortcode attributes. Optional.
     184     *
     185     *     @type int $width  Width of the embed in pixels.
     186     *     @type int $height Height of the embed in pixels.
     187     * }
     188     * @param string $url The URL attempting to be embedded.
     189     * @return string|false The embed HTML on success, otherwise the original URL.
     190     *                      `->maybe_make_link()` can return false on failure.
     191     */
     192    public function shortcode( $attr, $url = '' ) {
     193        $post = get_post();
     194
     195        if ( empty( $url ) && ! empty( $attr['src'] ) ) {
     196            $url = $attr['src'];
     197        }
     198
     199        $this->last_url = $url;
     200
     201        if ( empty( $url ) ) {
     202            $this->last_attr = $attr;
     203            return '';
     204        }
     205
     206        $rawattr = $attr;
     207        $attr    = wp_parse_args( $attr, wp_embed_defaults( $url ) );
     208
     209        $this->last_attr = $attr;
     210
     211        // KSES converts & into & and we need to undo this.
     212        // See https://core.trac.wordpress.org/ticket/11311
     213        $url = str_replace( '&', '&', $url );
     214
     215        // Look for known internal handlers.
     216        $embed_handler_html = $this->get_embed_handler_html( $rawattr, $url );
     217        if ( false !== $embed_handler_html ) {
     218            return $embed_handler_html;
    190219        }
    191220
Note: See TracChangeset for help on using the changeset viewer.