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';