-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Let Gutenberg be default editor for posts with blocks; add links to classic editor #1797
Conversation
I'll add unit tests for the new PHP functions once a 👍 on the functionality is given. |
b39d28e
to
de0ef8b
Compare
While there's the need to keep the links text as short as possible, given the limited space, I'd consider to try to improve them a bit.
Since the aria-label text is not visible, it could be expanded always specifying "in the classic editor" / "in the Gutenberg editor" |
@afercia I'm not entirely clear if your feedback here is about the design of the WordPress post list table in general, or if it is specifically regarding changes in this PR. |
@westonruter I meant the current list table design in WordPress is clear enough because there's just one "Edit" and just one editor. Now that this PR introduces 2 links to 2 different editors, it's not always immediately clear where the "Edit" link points. |
It links to the default editor. If you think it should be verbosely “Edit in Gutenberg”, I wouldn't be opposed, but again there is limited space. |
Yep that's what I meant 🙂 I see the limited space issue. Shortening the link text is not always so clear though. |
Please amend the PR with whatever you deem best. |
lib/register.php
Outdated
*/ | ||
function gutenberg_post_has_blocks( $post_id ) { | ||
$post = get_post( $post_id ); | ||
return $post && preg_match( '#<!-- wp:\w+#', $post->post_content ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about strpos( $post->post_content, '<!-- wp:' ) !== false
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably would be just as good in the vast majority of cases. That sequence of chars shouldn't be present unless there are blocks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think that if <!-- wp:
is already there, the chance is very high that it is followed by a word-like sequence anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the input. Changed in 53e2def.
326645d
to
5d55e39
Compare
+1 to getting this merged from me. Can we get a refresh to pass all checks? Be great to get this in for 1.1. |
@karmatosed I kindly disagree. There's still a design issue to solve here: the link destination is not always clear. |
@afercia to me, we get the PR in a state we can then see (it's not yet) and then either merge and iterate or iterate. What are you thinking is missing and would advise? |
@karmatosed for example: would you be able to understand what the two "Edit" links in the screenshot below do at first sight? To me, this seems confusing because I can understand the difference between the two "Edit" only by looking at the other link close to them. Not to mention, the link on the post title doesn't say anything either. I see potential confusion also in the toolbar: often times, users just click, they don't read (muscle memory also). They will see "Edit bla bla" and click and sometimes land in the classic editor, sometimes on Gutenberg. |
To me, it seems like it might be good to have edit actions as "Gutenberg Editor" (or "Edit in Gutenberg"), "Classic Editor" (or "Edit in Classic Editor") in all cases (never changing order or text), then set the behavior of the title link to the preferred default (Gutenberg if blocks exist, Classic otherwise). |
5d55e39
to
547d038
Compare
I've rebased to resolve conflicts and made the following revisions: Using the Always show "Classic Editor" and "Gutenberg" links in post actions, regardless of post contents: Always show full "Edit in ..." text in front-end admin bar: |
lib/register.php
Outdated
$gutenberg_action = sprintf( | ||
if ( gutenberg_post_has_blocks( $post->ID ) ) { | ||
remove_filter( 'get_edit_post_link', 'gutenberg_filter_edit_post_link', 10 ); | ||
add_filter( 'get_edit_post_link', 'gutenberg_filter_edit_post_link', 10, 3 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@westonruter Should we just add a default filter handler for get_edit_post_link
to always override with the preferred editor by content?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't that what is already done here?
Lines 210 to 231 in 547d038
/** | |
* Filters the post edit link to default to the Gutenberg editor when the post content contains a block. | |
* | |
* @since 0.5.0 | |
* | |
* @param string $url The edit link URL. | |
* @param int $post_id Post ID. | |
* @param string $context The link context. If set to 'display' then ampersands are encoded. | |
* @return string Edit post link. | |
*/ | |
function gutenberg_filter_edit_post_link( $url, $post_id, $context ) { | |
$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 ); | |
if ( 'display' === $context ) { | |
$gutenberg_url = esc_url( $gutenberg_url ); | |
} | |
$url = $gutenberg_url; | |
} | |
return $url; | |
} | |
add_filter( 'get_edit_post_link', 'gutenberg_filter_edit_post_link', 10, 3 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason why the remove_filter
and add_filter
are done above is to facilitate obtaining the classic post editor URL, even for a post that has blocks in it:
Lines 88 to 91 in 547d038
$classic_text = __( 'Edit in Classic Editor', 'gutenberg' ); | |
remove_filter( 'get_edit_post_link', 'gutenberg_filter_edit_post_link', 10 ); | |
$classic_url = get_edit_post_link( $post->ID, 'raw' ); | |
add_filter( 'get_edit_post_link', 'gutenberg_filter_edit_post_link', 10, 3 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, seeing that now in the changes prior to 63ff18d. I guess this might not be working correctly for the "Classic Editor" link for Gutenberg posts currently then.
lib/register.php
Outdated
$gutenberg_action = sprintf( | ||
if ( gutenberg_post_has_blocks( $post->ID ) ) { | ||
remove_filter( 'get_edit_post_link', 'gutenberg_filter_edit_post_link', 10 ); | ||
add_filter( 'get_edit_post_link', 'gutenberg_filter_edit_post_link', 10, 3 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As it stands right now, this if
condition with add/remove of the get_edit_post_link
filter is just removing and adding something right back, so it has no purpose right?
54df7bc should resolve the issue where Classic Editor would use an incorrect link for Gutenberg posts (from discussion thread at #1797 (comment)). From my perspective, this seems ready to go. |
Codecov Report
@@ Coverage Diff @@
## master #1797 +/- ##
========================================
+ Coverage 31.38% 32.39% +1%
========================================
Files 177 182 +5
Lines 5413 5933 +520
Branches 949 1087 +138
========================================
+ Hits 1699 1922 +223
- Misses 3139 3348 +209
- Partials 575 663 +88
Continue to review full report at Codecov.
|
`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
`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
…kspace [iOS] Remove xcworkspace.
Fixes #1779, #1627.
When a post contains blocks, the main edit link becomes the link to Gutenberg whereas the row action link then goes to the Classic Editor:
Any edit post link for a post with blocks becomes a link to the Gutenberg editor, including links on the frontend:
If a post does not contain blocks, then the main link remains pointing to the classic editor and the Gutenberg link is in the row actions.
Likewise, if a post does have blocks then when the post is viewed on the frontend, the “Edit Post” link will link to Gutenberg and it will have a “Edit in Gutenberg” title. The classic editor will then be available via a submenu item:
Likewise, when the post does not contain blocks, then the original Edit Post link is in place with a link to Gutenberg being in the submenu as the alternate edit mode:
Lastly, if the post type is not registered with
show_in_rest
then the Gutenberg editor is not shown, since the REST API is a dependency for Gutenberg.