Skip to content

get_site_option returns empty string causing exception in Plugin_Command.php #429

Closed
@Tiippex

Description

@Tiippex

Hi,

Issue

I've encountered an issue where get_site_option returns an empty string. This happens at Plugin_Command.php:694.

$auto_updates = get_site_option( Plugin_AutoUpdates_Command::SITE_OPTION );
Due to this, the following condition does not catch the empty string:

if ( false === $auto_updates ) {
    $auto_updates = [];
}

As a result, $auto_updates remains an empty string, which causes an exception later at Plugin_Command.php:720:

'auto_update' => in_array( $file, $auto_updates, true ),
The in_array function expects the haystack to be an array, and passing a string results in an exception.

According to the WordPress documentation, the get_site_option function can return a mixed value, but I'm not sure why it returns an empty string in this case.

PHP 8.0 in_array change

In PHP 8.0 and later, passing a non-array value to in_array results in a TypeError. In PHP 7.x and earlier, this would emit a warning and return false.

Workaround

My current workaround is to remove the strict comparison check: if ( false == $auto_updates ) {

Can you provide guidance on how to handle this scenario properly? Should there be an additional check to ensure $auto_updates is an array before using it in in_array?

Thanks for your help!

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions