Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#37223 closed defect (bug) (fixed)

Fatal error when adding a new multi-site user due to incorrect error handling.

Reported by: pbogdan's profile pbogdan Owned by: flixos90's profile flixos90
Milestone: 4.6 Priority: normal
Severity: normal Version: 4.5
Component: Users Keywords: has-patch
Focuses: multisite Cc:

Description

Hello,

we are seeing the following fatal error when adding a new user on multi-site installation:

PHP Fatal error:  Cannot use object of type WP_Error as array in wp-admin/user-new.php on line 154

due to a change introduced in ticket #35705 / changeset r36695. This appears to be due to the branches of the conditional on line 151 being in the wrong order - the second branch that will be taken if $new_user is a WP_Error tries to treat it as an array containing user's details.

In our specific case the call to wpmu_activate_signup() is returning a WP_Error as we call that ourselves earlier on when a user is added, and the second invocation will return an error in that case.

Apart from fixing the conditional it might be worth checking, if possible, whether the user has already been activated either before the call to wpmu_activate_signup() or by somehow inspecting the returned error.

Thanks,
Piotr

Attachments (1)

37223.diff (841 bytes) - added by jeremyfelt 9 years ago.

Download all attachments as: .zip

Change History (8)

#1 @jeremyfelt
9 years ago

  • Focuses multisite added
  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 4.6
  • Version changed from 4.5.3 to 4.5

Thanks for the ticket, @pbogdan. At first glance it does look like that conditional is ordered wrong.

#2 @DrewAPicture
9 years ago

  • Keywords needs-unit-tests added

#3 follow-up: @deronimo
9 years ago

  • Keywords has-patch added; needs-patch removed
  • Severity changed from normal to major

I created a pull request:
https://github.com/WordPress/WordPress/pull/221

Does it address the issue?

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


9 years ago

#5 in reply to: ↑ 3 @flixos90
9 years ago

  • Keywords needs-patch added; has-patch removed
  • Owner set to flixos90
  • Status changed from new to assigned

Replying to deronimo:

I created a pull request:
https://github.com/WordPress/WordPress/pull/221

Does it address the issue?

Thanks for the PR! However, it currently only masks your specific issue. As mentioned above, I think the problem here is that the conditionals are ordered wrong. Changing the ! is_wp_error( $new_user ) into is_wp_error( $new_user ) should fix this problem. Would you mind creating a new patch for this?

@jeremyfelt
9 years ago

#6 @jeremyfelt
9 years ago

  • Keywords has-patch added; needs-unit-tests needs-patch removed
  • Severity changed from major to normal

37223.diff fixes the fatal error by redirecting without a user ID of the activation response is an error.

This works for short term. We should probably figure out (in another ticket) what needs to be communicated when an error is returned here. Right now it's "User has been added to your site." no matter what the error is.

I don't think there's a friendly way to unit test this without doing some abstraction of the user-new screen.

#7 @jeremyfelt
9 years ago

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

In 38007:

Multisite: Correct logic used to display an Edit User link after adding a user.

Previously, if a user was added with the checkbox for no confirmation selected and an error was then encountered in wpmu_activate_signup(), a fatal error would trigger because $new_user was a WP_Error object rather than a user.

Fixes #37223.

Note: See TracTickets for help on using tickets.