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. Built from https://develop.svn.wordpress.org/trunk@32330 git-svn-id: http://core.svn.wordpress.org/trunk@32301 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
aaafb3113a
commit
2807b7146f
|
@ -2714,14 +2714,23 @@ function wp_ajax_parse_embed() {
|
||||||
}
|
}
|
||||||
|
|
||||||
$shortcode = wp_unslash( $_POST['shortcode'] );
|
$shortcode = wp_unslash( $_POST['shortcode'] );
|
||||||
$url = str_replace( '[embed]', '', str_replace( '[/embed]', '', $shortcode ) );
|
|
||||||
|
preg_match( '/' . get_shortcode_regex() . '/s', $shortcode, $matches );
|
||||||
|
$atts = shortcode_parse_atts( $matches[3] );
|
||||||
|
if ( ! empty( $matches[5] ) ) {
|
||||||
|
$url = $matches[5];
|
||||||
|
} elseif ( ! empty( $atts['src'] ) ) {
|
||||||
|
$url = $atts['src'];
|
||||||
|
} else {
|
||||||
|
$url = '';
|
||||||
|
}
|
||||||
|
|
||||||
$parsed = false;
|
$parsed = false;
|
||||||
setup_postdata( $post );
|
setup_postdata( $post );
|
||||||
|
|
||||||
$wp_embed->return_false_on_fail = true;
|
$wp_embed->return_false_on_fail = true;
|
||||||
|
|
||||||
if ( is_ssl() && preg_match( '%^\\[embed[^\\]]*\\]http://%i', $shortcode ) ) {
|
if ( is_ssl() && 0 === strpos( $url, 'http://' ) ) {
|
||||||
// Admin is ssl and the user pasted non-ssl URL.
|
// Admin is ssl and the user pasted non-ssl URL.
|
||||||
// Check if the provider supports ssl embeds and use that for the preview.
|
// Check if the provider supports ssl embeds and use that for the preview.
|
||||||
$ssl_shortcode = preg_replace( '%^(\\[embed[^\\]]*\\])http://%i', '$1https://', $shortcode );
|
$ssl_shortcode = preg_replace( '%^(\\[embed[^\\]]*\\])http://%i', '$1https://', $shortcode );
|
||||||
|
@ -2732,7 +2741,7 @@ function wp_ajax_parse_embed() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! $parsed ) {
|
if ( $url && ! $parsed ) {
|
||||||
$parsed = $wp_embed->run_shortcode( $shortcode );
|
$parsed = $wp_embed->run_shortcode( $shortcode );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2774,7 +2783,8 @@ function wp_ajax_parse_embed() {
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_send_json_success( array(
|
wp_send_json_success( array(
|
||||||
'body' => $parsed
|
'body' => $parsed,
|
||||||
|
'attr' => $wp_embed->last_attr
|
||||||
) );
|
) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,8 @@ class WP_Embed {
|
||||||
public $post_ID;
|
public $post_ID;
|
||||||
public $usecache = true;
|
public $usecache = true;
|
||||||
public $linkifunknown = true;
|
public $linkifunknown = true;
|
||||||
|
public $last_attr = array();
|
||||||
|
public $last_url = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When an URL cannot be embedded, return false instead of returning a link
|
* When an URL cannot be embedded, return false instead of returning a link
|
||||||
|
@ -134,13 +136,18 @@ class WP_Embed {
|
||||||
$url = $attr['src'];
|
$url = $attr['src'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->last_url = $url;
|
||||||
|
|
||||||
if ( empty( $url ) )
|
if ( empty( $url ) ) {
|
||||||
|
$this->last_attr = $attr;
|
||||||
return '';
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
$rawattr = $attr;
|
$rawattr = $attr;
|
||||||
$attr = wp_parse_args( $attr, wp_embed_defaults( $url ) );
|
$attr = wp_parse_args( $attr, wp_embed_defaults( $url ) );
|
||||||
|
|
||||||
|
$this->last_attr = $attr;
|
||||||
|
|
||||||
// kses converts & into & and we need to undo this
|
// kses converts & into & and we need to undo this
|
||||||
// See https://core.trac.wordpress.org/ticket/11311
|
// See https://core.trac.wordpress.org/ticket/11311
|
||||||
$url = str_replace( '&', '&', $url );
|
$url = str_replace( '&', '&', $url );
|
||||||
|
|
|
@ -4554,15 +4554,23 @@ EmbedLink = wp.media.view.Settings.extend({
|
||||||
}, 600 ),
|
}, 600 ),
|
||||||
|
|
||||||
fetch: function() {
|
fetch: function() {
|
||||||
|
var embed;
|
||||||
|
|
||||||
// check if they haven't typed in 500 ms
|
// check if they haven't typed in 500 ms
|
||||||
if ( $('#embed-url-field').val() !== this.model.get('url') ) {
|
if ( $('#embed-url-field').val() !== this.model.get('url') ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
embed = new wp.shortcode({
|
||||||
|
tag: 'embed',
|
||||||
|
attrs: _.pick( this.model.attributes, [ 'width', 'height', 'src' ] ),
|
||||||
|
content: this.model.get('url')
|
||||||
|
});
|
||||||
|
|
||||||
wp.ajax.send( 'parse-embed', {
|
wp.ajax.send( 'parse-embed', {
|
||||||
data : {
|
data : {
|
||||||
post_ID: wp.media.view.settings.post.id,
|
post_ID: wp.media.view.settings.post.id,
|
||||||
shortcode: '[embed]' + this.model.get('url') + '[/embed]'
|
shortcode: embed.string()
|
||||||
}
|
}
|
||||||
} )
|
} )
|
||||||
.done( _.bind( this.renderoEmbed, this ) )
|
.done( _.bind( this.renderoEmbed, this ) )
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.3-alpha-32329';
|
$wp_version = '4.3-alpha-32330';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue