-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add editor heading for screenreaders #3937
Conversation
@afercia in
Given that there's now a |
This just uses the stock WordPress objects.
@gziolo in e682f1e I adopted/adapted some code to output a translated and contextual label for the heading. It seems to work well, insofar as it outputs "Edit Post" and "Edit Page" when it needs to. I haven't tested with custom post types, but I'm assuming since it taps into the same function, that it should work. Can you help me with this? I need a sanity check my PHP, it's never been my forte. I'd also love some help testing with custom post types. Finally, the |
gutenberg.php
Outdated
@@ -27,9 +27,12 @@ | |||
* @since 0.1.0 | |||
*/ | |||
function the_gutenberg_project() { | |||
global $post_type, $post_type_object; | |||
$post_type_object = get_post_type_object( $post_type ); |
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.
I don't have much WP experience but it seems like $post_type_object
might be null. I don't know if that will be caught in another place so we might provide fallback:
$screen_reader_text = ! empty( $post_type_object->labels->edit_item ) ? $post_type_object->labels->edit_item : __( 'Default text' );
It would make sense to double check with someone else. /cc @pento
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.
We can assume that $post_type_object
is set by the time the_gutenberg_project()
is called.
For WordPress 4.9+:
- For new posts,
$post_type
is sanity checked at the start ofpost-new.php
, then$post_type_object
is set. Later, thereplace_editor
filter is run, which callsgutenberg_init()
, which may callthe_gutenberg_project()
. - For existing posts,
$post_type_object
is set at the start ofpost.php
, which bails before thereplace_editor
filter is run if$post_type_object
is empty.
For <WordPress 4.9, gutenberg_intercept_edit_post()
and gutenberg_intercept_post_new()
simulate the same behaviour.
So, we don't need to include the $post_type_object = get_post_type_object( $post_type );
line, we can just access the $post_type_object
global immediately.
I tested it with the page and post types. It works as advertised. Let's confirm PHP bits before we merge it. |
Yes! We can get rid of that ugly hack 🙂 |
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.
One minor change, everything else looks good.
gutenberg.php
Outdated
@@ -27,9 +27,12 @@ | |||
* @since 0.1.0 | |||
*/ | |||
function the_gutenberg_project() { | |||
global $post_type, $post_type_object; | |||
$post_type_object = get_post_type_object( $post_type ); |
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.
We can assume that $post_type_object
is set by the time the_gutenberg_project()
is called.
For WordPress 4.9+:
- For new posts,
$post_type
is sanity checked at the start ofpost-new.php
, then$post_type_object
is set. Later, thereplace_editor
filter is run, which callsgutenberg_init()
, which may callthe_gutenberg_project()
. - For existing posts,
$post_type_object
is set at the start ofpost.php
, which bails before thereplace_editor
filter is run if$post_type_object
is empty.
For <WordPress 4.9, gutenberg_intercept_edit_post()
and gutenberg_intercept_post_new()
simulate the same behaviour.
So, we don't need to include the $post_type_object = get_post_type_object( $post_type );
line, we can just access the $post_type_object
global immediately.
Thanks a bunch for the review! I pushed the change. If the change was correctly interpreted, and this is good to merge, feel free to do so. I'm heading out for some holiday today! ❤️ |
gutenberg.php
Outdated
@@ -25,7 +25,6 @@ | |||
*/ | |||
function the_gutenberg_project() { | |||
global $post_type, $post_type_object; |
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.
@jasmussen you don't need $post_type
in here. Otherwise is all good to go :)
I will give it a spin and merge today :) |
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.
👍🏻 after the change @gziolo mentioned.
@@ -110,7 +110,7 @@ class PostTitle extends Component { | |||
tabIndex={ -1 /* Necessary for Firefox to include relatedTarget in blur event */ } | |||
> | |||
{ isSelected && <PostPermalink /> } | |||
<h1> | |||
<div> |
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.
@jasmussen was this div needed?
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.
It was needed in order to let this "pseudo" block inherit styles that look exactly like our other blocks, without writing completely different CSS.
I did try to apply the on-select border to the textarea itself, or pseudo selectors, but it added a ton of complexity to the CSS, and I don't think I was able to get the responsive behavior to be the same. I decided it wasn't worth a complete rewrite to save this div, and I'm still unconvinced it can be done.
This is round 2 of #3801.
It mitigates/fixes #503 and fixes #2024.
What remains to be done in this branch is: