Make WordPress Core

Opened 15 months ago

Last modified 3 months ago

#58789 new defect (bug)

Not countable. row_actions @ /wp-admin/includes/class-wp-list-table.php

Reported by: nate1's profile Nate1 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: major Version: 6.2
Component: Administration Keywords: has-patch has-unit-tests needs-testing
Focuses: Cc:

Description (last modified by sabernhardt)

Commonly getting not countable for the users lists, across many sites not sure of the source of the issue, but easy solution seems to be to modify.

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

protected function row_actions( $actions, $always_visible = false ) 
++ if(!isset($actions)) { return ''; }

$action_count = count( $actions );
if ( ! $action_count ) {
return '';
}

Change History (5)

#1 @sabernhardt
11 months ago

  • Component changed from General to Administration
  • Description modified (diff)
  • Keywords needs-patch added

I think the problem might come from the user_row_actions filter returning false or an empty string, and then the $actions variable would be set but uncountable. Maybe row_actions() could check is_countable instead.

$action_count = is_countable( $actions ) ? count( $actions ) : 0;

#2 @Nate1
11 months ago

Provided is_countable handles NULL as well as false and empty strings then that will work well. The isset call has been applied to resolve the issue on PHP 8.1.X instances I've observed.

This ticket was mentioned in PR #6801 on WordPress/wordpress-develop by @m1r0.


4 months ago
#3

  • Keywords has-patch has-unit-tests added; needs-patch removed

#4 @m1r0
4 months ago

  • Keywords needs-testing added

Hey! 👋🙂 Here's a quick PR fixing this.

#5 @lalitmehra
4 months ago

Thanks m1r0 I check this GitHub pull request. It's helpful.
Also, To handle this more robustly, I can modify the code to ensure $actions is always treated as an array before attempting to count its elements by using this codes

protected function row_actions( $actions, $always_visible = false ) {
    // Ensure $actions is an array
    if ( ! is_array( $actions ) ) {
        $actions = array();
    }

    $action_count = count( $actions );
    if ( $action_count === 0 ) {
        return '';
    }
    // Continue processing $actions as needed...
}

By implementing these changes, thus avoiding errors related to null or non-array values. This should help in resolving the issue where $actions is "not countable" across sites.

Last edited 3 months ago by lalitmehra (previous) (diff)
Note: See TracTickets for help on using tickets.