Add user meta to users on registration

Support MB User Profile Add user meta to users on registration

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #45390
    MondenMonden
    Participant

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

    #45395
    PeterPeter
    Moderator

    Hello,

    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_user

    #45397
    MondenMonden
    Participant

    Thanks, 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 attributes

    How 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' );
    } );

    ?

    #45406
    PeterPeter
    Moderator

    Hello,

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

    #45412
    MondenMonden
    Participant

    Thank 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

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.