From 76020bd447b1ec7fabebba7bd7263db46213b0a1 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Fri, 22 Aug 2014 18:54:08 +0000 Subject: [PATCH] TinyMCE wpView: fix showing errors for non-embeddable URLs, no-ssl or no items. Props avryl, fixes #29114, see #29268. git-svn-id: https://develop.svn.wordpress.org/trunk@29577 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/ajax-actions.php | 5 ++- src/wp-includes/js/mce-view.js | 45 +++++++++++++++++--------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php index 82ec147afc..f4b043dba2 100644 --- a/src/wp-admin/includes/ajax-actions.php +++ b/src/wp-admin/includes/ajax-actions.php @@ -2723,7 +2723,10 @@ function wp_ajax_parse_media_shortcode() { $shortcode = do_shortcode( wp_unslash( $_REQUEST['shortcode'] ) ); if ( empty( $shortcode ) ) { - wp_send_json_error( array( 'statusText' => __( 'No items found.' ) ) ); + wp_send_json_error( array( + 'type' => 'no-items', + 'message' => __( 'No items found.' ), + ) ); } ob_start(); diff --git a/src/wp-includes/js/mce-view.js b/src/wp-includes/js/mce-view.js index 3ce42e9000..d3ea8fc4ae 100644 --- a/src/wp-includes/js/mce-view.js +++ b/src/wp-includes/js/mce-view.js @@ -561,8 +561,8 @@ window.wp = window.wp || {}; setNodes: function () { if ( this.parsed ) { this.setIframes( this.parsed ); - } else if ( this.parsed === false ) { - this.setContent( '

' + this.original + '

', 'replace' ); + } else { + this.fail(); } }, @@ -576,30 +576,43 @@ window.wp = window.wp || {}; shortcode: this.shortcode.string() } } ) - .always( function() { - self.parsed = false; - } ) .done( function( response ) { if ( response ) { self.parsed = response; self.setIframes( response ); + } else { + self.fail( true ); } } ) .fail( function( response ) { - if ( response && response.message ) { - if ( ( response.type === 'not-embeddable' && self.type === 'embed' ) || - response.type === 'not-ssl' ) { - - self.setError( response.message, 'admin-media' ); - } else { - self.setContent( '

' + self.original + '

', 'replace' ); - } - } else if ( response && response.statusText ) { - self.setError( response.statusText, 'admin-media' ); - } + self.fail( response || true ); } ); }, + fail: function( error ) { + if ( ! this.error ) { + if ( error ) { + this.error = error + } else { + return; + } + } + + if ( this.error.message ) { + if ( ( this.error.type === 'not-embeddable' && this.type === 'embed' ) || this.error.type === 'not-ssl' || + this.error.type === 'no-items' ) { + + this.setError( this.error.message, 'admin-media' ); + } else { + this.setContent( '

' + this.original + '

', 'replace' ); + } + } else if ( this.error.statusText ) { + this.setError( this.error.statusText, 'admin-media' ); + } else if ( this.original ) { + this.setContent( '

' + this.original + '

', 'replace' ); + } + }, + stopPlayers: function( remove ) { var rem = remove === 'remove';