| @@ -7,8 +7,10 @@ | ||
| 7 | 7 | * @author Tobias Bäthge |
| 8 | 8 | * @since 2.0.0 |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | +declare(strict_types=1); | |
| 12 | + | |
| 11 | 13 | // Prohibit direct script loading. |
| 12 | 14 | defined( 'ABSPATH' ) || die( 'No direct script access allowed!' ); |
| 13 | 15 | |
| 14 | 16 | /** |
| @@ -24,11 +26,10 @@ | ||
| 24 | 26 | /** |
| 25 | 27 | * Number of items of the initial data set (before sort, search, and pagination). |
| 26 | 28 | * |
| 27 | 29 | * @since 1.0.0 |
| 28 | - * @var int | |
| 29 | 30 | */ |
| 30 | - protected $items_count = 0; | |
| 31 | + protected int $items_count = 0; | |
| 31 | 32 | |
| 32 | 33 | /** |
| 33 | 34 | * Cached bulk actions. |
| 34 | 35 | * |
| @@ -35,11 +36,11 @@ | ||
| 35 | 36 | * This property has to be declared here, as it's `private` in the parent class |
| 36 | 37 | * and thus can't be inherited. |
| 37 | 38 | * |
| 38 | 39 | * @since 1.0.0 |
| 39 | - * @var array<string, string>|null | |
| 40 | + * @var array<string, string> | |
| 40 | 41 | */ |
| 41 | - protected $_actions; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore | |
| 42 | + protected array $_actions; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore | |
| 42 | 43 | |
| 43 | 44 | /** |
| 44 | 45 | * Initialize the List Table. |
| 45 | 46 | * |
| @@ -48,13 +49,13 @@ | ||
| 48 | 49 | public function __construct() { |
| 49 | 50 | $screen = get_current_screen(); |
| 50 | 51 | |
| 51 | 52 | // Hide "Last Modified By" column by default. |
| 52 | - if ( false === get_user_option( "manage{$screen->id}columnshidden" ) ) { | |
| 53 | - update_user_option( get_current_user_id(), "manage{$screen->id}columnshidden", array( 'table_last_modified_by' ), true ); | |
| 53 | + if ( false === get_user_option( "manage{$screen->id}columnshidden" ) ) { // @phpstan-ignore property.nonObject | |
| 54 | + update_user_option( get_current_user_id(), "manage{$screen->id}columnshidden", array( 'table_last_modified_by' ), true ); // @phpstan-ignore property.nonObject | |
| 54 | 55 | } |
| 55 | 56 | |
| 56 | - // @phpstan-ignore-next-line (WordPress Core's docblocks state wrong argument types in some places.) | |
| 57 | + // @phpstan-ignore argument.type (WordPress Core's docblocks state wrong argument types in some places.) | |
| 57 | 58 | parent::__construct( array( |
| 58 | 59 | 'singular' => 'tablepress-table', // Singular name of the listed records. |
| 59 | 60 | 'plural' => 'tablepress-all-tables', // Plural name of the listed records. |
| 60 | 61 | 'ajax' => false, // Does this list table support AJAX? |
| @@ -174,12 +175,11 @@ | ||
| 174 | 175 | $item['name'] = __( '(no name)', 'tablepress' ); |
| 175 | 176 | } |
| 176 | 177 | |
| 177 | 178 | return sprintf( |
| 178 | - // The `label-covers-full-cell` class on the <label> is kept for (some) backward compatibility with WordPress 6.3, and can be removed once TablePress requires WordPress 6.4. | |
| 179 | - '<input type="checkbox" id="cb-select-%1$s" name="table[]" value="%1$s"><label class="label-covers-full-cell" for="cb-select-%1$s"><span class="screen-reader-text">%2$s</span></label>', | |
| 179 | + '<input type="checkbox" id="cb-select-%1$s" name="table[]" value="%1$s"><label for="cb-select-%1$s"><span class="screen-reader-text">%2$s</span></label>', | |
| 180 | 180 | esc_attr( $item['id'] ), |
| 181 | - esc_html( sprintf( __( 'Select table “%s”', 'tablepress' ), $item['name'] ) ) | |
| 181 | + esc_html( sprintf( __( 'Select table “%s”', 'tablepress' ), $item['name'] ) ), | |
| 182 | 182 | ); |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
| @@ -194,8 +194,25 @@ | ||
| 194 | 194 | return esc_html( $item['id'] ); |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
| 198 | + * Returns a clean label for the primary (Table Name) column's row header `aria-label`. | |
| 199 | + * | |
| 200 | + * Provides screen readers with just the table name as the row header name, | |
| 201 | + * preventing them from computing the name from the full cell content. | |
| 202 | + * | |
| 203 | + * @since 3.3.4 | |
| 204 | + * | |
| 205 | + * @param array<string, mixed> $item Data item for the current row. | |
| 206 | + * @return string The table name. | |
| 207 | + */ | |
| 208 | + protected function get_primary_column_aria_label( /* array */ $item ): string { | |
| 209 | + // Don't use type hints in the method declaration to prevent PHP errors, as the method is inherited. | |
| 210 | + | |
| 211 | + return trim( $item['name'] ); | |
| 212 | + } | |
| 213 | + | |
| 214 | + /** | |
| 198 | 215 | * Render a cell in the "table_name" column. |
| 199 | 216 | * |
| 200 | 217 | * @since 1.0.0 |
| 201 | 218 | * |
| @@ -236,9 +253,9 @@ | ||
| 236 | 253 | if ( $user_can_export_table ) { |
| 237 | 254 | $row_actions['export'] = sprintf( '<a href="%1$s" title="%2$s">%3$s</a>', $export_url, esc_attr( sprintf( __( 'Export “%s”', 'tablepress' ), $item['name'] ) ), _x( 'Export', 'row action', 'tablepress' ) ); |
| 238 | 255 | } |
| 239 | 256 | if ( $user_can_delete_table ) { |
| 240 | - $row_actions['delete'] = sprintf( '<a href="%1$s" title="%2$s" class="delete-link">%3$s</a>', $delete_url, esc_attr( sprintf( __( 'Delete “%s”', 'tablepress' ), $item['name'] ) ), __( 'Delete', 'tablepress' ) ); | |
| 257 | + $row_actions['delete'] = sprintf( '<a href="%1$s" title="%2$s">%3$s</a>', $delete_url, esc_attr( sprintf( __( 'Delete “%1$s” (ID %2$s)', 'tablepress' ), $item['name'], $item['id'] ) ), __( 'Delete', 'tablepress' ) ); | |
| 241 | 258 | } |
| 242 | 259 | if ( $user_can_preview_table ) { |
| 243 | 260 | $row_actions['table-preview'] = sprintf( '<a href="%1$s" title="%2$s">%3$s</a>', $preview_url, esc_attr( sprintf( __( 'Preview of table “%1$s” (ID %2$s)', 'tablepress' ), $item['name'], $item['id'] ) ), __( 'Preview', 'tablepress' ) ); |
| 244 | 261 | } |
| @@ -391,9 +408,9 @@ | ||
| 391 | 408 | #[\Override] |
| 392 | 409 | protected function bulk_actions( /* string */ $which = 'top' ): void { |
| 393 | 410 | // Don't use type hints in the method declaration to prevent PHP errors, as the method is inherited. |
| 394 | 411 | |
| 395 | - if ( is_null( $this->_actions ) ) { | |
| 412 | + if ( ! isset( $this->_actions ) ) { | |
| 396 | 413 | $this->_actions = $this->get_bulk_actions(); |
| 397 | 414 | $no_new_actions = $this->_actions; |
| 398 | 415 | /** This filter is documented in the WordPress function WP_List_Table::bulk_actions() in wp-admin/includes/class-wp-list-table.php */ |
| 399 | 416 | $this->_actions = apply_filters( 'bulk_actions-' . $this->screen->id, $this->_actions ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
| @@ -407,16 +424,19 @@ | ||
| 407 | 424 | return; |
| 408 | 425 | } |
| 409 | 426 | |
| 410 | 427 | $name_id = "bulk-action-selector-{$which}"; |
| 411 | - echo "<label for='{$name_id}' class='screen-reader-text'>" . __( 'Select Bulk Action', 'tablepress' ) . "</label>\n"; | |
| 428 | + echo "<label for='{$name_id}' class='screen-reader-text'>" . | |
| 429 | + /* translators: Hidden accessibility text. */ | |
| 430 | + __( 'Select bulk action', 'default' ) . | |
| 431 | + '</label>'; | |
| 412 | 432 | echo "<select name='{$name_id}' id='{$name_id}'>\n"; |
| 413 | - echo "<option value='-1' selected='selected'>" . __( 'Bulk Actions', 'tablepress' ) . "</option>\n"; | |
| 433 | + echo "<option value='-1' selected='selected'>" . __( 'Bulk actions', 'default' ) . "</option>\n"; | |
| 414 | 434 | foreach ( $this->_actions as $name => $title ) { |
| 415 | 435 | echo "\t<option value='{$name}'>{$title}</option>\n"; |
| 416 | 436 | } |
| 417 | 437 | echo "</select>\n"; |
| 418 | - submit_button( __( 'Apply', 'tablepress' ), 'action', '', false, array( 'id' => "doaction{$two}" ) ); | |
| 438 | + submit_button( __( 'Apply', 'default' ), 'action', 'bulk_action', false, array( 'id' => "doaction{$two}" ) ); | |
| 419 | 439 | echo "\n"; |
| 420 | 440 | } |
| 421 | 441 | |
| 422 | 442 | /** |
| @@ -491,8 +511,9 @@ | ||
| 491 | 511 | * @return string The changed translation. |
| 492 | 512 | */ |
| 493 | 513 | public function change_pagination_items_string( string $translation, string $single, string $plural, int $number, string $domain ): string { |
| 494 | 514 | if ( '%s item' === $single && '%s items' === $plural ) { |
| 515 | + /* translators: %s: Number of tables */ | |
| 495 | 516 | $translation = _n( '%s table', '%s tables', $number, 'tablepress' ); |
| 496 | 517 | } |
| 497 | 518 | return $translation; |
| 498 | 519 | } |
| @@ -509,9 +530,9 @@ | ||
| 509 | 530 | static $term; |
| 510 | 531 | static $json_encoded_term; |
| 511 | 532 | if ( is_null( $term ) || is_null( $json_encoded_term ) ) { |
| 512 | 533 | $term = wp_unslash( $_GET['s'] ); |
| 513 | - $json_encoded_term = substr( wp_json_encode( $term, TABLEPRESS_JSON_OPTIONS ), 1, -1 ); // @phpstan-ignore-line | |
| 534 | + $json_encoded_term = substr( wp_json_encode( $term, TABLEPRESS_JSON_OPTIONS ), 1, -1 ); // @phpstan-ignore argument.type | |
| 514 | 535 | } |
| 515 | 536 | |
| 516 | 537 | static $debug; |
| 517 | 538 | if ( is_null( $debug ) ) { |
| @@ -530,16 +551,18 @@ | ||
| 530 | 551 | if ( ! $debug && isset( $item['is_corrupted'] ) && $item['is_corrupted'] ) { |
| 531 | 552 | return false; |
| 532 | 553 | } |
| 533 | 554 | |
| 555 | + $fn_stripos = function_exists( 'mb_stripos' ) ? 'mb_stripos' : 'stripos'; | |
| 556 | + | |
| 534 | 557 | // Search from easy to hard, so that "expensive" code maybe doesn't have to run. |
| 535 | - if ( false !== stripos( $item['id'], $term ) | |
| 536 | - || false !== stripos( $item['name'], $term ) | |
| 537 | - || false !== stripos( $item['description'], $term ) | |
| 538 | - || false !== stripos( TablePress::get_user_display_name( $item['author'] ), $term ) | |
| 539 | - || false !== stripos( TablePress::get_user_display_name( $item['options']['last_editor'] ), $term ) | |
| 540 | - || false !== stripos( TablePress::format_datetime( $item['last_modified'] ), $term ) | |
| 541 | - || false !== stripos( wp_json_encode( $item['data'], TABLEPRESS_JSON_OPTIONS ), $json_encoded_term ) ) { // @phpstan-ignore-line | |
| 558 | + if ( false !== $fn_stripos( $item['id'], (string) $term ) | |
| 559 | + || false !== $fn_stripos( $item['name'], (string) $term ) | |
| 560 | + || false !== $fn_stripos( $item['description'], (string) $term ) | |
| 561 | + || false !== $fn_stripos( TablePress::get_user_display_name( $item['author'] ), (string) $term ) | |
| 562 | + || false !== $fn_stripos( TablePress::get_user_display_name( $item['options']['last_editor'] ), (string) $term ) | |
| 563 | + || false !== $fn_stripos( TablePress::format_datetime( $item['last_modified'] ), (string) $term ) | |
| 564 | + || false !== $fn_stripos( wp_json_encode( $item['data'], TABLEPRESS_JSON_OPTIONS ), (string) $json_encoded_term ) ) { // @phpstan-ignore argument.type | |
| 542 | 565 | return true; |
| 543 | 566 | } |
| 544 | 567 | |
| 545 | 568 | return false; |