Add user meta to users on registration
Support › MB User Profile › Add user meta to users on registration
- This topic has 4 replies, 2 voices, and was last updated 11 months, 2 weeks ago by
Monden.
-
AuthorPosts
-
May 7, 2024 at 5:53 PM #45390
Monden
ParticipantHow do I insert ANY custom information to user when a new user registers?
Specifically, I want to add a custom ID to new users called 'some-custom-id' upon registration. Not a field they could edit but for the backend functionality.
I tried dozens of ways, ChatGPT, stackoverflow etc and nothing works.
In addition, the documentation for the extension is EXTREMELY POOR. I mean what am I supposed to do with:
$data = apply_filters( 'rwmb_profile_insert_user_data', $data, $config );I know you know what you meant but I'm not a warlock.
Give an example of actually using this, unless you want to torture us an watch us squirm, it's inhumanely little documentation.
May 7, 2024 at 10:44 PM #45395Peter
ModeratorHello,
There are some ways to add a custom field to a user (user meta), here is an example of using the action hook
rwmb_profile_after_save_user
:add_action( 'rwmb_profile_after_save_user', function( $user ) { $user_id = $user->user_id; update_user_meta( $user_id, 'custom_field_ID', 'custom_field_value' ); } );
Please follow the documentation https://developer.wordpress.org/reference/functions/update_user_meta/
https://docs.metabox.io/extensions/mb-user-profile/#rwmb_profile_after_save_userMay 7, 2024 at 11:41 PM #45397Monden
ParticipantThanks, I managed to store the value.
As for the documentation regarding 'rwmb_profile_after_save_user', When it says:
The action accepts 1 parameter: the instance of the MB_User_Profile_User class, which handles the submission. It has the following public properties that you can use:
$user_id: The submitted user ID
$config: The configuration, taken from the shortcode attributesHow do I access values from $config when in: add_action( 'rwmb_profile_after_save_user', function( $user ) { $user_id = $user->user_id; update_user_meta( $user_id, 'custom_field_ID', 'custom_field_value' ); } );
?
May 8, 2024 at 9:50 PM #45406Peter
ModeratorHello,
You can follow the sample code to use the config, same as user_id:
add_action( 'rwmb_profile_after_save_user', function( $user ) { $config = $user->config; if ( 'my-meta-box' === $config['id'] ) { ... } } );
If you want to use the filter hook, you need to have a basic knowledge of coding. If you are not familiar with coding, we offer a customization code for an extra fee. Please contact us here for more details https://metabox.io/contact/.
May 9, 2024 at 2:09 AM #45412Monden
ParticipantThank you,
You can just provide an example without the insult. To put it in your wording, if you want to sell "Lifetime support" to your highest-tier customers, you need to have a basic knowledge of customer support.
I didn't ask for customization, I asked for an example in the documentation. You should put those 5 lines of code in the documentation on MB User Profile
-
AuthorPosts
- You must be logged in to reply to this topic.