Make WordPress Core

Opened 8 years ago

Last modified 6 weeks ago

#41757 new enhancement

Add action inside of add_new_user_to_blog() function

Reported by: johnjamesjacoby's profile johnjamesjacoby Owned by:
Milestone: Future Release Priority: low
Severity: minor Version: 3.0
Component: Users Keywords: has-patch has-testing-info dev-feedback
Focuses: multisite Cc:

Description

When adding a new user to a site in multisite, the full $meta array is passed in from the relative entry in the wp_signups database table, but it's impossible to do anything with it here because no action exists in this function.

  • A similar action does already exist in add_existing_user_to_blog().
  • We could use the wpmu_activate_user hook, but we'd need to reconfirm if the user was added to the site again, which is not ideal because some complex blog switching may need to occur to do so

I'll attach a patch shortly that adds an action to match add_existing_user_to_blog().

Attachments (2)

41757.diff (691 bytes) - added by johnjamesjacoby 8 years ago.
Adds added_new_user action (no prefix, no suffix, because multisite)
ms-functions.diff (1.1 KB) - added by danieltj 8 years ago.
Adds hook to new user function.

Download all attachments as: .zip

Change History (11)

@johnjamesjacoby
8 years ago

Adds added_new_user action (no prefix, no suffix, because multisite)

#1 @birgire
8 years ago

  • Keywords has-patch added

#2 @jeremyfelt
8 years ago

  • Milestone changed from Awaiting Review to Future Release

I think a hook here makes sense.

I *could* see calling it added_new_user_to_blog to match with the add_new_user_to_blog action rather than the added_existing_user action. It at least seems a little less generic then. :)

Also - the function docs need to be updated to indicate that $password is no longer an ignored parameter, but is passed to the action.

@danieltj
8 years ago

Adds hook to new user function.

#3 @danieltj
8 years ago

I've added a patch which includes the new hook with the proposed name by @jeremyfelt.

To note:

  • Updated the docs for $password to reflect it's new use.
  • Added $blog_id as the last function to match the main functions order.
  • Hook is only run when there is no error from ! is_wp_error( $result ).

Thoughts? :)

#4 @danieltj
8 years ago

  • Keywords needs-testing added

Is anyone available to test this out? Any opinions on this at all etc?

This ticket was mentioned in Slack in #core by danieltj. View the logs.


8 years ago

This ticket was mentioned in PR #8476 on WordPress/wordpress-develop by @SirLouen.


7 weeks ago
#6

Trac ticket: [](https://core.trac.wordpress.org/ticket/41757)

Given that the original patch was posted 8 years ago some little modifications have occurred in the function hence the patch is not working anymore. Here is an updated PR with the updated patch with the same contents.

Props to /johnjamesjacoby /jeremyfelt and /danieltj

More info in the Trac report.

#7 @SirLouen
7 weeks ago

  • Keywords has-testing-info dev-feedback added; needs-testing removed

Combined Test Report

Description

This report validates that the patch works as expected using a test plugin for the hook.

To the original patch: https://core.trac.wordpress.org/raw-attachment/ticket/41757/ms-functions.diff
There have been minor mods in the file after 8 years, so I have submitted a Github PR with the patch. So this is the current patch tested here: https://patch-diff.githubusercontent.com/raw/WordPress/wordpress-develop/pull/8476.diff

Environment

  • WordPress: 6.8-beta1-59933-src
  • PHP: 8.2.27
  • Server: nginx/1.27.4
  • Database: mysqli (Server: 8.4.4 / Client: mysqlnd 8.2.27)
  • Browser: Chrome 133.0.0.0
  • OS: Windows 10/11
  • Theme: Twenty Twenty-Five 1.1
  • MU Plugins: None activated
  • Plugins:
    • Test Reports 1.2.0

Use-Case Reproduction

  1. First we need to set up a multisite.
  2. Second, we can create a second site for diversity. We are going to be working in this testing with id = 2
  3. I have created an ad-hoc plugin to test and showcase a couple use-cases of this hook: https://github.com/SirLouen/testing-41757/archive/refs/tags/1.0.1.zip
  4. This plugin adds 3 simple use-cases
    1. It displays a log record with the data
    2. It adds some metadata based on the network blog
    3. It adds some extra capabilities
  5. We simply create a new user in the new network blog (must be id = 2).
  6. We check in wp-content the user-blog-additions.log
# cat user-blog-additions.log 
[2025-03-08 16:34:08] User ID: 3 was added to Blog ID: 2 with role: subscriber and password ODf8YH7j1sSO
  1. We check the database in wp_usermeta to check for a record with user_id = 3 date_added_to_blog_2 and current date
  2. Same for wp_2_capabilities and two roles: subscriber (or whatever we gave on use creation) and access_premium_content

Actual Results

  1. ✅ Use-cases can be proven with this patch.

Supplemental Artifacts

All the required artifacts have been linked in the corresponding tests.

Last edited 7 weeks ago by SirLouen (previous) (diff)

#8 @SirLouen
6 weeks ago

Raising awareness, of any of the current component maintainers @kenshino @flixos90 @peterwilsoncc

#9 @peterwilsoncc
6 weeks ago

@SirLouen I've set a reminder for early May, after my post release time off, so I can focus on 6.8 for now.

Note: See TracTickets for help on using tickets.