WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 years ago

#40545 closed enhancement (fixed)

Add hook for wp_insert_user

Reported by: DaveFX Owned by: boonebgorges
Milestone: 4.9 Priority: normal
Severity: normal Version: 4.8
Component: Users Keywords: has-patch needs-testing
Focuses: administration Cc:

Description

In the WordCamp Madrid contributor day, I'm developing a plugin that randomizes the user_id for every created user.

However, at the moment, there's no hook I can attach to customize the data of the created user.

Here I'm including a patch to add it.

Attachments (4)

patch-add-hook.diff (533 bytes) - added by DaveFX 2 years ago.
Adds filter wp_insert_user
patch-add-hook.v2.diff (1.8 KB) - added by DaveFX 2 years ago.
I'm now including a new version of the patch, including documentation for the filter and now also filtering user_login in the case of user insertion (not updating)
patch-add-hook.v3.diff (1.9 KB) - added by DaveFX 2 years ago.
New version of the patch, now renaming the filter name, according to what @rachelbaker suggested
patch-add-hook.V4.diff (2.0 KB) - added by DaveFX 2 years ago.

Download all attachments as: .zip

Change History (15)

@DaveFX
2 years ago

Adds filter wp_insert_user

#1 @milana_cap
2 years ago

  • Keywords has-patch added

#2 @bhargavbhandari90
2 years ago

@DaveFX It would be great if you add documentation for the filter.

@DaveFX
2 years ago

I'm now including a new version of the patch, including documentation for the filter and now also filtering user_login in the case of user insertion (not updating)

#3 @bhargavbhandari90
2 years ago

@DaveFX Looks good now. :-)

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


2 years ago

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


2 years ago

#6 @jbpaul17
2 years ago

  • Keywords needs-testing added

@DaveFX
2 years ago

New version of the patch, now renaming the filter name, according to what @rachelbaker suggested

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


2 years ago

#8 @boonebgorges
2 years ago

  • Milestone changed from Awaiting Review to 4.9

Hi @DaveFX - Thanks very much for the updated patch.

It seems to me that the filter would be a bit easier to work with if the user ID were passed to it. I know that the ID is available only in the case of $update, and I know that ID can generally be inferred from $user_login etc, but it seems good practice to pass this info along when available. Since it's not part of the array of data that's actually used in the SQL query, perhaps it could be another filter parameter? What do you think?

Regarding the hook name - I see that you changed it due to a conversation with @rachelbaker. Was it in Slack? I'd like to see what she had to say. The hook name seems fine to me, though in the case of posts we call it wp_insert_post_data, without _pre_.

#9 @DaveFX
2 years ago

Hi @boonebgorges. It was in a private conversation between me and @rachelbaker. I'm pasting it here:

davefx [5:29 AM]
Hi.
I was told by @jeffpaul at #core that I should talk to someone from Users component team so #40545 is evaluated to be included in 4.8.1.
Sorry if this is not the correct way, but as I don't know anyone from https://make.wordpress.org/core/components/users/ (this is my first contribution to core), I'm trying with the component maintainer!

rachelbaker [5:36 AM]
wp_pre_insert_user_data would match the filter name with the similar Post filter

[5:37]
Can take a deeper look in a few weeks

davefx [5:39 AM]
Ok. I'll change the name of the filter ASAP. Thank you!

I'm uploading a new version of the patch, including the $ID as a filter parameter in the case of user updates.

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


2 years ago

#11 @boonebgorges
2 years ago

  • Owner set to boonebgorges
  • Resolution set to fixed
  • Status changed from new to closed

In 40980:

Users: Allow data to be filtered before updating or creating a user.

Props DaveFX.
Fixes #40545.

Note: See TracTickets for help on using tickets.