WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#37607 closed defect (bug) (fixed)

get_site() does not return the current site when multisite is in a switched state

Reported by: jeremyfelt Owned by: jeremyfelt
Milestone: 4.6 Priority: normal
Severity: normal Version: 4.6
Component: Networks and Sites Keywords: has-patch has-unit-tests commit dev-reviewed
Focuses: multisite Cc:

Description

get_site() uses the global $current_blog as a fallback if a site ID is not passed. When in a switched state via switch_to_blog(), this global continues to contain the original site information. If get_site() is called, then the originally loaded site will be returned, not that of the switched site.

$blog_id should be used instead as it is modified during switch_to_blog() and restore_current_blog().

Attachments (2)

37607.diff (706 bytes) - added by jeremyfelt 5 years ago.
37607.2.diff (2.1 KB) - added by jeremyfelt 5 years ago.

Download all attachments as: .zip

Change History (11)

@jeremyfelt
5 years ago

#1 @jeremyfelt
5 years ago

37607.diff makes the change from global $current_blog to get_current_blog_id().

#2 @ocean90
5 years ago

  • Keywords needs-unit-tests added

😉

@jeremyfelt
5 years ago

#3 @jeremyfelt
5 years ago

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

37607.2.diff adds a test showing the issue. This fails pre-patch.

#4 @jeremyfelt
5 years ago

  • Owner set to jeremyfelt
  • Status changed from new to accepted

#5 @jeremyfelt
5 years ago

In 38217:

Multisite: Use get_current_blog_id() in get_site() for current site.

The global $current_blog is not switched in switch_to_blog() and can
not be used to properly retrieve current switched site information.

See #37607.

#6 @jeremyfelt
5 years ago

  • Keywords dev-feedback added

Keeping this open for review before merging [38217] to the 4.6 branch.

#7 @ocean90
5 years ago

  • Keywords commit dev-reviewed added; dev-feedback removed

[38217] looks good for the 4.6 branch.

This ticket was mentioned in Slack in #core-multisite by jeremyfelt. View the logs.


5 years ago

#9 @jeremyfelt
5 years ago

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

In 38231:

Multisite: Use get_current_blog_id() in get_site() for current site.

The global $current_blog is not switched in switch_to_blog() and can
not be used to properly retrieve current switched site information.

Merge of [38217] to the 4.6 branch.

Props ocean90 for review.
Fixes #37607.

Note: See TracTickets for help on using tickets.