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
This commit is contained in:
Andrew Ozz 2014-06-15 22:52:45 +00:00
parent 084cc046ac
commit ed07c215dc
4 changed files with 35 additions and 17 deletions

View File

@ -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 );

View File

@ -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 ) ),
) );
}

View File

@ -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, ( '<a href' ).length ) === '<a href' ) {
} )
.done( function( response ) {
if ( response ) {
self.parsed = response;
self.setHtml( response );
}
} )
.fail( function( response ) {
if ( response && response.message ) {
if ( self.type === 'embed' ) {
self.setError( self.original + ' failed to embed.', 'admin-media' );
self.setError( response.message, 'admin-media' );
} else {
self.setContent( self.original, null, true );
self.setContent( '<p>' + self.original + '</p>', 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 */

View File

@ -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 {