PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 All 45 releases
← All changes | views/class-editor-button-thickbox-list-table.php +34 -14 2.2.4 → 3.4 View file →
@@ -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 * Initializes the List Table.
34 35 *
@@ -34,9 +35,9 @@
34 35 *
35 36 * @since 1.0.0
36 37 */
37 38 public function __construct() {
38 - // @phpstan-ignore-next-line (WordPress Core's docblocks state wrong argument types in some places.)
39 + // @phpstan-ignore argument.type (WordPress Core's docblocks state wrong argument types in some places.)
39 40 parent::__construct( array(
40 41 'singular' => 'tablepress-table', // Singular name of the listed records.
41 42 'plural' => 'tablepress-editor-button-list', // Plural name of the listed records.
42 43 'ajax' => false, // Does this list table support AJAX?
@@ -138,8 +139,25 @@
138 139 return esc_html( $item['id'] );
139 140 }
140 141
141 142 /**
143 + * Returns a clean label for the primary (Table Name) column's row header `aria-label`.
144 + *
145 + * Provides screen readers with just the table name as the row header name,
146 + * preventing them from computing the name from the full cell content.
147 + *
148 + * @since 3.3.4
149 + *
150 + * @param array<string, mixed> $item Data item for the current row.
151 + * @return string The table name.
152 + */
153 + protected function get_primary_column_aria_label( /* array */ $item ): string {
154 + // Don't use type hints in the method declaration to prevent PHP errors, as the method is inherited.
155 +
156 + return trim( $item['name'] );
157 + }
158 +
159 + /**
142 160 * Renders a cell in the "table_name" column.
143 161 *
144 162 * @since 1.0.0
145 163 *
@@ -176,9 +194,9 @@
176 194 * @param array<string, mixed> $item Data item for the current row.
177 195 * @return string HTML content of the cell.
178 196 */
179 197 protected function column_table_action( array $item ): string {
180 - return '<input type="button" class="insert-shortcode button" title="' . esc_attr( '[' . TablePress::$shortcode . " id={$item['id']} /]" ) . '" value="' . esc_attr__( 'Insert Shortcode', 'tablepress' ) . '" />';
198 + return '<input type="button" class="insert-shortcode button button-compact" title="' . esc_attr( '[' . TablePress::$shortcode . " id={$item['id']} /]" ) . '" value="' . esc_attr__( 'Insert Shortcode', 'tablepress' ) . '">';
181 199 }
182 200
183 201 /**
184 202 * Holds the message to be displayed when there are no items in the table.
@@ -220,9 +238,9 @@
220 238 add_filter( 'ngettext_default', array( $this, 'change_pagination_items_string' ), 10, 5 );
221 239 $this->pagination( $which );
222 240 remove_filter( 'ngettext_default', array( $this, 'change_pagination_items_string' ), 10 );
223 241 ?>
224 - <br class="clear" />
242 + <br class="clear">
225 243 </div>
226 244 <?php
227 245 }
228 246
@@ -239,8 +257,9 @@
239 257 * @return string The changed translation.
240 258 */
241 259 public function change_pagination_items_string( string $translation, string $single, string $plural, int $number, string $domain ): string {
242 260 if ( '%s item' === $single && '%s items' === $plural ) {
261 + /* translators: %s: Number of tables */
243 262 $translation = _n( '%s table', '%s tables', $number, 'tablepress' );
244 263 }
245 264 return $translation;
246 265 }
@@ -257,9 +276,9 @@
257 276 static $term;
258 277 static $json_encoded_term;
259 278 if ( is_null( $term ) || is_null( $json_encoded_term ) ) {
260 279 $term = wp_unslash( $_GET['s'] );
261 - $json_encoded_term = substr( wp_json_encode( $term, TABLEPRESS_JSON_OPTIONS ), 1, -1 ); // @phpstan-ignore-line
280 + $json_encoded_term = substr( wp_json_encode( $term, TABLEPRESS_JSON_OPTIONS ), 1, -1 ); // @phpstan-ignore argument.type
262 281 }
263 282
264 283 // Load table again, with table data, but without options and visibility settings.
265 284 $item = TablePress::$model_table->load( $item, true, false );
@@ -272,15 +291,17 @@
272 291 if ( isset( $item['is_corrupted'] ) && $item['is_corrupted'] ) {
273 292 return false;
274 293 }
275 294
295 + $fn_stripos = function_exists( 'mb_stripos' ) ? 'mb_stripos' : 'stripos';
296 +
276 297 // Search from easy to hard, so that "expensive" code maybe doesn't have to run.
277 - if ( false !== stripos( $item['id'], $term )
278 - || false !== stripos( $item['name'], $term )
279 - || false !== stripos( $item['description'], $term )
280 - || false !== stripos( TablePress::get_user_display_name( $item['author'] ), $term )
281 - || false !== stripos( TablePress::format_datetime( $item['last_modified'] ), $term )
282 - || false !== stripos( wp_json_encode( $item['data'], TABLEPRESS_JSON_OPTIONS ), $json_encoded_term ) ) { // @phpstan-ignore-line
298 + if ( false !== $fn_stripos( $item['id'], (string) $term )
299 + || false !== $fn_stripos( $item['name'], (string) $term )
300 + || false !== $fn_stripos( $item['description'], (string) $term )
301 + || false !== $fn_stripos( TablePress::get_user_display_name( $item['author'] ), (string) $term )
302 + || false !== $fn_stripos( TablePress::format_datetime( $item['last_modified'] ), (string) $term )
303 + || false !== $fn_stripos( wp_json_encode( $item['data'], TABLEPRESS_JSON_OPTIONS ), (string) $json_encoded_term ) ) { // @phpstan-ignore argument.type
283 304 return true;
284 305 }
285 306
286 307 return false;
@@ -327,10 +348,9 @@
327 348 foreach ( $this->items as &$item ) {
328 349 // Don't load data nor table options.
329 350 $item = TablePress::$model_table->load( $item, false, false );
330 351 }
331 - // Break reference in foreach iterator.
332 - unset( $item );
352 + unset( $item ); // Unset use-by-reference parameter of foreach loop.
333 353
334 354 // Maybe sort the items.
335 355 $_sortable_columns = $this->get_sortable_columns();
336 356 if ( $orderby && ! empty( $this->items ) && isset( $_sortable_columns[ "table_{$orderby}" ] ) ) {