Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid deprecation notice on PHP 8.1 due to converting false to array #1040

Merged
merged 2 commits into from
Apr 20, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -832,12 +832,13 @@ public static function build_available_authorized_sites( $user_id = false, $cont
$authorized_sites = get_transient( $cache_key );

if ( $force || false === $authorized_sites ) {
$sites = get_sites(
$authorized_sites = ! is_array( $authorized_sites ) ? array() : $authorized_sites;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$authorized_sites = ! is_array( $authorized_sites ) ? array() : $authorized_sites;
$authorized_sites = array();

I think it should always start empty:

  • === false it's not an array
  • $force === true then we're repopulating the authorized sites from 0. If the old value is retained then each site will appear in the array twice.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good point, I think this should always be a new empty array if we make it inside this conditional. I've made that change

$sites = get_sites(
array(
'number' => 1000,
)
);
$current_blog_id = (int) get_current_blog_id();
$current_blog_id = (int) get_current_blog_id();

foreach ( $sites as $site ) {
$blog_id = (int) $site->blog_id;
Expand Down