List Tables/WP_Screen: in `WP_Screen`, add methods to store, retrieve, and render screen reader text, primarily used by list table screens.

These additions are based on an audit and recommendations by the Accessibility team. #a11y'all

Props afercia.
Fixes #32147.

Built from https://develop.svn.wordpress.org/trunk@34891


git-svn-id: http://core.svn.wordpress.org/trunk@34856 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2015-10-07 01:28:25 +00:00
parent b3a07ab8ea
commit 0c2b2a0e3d
22 changed files with 194 additions and 2 deletions

View File

@ -165,6 +165,12 @@ get_current_screen()->set_help_sidebar(
'<p>' . __( '<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
);
get_current_screen()->set_screen_reader_content( array(
'heading_views' => __( 'Filter comments list' ),
'heading_pagination' => __( 'Comments list navigation' ),
'heading_list' => __( 'Comments list' ),
) );
require_once( ABSPATH . 'wp-admin/admin-header.php' );
?>

View File

@ -54,6 +54,11 @@ if ( 'post' != $post_type ) {
add_screen_option( 'per_page', array( 'default' => 20, 'option' => 'edit_' . $tax->name . '_per_page' ) );
get_current_screen()->set_screen_reader_content( array(
'heading_pagination' => $tax->labels->pagination,
'heading_list' => $tax->labels->list,
) );
$location = false;
$referer = wp_get_referer();

View File

@ -245,8 +245,15 @@ if ( 'post' == $post_type ) {
'<p>' . __('<a href="https://codex.wordpress.org/Pages_Screen" target="_blank">Documentation on Managing Pages</a>') . '</p>' .
'<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
);
}
get_current_screen()->set_screen_reader_content( array(
'heading_views' => $post_type_object->labels->views,
'heading_pagination' => $post_type_object->labels->pagination,
'heading_list' => $post_type_object->labels->list,
) );
add_screen_option( 'per_page', array( 'default' => 20, 'option' => 'edit_' . $post_type . '_per_page' ) );
$bulk_counts = array(

View File

@ -443,6 +443,8 @@ class WP_Comments_List_Table extends WP_List_Table {
$this->display_tablenav( 'top' );
$this->screen->render_screen_reader_content( 'heading_list' );
?>
<table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
<thead>

View File

@ -382,6 +382,8 @@ class WP_List_Table {
if ( empty( $views ) )
return;
$this->screen->render_screen_reader_content( 'heading_views' );
echo "<ul class='subsubsub'>\n";
foreach ( $views as $class => $view ) {
$views[ $class ] = "\t<li class='$class'>$view";
@ -734,6 +736,10 @@ class WP_List_Table {
$infinite_scroll = $this->_pagination_args['infinite_scroll'];
}
if ( 'top' === $which && $total_pages > 1 ) {
$this->screen->render_screen_reader_content( 'heading_pagination' );
}
$output = '<span class="displaying-num">' . sprintf( _n( '%s item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>';
$current = $this->get_pagenum();
@ -1117,6 +1123,8 @@ class WP_List_Table {
$singular = $this->_args['singular'];
$this->display_tablenav( 'top' );
$this->screen->render_screen_reader_content( 'heading_list' );
?>
<table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
<thead>

View File

@ -217,6 +217,8 @@ class WP_Media_List_Table extends WP_List_Table {
global $mode;
$views = $this->get_views();
$this->screen->render_screen_reader_content( 'heading_views' );
?>
<div class="wp-filter">
<div class="filter-items">

View File

@ -258,6 +258,7 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
/** This filter is documented in wp-admin/inclues/class-wp-list-table.php */
$views = apply_filters( "views_{$this->screen->id}", $views );
$this->screen->render_screen_reader_content( 'heading_views' );
?>
<div class="wp-filter">
<ul class="filter-links">
@ -292,7 +293,9 @@ class WP_Plugin_Install_List_Table extends WP_List_Table {
?>
<div class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
<?php
$this->screen->render_screen_reader_content( 'heading_list' );
?>
<div id="the-list"<?php echo $data_attr; ?>>
<?php $this->display_rows_or_placeholder(); ?>
</div>

View File

@ -142,6 +142,15 @@ final class WP_Screen {
*/
private $_help_sidebar = '';
/**
* The accessible hidden headings and text associated with the screen, if any.
*
* @since 4.4.0
* @access private
* @var array
*/
private $_screen_reader_content = array();
/**
* Stores old string-based help.
*
@ -644,6 +653,70 @@ final class WP_Screen {
return $this->columns;
}
/**
* Get the accessible hidden headings and text used in the screen.
*
* @since 4.4.0
*
* @see set_screen_reader_content() For more information on the array format.
*
* @return array An associative array of screen reader text strings.
*/
public function get_screen_reader_content() {
return $this->_screen_reader_content;
}
/**
* Get a screen reader text string.
*
* @since 4.4.0
*
* @param string $key Screen reader text array named key.
* @return string Screen reader text string.
*/
public function get_screen_reader_text( $key ) {
if ( ! isset( $this->_screen_reader_content[ $key ] ) ) {
return null;
}
return $this->_screen_reader_content[ $key ];
}
/**
* Add accessible hidden headings and text for the screen.
*
* @since 4.4.0
*
* @param array $content {
* An associative array of screen reader text strings.
*
* @type string $heading_views Screen reader text for the filter links heading.
* Default 'Filter items list'.
* @type string $heading_pagination Screen reader text for the pagination heading.
* Default 'Items list navigation'.
* @type string heading_list Screen reader text for the items list heading.
* Default 'Items list'.
* }
*/
public function set_screen_reader_content( $content = array() ) {
$defaults = array(
'heading_views' => __( 'Filter items list' ),
'heading_pagination' => __( 'Items list navigation' ),
'heading_list' => __( 'Items list' ),
);
$content = wp_parse_args( $content, $defaults );
$this->_screen_reader_content = $content;
}
/**
* Remove all the accessible hidden headings and text for the screen.
*
* @since 4.4.0
*/
public function remove_screen_reader_content() {
$this->_screen_reader_content = array();
}
/**
* Render the screen's help section.
*
@ -1064,4 +1137,20 @@ final class WP_Screen {
</div>
<?php
}
/**
* Render screen reader text.
*
* @since 4.4.0
*
* @param string $key The screen reader text array named key.
* @param string $tag Optional. The HTML tag to wrap the screen reader text. Default h2.
*/
public function render_screen_reader_content( $key = '', $tag = 'h2' ) {
if ( ! isset( $this->_screen_reader_content[ $key ] ) ) {
return;
}
echo "<$tag class='screen-reader-text'>" . $this->_screen_reader_content[ $key ] . "</$tag>";
}
}

View File

@ -61,6 +61,10 @@ get_current_screen()->set_help_sidebar(
'<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
);
get_current_screen()->set_screen_reader_content( array(
'heading_list' => __( 'Links list' ),
) );
include_once( ABSPATH . 'wp-admin/admin-header.php' );
if ( ! current_user_can('manage_links') )

View File

@ -33,6 +33,12 @@ get_current_screen()->set_help_sidebar(
'<p>' . __('<a href="https://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>'
);
get_current_screen()->set_screen_reader_content( array(
'heading_views' => __( 'Filter site themes list' ),
'heading_pagination' => __( 'Site themes list navigation' ),
'heading_list' => __( 'Site themes list' ),
) );
$wp_list_table = _get_list_table('WP_MS_Themes_List_Table');
$action = $wp_list_table->current_action();

View File

@ -36,6 +36,12 @@ get_current_screen()->set_help_sidebar(
'<p>' . __('<a href="https://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>'
);
get_current_screen()->set_screen_reader_content( array(
'heading_views' => __( 'Filter site users list' ),
'heading_pagination' => __( 'Site users list navigation' ),
'heading_list' => __( 'Site users list' ),
) );
$_SERVER['REQUEST_URI'] = remove_query_arg( 'update', $_SERVER['REQUEST_URI'] );
$referer = remove_query_arg( 'update', wp_get_referer() );

View File

@ -46,6 +46,11 @@ get_current_screen()->set_help_sidebar(
'<p>' . __('<a href="https://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>'
);
get_current_screen()->set_screen_reader_content( array(
'heading_pagination' => __( 'Sites list navigation' ),
'heading_list' => __( 'Sites list' ),
) );
$id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
if ( isset( $_GET['action'] ) ) {

View File

@ -251,6 +251,12 @@ get_current_screen()->set_help_sidebar(
'<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
);
get_current_screen()->set_screen_reader_content( array(
'heading_views' => __( 'Filter themes list' ),
'heading_pagination' => __( 'Themes list navigation' ),
'heading_list' => __( 'Themes list' ),
) );
$title = __('Themes');
$parent_file = 'themes.php';

View File

@ -172,6 +172,12 @@ get_current_screen()->set_help_sidebar(
'<p>' . __('<a href="https://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>'
);
get_current_screen()->set_screen_reader_content( array(
'heading_views' => __( 'Filter users list' ),
'heading_pagination' => __( 'Users list navigation' ),
'heading_list' => __( 'Users list' ),
) );
require_once( ABSPATH . 'wp-admin/admin-header.php' );
if ( isset( $_REQUEST['updated'] ) && $_REQUEST['updated'] == 'true' && ! empty( $_REQUEST['action'] ) ) {

View File

@ -88,6 +88,12 @@ get_current_screen()->set_help_sidebar(
'<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
);
get_current_screen()->set_screen_reader_content( array(
'heading_views' => __( 'Filter plugins list' ),
'heading_pagination' => __( 'Plugins list navigation' ),
'heading_list' => __( 'Plugins list' ),
) );
/**
* WordPress Administration Template Header.
*/

View File

@ -426,6 +426,12 @@ get_current_screen()->set_help_sidebar(
'<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
);
get_current_screen()->set_screen_reader_content( array(
'heading_views' => __( 'Filter plugins list' ),
'heading_pagination' => __( 'Plugins list navigation' ),
'heading_list' => __( 'Plugins list' ),
) );
$title = __('Plugins');
$parent_file = 'plugins.php';

View File

@ -128,6 +128,8 @@ include(ABSPATH . 'wp-admin/admin-header.php');
<?php install_themes_upload(); ?>
</div>
<h2 class="screen-reader-text"><?php _e( 'Filter themes list' ); ?></h2>
<div class="wp-filter">
<div class="filter-count">
<span class="count theme-count"></span>
@ -171,6 +173,7 @@ include(ABSPATH . 'wp-admin/admin-header.php');
</div>
</div>
</div>
<h2 class="screen-reader-text"><?php _e( 'Themes list' ); ?></h2>
<div class="theme-browser content-filterable"></div>
<div class="theme-install-overlay wp-full-overlay expanded"></div>

View File

@ -204,6 +204,12 @@ get_current_screen()->set_help_sidebar(
'<p>' . __( '<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
);
get_current_screen()->set_screen_reader_content( array(
'heading_views' => __( 'Filter media items list' ),
'heading_pagination' => __( 'Media items list navigation' ),
'heading_list' => __( 'Media items list' ),
) );
require_once( ABSPATH . 'wp-admin/admin-header.php' );
?>

View File

@ -68,6 +68,12 @@ get_current_screen()->set_help_sidebar(
'<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
);
get_current_screen()->set_screen_reader_content( array(
'heading_views' => __( 'Filter users list' ),
'heading_pagination' => __( 'Users list navigation' ),
'heading_list' => __( 'Users list' ),
) );
if ( empty($_REQUEST) ) {
$referer = '<input type="hidden" name="wp_http_referer" value="'. esc_attr( wp_unslash( $_SERVER['REQUEST_URI'] ) ) . '" />';
} elseif ( isset($_REQUEST['wp_http_referer']) ) {

View File

@ -1322,6 +1322,9 @@ function _post_type_meta_capabilities( $capabilities = null ) {
* - remove_featured_image - Default is Remove featured image.
* - use_featured_image - Default is Use as featured image.
* - menu_name - Default is the same as `name`.
* - views - String for the table views hidden heading.
* - pagination - String for the table pagination hidden heading.
* - list - String for the table hidden heading.
*
* Above, the first default value is for non-hierarchical post types (like posts)
* and the second one is for hierarchical post types (like pages).
@ -1356,6 +1359,9 @@ function get_post_type_labels( $post_type_object ) {
'set_featured_image' => array( __( 'Set featured image' ), __( 'Set featured image' ) ),
'remove_featured_image' => array( __( 'Remove featured image' ), __( 'Remove featured image' ) ),
'use_featured_image' => array( __( 'Use as featured image' ), __( 'Use as featured image' ) ),
'views' => array( __( 'Filter posts list' ), __( 'Filter pages list' ) ),
'pagination' => array( __( 'Posts list navigation' ), __( 'Pages list navigation' ) ),
'list' => array( __( 'Posts list' ), __( 'Pages list' ) ),
);
$nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name'];

View File

@ -495,6 +495,8 @@ function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
* - choose_from_most_used - This string isn't used on hierarchical taxonomies. Default is "Choose from the most used tags", used in the meta box.
* - not_found - Default is "No tags found"/"No categories found", used in the meta box and taxonomy list table.
* - no_terms - Default is "No tags"/"No categories", used in the posts and media list tables.
* - pagination - String for the table pagination hidden heading.
* - list - String for the table hidden heading.
*
* Above, the first default value is for non-hierarchical taxonomies (like tags) and the second one is for hierarchical taxonomies (like categories).
*
@ -534,6 +536,8 @@ function get_taxonomy_labels( $tax ) {
'choose_from_most_used' => array( __( 'Choose from the most used tags' ), null ),
'not_found' => array( __( 'No tags found.' ), __( 'No categories found.' ) ),
'no_terms' => array( __( 'No tags' ), __( 'No categories' ) ),
'pagination' => array( __( 'Tags list navigation' ), __( 'Categories list navigation' ) ),
'list' => array( __( 'Tags list' ), __( 'Categories list' ) ),
);
$nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name'];

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.4-alpha-34890';
$wp_version = '4.4-alpha-34891';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.