From 8567bba0bf14dad9b636633c3a96d9382b811b7b Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Mon, 26 May 2014 23:42:08 +0000 Subject: [PATCH] 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 --- src/wp-admin/admin-ajax.php | 2 +- src/wp-admin/includes/ajax-actions.php | 12 ++++++++---- src/wp-includes/js/mce-view.js | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/wp-admin/admin-ajax.php b/src/wp-admin/admin-ajax.php index 0606f228a9..d32dad522d 100644 --- a/src/wp-admin/admin-ajax.php +++ b/src/wp-admin/admin-ajax.php @@ -60,7 +60,7 @@ $core_actions_post = array( 'wp-remove-post-lock', 'dismiss-wp-pointer', 'upload-attachment', 'get-attachment', 'query-attachments', 'save-attachment', 'save-attachment-compat', 'send-link-to-editor', '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. diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php index d265830d24..10fedc2baa 100644 --- a/src/wp-admin/includes/ajax-actions.php +++ b/src/wp-admin/includes/ajax-actions.php @@ -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 */ -function wp_ajax_filter_content() { - global $post; +function wp_ajax_parse_embed() { + global $post, $wp_embed; if ( ! $post = get_post( (int) $_REQUEST['post_ID'] ) ) { wp_send_json_error(); @@ -2523,5 +2523,9 @@ function wp_ajax_filter_content() { 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 ); } diff --git a/src/wp-includes/js/mce-view.js b/src/wp-includes/js/mce-view.js index 2c5df52b99..bc7bb0b71d 100644 --- a/src/wp-includes/js/mce-view.js +++ b/src/wp-includes/js/mce-view.js @@ -708,7 +708,7 @@ window.wp = window.wp || {}; } }, fetch: function () { - wp.ajax.send( 'filter-content', { + wp.ajax.send( 'parse-embed', { data: { post_ID: $( '#post_ID' ).val(), content: this.shortcode.string()