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: |
|
Owned by: |
|
---|---|---|---|
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)
Change History (8)
#1
@
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
#3
follow-up:
↓ 5
@
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
@
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?
#6
@
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.
Thanks for the ticket, @pbogdan. At first glance it does look like that conditional is ordered wrong.