Accessibility: Remove post format filter links from format icons in the Posts list table.

Introduce a dedicated 'Formats' drop-down filter as a replacement.

Keep the icons as a simple visual indicator of the post format for now.

Props afercia, melchoyce, GaryJ, chiaralovelaces, SergeyBiryukov.
Fixes #35497.

git-svn-id: https://develop.svn.wordpress.org/trunk@44961 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2019-03-21 15:30:52 +00:00
parent 5c2b9cca3f
commit 1d41c6e787
3 changed files with 88 additions and 80 deletions

View File

@ -863,33 +863,21 @@ span.wp-media-buttons-icon:before {
11.4 - Post formats
------------------------------------------------------------------------------*/
.post-state-format {
overflow: hidden;
.post-format-icon::before {
display: inline-block;
vertical-align: middle;
height: 20px;
width: 20px;
margin-right: 5px;
margin-top: -4px;
}
.post-state-format:before {
display: block;
height: 20px;
width: 20px;
font: normal 20px/1 dashicons !important;
margin-right: 7px;
color: #ddd;
font: normal 20px/1 dashicons;
speak: none;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.post-state-format:before,
.post-format-icon:before {
color: #ddd;
transition: all .1s ease-in-out;
}
a.post-state-format:hover:before,
a.post-format-icon:hover:before {
color: #00a0d2;
}
@ -898,7 +886,7 @@ a.post-format-icon:hover:before {
line-height: 2em;
}
#post-formats-select .post-format-icon:before {
#post-formats-select .post-format-icon::before {
top: 5px;
}
@ -907,77 +895,47 @@ input.post-format {
}
label.post-format-icon {
margin-left: 0px;
padding: 2px 0 2px 0px;
margin-left: 0;
padding: 2px 0;
}
.post-format-icon:before {
position: relative;
display: inline-block;
margin-right: 7px;
font: normal 20px/1 dashicons;
speak: none;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.post-state-format.post-format-standard:before,
.post-format-icon.post-format-standard:before,
a.post-state-format.format-standard:before {
.post-format-icon.post-format-standard::before {
content: "\f109";
}
.post-state-format.post-format-image:before,
.post-format-icon.post-format-image:before,
a.post-state-format.format-image:before {
.post-format-icon.post-format-image::before {
content: "\f128";
}
.post-state-format.post-format-gallery:before,
.post-format-icon.post-format-gallery:before,
a.post-state-format.format-gallery:before {
.post-format-icon.post-format-gallery::before {
content: "\f161";
}
.post-state-format.post-format-audio:before,
.post-format-icon.post-format-audio:before,
a.post-state-format.format-audio:before {
.post-format-icon.post-format-audio::before {
content: "\f127";
}
.post-state-format.post-format-video:before,
.post-format-icon.post-format-video:before,
a.post-state-format.format-video:before {
.post-format-icon.post-format-video::before {
content: "\f126";
}
.post-state-format.post-format-chat:before,
.post-format-icon.post-format-chat:before,
a.post-state-format.format-chat:before {
.post-format-icon.post-format-chat::before {
content: "\f125";
}
.post-state-format.post-format-status:before,
.post-format-icon.post-format-status:before,
a.post-state-format.format-status:before {
.post-format-icon.post-format-status::before {
content: "\f130";
}
.post-state-format.post-format-aside:before,
.post-format-icon.post-format-aside:before,
a.post-state-format.format-aside:before {
.post-format-icon.post-format-aside::before {
content: "\f123";
}
.post-state-format.post-format-quote:before,
.post-format-icon.post-format-quote:before,
a.post-state-format.format-quote:before {
.post-format-icon.post-format-quote::before {
content: "\f122";
}
.post-state-format.post-format-link:before,
.post-format-icon.post-format-link:before,
a.post-state-format.format-link:before {
.post-format-icon.post-format-link::before {
content: "\f103";
}

View File

@ -471,12 +471,6 @@ div#dashboard-widgets {
display: inline;
}
a.post-state-format {
text-indent: 0;
line-height: 0;
font-size: 0;
}
table.ie-fixed {
table-layout: fixed;
}

View File

@ -458,6 +458,66 @@ class WP_Posts_List_Table extends WP_List_Table {
}
}
/**
* Displays a formats drop-down for filtering items.
*
* @since 5.2.0
* @access protected
*
* @param string $post_type Post type key.
*/
protected function formats_dropdown( $post_type ) {
/**
* Filters whether to remove the 'Formats' drop-down from the post list table.
*
* @since 5.2.0
*
* @param bool $disable Whether to disable the drop-down. Default false.
*/
if ( apply_filters( 'disable_formats_dropdown', false ) ) {
return;
}
// Make sure the dropdown shows only formats with a post count greater than 0.
$used_post_formats = get_terms(
array(
'taxonomy' => 'post_format',
'hide_empty' => true,
)
);
/*
* Return if the post type doesn't have post formats, or there are no posts using formats,
* or if we're in the trash.
*/
if ( ! is_object_in_taxonomy( $post_type, 'post_format' ) || ! $used_post_formats || $this->is_trash ) {
return;
}
$displayed_post_format = isset( $_GET['post_format'] ) ? $_GET['post_format'] : '';
?>
<label for="filter-by-format" class="screen-reader-text"><?php _e( 'Filter by post format' ); ?></label>
<select name="post_format" id="filter-by-format">
<option<?php selected( $displayed_post_format, '' ); ?> value=""><?php _e( 'All formats' ); ?></option>
<?php
foreach ( $used_post_formats as $used_post_format ) {
// Post format slug.
$slug = str_replace( 'post-format-', '', $used_post_format->slug );
// Pretty, translated version of the post format slug.
$pretty_name = get_post_format_string( $slug );
// Skip the standard post format.
if ( 'standard' === $slug ) {
continue;
}
?>
<option<?php selected( $displayed_post_format, $slug ); ?> value="<?php echo esc_attr( $slug ); ?>"><?php echo esc_html( $pretty_name ); ?></option>
<?php
}
?>
</select>
<?php
}
/**
* @param string $which
*/
@ -470,6 +530,7 @@ class WP_Posts_List_Table extends WP_List_Table {
$this->months_dropdown( $this->screen->post_type );
$this->categories_dropdown( $this->screen->post_type );
$this->formats_dropdown( $this->screen->post_type );
/**
* Fires before the Filter button on the Posts and Pages list tables.
@ -944,24 +1005,14 @@ class WP_Posts_List_Table extends WP_List_Table {
echo '<strong>';
$format = get_post_format( $post->ID );
if ( $format ) {
$label = get_post_format_string( $format );
$format_class = 'post-state-format post-format-icon post-format-' . $format;
$format_args = array(
'post_format' => $format,
'post_type' => $post->post_type,
);
echo $this->get_edit_link( $format_args, $label . ':', $format_class );
}
$format_classes = ( $format ) ? 'post-format-icon post-format-' . esc_attr( $format ) : '';
$title = _draft_or_post_title();
if ( $can_edit_post && $post->post_status != 'trash' ) {
printf(
'<a class="row-title" href="%s" aria-label="%s">%s%s</a>',
'<a class="row-title %s" href="%s" aria-label="%s">%s%s</a>',
$format_classes,
get_edit_post_link( $post->ID ),
/* translators: %s: post title */
esc_attr( sprintf( __( '&#8220;%s&#8221; (Edit)' ), $title ) ),
@ -969,7 +1020,12 @@ class WP_Posts_List_Table extends WP_List_Table {
$title
);
} else {
echo $pad . $title;
printf(
'<span class="%s">%s%s</span>',
$format_classes,
$pad,
$title
);
}
_post_states( $post );