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-all-tables-list-table.php +130 -80 2.1.8 → 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 * 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|null
40 + * @var array<string, string>
40 41 */
41 - protected $_actions;
42 + protected array $_actions; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore
42 43
43 44 /**
44 45 * Initialize the List Table.
45 46 *
@@ -48,12 +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
57 + // @phpstan-ignore argument.type (WordPress Core's docblocks state wrong argument types in some places.)
56 58 parent::__construct( array(
57 59 'singular' => 'tablepress-table', // Singular name of the listed records.
58 60 'plural' => 'tablepress-all-tables', // Plural name of the listed records.
59 61 'ajax' => false, // Does this list table support AJAX?
@@ -65,11 +67,11 @@
65 67 * Set the data items (here: tables) that are to be displayed by the List Tables, and their original count.
66 68 *
67 69 * @since 1.0.0
68 70 *
69 - * @param array $items Tables to be displayed in the List Table.
71 + * @param string[] $items Tables to be displayed in the List Table.
70 72 */
71 - public function set_items( array $items ) {
73 + public function set_items( array $items ): void {
72 74 $this->items = $items;
73 75 $this->items_count = count( $items );
74 76 }
75 77
@@ -80,9 +82,10 @@
80 82 * @since 1.0.0
81 83 *
82 84 * @return bool true (Default value).
83 85 */
84 - public function ajax_user_can() {
86 + #[\Override]
87 + public function ajax_user_can(): bool {
85 88 return true;
86 89 }
87 90
88 91 /**
@@ -91,13 +94,14 @@
91 94 * Format: 'internal-name' => 'Column Title'.
92 95 *
93 96 * @since 1.0.0
94 97 *
95 - * @return array List of columns in this List Table.
98 + * @return array<string, string> List of columns in this List Table.
96 99 */
97 - public function get_columns() {
100 + #[\Override]
101 + public function get_columns(): array {
98 102 $columns = array(
99 - 'cb' => $this->has_items() ? '<input type="checkbox" />' : '', // Checkbox for "Select all", but only if there are items in the table.
103 + 'cb' => $this->has_items() ? '<input type="checkbox">' : '', // Checkbox for "Select all", but only if there are items in the table.
100 104 // "name" is special in WP, which is why we prefix every entry here, to be safe!
101 105 'table_id' => __( 'ID', 'tablepress' ),
102 106 'table_name' => __( 'Table Name', 'tablepress' ),
103 107 'table_description' => __( 'Description', 'tablepress' ),
@@ -114,11 +118,12 @@
114 118 * Format: 'internal-name' => array( $field for $item[ $field ], true for already sorted ).
115 119 *
116 120 * @since 1.0.0
117 121 *
118 - * @return array List of sortable columns in this List Table.
122 + * @return array<string, array{string, bool}> List of sortable columns in this List Table.
119 123 */
120 - protected function get_sortable_columns() {
124 + #[\Override]
125 + protected function get_sortable_columns(): array {
121 126 // No sorting on the Empty List placeholder.
122 127 if ( ! $this->has_items() ) {
123 128 return array();
124 129 }
@@ -140,9 +145,10 @@
140 145 * @since 1.7.0
141 146 *
142 147 * @return string Name of the default primary column, in this case, the table name.
143 148 */
144 - protected function get_default_primary_column_name() {
149 + #[\Override]
150 + protected function get_default_primary_column_name(): string {
145 151 return 'table_name';
146 152 }
147 153
148 154 /**
@@ -149,13 +155,15 @@
149 155 * Render a cell in the "cb" column.
150 156 *
151 157 * @since 1.0.0
152 158 *
153 - * @param array $item Data item for the current row.
159 + * @param array<string, mixed> $item Data item for the current row.
154 160 * @return string HTML content of the cell.
155 161 */
156 - protected function column_cb( /* array */ $item ) {
157 - // Don't use `array` type hint in method declaration to prevent a Strict Standards notice, as the method is inherited.
162 + #[\Override]
163 + protected function column_cb( /* array */ $item ): string {
164 + // Don't use type hints in the method declaration to prevent PHP errors, as the method is inherited.
165 +
158 166 $user_can_copy_table = current_user_can( 'tablepress_copy_table', $item['id'] );
159 167 $user_can_delete_table = current_user_can( 'tablepress_delete_table', $item['id'] );
160 168 $user_can_export_table = current_user_can( 'tablepress_export_table', $item['id'] );
161 169
@@ -167,12 +175,11 @@
167 175 $item['name'] = __( '(no name)', 'tablepress' );
168 176 }
169 177
170 178 return sprintf(
171 - // The `label-covers-full-cell` class on the <label> is kept for (some) backwards compatibility with WordPress 6.3, and can be removed once TablePress requires WordPress 6.4.
172 - '<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>',
173 180 esc_attr( $item['id'] ),
174 - esc_html( sprintf( __( 'Select table “%s”', 'tablepress' ), $item['name'] ) )
181 + esc_html( sprintf( __( 'Select table “%s”', 'tablepress' ), $item['name'] ) ),
175 182 );
176 183 }
177 184
178 185 /**
@@ -179,24 +186,41 @@
179 186 * Render a cell in the "table_id" column.
180 187 *
181 188 * @since 1.0.0
182 189 *
183 - * @param array $item Data item for the current row.
190 + * @param array<string, mixed> $item Data item for the current row.
184 191 * @return string HTML content of the cell.
185 192 */
186 - protected function column_table_id( array $item ) {
193 + protected function column_table_id( array $item ): string {
187 194 return esc_html( $item['id'] );
188 195 }
189 196
190 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 + /**
191 215 * Render a cell in the "table_name" column.
192 216 *
193 217 * @since 1.0.0
194 218 *
195 - * @param array $item Data item for the current row.
219 + * @param array<string, mixed> $item Data item for the current row.
196 220 * @return string HTML content of the cell.
197 221 */
198 - protected function column_table_name( array $item ) {
222 + protected function column_table_name( array $item ): string {
199 223 $user_can_edit_table = current_user_can( 'tablepress_edit_table', $item['id'] );
200 224 $user_can_copy_table = current_user_can( 'tablepress_copy_table', $item['id'] );
201 225 $user_can_export_table = current_user_can( 'tablepress_export_table', $item['id'] );
202 226 $user_can_delete_table = current_user_can( 'tablepress_delete_table', $item['id'] );
@@ -229,9 +253,9 @@
229 253 if ( $user_can_export_table ) {
230 254 $row_actions['export'] = sprintf( '<a href="%1$s" title="%2$s">%3$s</a>', $export_url, esc_attr( sprintf( __( 'Export &#8220;%s&#8221;', 'tablepress' ), $item['name'] ) ), _x( 'Export', 'row action', 'tablepress' ) );
231 255 }
232 256 if ( $user_can_delete_table ) {
233 - $row_actions['delete'] = sprintf( '<a href="%1$s" title="%2$s" class="delete-link">%3$s</a>', $delete_url, esc_attr( sprintf( __( 'Delete &#8220;%s&#8221;', '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' ) );
234 258 }
235 259 if ( $user_can_preview_table ) {
236 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' ) );
237 261 }
@@ -243,12 +267,12 @@
243 267 * Render a cell in the "table_description" column.
244 268 *
245 269 * @since 1.0.0
246 270 *
247 - * @param array $item Data item for the current row.
271 + * @param array<string, mixed> $item Data item for the current row.
248 272 * @return string HTML content of the cell.
249 273 */
250 - protected function column_table_description( array $item ) {
274 + protected function column_table_description( array $item ): string {
251 275 if ( '' === trim( $item['description'] ) ) {
252 276 $item['description'] = __( '(no description)', 'tablepress' );
253 277 }
254 278 return esc_html( $item['description'] );
@@ -258,12 +282,12 @@
258 282 * Render a cell in the "table_author" column.
259 283 *
260 284 * @since 1.0.0
261 285 *
262 - * @param array $item Data item for the current row.
286 + * @param array<string, mixed> $item Data item for the current row.
263 287 * @return string HTML content of the cell.
264 288 */
265 - protected function column_table_author( array $item ) {
289 + protected function column_table_author( array $item ): string {
266 290 return TablePress::get_user_display_name( $item['author'] );
267 291 }
268 292
269 293 /**
@@ -270,12 +294,12 @@
270 294 * Render a cell in the "last_modified_by" column.
271 295 *
272 296 * @since 1.0.0
273 297 *
274 - * @param array $item Data item for the current row.
298 + * @param array<string, mixed> $item Data item for the current row.
275 299 * @return string HTML content of the cell.
276 300 */
277 - protected function column_table_last_modified_by( array $item ) {
301 + protected function column_table_last_modified_by( array $item ): string {
278 302 return TablePress::get_user_display_name( $item['options']['last_editor'] );
279 303 }
280 304
281 305 /**
@@ -282,14 +306,18 @@
282 306 * Render a cell in the "table_last_modified" column.
283 307 *
284 308 * @since 1.0.0
285 309 *
286 - * @param array $item Data item for the current row.
310 + * @param array<string, mixed> $item Data item for the current row.
287 311 * @return string HTML content of the cell.
288 312 */
289 - protected function column_table_last_modified( array $item ) {
313 + protected function column_table_last_modified( array $item ): string {
290 314 $modified_timestamp = date_create( $item['last_modified'], wp_timezone() );
291 - $modified_timestamp = $modified_timestamp->getTimestamp();
315 + if ( false === $modified_timestamp ) {
316 + $modified_timestamp = $item['last_modified'];
317 + } else {
318 + $modified_timestamp = $modified_timestamp->getTimestamp();
319 + }
292 320 $current_timestamp = time();
293 321 $time_diff = $current_timestamp - $modified_timestamp;
294 322 // Time difference is only shown up to one week.
295 323 if ( $time_diff >= 0 && $time_diff < WEEK_IN_SECONDS ) {
@@ -294,9 +322,9 @@
294 322 // Time difference is only shown up to one week.
295 323 if ( $time_diff >= 0 && $time_diff < WEEK_IN_SECONDS ) {
296 324 $time_diff = sprintf( __( '%s ago', 'default' ), human_time_diff( $modified_timestamp, $current_timestamp ) );
297 325 } else {
298 - $time_diff = TablePress::format_datetime( $item['last_modified'], '<br />' );
326 + $time_diff = TablePress::format_datetime( $item['last_modified'], '<br>' );
299 327 }
300 328 $readable_time = TablePress::format_datetime( $item['last_modified'] );
301 329 return '<abbr title="' . esc_attr( $readable_time ) . '">' . $time_diff . '</abbr>';
302 330 }
@@ -305,20 +333,22 @@
305 333 * Handles output for the default column.
306 334 *
307 335 * @since 1.8.0
308 336 *
309 - * @param array $item Data item for the current row.
310 - * @param string $column_name Current column name.
337 + * @param array<string, mixed> $item Data item for the current row.
338 + * @param string $column_name Current column name.
311 339 */
312 - protected function column_default( /* array */ $item, $column_name ) {
313 - // Don't use `array` type hint in method declaration to prevent a Strict Standards notice, as the method is inherited.
340 + #[\Override]
341 + protected function column_default( /* array */ $item, /* string */ $column_name ): void {
342 + // Don't use type hints in the method declaration to prevent PHP errors, as the method is inherited.
343 +
314 344 /**
315 345 * Fires inside each custom column of the TablePress list table.
316 346 *
317 347 * @since 1.8.0
318 348 *
319 - * @param array $column_name Current column name.
320 - * @param string $item Data item for the current row.
349 + * @param string $column_name Current column name.
350 + * @param array<string, mixed> $item Data item for the current row.
321 351 */
322 352 do_action( 'manage_tablepress_list_custom_column', $column_name, $item );
323 353 }
324 354
@@ -328,15 +358,17 @@
328 358 * The "Table Name" column already gets these, so return an empty string here to prevent them from being duplicated.
329 359 *
330 360 * @since 2.0.0
331 361 *
332 - * @param object|array $item The item being acted upon.
333 - * @param string $column_name Current column name.
334 - * @param string $primary Primary column name.
335 - * @return string The row actions HTML, or an empty string
336 - * if the current column is not the primary column.
362 + * @param object|array<string, mixed> $item The item being acted upon.
363 + * @param string $column_name Current column name.
364 + * @param string $primary Primary column name.
365 + * @return string The row actions HTML, or an empty string if the current column is not the primary column.
337 366 */
338 - protected function handle_row_actions( $item, $column_name, $primary ) {
367 + #[\Override]
368 + protected function handle_row_actions( /* object|array */ $item, /* string */ $column_name, /* string */ $primary ): string {
369 + // Don't use type hints in the method declaration to prevent PHP errors, as the method is inherited.
370 +
339 371 return '';
340 372 }
341 373
342 374 /**
@@ -343,11 +375,12 @@
343 375 * Get a list (name => title) bulk actions that are available.
344 376 *
345 377 * @since 1.0.0
346 378 *
347 - * @return array Bulk actions for this table.
379 + * @return array<string, string> Bulk actions for this table.
348 380 */
349 - protected function get_bulk_actions() {
381 + #[\Override]
382 + protected function get_bulk_actions(): array {
350 383 $bulk_actions = array();
351 384
352 385 if ( current_user_can( 'tablepress_copy_tables' ) ) {
353 386 $bulk_actions['copy'] = _x( 'Copy', 'bulk action', 'tablepress' );
@@ -368,13 +401,16 @@
368 401 * In comparison with parent class, this has modified HTML (especially no field named "action" as that's being used already)!
369 402 *
370 403 * @since 1.0.0
371 404 *
372 - * @param string $which The location of the bulk actions: 'top' or 'bottom'.
373 - * This is designated as optional for backwards-compatibility.
405 + * @param 'top'|'bottom' $which The location of the bulk actions: 'top' or 'bottom'.
406 + * This is designated as optional for backwards-compatibility.
374 407 */
375 - protected function bulk_actions( $which = '' ) {
376 - if ( is_null( $this->_actions ) ) {
408 + #[\Override]
409 + protected function bulk_actions( /* string */ $which = 'top' ): void {
410 + // Don't use type hints in the method declaration to prevent PHP errors, as the method is inherited.
411 +
412 + if ( ! isset( $this->_actions ) ) {
377 413 $this->_actions = $this->get_bulk_actions();
378 414 $no_new_actions = $this->_actions;
379 415 /** This filter is documented in the WordPress function WP_List_Table::bulk_actions() in wp-admin/includes/class-wp-list-table.php */
380 416 $this->_actions = apply_filters( 'bulk_actions-' . $this->screen->id, $this->_actions ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
@@ -388,16 +424,19 @@
388 424 return;
389 425 }
390 426
391 427 $name_id = "bulk-action-selector-{$which}";
392 - 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>';
393 432 echo "<select name='{$name_id}' id='{$name_id}'>\n";
394 - echo "<option value='-1' selected='selected'>" . __( 'Bulk Actions', 'tablepress' ) . "</option>\n";
433 + echo "<option value='-1' selected='selected'>" . __( 'Bulk actions', 'default' ) . "</option>\n";
395 434 foreach ( $this->_actions as $name => $title ) {
396 435 echo "\t<option value='{$name}'>{$title}</option>\n";
397 436 }
398 437 echo "</select>\n";
399 - submit_button( __( 'Apply', 'tablepress' ), 'action', '', false, array( 'id' => "doaction{$two}" ) );
438 + submit_button( __( 'Apply', 'default' ), 'action', 'bulk_action', false, array( 'id' => "doaction{$two}" ) );
400 439 echo "\n";
401 440 }
402 441
403 442 /**
@@ -404,9 +443,10 @@
404 443 * Holds the message to be displayed when there are no items in the table.
405 444 *
406 445 * @since 1.0.0
407 446 */
408 - public function no_items() {
447 + #[\Override]
448 + public function no_items(): void {
409 449 _e( 'No tables found.', 'tablepress' );
410 450 if ( 0 === $this->items_count ) {
411 451 $user_can_add_tables = current_user_can( 'tablepress_add_tables' );
412 452 $user_can_import_tables = current_user_can( 'tablepress_import_tables' );
@@ -430,11 +470,14 @@
430 470 * In comparison with parent class, this has no nonce field in its HTML code and a one-time filter around the pagination call, to change a string.
431 471 *
432 472 * @since 1.0.0
433 473 *
434 - * @param string $which Location ("top" or "bottom").
474 + * @param 'top'|'bottom' $which Location ("top" or "bottom").
435 475 */
436 - protected function display_tablenav( $which ) {
476 + #[\Override]
477 + protected function display_tablenav( /* string */ $which ): void {
478 + // Don't use type hints in the method declaration to prevent PHP errors, as the method is inherited.
479 +
437 480 ?>
438 481 <div class="tablenav <?php echo esc_attr( $which ); ?>">
439 482
440 483 <?php if ( $this->has_items() ) : ?>
@@ -446,12 +489,12 @@
446 489 $this->extra_tablenav( $which );
447 490
448 491 add_filter( 'ngettext_default', array( $this, 'change_pagination_items_string' ), 10, 5 );
449 492 $this->pagination( $which );
450 - remove_filter( 'ngettext_default', array( $this, 'change_pagination_items_string' ), 10, 5 );
493 + remove_filter( 'ngettext_default', array( $this, 'change_pagination_items_string' ), 10 );
451 494 ?>
452 495
453 - <br class="clear" />
496 + <br class="clear">
454 497 </div>
455 498 <?php
456 499 }
457 500
@@ -466,10 +509,11 @@
466 509 * @param int $number The number to compare against to use either the singular or plural form.
467 510 * @param string $domain Text domain. Defaults to 'default'.
468 511 * @return string The changed translation.
469 512 */
470 - public function change_pagination_items_string( $translation, $single, $plural, $number, $domain ) {
513 + public function change_pagination_items_string( string $translation, string $single, string $plural, int $number, string $domain ): string {
471 514 if ( '%s item' === $single && '%s items' === $plural ) {
515 + /* translators: %s: Number of tables */
472 516 $translation = _n( '%s table', '%s tables', $number, 'tablepress' );
473 517 }
474 518 return $translation;
475 519 }
@@ -481,14 +525,14 @@
481 525 *
482 526 * @param string $item Table ID that shall be searched.
483 527 * @return bool Whether the search term was found or not.
484 528 */
485 - protected function _search_callback( $item ) {
529 + protected function _search_callback( string $item ): bool {
486 530 static $term;
487 531 static $json_encoded_term;
488 532 if ( is_null( $term ) || is_null( $json_encoded_term ) ) {
489 533 $term = wp_unslash( $_GET['s'] );
490 - $json_encoded_term = substr( wp_json_encode( $term, TABLEPRESS_JSON_OPTIONS ), 1, -1 );
534 + $json_encoded_term = substr( wp_json_encode( $term, TABLEPRESS_JSON_OPTIONS ), 1, -1 ); // @phpstan-ignore argument.type
491 535 }
492 536
493 537 static $debug;
494 538 if ( is_null( $debug ) ) {
@@ -495,24 +539,30 @@
495 539 // Set debug variable to allow searching in corrupted tables.
496 540 $debug = isset( $_GET['debug'] ) ? ( 'true' === $_GET['debug'] ) : WP_DEBUG;
497 541 }
498 542
499 - // load table again, with data and options (for last_editor).
543 + // Load table again, with data and options (for last_editor).
500 544 $item = TablePress::$model_table->load( $item, true, true );
501 545
546 + if ( is_wp_error( $item ) ) {
547 + return false;
548 + }
549 +
502 550 // Don't search corrupted tables, except when debug mode is enabled via $_GET parameter or WP_DEBUG constant.
503 551 if ( ! $debug && isset( $item['is_corrupted'] ) && $item['is_corrupted'] ) {
504 552 return false;
505 553 }
506 554
555 + $fn_stripos = function_exists( 'mb_stripos' ) ? 'mb_stripos' : 'stripos';
556 +
507 557 // Search from easy to hard, so that "expensive" code maybe doesn't have to run.
508 - if ( false !== stripos( $item['id'], $term )
509 - || false !== stripos( $item['name'], $term )
510 - || false !== stripos( $item['description'], $term )
511 - || false !== stripos( TablePress::get_user_display_name( $item['author'] ), $term )
512 - || false !== stripos( TablePress::get_user_display_name( $item['options']['last_editor'] ), $term )
513 - || false !== stripos( TablePress::format_datetime( $item['last_modified'] ), $term )
514 - || false !== stripos( wp_json_encode( $item['data'], TABLEPRESS_JSON_OPTIONS ), $json_encoded_term ) ) {
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
515 565 return true;
516 566 }
517 567
518 568 return false;
@@ -522,13 +572,13 @@
522 572 * Callback to for the array sort function.
523 573 *
524 574 * @since 1.0.0
525 575 *
526 - * @param array $item_a First item that shall be compared to.
527 - * @param array $item_b The second item for the comparison.
576 + * @param array<string, mixed> $item_a First item that shall be compared to.
577 + * @param array<string, mixed> $item_b The second item for the comparison.
528 578 * @return int (-1, 0, 1) depending on which item sorts "higher".
529 579 */
530 - protected function _order_callback( array $item_a, array $item_b ) {
580 + protected function _order_callback( array $item_a, array $item_b ): int {
531 581 global $orderby, $order;
532 582
533 583 if ( 'last_modified_by' !== $orderby ) {
534 584 if ( $item_a[ $orderby ] === $item_b[ $orderby ] ) {
@@ -533,9 +583,9 @@
533 583 if ( 'last_modified_by' !== $orderby ) {
534 584 if ( $item_a[ $orderby ] === $item_b[ $orderby ] ) {
535 585 return 0;
536 586 }
537 - } else {
587 + } else { // phpcs:ignore Universal.ControlStructures.DisallowLonelyIf.Found
538 588 if ( $item_a['options']['last_editor'] === $item_b['options']['last_editor'] ) {
539 589 return 0;
540 590 }
541 591 }
@@ -566,9 +616,10 @@
566 616 * Prepares the list of items for displaying, by maybe searching and sorting, and by doing pagination.
567 617 *
568 618 * @since 1.0.0
569 619 */
570 - public function prepare_items() {
620 + #[\Override]
621 + public function prepare_items(): void {
571 622 global $orderby, $order, $s;
572 623 wp_reset_vars( array( 'orderby', 'order', 's' ) );
573 624
574 625 // Maybe search in the items.
@@ -580,10 +631,9 @@
580 631 foreach ( $this->items as &$item ) {
581 632 // Don't load data, but load table options for access to last_editor.
582 633 $item = TablePress::$model_table->load( $item, false, true );
583 634 }
584 - // Break reference in foreach iterator.
585 - unset( $item );
635 + unset( $item ); // Unset use-by-reference parameter of foreach loop.
586 636
587 637 // Maybe sort the items.
588 638 $_sortable_columns = $this->get_sortable_columns();
589 639 if ( $orderby && ! empty( $this->items ) && isset( $_sortable_columns[ "table_{$orderby}" ] ) ) {