From 0c79d7564d614e014da4b3b3eb676e0a47cd5fba Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Sat, 9 Sep 2017 02:27:11 -0400 Subject: [PATCH 1/2] FIX: Saving in Classic Editor shouldn't redirect to Gutenberg `get_edit_post_link` is used in `post.php` to redirect when saving. See https://core.trac.wordpress.org/browser/trunk/src/wp-admin/post.php#L190 By checking to see if the referer is the classic editor, modification to the edit post link is preserved. Introduced in #1797 Fixes #2707 --- lib/register.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/register.php b/lib/register.php index d1a4e4d609b2e4..3d03aa5e811e24 100644 --- a/lib/register.php +++ b/lib/register.php @@ -221,6 +221,13 @@ function gutenberg_get_edit_post_url( $post_id ) { * @return string Edit post link. */ function gutenberg_filter_edit_post_link( $url, $post_id, $context ) { + $sendback = wp_get_referer(); + if ( $sendback && ( + strpos( $sendback, 'post.php' ) !== false || + strpos( $sendback, 'post-new.php' ) !== false ) ) { + return $url; + } + $post = get_post( $post_id ); if ( gutenberg_can_edit_post( $post_id ) && gutenberg_post_has_blocks( $post_id ) && post_type_supports( get_post_type( $post_id ), 'editor' ) ) { $gutenberg_url = gutenberg_get_edit_post_url( $post->ID ); From 4abf2596cd218cbe2f913ea163667ce474ec7956 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Wed, 27 Sep 2017 08:37:37 -0400 Subject: [PATCH 2/2] Compat: Test classic referrer using admin_url --- lib/register.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/register.php b/lib/register.php index 3d03aa5e811e24..73daf3a8702cf6 100644 --- a/lib/register.php +++ b/lib/register.php @@ -221,10 +221,11 @@ function gutenberg_get_edit_post_url( $post_id ) { * @return string Edit post link. */ function gutenberg_filter_edit_post_link( $url, $post_id, $context ) { + // Avoid redirect to Gutenberg after saving a block post in Classic editor. $sendback = wp_get_referer(); if ( $sendback && ( - strpos( $sendback, 'post.php' ) !== false || - strpos( $sendback, 'post-new.php' ) !== false ) ) { + 0 === strpos( $sendback, parse_url( admin_url( 'post.php' ), PHP_URL_PATH ) ) || + 0 === strpos( $sendback, parse_url( admin_url( 'post-new.php' ), PHP_URL_PATH ) ) ) ) { return $url; }