Opened 7 years ago
Last modified 6 months ago
#49102 reviewing feature request
Multisite: removed_user_from_blog hook
| Reported by: | kevinu | Owned by: | SergeyBiryukov |
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | Users | Version: | 5.3.2 |
| Severity: | minor | Keywords: | needs-dev-note has-patch |
| Cc: | Focuses: | multisite |
Description
I useful hook would be something like "removed_user_from_blog". As it is now there is not a way to hook in once a user has been removed from a multisite blog.
There could be many use cases for this such as a custom notice to the user that was removed, doing something with the user after they are removed, etc.
Attachments (2)
Change History (14)
#2
@
7 years ago
Hello! I have created a patch to make this change and attached it to this ticket. When a maintainer gets a chance I would love a review.
#4
follow-up:
↓ 5
@
7 years ago
- Owner set to
- Status new → reviewing
Hi there, welcome to WordPress Trac! Thanks for the ticket and the patch.
My first thought was that it might be good idea to have a corresponding added_user_to_blog action, however that turned out to be more complicated than I expected.
Looks like there are some inconsistencies between these related functions:
- In add_user_to_blog(), the
add_user_to_blogaction fires immediately after a user is added to a site. - In remove_user_from_blog(), the
remove_user_from_blogaction fires before a user is removed from a site. - In add_existing_user_to_blog(), the
added_existing_useraction fires immediately after a user is added. - In add_new_user_to_blog(), no action is fired.
That does not necessarily block introducing a removed_user_from_blog action here, just something to keep in mind.
At a glance, 0001-Add-removed_user_from_blog-action-hook.patch seems OK to proceed.
If we decide to address the discrepancies while we're at it, some options could be:
- Introduce
added_new_userinadd_new_user_to_blog(), for consistency withadded_existing_user. - Introduce
added_user_to_bloginadd_user_to_blog()after the user cache has been cleaned. That would be similar tocreate_term/created_termactions. - Deprecate both
add_user_to_blogandremove_user_from_blogactions and introduce new actions instead. Something like:add_user_to_blog_beforeadd_user_to_blog_afterremove_user_from_blog_beforeremove_user_from_blog_after
I'm leaning to options 1 and 2 at the moment.
Somewhat related: #15173
#5
in reply to: ↑ 4
;
follow-up:
↓ 9
@
7 years ago
Hello @SergeyBiryukov, and thank you for the welcoming and your review!
That makes a lot of sense and I think it should definitely be kept somewhat consistent between these four functions. So I have uploaded 49102.2.patch which includes making the suggested changes 1 & 2.
While working on it I noticed three other discrepancies I wanted to bring up and and if you feel these should be addressed I would be happy to add it into this patch as well.
- The already present actions
add_user_to_blogandremove_user_from_blogas well as my addition ofremoved_user_from_blogall use the terms "to_blog" or "from_blog".
Should the action added_existing_user in add_existing_user_to_blog() and added_new_user in add_new_user_to_blog() also share that same
- All the actions current and suggested provide the arguments of
$user_idand$blog_id, (some providing $role as well) except foradded_existing_user. This provides the arguments$user_idand$result.
I feel as though the name added_existing_user already implies a success. Should this be changed to be surrounded in an if-statement and provide $blog_id like the others?
- I noticed that in
remove_user_from_blog()and it's actionremove_user_from_blogthe doc-blocks refer to$blog_idbeing an (int). But it actually comes through as a string.
We could either update the doc-blocks, or type cast it as (int) like we do to $user_id in that same function perhaps?
If this one needs to be tracked in a separate ticket I could do so.
This ticket was mentioned in Slack in #core by kevinu. View the logs.
7 years ago
#7
@
7 years ago
- Keywords needs-dev-note added
With the added actions here, this at least deserves a small call out on the Misc Dev Note, when the time comes.
This ticket was mentioned in Slack in #core by david.baumwald. View the logs.
7 years ago
#9
in reply to: ↑ 5
@
7 years ago
Replying to kevinu:
- The already present actions
add_user_to_blogandremove_user_from_blogas well as my addition ofremoved_user_from_blogall use the terms "to_blog" or "from_blog".Should the action
added_existing_userinadd_existing_user_to_blog()andadded_new_userinadd_new_user_to_blog()also share that same
I think it would be good to a new added_existing_user_to_blog action to add_existing_user_to_blog(), but not change the name (or deprecate) the current added_existing_user action.
I'm on the fence about the name of the new added_new_user action in add_new_user_to_blog(). On the one hand, using the same action name as the existing action in add_existing_user_to_blog() makes sense. But if the suggestion above about adding a new added_existing_user_to_blog action is agreed to, then the question becomes: should both actions be added to add_new_user_to_blog()?
- All the actions current and suggested provide the arguments of
$user_idand$blog_id, (some providing $role as well) except foradded_existing_user. This provides the arguments$user_idand$result.I feel as though the name
added_existing_useralready implies a success. Should this be changed to be surrounded in an if-statement and provide$blog_idlike the others?
For backwards-compat reasons, I don't think it would be good to change that (at least not as part of this ticket...maybe that question deserves a ticket of it's own?).
- I noticed that in
remove_user_from_blog()and it's actionremove_user_from_blogthe doc-blocks refer to$blog_idbeing an (int). But it actually comes through as a string.We could either update the doc-blocks, or type cast it as (int) like we do to
$user_idin that same function perhaps?
If this one needs to be tracked in a separate ticket I could do so.
Really? It should be an int in all the places I find that function called...but I haven't done an exhaustive search. Again, that issue is probably worth another ticket.
A few other comments about 49102.2.patch:
- it uses spaces for indenting, and should use tabs
- the
@sincetags for the new actions should just be@since 5.4.0instead of@since MU (5.4.0). Yes, the current actions have@since MU (3.0.0), but that's because 3.0.0 was also called "MU". - the DocBlocks of the functions the new actions have been added to should get
@since 5.4.0tags that mention the new actions.
#10
@
7 years ago
- Milestone 5.4 → Future Release
This ticket still needs a decision, and with 5.4 Beta 1 landing shortly, this is being moved to Future Release. If any maintainer or committer feels this can be included in 5.4 or wishes to assume ownership during a specific cycle, feel free to update the milestone accordingly.
This ticket was mentioned in PR #11616 on WordPress/wordpress-develop by @sainathpoojary.
6 months ago
#12
- Keywords needs-refresh removed
Trac ticket: #49102
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Patch file for changes to add this hook