<?php

$context = array();
$context['theme'] = get_template_directory_uri();
if ($_POST) {
    $phone = $_POST['phone'];
    $code = $_POST['code'];
    $password = $_POST['password'];
    if(!$phone){
        $context['phoneError'] = '请输入11位手机号';
    }else if(!$code){
        $context['codeError'] = '请输入验证码';
    }else if(!$password){
        $context['passwordError'] = '请输入密码';
    }else{

        $result = wp_create_user($phone, $password);
        if (is_integer($result)) {
            $creds['user_login'] = $phone;
            $creds['user_password'] = $password;
            $creds['remember'] = true;
            echo '注册成功';
            $user = wp_signon($creds, false);
            if(!is_wp_error($user)){
                echo '自动登录，跳转页面';
            }
        }else{
            $context['phoneError'] = '抱歉，用户名已存在';
        }
    }
}
Timber::render('register.html', $context);

?>