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 10 replies - 1 through 10 (of 10 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 9 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 8 months, 3 weeks 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 2 months, 1 week ago by eduardoomota.
    eduardoomota

    (@eduardoomota)

    luchoster

    (@luchoster)

    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'] );
        }
      }
Viewing 10 replies - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.