Support » Plugin: WP REST User » Create user with custom fields

  • Resolved luchoster

    (@luchoster)


    I got the registration working just fine, thank you for your plugin!

    I see right now, I can create a user and will only submit the username, email and password. What if I need to send the description, name and maybe some custom fields?

    Is it possible and if so, how can we do that?

    thank you!

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author sk8tech

    (@sk8tech)

    Hello @luchoster

    That’s possible since version 1.4.0. Just add an action

    add_action('wp_rest_user_create_user', 'user_created');
    function user_created($user) {
    	// Do Actions
    }
    • This reply was modified 1 year, 8 months ago by sk8tech.

    Hm. This is not enough actually.
    You need to pass form data to same action as well so I can access data sent via register form.

    add_action('wp_rest_user_create_user', 'user_created', 10, 2);
    function user_created($user, $parameters) {
    	// Do Actions
    }

    Need to extend action in plugin L:140:
    do_action('wp_rest_user_user_register', $user, $parameters)

    • This reply was modified 1 year, 7 months ago by Bobz.

    @bobz I’ve tried this, but $parameters is empty in

    function user_created($user, $parameters) {
    	// Do Actions
    }

    Any suggestions ?

    Nevermind its fixed, the problem was I had this

    add_action('wp_rest_user_create_user', 'user_created');

    instead of this

    add_action('wp_rest_user_create_user', 'user_created', 10, 2);

    Correct, it’s needed to modify plugin code.
    Mr. President

    is there a plan to extend the plugin, so this doesn’t break when there’s a new update?

    I second what @luchoster is asking.
    Without directly modifying the plugin I don’t see how I can access $parameters.

    I want add description in my form of register. can someone show code of exemplo for get description too ?

    • This reply was modified 1 year, 1 month ago by eduardoomota.

    hey @eduardoomota as @bobz mentioned, you need to add this https://wordpress.org/support/topic/create-user-with-custom-fields/#post-11270122

    The first part can be done on your functions.php file.

    Then the user_created function could look like this (this could be your /user endpoint):

    function user_created($user, $parameters) {
        $user_id = $user->id;
        if (isset($parameters['description'])) {
          update_user_meta( $user_id, 'description', $parameters['description'] );
        }
      }
    imokweb

    (@imokweb)

    @sk8tech
    It looks like we still can’t insert first_name / last_name or other user-related fields on wp_rest_user_create_user action.

    The reason is because the parameters are not being passed.
    Two workarounds:
    1. Create a custom API endpoint and recreate the whole user_create function

    Ups: Keeps update compatibility with WordPress but we will have custom code on the create_user function
    Downs: If there will be vulnerabilities in the user_create function that WP team or Rest API team will fix we will have the old code.

    2. Extend the Rest API plugin code – this is bad because things break if the plugin is updated

    So please shed some light on how exactly this is done the right way.
    Thanks!

    stuiegreen

    (@stuiegreen)

    Any update on adding First and Last names?

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Create user with custom fields’ is closed to new replies.