Make WordPress Core

Opened 4 years ago

Last modified 3 weeks ago

#41950 reviewing enhancement

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
Focuses: Cc:


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 (5)

#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.

2 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
2 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
7 weeks ago

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

#5 @desrosj
3 weeks 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!

Note: See TracTickets for help on using tickets.