WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 13 days ago

Last modified 13 days ago

#41950 closed enhancement (fixed)

wp_insert_user() should accept a meta_input argument

Reported by: desrosj Owned by: johnbillion
Milestone: 5.9 Priority: normal
Severity: normal Version: 2.0
Component: Users Keywords: has-patch has-unit-tests needs-dev-note
Focuses: Cc:

Description

wp_insert_user() does insert user meta, but only meta generated by the function (nickname, first_name, etc.), or added to that list by using the insert_user_meta filter.

It would be nice to be able to pass the additional meta to the function when called, like in wp_insert_post().

Change History (9)

#1 @technosailor
4 years ago

This sounds like a good candidate for a filter. We shouldn’t support non-core meta in core but should allow plugins to hook in and define their own.

This ticket was mentioned in PR #1177 on WordPress/wordpress-develop by donmhico.


6 months ago

  • Keywords has-patch has-unit-tests added; needs-patch removed

This PR allows the addition of meta_input key in $userdata args in wp_insert_user( $userdata ) to add user meta. Like how wp_insert_post() allows meta_input.

Trac ticket: https://core.trac.wordpress.org/ticket/41950

#3 @donmhico
6 months ago

I attached a PR that should address this enhancement requests. One thing to note though.

I decided to have a separate filter for the meta_input, usage - apply_filters( 'insert_user_custom_meta', $custom_meta, $user, $update ); instead of using the existing filter - apply_filters( 'insert_user_meta', $meta, $user, $update );.

The main reason is to just not touch that filter and prevent any possible backward compat issue. And to also have different filters between built-in user meta and custom ones.

Any feedback is welcome.

#4 @johnbillion
5 months ago

  • Milestone changed from Awaiting Review to 5.8
  • Owner set to johnbillion
  • Status changed from new to reviewing

#5 @desrosj
4 months ago

  • Milestone changed from 5.8 to 5.9

Today is the feature cut off for 5.8. I'm going to punt this to 5.9 with the intention of returning for that cycle.

Thanks for the work here so far! We'll get this one attention soon!

#6 @johnbillion
13 days ago

The PR at https://github.com/WordPress/wordpress-develop/pull/1177 all looks good to me. I agree that separating the filters makes sense.

I've refreshed the branch and tweaked the docs. If the tests pass then this is ready to go.

#7 @johnbillion
13 days ago

  • Keywords needs-dev-note added

#8 @johnbillion
13 days ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 51738:

Users: Introduce a meta_input argument for wp_insert_user().

This allows custom user meta values to be provided when creating or updating a user in the same way custom post meta can be provided to wp_insert_post() when creating or updating a post.

Also introduces the insert_custom_user_meta to filter these values.

Props desrosj, donmhico

Fixes #41950

Note: See TracTickets for help on using tickets.