From ed07c215dcf41adfd96524473e8ed4546850f574 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Sun, 15 Jun 2014 22:52:45 +0000 Subject: [PATCH] wpView: improve handling of embed errors/error messages, see #28195 git-svn-id: https://develop.svn.wordpress.org/trunk@28754 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/ajax-actions.php | 7 +++-- src/wp-admin/includes/misc.php | 12 ++++++++ src/wp-includes/js/mce-view.js | 30 ++++++++++--------- .../js/tinymce/skins/wordpress/wp-content.css | 3 +- 4 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php index 47061aa7dd..091cc5febb 100644 --- a/src/wp-admin/includes/ajax-actions.php +++ b/src/wp-admin/includes/ajax-actions.php @@ -2530,13 +2530,16 @@ function wp_ajax_parse_embed() { wp_send_json_error(); } - if ( ! current_user_can( 'read_post', $post->ID ) ) { + if ( empty( $_POST['shortcode'] ) || ! current_user_can( 'read_post', $post->ID ) ) { wp_send_json_error(); } setup_postdata( $post ); - $parsed = $wp_embed->run_shortcode( $_POST['content'] ); + // If the URL cannot be embedded, return an eror message with wp_send_json_error() + add_filter( 'embed_maybe_make_link', '_wpview_embed_error', 20, 2 ); + + $parsed = $wp_embed->run_shortcode( $_POST['shortcode'] ); $parsed = do_shortcode( $parsed ); wp_send_json_success( $parsed ); diff --git a/src/wp-admin/includes/misc.php b/src/wp-admin/includes/misc.php index 9df880581f..17ab62f1c8 100644 --- a/src/wp-admin/includes/misc.php +++ b/src/wp-admin/includes/misc.php @@ -824,3 +824,15 @@ function heartbeat_autosave( $response, $data ) { } // Run later as we have to set DOING_AUTOSAVE for back-compat add_filter( 'heartbeat_received', 'heartbeat_autosave', 500, 2 ); + +/** + * Send error message when an URL cannot be embedded. Used in wp_ajax_parse_embed(). + * + * @access private + * @since 4.0 + */ +function _wpview_embed_error( $output, $url ) { + wp_send_json_error( array( + 'message' => sprintf( __( '%s failed to embed.' ), esc_url( $url ) ), + ) ); +} diff --git a/src/wp-includes/js/mce-view.js b/src/wp-includes/js/mce-view.js index f9b318dae1..9dfef40034 100644 --- a/src/wp-includes/js/mce-view.js +++ b/src/wp-includes/js/mce-view.js @@ -718,27 +718,29 @@ window.wp = window.wp || {}; wp.ajax.send( 'parse-embed', { data: { - post_ID: $( '#post_ID' ).val(), - content: this.shortcode + post_ID: $( '#post_ID' ).val() || 0, + shortcode: this.shortcode } } ) - .done( function( content ) { + .always( function() { self.fetching = false; - - if ( content.substring( 0, ( '' + self.original + '

', null, true ); } - } else { - self.parsed = content; - self.setHtml( content ); + } else if ( response && response.statusText ) { + self.setError( response.statusText, 'admin-media' ); } - } ) - .fail( function() { - self.fetching = false; - self.setError( self.original + ' failed to embed due to a server error.', 'admin-media' ); } ); }, /* jshint scripturl: true */ diff --git a/src/wp-includes/js/tinymce/skins/wordpress/wp-content.css b/src/wp-includes/js/tinymce/skins/wordpress/wp-content.css index cb9b865cb9..947e3fda2b 100644 --- a/src/wp-includes/js/tinymce/skins/wordpress/wp-content.css +++ b/src/wp-includes/js/tinymce/skins/wordpress/wp-content.css @@ -306,8 +306,9 @@ audio { .wpview-error { border: 1px solid #dedede; - padding: 20px 0; + padding: 1em 0; margin: 0; + word-wrap: break-word; } .wpview-wrap[data-mce-selected] .wpview-error {