Skip to content

Instantly share code, notes, and snippets.

@anthonybudd
Last active October 3, 2017 14:58
Show Gist options
  • Save anthonybudd/876412074a990b1374eb6890584e5a2f to your computer and use it in GitHub Desktop.
Save anthonybudd/876412074a990b1374eb6890584e5a2f to your computer and use it in GitHub Desktop.
<form action="<?= admin_url('/admin-ajax.php') ?>" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="register">
<input type="email" name="email" value="">
<input type="password" name="password" value="">
</form>
<?php if(isset($_GET['suceess'])): ?>
<p>succesfil blah blah blah</p>
<?php enif; ?>
<?php
class RegisterForm extends WP_AJAX{
protected $action = 'register';
protected function run(){
$user = wp_insert_user([
'user_login' => $this->get('email'),
'user_email' => $this->get('email'),
'user_pass' => $this->get('password'),
'display_name' => $this->get('name'),
]);
if(is_wp_error($user)){
$message = 'Register Error';
$errors = array_keys($user->errors);
if(in_array('existing_user_login', $errors)){
$message = 'Email already in use';
}
wp_redirect(sprintf("%s/login?message=%s", home_url(), urlencode($message)));
exit;
}
$user = wp_signon([
'user_login' => $this->get('email'),
'user_password' => $this->get('password'),
'remember' => TRUE
], false);
wp_redirect(home_url() .'/home?success=true');
exit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment