From a7c6a25ebace7a1781a1e0e29f9def27a433261a Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 18 Oct 2017 17:39:46 +0000 Subject: [PATCH] Widgets: Fix previewing embeds in Text widget by allowing `parse-embed` admin ajax requests with an empty `post_ID` just as `WP_oEmbed_Controller::get_proxy_item_permissions_check()` allows. As of #34115 if there is no post context the oEmbed will be cached in an `oembed_cache` custom post type, so having a post as context is no longer a requirement for caching. Props biskobe, westonruter. See #34115, #40450. Fixes #40854. git-svn-id: https://develop.svn.wordpress.org/trunk@41913 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/ajax-actions.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php index 5c53f6805c..c523411efb 100644 --- a/src/wp-admin/includes/ajax-actions.php +++ b/src/wp-admin/includes/ajax-actions.php @@ -3005,11 +3005,17 @@ function wp_ajax_query_themes() { function wp_ajax_parse_embed() { global $post, $wp_embed; - if ( ! $post = get_post( (int) $_POST['post_ID'] ) ) { + if ( empty( $_POST['shortcode'] ) ) { wp_send_json_error(); } - - if ( empty( $_POST['shortcode'] ) || ! current_user_can( 'edit_post', $post->ID ) ) { + $post_id = isset( $_POST[ 'post_ID' ] ) ? intval( $_POST[ 'post_ID' ] ) : 0; + if ( $post_id > 0 ) { + $post = get_post( $post_id ); + if ( ! $post || ! current_user_can( 'edit_post', $post->ID ) ) { + wp_send_json_error(); + } + setup_postdata( $post ); + } elseif ( ! current_user_can( 'edit_posts' ) ) { // See WP_oEmbed_Controller::get_proxy_item_permissions_check(). wp_send_json_error(); } @@ -3026,8 +3032,6 @@ function wp_ajax_parse_embed() { } $parsed = false; - setup_postdata( $post ); - $wp_embed->return_false_on_fail = true; if ( is_ssl() && 0 === strpos( $url, 'http://' ) ) {