Validate wordpress password repeat with REST api -


i have registeration form custom fields , need register users wordpress rest api,

$('#user_register_form').submit(function(e){     e.preventdefault();      var form = $(this),         rest = new dwrest();      rest.registeruser({         first_name: '',         last_name:  '',         username:   'amin',         name    :   'amin',         email   :   'aaaa@amin.ev',         password:   '11111',         // passwrod2: '11111' -confirm password field         // custom_field1: ''         // ....      }, function( res ){         console.log( res );     }); }); 

the user registeration works fine problem can't confirm wether password repeat matches or not, searched lot , didn't find action modify /users/ validation

the second question is possible automatically login user created rest api after registeration?

i appreciate help.

i searched in rest-api source codes, sadly didn't find proper hook needed, there's rest_pre_insert_user hook getting intend bit tricky, here's work around, in case 1 has same problem:

add_filter('rest_pre_insert_user', function( $user, $request ){     $params = $request->get_params();      if( $params['password'] !== $params['password2'] ) {         $error = new wp_error( 'rest_no_matching_passwords', __( 'passwords don\'t match' ), array( 'status' => 400 ) );          foreach( $error->error_data $data ) {             http_response_code( $data['status'] );         }          header('content-type: application/json; charset=utf-8;');          foreach( $error->errors $key => $val ){             $json = json_encode([                 'code'    => $key,                 'type'    => 'error',                 'message' => $val[0]             ]);         }          die( $json );     }      return $user; }, 10, 2 ); 

reference


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -