HEX
Server: Apache/2.4.59 (Debian)
System: Linux keymana 4.19.0-21-cloud-amd64 #1 SMP Debian 4.19.249-2 (2022-06-30) x86_64
User: lijunjie (1003)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/dk/wp-content/themes/food/api/user/u_user_register.php
<?php
/**
 * 注册 邮箱注册
 * @param $userObj
 * @return stdClass
 */
//$current_user = wp_get_current_user();
//$current_id = $current_user->ID;
//if ($current_id == 0) {
//    $rc = 1;
//    return false;
//}

//$res = [
//    'user_nicename' => $current_user->data->user_nicename,
//    'user_phone' => get_user_meta($current_id, 'user_phone', true),
//    'user_email' => get_user_meta($current_id, 'user_email', true),
//    'user_address' => [
//        'address1' => get_user_meta($current_id, 'address1', true),
//        'address2' => get_user_meta($current_id, 'address2', true),
//        'address3' => get_user_meta($current_id, 'address3', true),
//        'address4' => get_user_meta($current_id, 'address4', true),
//    ],
//    'address_current' => get_user_meta($current_id, 'address_current', true)
//];

$userObj = new stdClass();
$userObj->email = CheckFunc::checkInput2('email', 50);
$userObj->pwd = CheckFunc::checkInput2('pwd', 50);
$userObj->type = CheckFunc::checkInputInt2('type', 5);
$resObj = registerFunc($userObj);

$rc = $resObj->rc;
$rv->msg = $resObj->msg;

if(isset($resObj->wpuid)) {
    $res = $resObj->wpuid;
}


/**
 * 注册 邮箱注册
 * @param $userObj
 * @return stdClass
 */
function registerFunc($userObj)
{

//    print_r($userObj);
    $resInfo = new stdClass();
    $resInfo->wpuid = 0;

    $type = $userObj->type;
    $user_email = $userObj->email;
    $user_pass = $userObj->pwd;

    $resInfo->rc = ApiErrorDesc::ERR_PARAMS[0];
    $resInfo->msg = ApiErrorDesc::ERR_PARAMS[1];

    if ($type == 1) {
        $user_login = $user_email;

        //判斷用戶名是否重複
        if (username_exists($user_login)) {
//                $resInfo->errors = '用戶名重複';
            $resInfo->rc = ApiErrorDesc::ERR_USERNAME_DUPLICATION[0];
            $resInfo->msg = ApiErrorDesc::ERR_USERNAME_DUPLICATION[1];
            return $resInfo;
        }

        $wpuser_id = wp_create_user($user_login, $user_pass, '');
//                echo '$wpuser_id == '.$wpuser_id;
//          wp_update_user(array('ID' => $wpuser_id, 'role' => "subscriber"));

        if ($wpuser_id > 0) {
            //註冊成功
            $resInfo->rc = ApiErrorDesc::SUCCESS[0];
            $resInfo->msg = ApiErrorDesc::SUCCESS[1];
            $resInfo->wpuid = $wpuser_id;
        } else {
//                    echo '註冊失敗';
            $resInfo->rc = ApiErrorDesc::ERR_USER_REGISTERFALSE[0];
            $resInfo->msg = ApiErrorDesc::ERR_USER_REGISTERFALSE[1];
        }

    } elseif ($type == 2) {
        if (filter_var($user_email, FILTER_VALIDATE_EMAIL)) //判斷是否郵箱 || strlen($user_login) < 11
        {
            //郵箱 是有效的。';
            //判斷郵箱是否重複
            if (email_exists($user_email)) {
//                $resInfo->errors = '郵箱重複';
                $resInfo->rc = ApiErrorDesc::ERR_USEREMAIL_DUPLICATION[0];
                $resInfo->msg = ApiErrorDesc::ERR_USEREMAIL_DUPLICATION[1];
                return $resInfo;
            }

            $wpuser_id = wp_create_user($user_email, $user_pass, $user_email);
//                echo '$wpuser_id == '.$wpuser_id;
//                    wp_update_user(array('ID' => $wpuser_id, 'role' => "subscriber"));

            if ($wpuser_id > 0) {
                //註冊成功
                $resInfo->rc = ApiErrorDesc::SUCCESS[0];
                $resInfo->msg = ApiErrorDesc::SUCCESS[1];
                $resInfo->wpuid = $wpuser_id;
            } else {
//                    echo '註冊失敗';
                $resInfo->rc = ApiErrorDesc::ERR_USER_REGISTERFALSE[0];
                $resInfo->msg = ApiErrorDesc::ERR_USER_REGISTERFALSE[1];
            }

        } else {
            //'用戶邮箱格式錯誤'
            $resInfo->rc = ApiErrorDesc::ERR_USEREMAIL_ERROR[0];
            $resInfo->msg = ApiErrorDesc::ERR_USEREMAIL_ERROR[1];
        }
    }

    return $resInfo;
}