mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-12 13:44:21 +01:00
wpView: improve handling of embed errors/error messages, see #28195
Built from https://develop.svn.wordpress.org/trunk@28754 git-svn-id: http://core.svn.wordpress.org/trunk@28568 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
16595af731
commit
84f3e30f7b
@ -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 );
|
||||
|
@ -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 ) ),
|
||||
) );
|
||||
}
|
||||
|
@ -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 */
|
||||
|
2
wp-includes/js/mce-view.min.js
vendored
2
wp-includes/js/mce-view.min.js
vendored
File diff suppressed because one or more lines are too long
@ -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 {
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.0-alpha-20140614';
|
||||
$wp_version = '4.0-alpha-20140615';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user