WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 20 months ago

Last modified 13 months ago

#38430 closed defect (bug) (fixed)

Inconsistent return type in `get_active_blog_for_user()`

Reported by: flixos90 Owned by: jeremyfelt
Milestone: 5.1 Priority: normal
Severity: normal Version:
Component: Networks and Sites Keywords: has-patch
Focuses: multisite Cc:
PR Number:

Description

While writing unit tests for #38355, I discovered that get_active_blog_for_user() may possibly return a plain object like those in the array returned by get_blogs_of_user(). We should make sure that only WP_Site objects are returned.

On the other hand, this issue is not really critical since, as far as I could see, the entire clause starting with ! is_object(... will never be reached - I might have missed a use-case, but I tried several "combinations" of what could happen, but never got to the point where it was executed.

Attachments (1)

38430.diff (809 bytes) - added by jeremyfelt 3 years ago.

Download all attachments as: .zip

Change History (5)

@jeremyfelt
3 years ago

#1 @jeremyfelt
3 years ago

  • Keywords has-patch added; needs-patch dev-feedback removed
  • Milestone changed from Awaiting Review to Future Release

This statement should be reachable if the user's primary_blog happens to be set as archived, spam, or deleted.

What I don't get is that we do another call to get_blogs_of_user() and pass the second parameter to get a list of all sites, including those set as archived, spam, or deleted. We then ignore those when trying to find a new primary to set for the user. That's probably another ticket.

Quite a bit about this could be refactored, but 38430.diff is pretty non-intrusive and should result in a consistent WP_Site return as we already have a better object available to us.

#2 @jeremyfelt
20 months ago

  • Milestone changed from Future Release to 5.0
  • Owner set to jeremyfelt
  • Status changed from new to reviewing

#3 @jeremyfelt
20 months ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 42866:

Multisite: Return WP_Site as expected in get_active_blog_for_user().

Previously it was possible for a standard object representing the site to be returned in some cases.

Fixes #38430.

#4 @flixos90
13 months ago

  • Milestone changed from 5.0 to 5.1
Note: See TracTickets for help on using tickets.