Don't pass embeds through `the_content()` when trying to render MCE previews, leverage `WP_Embed` and `do_shortcode()` instead.

Props kovshenin.
See #28195.



git-svn-id: https://develop.svn.wordpress.org/trunk@28580 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor 2014-05-26 23:42:08 +00:00
parent 6cd28991e3
commit 8567bba0bf
3 changed files with 10 additions and 6 deletions

View File

@ -60,7 +60,7 @@ $core_actions_post = array(
'wp-remove-post-lock', 'dismiss-wp-pointer', 'upload-attachment', 'get-attachment', 'wp-remove-post-lock', 'dismiss-wp-pointer', 'upload-attachment', 'get-attachment',
'query-attachments', 'save-attachment', 'save-attachment-compat', 'send-link-to-editor', 'query-attachments', 'save-attachment', 'save-attachment-compat', 'send-link-to-editor',
'send-attachment-to-editor', 'save-attachment-order', 'heartbeat', 'get-revision-diffs', 'send-attachment-to-editor', 'save-attachment-order', 'heartbeat', 'get-revision-diffs',
'save-user-color-scheme', 'update-widget', 'query-themes', 'filter-content' 'save-user-color-scheme', 'update-widget', 'query-themes', 'parse-embed'
); );
// Register core Ajax calls. // Register core Ajax calls.

View File

@ -2506,12 +2506,12 @@ function wp_ajax_query_themes() {
} }
/** /**
* Apply `the_content` filters to a string based on the post ID. * Apply [embed] handlers to a string.
* *
* @since 4.0.0 * @since 4.0.0
*/ */
function wp_ajax_filter_content() { function wp_ajax_parse_embed() {
global $post; global $post, $wp_embed;
if ( ! $post = get_post( (int) $_REQUEST['post_ID'] ) ) { if ( ! $post = get_post( (int) $_REQUEST['post_ID'] ) ) {
wp_send_json_error(); wp_send_json_error();
@ -2523,5 +2523,9 @@ function wp_ajax_filter_content() {
setup_postdata( $post ); setup_postdata( $post );
wp_send_json_success( apply_filters( 'the_content', wp_unslash( $_POST['content'] ) ) ); $parsed = $wp_embed->run_shortcode( $_POST['content'] );
if ( preg_match( '/' . get_shortcode_regex() . '/s', $parsed ) ) {
$parsed = do_shortcode( $parsed );
}
wp_send_json_success( $parsed );
} }

View File

@ -708,7 +708,7 @@ window.wp = window.wp || {};
} }
}, },
fetch: function () { fetch: function () {
wp.ajax.send( 'filter-content', { wp.ajax.send( 'parse-embed', {
data: { data: {
post_ID: $( '#post_ID' ).val(), post_ID: $( '#post_ID' ).val(),
content: this.shortcode.string() content: this.shortcode.string()