Make WordPress Core

Changeset 32330


Ignore:
Timestamp:
04/30/2015 09:39:52 PM (7 years ago)
Author:
wonderboymusic
Message:

After [32258], restore the parts of [31620] and [31626] that weren't changes to the UI, but were improvements to existing code.

  • Use wp.shortcode() instead of manually constructing a shortcode in views/embed/link
  • In WP_Embed, store the last URL and last set of attributes requested in class properties
  • wp_ajax_parse_embed(), allow [embed]s to have attributes. Return attr in the response.

See #31139.

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/ajax-actions.php

    r32258 r32330  
    27152715
    27162716    $shortcode = wp_unslash( $_POST['shortcode'] );
    2717     $url = str_replace( '[embed]', '', str_replace( '[/embed]', '', $shortcode ) );
     2717
     2718    preg_match( '/' . get_shortcode_regex() . '/s', $shortcode, $matches );
     2719    $atts = shortcode_parse_atts( $matches[3] );
     2720    if ( ! empty( $matches[5] ) ) {
     2721        $url = $matches[5];
     2722    } elseif ( ! empty( $atts['src'] ) ) {
     2723        $url = $atts['src'];
     2724    } else {
     2725        $url = '';
     2726    }
    27182727
    27192728    $parsed = false;
     
    27222731    $wp_embed->return_false_on_fail = true;
    27232732
    2724     if ( is_ssl() && preg_match( '%^\\[embed[^\\]]*\\]http://%i', $shortcode ) ) {
     2733    if ( is_ssl() && 0 === strpos( $url, 'http://' ) ) {
    27252734        // Admin is ssl and the user pasted non-ssl URL.
    27262735        // Check if the provider supports ssl embeds and use that for the preview.
     
    27332742    }
    27342743
    2735     if ( ! $parsed ) {
     2744    if ( $url && ! $parsed ) {
    27362745        $parsed = $wp_embed->run_shortcode( $shortcode );
    27372746    }
     
    27752784
    27762785    wp_send_json_success( array(
    2777         'body' => $parsed
     2786        'body' => $parsed,
     2787        'attr' => $wp_embed->last_attr
    27782788    ) );
    27792789}
  • trunk/src/wp-includes/class-wp-embed.php

    r32258 r32330  
    1212    public $usecache = true;
    1313    public $linkifunknown = true;
     14    public $last_attr = array();
     15    public $last_url = '';
    1416
    1517    /**
     
    135137        }
    136138
    137 
    138         if ( empty( $url ) )
     139        $this->last_url = $url;
     140
     141        if ( empty( $url ) ) {
     142            $this->last_attr = $attr;
    139143            return '';
     144        }
    140145
    141146        $rawattr = $attr;
    142147        $attr = wp_parse_args( $attr, wp_embed_defaults( $url ) );
     148
     149        $this->last_attr = $attr;
    143150
    144151        // kses converts & into & and we need to undo this
  • trunk/src/wp-includes/js/media-views.js

    r32258 r32330  
    45554555
    45564556    fetch: function() {
     4557        var embed;
     4558
    45574559        // check if they haven't typed in 500 ms
    45584560        if ( $('#embed-url-field').val() !== this.model.get('url') ) {
     
    45604562        }
    45614563
     4564        embed = new wp.shortcode({
     4565            tag: 'embed',
     4566            attrs: _.pick( this.model.attributes, [ 'width', 'height', 'src' ] ),
     4567            content: this.model.get('url')
     4568        });
     4569
    45624570        wp.ajax.send( 'parse-embed', {
    45634571            data : {
    45644572                post_ID: wp.media.view.settings.post.id,
    4565                 shortcode: '[embed]' + this.model.get('url') + '[/embed]'
     4573                shortcode: embed.string()
    45664574            }
    45674575        } )
  • trunk/src/wp-includes/js/media/views/embed/link.js

    r32258 r32330  
    3939
    4040    fetch: function() {
     41        var embed;
     42
    4143        // check if they haven't typed in 500 ms
    4244        if ( $('#embed-url-field').val() !== this.model.get('url') ) {
     
    4446        }
    4547
     48        embed = new wp.shortcode({
     49            tag: 'embed',
     50            attrs: _.pick( this.model.attributes, [ 'width', 'height', 'src' ] ),
     51            content: this.model.get('url')
     52        });
     53
    4654        wp.ajax.send( 'parse-embed', {
    4755            data : {
    4856                post_ID: wp.media.view.settings.post.id,
    49                 shortcode: '[embed]' + this.model.get('url') + '[/embed]'
     57                shortcode: embed.string()
    5058            }
    5159        } )
Note: See TracChangeset for help on using the changeset viewer.