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