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 +145 -79 2.0.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,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
@@ -151,12 +170,16 @@
151 170 if ( ! ( $user_can_copy_table || $user_can_delete_table || $user_can_export_table ) ) {
152 171 return '';
153 172 }
154 173
174 + if ( '' === trim( $item['name'] ) ) {
175 + $item['name'] = __( '(no name)', 'tablepress' );
176 + }
177 +
155 178 return sprintf(
156 - '<label><span class="screen-reader-text">%1$s</span><input type="checkbox" name="table[]" value="%2$s" /></label>',
157 - esc_html__( 'Bulk action selector', 'tablepress' ),
158 - esc_attr( $item['id'] )
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'] ),
181 + esc_html( sprintf( __( 'Select table “%s”', 'tablepress' ), $item['name'] ) ),
159 182 );
160 183 }
161 184
162 185 /**
@@ -163,24 +186,41 @@
163 186 * Render a cell in the "table_id" column.
164 187 *
165 188 * @since 1.0.0
166 189 *
167 - * @param array $item Data item for the current row.
190 + * @param array<string, mixed> $item Data item for the current row.
168 191 * @return string HTML content of the cell.
169 192 */
170 - protected function column_table_id( array $item ) {
193 + protected function column_table_id( array $item ): string {
171 194 return esc_html( $item['id'] );
172 195 }
173 196
174 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 + /**
175 215 * Render a cell in the "table_name" column.
176 216 *
177 217 * @since 1.0.0
178 218 *
179 - * @param array $item Data item for the current row.
219 + * @param array<string, mixed> $item Data item for the current row.
180 220 * @return string HTML content of the cell.
181 221 */
182 - protected function column_table_name( array $item ) {
222 + protected function column_table_name( array $item ): string {
183 223 $user_can_edit_table = current_user_can( 'tablepress_edit_table', $item['id'] );
184 224 $user_can_copy_table = current_user_can( 'tablepress_copy_table', $item['id'] );
185 225 $user_can_export_table = current_user_can( 'tablepress_export_table', $item['id'] );
186 226 $user_can_delete_table = current_user_can( 'tablepress_delete_table', $item['id'] );
@@ -213,9 +253,9 @@
213 253 if ( $user_can_export_table ) {
214 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' ) );
215 255 }
216 256 if ( $user_can_delete_table ) {
217 - $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' ) );
218 258 }
219 259 if ( $user_can_preview_table ) {
220 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' ) );
221 261 }
@@ -227,12 +267,12 @@
227 267 * Render a cell in the "table_description" column.
228 268 *
229 269 * @since 1.0.0
230 270 *
231 - * @param array $item Data item for the current row.
271 + * @param array<string, mixed> $item Data item for the current row.
232 272 * @return string HTML content of the cell.
233 273 */
234 - protected function column_table_description( array $item ) {
274 + protected function column_table_description( array $item ): string {
235 275 if ( '' === trim( $item['description'] ) ) {
236 276 $item['description'] = __( '(no description)', 'tablepress' );
237 277 }
238 278 return esc_html( $item['description'] );
@@ -242,12 +282,12 @@
242 282 * Render a cell in the "table_author" column.
243 283 *
244 284 * @since 1.0.0
245 285 *
246 - * @param array $item Data item for the current row.
286 + * @param array<string, mixed> $item Data item for the current row.
247 287 * @return string HTML content of the cell.
248 288 */
249 - protected function column_table_author( array $item ) {
289 + protected function column_table_author( array $item ): string {
250 290 return TablePress::get_user_display_name( $item['author'] );
251 291 }
252 292
253 293 /**
@@ -254,12 +294,12 @@
254 294 * Render a cell in the "last_modified_by" column.
255 295 *
256 296 * @since 1.0.0
257 297 *
258 - * @param array $item Data item for the current row.
298 + * @param array<string, mixed> $item Data item for the current row.
259 299 * @return string HTML content of the cell.
260 300 */
261 - protected function column_table_last_modified_by( array $item ) {
301 + protected function column_table_last_modified_by( array $item ): string {
262 302 return TablePress::get_user_display_name( $item['options']['last_editor'] );
263 303 }
264 304
265 305 /**
@@ -266,14 +306,18 @@
266 306 * Render a cell in the "table_last_modified" column.
267 307 *
268 308 * @since 1.0.0
269 309 *
270 - * @param array $item Data item for the current row.
310 + * @param array<string, mixed> $item Data item for the current row.
271 311 * @return string HTML content of the cell.
272 312 */
273 - protected function column_table_last_modified( array $item ) {
313 + protected function column_table_last_modified( array $item ): string {
274 314 $modified_timestamp = date_create( $item['last_modified'], wp_timezone() );
275 - $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 + }
276 320 $current_timestamp = time();
277 321 $time_diff = $current_timestamp - $modified_timestamp;
278 322 // Time difference is only shown up to one week.
279 323 if ( $time_diff >= 0 && $time_diff < WEEK_IN_SECONDS ) {
@@ -278,9 +322,9 @@
278 322 // Time difference is only shown up to one week.
279 323 if ( $time_diff >= 0 && $time_diff < WEEK_IN_SECONDS ) {
280 324 $time_diff = sprintf( __( '%s ago', 'default' ), human_time_diff( $modified_timestamp, $current_timestamp ) );
281 325 } else {
282 - $time_diff = TablePress::format_datetime( $item['last_modified'], '<br />' );
326 + $time_diff = TablePress::format_datetime( $item['last_modified'], '<br>' );
283 327 }
284 328 $readable_time = TablePress::format_datetime( $item['last_modified'] );
285 329 return '<abbr title="' . esc_attr( $readable_time ) . '">' . $time_diff . '</abbr>';
286 330 }
@@ -289,20 +333,22 @@
289 333 * Handles output for the default column.
290 334 *
291 335 * @since 1.8.0
292 336 *
293 - * @param array $item Data item for the current row.
294 - * @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.
295 339 */
296 - protected function column_default( /* array */ $item, $column_name ) {
297 - // 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 +
298 344 /**
299 345 * Fires inside each custom column of the TablePress list table.
300 346 *
301 347 * @since 1.8.0
302 348 *
303 - * @param array $column_name Current column name.
304 - * @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.
305 351 */
306 352 do_action( 'manage_tablepress_list_custom_column', $column_name, $item );
307 353 }
308 354
@@ -312,15 +358,17 @@
312 358 * The "Table Name" column already gets these, so return an empty string here to prevent them from being duplicated.
313 359 *
314 360 * @since 2.0.0
315 361 *
316 - * @param object|array $item The item being acted upon.
317 - * @param string $column_name Current column name.
318 - * @param string $primary Primary column name.
319 - * @return string The row actions HTML, or an empty string
320 - * 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.
321 366 */
322 - 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 +
323 371 return '';
324 372 }
325 373
326 374 /**
@@ -327,11 +375,12 @@
327 375 * Get a list (name => title) bulk actions that are available.
328 376 *
329 377 * @since 1.0.0
330 378 *
331 - * @return array Bulk actions for this table.
379 + * @return array<string, string> Bulk actions for this table.
332 380 */
333 - protected function get_bulk_actions() {
381 + #[\Override]
382 + protected function get_bulk_actions(): array {
334 383 $bulk_actions = array();
335 384
336 385 if ( current_user_can( 'tablepress_copy_tables' ) ) {
337 386 $bulk_actions['copy'] = _x( 'Copy', 'bulk action', 'tablepress' );
@@ -352,13 +401,16 @@
352 401 * In comparison with parent class, this has modified HTML (especially no field named "action" as that's being used already)!
353 402 *
354 403 * @since 1.0.0
355 404 *
356 - * @param string $which The location of the bulk actions: 'top' or 'bottom'.
357 - * 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.
358 407 */
359 - protected function bulk_actions( $which = '' ) {
360 - 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 ) ) {
361 413 $this->_actions = $this->get_bulk_actions();
362 414 $no_new_actions = $this->_actions;
363 415 /** This filter is documented in the WordPress function WP_List_Table::bulk_actions() in wp-admin/includes/class-wp-list-table.php */
364 416 $this->_actions = apply_filters( 'bulk_actions-' . $this->screen->id, $this->_actions ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
@@ -372,16 +424,19 @@
372 424 return;
373 425 }
374 426
375 427 $name_id = "bulk-action-selector-{$which}";
376 - 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>';
377 432 echo "<select name='{$name_id}' id='{$name_id}'>\n";
378 - echo "<option value='-1' selected='selected'>" . __( 'Bulk Actions', 'tablepress' ) . "</option>\n";
433 + echo "<option value='-1' selected='selected'>" . __( 'Bulk actions', 'default' ) . "</option>\n";
379 434 foreach ( $this->_actions as $name => $title ) {
380 435 echo "\t<option value='{$name}'>{$title}</option>\n";
381 436 }
382 437 echo "</select>\n";
383 - submit_button( __( 'Apply', 'tablepress' ), 'action', '', false, array( 'id' => "doaction{$two}" ) );
438 + submit_button( __( 'Apply', 'default' ), 'action', 'bulk_action', false, array( 'id' => "doaction{$two}" ) );
384 439 echo "\n";
385 440 }
386 441
387 442 /**
@@ -388,9 +443,10 @@
388 443 * Holds the message to be displayed when there are no items in the table.
389 444 *
390 445 * @since 1.0.0
391 446 */
392 - public function no_items() {
447 + #[\Override]
448 + public function no_items(): void {
393 449 _e( 'No tables found.', 'tablepress' );
394 450 if ( 0 === $this->items_count ) {
395 451 $user_can_add_tables = current_user_can( 'tablepress_add_tables' );
396 452 $user_can_import_tables = current_user_can( 'tablepress_import_tables' );
@@ -414,11 +470,14 @@
414 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.
415 471 *
416 472 * @since 1.0.0
417 473 *
418 - * @param string $which Location ("top" or "bottom").
474 + * @param 'top'|'bottom' $which Location ("top" or "bottom").
419 475 */
420 - 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 +
421 480 ?>
422 481 <div class="tablenav <?php echo esc_attr( $which ); ?>">
423 482
424 483 <?php if ( $this->has_items() ) : ?>
@@ -430,12 +489,12 @@
430 489 $this->extra_tablenav( $which );
431 490
432 491 add_filter( 'ngettext_default', array( $this, 'change_pagination_items_string' ), 10, 5 );
433 492 $this->pagination( $which );
434 - remove_filter( 'ngettext_default', array( $this, 'change_pagination_items_string' ), 10, 5 );
493 + remove_filter( 'ngettext_default', array( $this, 'change_pagination_items_string' ), 10 );
435 494 ?>
436 495
437 - <br class="clear" />
496 + <br class="clear">
438 497 </div>
439 498 <?php
440 499 }
441 500
@@ -450,10 +509,11 @@
450 509 * @param int $number The number to compare against to use either the singular or plural form.
451 510 * @param string $domain Text domain. Defaults to 'default'.
452 511 * @return string The changed translation.
453 512 */
454 - 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 {
455 514 if ( '%s item' === $single && '%s items' === $plural ) {
515 + /* translators: %s: Number of tables */
456 516 $translation = _n( '%s table', '%s tables', $number, 'tablepress' );
457 517 }
458 518 return $translation;
459 519 }
@@ -465,14 +525,14 @@
465 525 *
466 526 * @param string $item Table ID that shall be searched.
467 527 * @return bool Whether the search term was found or not.
468 528 */
469 - protected function _search_callback( $item ) {
529 + protected function _search_callback( string $item ): bool {
470 530 static $term;
471 531 static $json_encoded_term;
472 532 if ( is_null( $term ) || is_null( $json_encoded_term ) ) {
473 533 $term = wp_unslash( $_GET['s'] );
474 - $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
475 535 }
476 536
477 537 static $debug;
478 538 if ( is_null( $debug ) ) {
@@ -479,24 +539,30 @@
479 539 // Set debug variable to allow searching in corrupted tables.
480 540 $debug = isset( $_GET['debug'] ) ? ( 'true' === $_GET['debug'] ) : WP_DEBUG;
481 541 }
482 542
483 - // load table again, with data and options (for last_editor).
543 + // Load table again, with data and options (for last_editor).
484 544 $item = TablePress::$model_table->load( $item, true, true );
485 545
546 + if ( is_wp_error( $item ) ) {
547 + return false;
548 + }
549 +
486 550 // Don't search corrupted tables, except when debug mode is enabled via $_GET parameter or WP_DEBUG constant.
487 551 if ( ! $debug && isset( $item['is_corrupted'] ) && $item['is_corrupted'] ) {
488 552 return false;
489 553 }
490 554
555 + $fn_stripos = function_exists( 'mb_stripos' ) ? 'mb_stripos' : 'stripos';
556 +
491 557 // Search from easy to hard, so that "expensive" code maybe doesn't have to run.
492 - if ( false !== stripos( $item['id'], $term )
493 - || false !== stripos( $item['name'], $term )
494 - || false !== stripos( $item['description'], $term )
495 - || false !== stripos( TablePress::get_user_display_name( $item['author'] ), $term )
496 - || false !== stripos( TablePress::get_user_display_name( $item['options']['last_editor'] ), $term )
497 - || false !== stripos( TablePress::format_datetime( $item['last_modified'] ), $term )
498 - || 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
499 565 return true;
500 566 }
501 567
502 568 return false;
@@ -506,13 +572,13 @@
506 572 * Callback to for the array sort function.
507 573 *
508 574 * @since 1.0.0
509 575 *
510 - * @param array $item_a First item that shall be compared to.
511 - * @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.
512 578 * @return int (-1, 0, 1) depending on which item sorts "higher".
513 579 */
514 - protected function _order_callback( array $item_a, array $item_b ) {
580 + protected function _order_callback( array $item_a, array $item_b ): int {
515 581 global $orderby, $order;
516 582
517 583 if ( 'last_modified_by' !== $orderby ) {
518 584 if ( $item_a[ $orderby ] === $item_b[ $orderby ] ) {
@@ -517,9 +583,9 @@
517 583 if ( 'last_modified_by' !== $orderby ) {
518 584 if ( $item_a[ $orderby ] === $item_b[ $orderby ] ) {
519 585 return 0;
520 586 }
521 - } else {
587 + } else { // phpcs:ignore Universal.ControlStructures.DisallowLonelyIf.Found
522 588 if ( $item_a['options']['last_editor'] === $item_b['options']['last_editor'] ) {
523 589 return 0;
524 590 }
525 591 }
@@ -550,9 +616,10 @@
550 616 * Prepares the list of items for displaying, by maybe searching and sorting, and by doing pagination.
551 617 *
552 618 * @since 1.0.0
553 619 */
554 - public function prepare_items() {
620 + #[\Override]
621 + public function prepare_items(): void {
555 622 global $orderby, $order, $s;
556 623 wp_reset_vars( array( 'orderby', 'order', 's' ) );
557 624
558 625 // Maybe search in the items.
@@ -564,10 +631,9 @@
564 631 foreach ( $this->items as &$item ) {
565 632 // Don't load data, but load table options for access to last_editor.
566 633 $item = TablePress::$model_table->load( $item, false, true );
567 634 }
568 - // Break reference in foreach iterator.
569 - unset( $item );
635 + unset( $item ); // Unset use-by-reference parameter of foreach loop.
570 636
571 637 // Maybe sort the items.
572 638 $_sortable_columns = $this->get_sortable_columns();
573 639 if ( $orderby && ! empty( $this->items ) && isset( $_sortable_columns[ "table_{$orderby}" ] ) ) {
@@ -587,9 +653,9 @@
587 653 // Register pagination options and calculation results.
588 654 $this->set_pagination_args( array(
589 655 'total_items' => $total_items, // Total number of records/items.
590 656 'per_page' => $per_page, // Number of items per page.
591 - 'total_pages' => ceil( $total_items / $per_page ), // Total number of pages.
657 + 'total_pages' => (int) ceil( $total_items / $per_page ), // Total number of pages.
592 658 ) );
593 659 }
594 660
595 661 } // class TablePress_All_Tables_List_Table