WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#16444 closed defect (bug) (fixed)

add_user_to_blog() and remove_user_from_blog() can break the switch_to_blog() stack

Reported by: mdawaffe Owned by: markjaquith
Milestone: 3.1 Priority: normal
Severity: normal Version: 3.0.1
Component: Users Keywords: has-patch dev-feedback
Focuses: Cc:

Description

Both add_user_to_blog() and remove_user_from_blog() call switch_to_blog() first thing. On encountering an error, however, they can return before calling restore_current_blog().

See #13903

Patch attached.

Attachments (1)

16444.diff (834 bytes) - added by mdawaffe 3 years ago.

Download all attachments as: .zip

Change History (7)

mdawaffe3 years ago

comment:1 markjaquith3 years ago

  • Keywords dev-feedback added
  • Milestone changed from Awaiting Review to 3.1
  • Owner set to markjaquith
  • Status changed from new to accepted

Straightforward fix, for what could be a tricky bug to track down if encountered. Can I get some more people to weigh in?

comment:2 follow-up: nacin3 years ago

Looks good -- wondering if there are other places we're doing the same thing.

comment:3 PeteMall3 years ago

+1 from me as discussed in the IRC channel.

comment:4 in reply to: ↑ 2 PeteMall3 years ago

Replying to nacin:

Looks good -- wondering if there are other places we're doing the same thing.

Just browsed through all instances of switch_to_blog and doesn't look like we're doing this anywhere else.

Last edited 3 years ago by PeteMall (previous) (diff)

comment:5 markjaquith3 years ago

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

(In [17379]) restore_current_blog() in add_user_to_blog() and remove_user_from_blog() before early return, to avoid being stuck in a switched state. props mdawaffe. fixes #16444 for trunk.

comment:6 markjaquith3 years ago

(In [17380]) restore_current_blog() in add_user_to_blog() and remove_user_from_blog() before early return, to avoid being stuck in a switched state. props mdawaffe. fixes #16444 for trunk.

Note: See TracTickets for help on using tickets.