Skip to content

Commit af65021

Browse files
committed
Fix WP_List_Table::row_actions throwing TypeError when non-countable $actions is passed
1 parent 3806b25 commit af65021

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/wp-admin/includes/class-wp-list-table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ public function current_action() {
658658
* @return string The HTML for the row actions.
659659
*/
660660
protected function row_actions( $actions, $always_visible = false ) {
661-
$action_count = count( $actions );
661+
$action_count = is_countable( $actions ) ? count( $actions ) : 0;
662662

663663
if ( ! $action_count ) {
664664
return '';

tests/phpunit/tests/admin/wpListTable.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,4 +584,21 @@ public function test_search_box_works_with_orderby_string() {
584584

585585
$this->assertStringContainsString( $expected_html, $actual );
586586
}
587+
588+
/**
589+
* Tests that `WP_List_Table::row_actions()` is returning an empty string
590+
* and not throwing a TypeError when a non-countable `$actions` param is passed.
591+
*
592+
* @ticket 58789
593+
*
594+
* @covers WP_List_Table::row_actions()
595+
*/
596+
public function test_row_actions_should_return_empty_string_when_non_countable_actions_is_passed() {
597+
$row_actions = new ReflectionMethod( $this->list_table, 'row_actions' );
598+
$row_actions->setAccessible( true );
599+
600+
$actual = $row_actions->invokeArgs( $this->list_table, array( '' ) );
601+
602+
$this->assertSame( '', $actual );
603+
}
587604
}

0 commit comments

Comments
 (0)