diff --git a/src/wp-admin/css/press-this.css b/src/wp-admin/css/press-this.css index e047802974..d5459865c2 100644 --- a/src/wp-admin/css/press-this.css +++ b/src/wp-admin/css/press-this.css @@ -1888,6 +1888,15 @@ html { padding: 0 10px; } +.publish-button .saving-draft, +.publish-button.is-saving .publish { + display: none; +} + +.publish-button.is-saving .saving-draft { + display: inline; +} + /* TinyMCE styles */ .editor .wp-media-buttons { float: none; diff --git a/src/wp-admin/includes/class-wp-press-this.php b/src/wp-admin/includes/class-wp-press-this.php index d74dd63dc9..5150b36a14 100644 --- a/src/wp-admin/includes/class-wp-press-this.php +++ b/src/wp-admin/includes/class-wp-press-this.php @@ -146,8 +146,13 @@ class WP_Press_This { } } + $forceRedirect = false; + if ( 'publish' === get_post_status( $post_id ) ) { $redirect = get_post_permalink( $post_id ); + } elseif ( isset( $_POST['pt-force-redirect'] ) && $_POST['pt-force-redirect'] === 'true' ) { + $forceRedirect = true; + $redirect = get_edit_post_link( $post_id, 'js' ); } else { $redirect = false; } @@ -165,7 +170,7 @@ class WP_Press_This { $redirect = apply_filters( 'press_this_save_redirect', $redirect, $post_id, $post['post_status'] ); if ( $redirect ) { - wp_send_json_success( array( 'redirect' => $redirect ) ); + wp_send_json_success( array( 'redirect' => $redirect, 'force' => $forceRedirect ) ); } else { wp_send_json_success( array( 'postSaved' => true ) ); } @@ -1329,6 +1334,7 @@ class WP_Press_This { +  
-
diff --git a/src/wp-admin/js/press-this.js b/src/wp-admin/js/press-this.js index c65da9228d..e1b03e79bb 100644 --- a/src/wp-admin/js/press-this.js +++ b/src/wp-admin/js/press-this.js @@ -182,21 +182,24 @@ }).always( function() { hideSpinner(); clearNotices(); + $( '.publish-button' ).removeClass( 'is-saving' ); }).done( function( response ) { if ( ! response.success ) { renderError( response.data.errorMessage ); } else if ( response.data.redirect ) { - if ( window.opener && settings.redirInParent ) { + if ( window.opener && ( settings.redirInParent || response.data.force ) ) { try { window.opener.location.href = response.data.redirect; - } catch( er ) {} - window.self.close(); + window.setTimeout( function() { + window.self.close(); + }, 200 ) + } catch( er ) { + window.location.href = response.data.redirect; + } } else { window.location.href = response.data.redirect; } - } else if ( response.data.postSaved ) { - // consider showing "Saved" message } }).fail( function() { renderError( __( 'serverError' ) ); @@ -660,8 +663,10 @@ if ( $button.length ) { if ( $button.hasClass( 'draft-button' ) ) { + $( '.publish-button' ).addClass( 'is-saving' ); submitPost( 'draft' ); } else if ( $button.hasClass( 'publish-button' ) ) { + $button.addClass( 'is-saving' ); submitPost( 'publish' ); } else if ( $button.hasClass( 'preview-button' ) ) { prepareFormData(); @@ -670,6 +675,10 @@ $( '#wp-preview' ).val( 'dopreview' ); $( '#pressthis-form' ).attr( 'target', '_blank' ).submit().attr( 'target', '' ); $( '#wp-preview' ).val( '' ); + } else if ( $button.hasClass( 'standard-editor-button' ) ) { + $( '.publish-button' ).addClass( 'is-saving' ); + $( '#pt-force-redirect' ).val( 'true' ); + submitPost( 'draft' ); } else if ( $button.hasClass( 'split-button-toggle' ) ) { if ( $splitButton.hasClass( 'is-open' ) ) { $splitButton.removeClass( 'is-open' ); @@ -679,9 +688,6 @@ $button.attr( 'aria-expanded', 'true' ); } } - } else if ( $target.hasClass( 'edit-post-link' ) && window.opener ) { - window.opener.focus(); - window.self.close(); } });