[wp-trac] [WordPress Trac] #49102: Multisite: removed_user_from_blog hook

WordPress Trac noreply at wordpress.org
Tue Dec 31 02:53:02 UTC 2019


#49102: Multisite: removed_user_from_blog hook
-----------------------------+-----------------------------
 Reporter:  kevinu           |       Owner:  SergeyBiryukov
     Type:  feature request  |      Status:  reviewing
 Priority:  normal           |   Milestone:  5.4
Component:  Users            |     Version:  5.3.2
 Severity:  minor            |  Resolution:
 Keywords:                   |     Focuses:  multisite
-----------------------------+-----------------------------
Changes (by SergeyBiryukov):

 * owner:  (none) => SergeyBiryukov
 * status:  new => reviewing


Comment:

 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 [source:tags/5.3.2/src/wp-includes/ms-
 functions.php?marks=199-208#L179 add_user_to_blog()], the
 `add_user_to_blog` action fires ''immediately after'' a user is added to a
 site.
 * In [source:tags/5.3.2/src/wp-includes/ms-
 functions.php?marks=240-248#L218 remove_user_from_blog()], the
 `remove_user_from_blog` action fires ''before'' a user is removed from a
 site.
 * In [source:tags/5.3.2/src/wp-includes/ms-
 functions.php?marks=2124-2133#L2111 add_existing_user_to_blog()], the
 `added_existing_user` action fires ''immediately after'' a user is added.
 * In [source:tags/5.3.2/src/wp-includes/ms-functions.php#L2139
 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, [attachment:"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:
 1. Introduce `added_new_user` in `add_new_user_to_blog()`, for consistency
 with `added_existing_user`.
 2. Introduce `added_user_to_blog` in `add_user_to_blog()` after the user
 cache has been cleaned. That would be similar to
 `create_term`/`created_term` actions.
 3. Deprecate both `add_user_to_blog` and `remove_user_from_blog` actions
 and introduce new actions instead. Something like:
   * `add_user_to_blog_before`
   * `add_user_to_blog_after`
   * `remove_user_from_blog_before`
   * `remove_user_from_blog_after`

 I'm leaning to options 1 and 2 at the moment.

 Somewhat related: #15173

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/49102#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list