当前位置: 首页>>代码示例>>PHP>>正文


PHP wp_insert_user函数代码示例

本文整理汇总了PHP中wp_insert_user函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_insert_user函数的具体用法?PHP wp_insert_user怎么用?PHP wp_insert_user使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了wp_insert_user函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: users

 /**
  * Generate users
  *
  * @param array $args
  * @param array $assoc_args
  **/
 public function users($args, $assoc_args)
 {
     global $blog_id;
     $defaults = array('count' => 100, 'role' => get_option('default_role'));
     extract(wp_parse_args($assoc_args, $defaults), EXTR_SKIP);
     if ('none' == $role) {
         $role = false;
     } elseif (is_null(get_role($role))) {
         WP_CLI::warning("invalid role.");
         exit;
     }
     $user_count = count_users();
     $total = $user_count['total_users'];
     $limit = $count + $total;
     $notify = new \cli\progress\Bar('Generating users', $count);
     for ($i = $total; $i < $limit; $i++) {
         $login = sprintf('user_%d_%d', $blog_id, $i);
         $name = "User {$i}";
         $user_id = wp_insert_user(array('user_login' => $login, 'user_pass' => $login, 'nickname' => $name, 'display_name' => $name, 'role' => $role));
         if (false === $role) {
             delete_user_option($user_id, 'capabilities');
             delete_user_option($user_id, 'user_level');
         }
         $notify->tick();
     }
     $notify->finish();
 }
开发者ID:bytewang,项目名称:wp-cli,代码行数:33,代码来源:generate.php

示例2: subscribe

 function subscribe()
 {
     global $videotube;
     $name = wp_filter_nohtml_kses($_POST['name']);
     $email = wp_filter_nohtml_kses($_POST['email']);
     $agree = wp_filter_nohtml_kses($_POST['agree']);
     $referer = wp_filter_nohtml_kses($_POST['referer']);
     $role = isset($videotube['subscribe_roles']) ? $videotube['subscribe_roles'] : 'subscriber';
     if (!$name) {
         echo json_encode(array('resp' => 'error', 'message' => __('Please enter your name.', 'mars'), 'id' => 'name'));
         exit;
     }
     if (!$email || !is_email($email)) {
         echo json_encode(array('resp' => 'error', 'message' => __('Please enter a valid email address.', 'mars'), 'id' => 'email'));
         exit;
     }
     if ($agree != true || $agree != 'true') {
         echo json_encode(array('resp' => 'error', 'message' => __('Please agree with our Private Policy.', 'mars'), 'id' => 'agree'));
         exit;
     }
     $user_id = wp_insert_user(array('user_login' => $email, 'user_email' => $email, 'display_name' => $name, 'user_pass' => wp_generate_password(6, true), 'role' => $role));
     if (is_wp_error($user_id)) {
         echo json_encode(array('resp' => 'error', 'message' => $user_id->get_error_message()));
         exit;
     }
     update_user_meta($user_id, 'referer', $referer);
     echo json_encode(array('resp' => 'success', 'message' => __('Congratulation.', 'mars'), 'redirect_to' => get_permalink($referer)));
     exit;
 }
开发者ID:chypriote,项目名称:wp-video,代码行数:29,代码来源:Mars_Subscribe_Ajax.php

示例3: ajax_register

function ajax_register()
{
    // First check the nonce, if it fails the function will break
    check_ajax_referer('ajax-register-nonce', 'security');
    // Nonce is checked, get the POST data and sign user on
    $info = array();
    $info['user_nicename'] = $info['nickname'] = $info['display_name'] = $info['first_name'] = $info['user_login'] = sanitize_user($_POST['username']);
    $info['user_pass'] = sanitize_text_field($_POST['password']);
    $info['user_email'] = sanitize_email($_POST['email']);
    // Register the user
    $user_register = wp_insert_user($info);
    if (is_wp_error($user_register)) {
        $error = $user_register->get_error_codes();
        if (in_array('empty_user_login', $error)) {
            echo json_encode(array('loggedin' => false, 'message' => __('Xin lỗi, thông tin đăng nhập không hợp lệ.')));
        } else {
            if (in_array('existing_user_login', $error)) {
                echo json_encode(array('loggedin' => false, 'message' => __('Xin lỗi, tên đăng nhập này đã tồn tại.')));
            } else {
                if (in_array('existing_user_email', $error)) {
                    echo json_encode(array('loggedin' => false, 'message' => __('Xin lỗi, thư điện tử này đã tồn tại.')));
                }
            }
        }
        //        else echo json_encode(array('loggedin'=>false, 'message'=>__($user_register->get_error_messages($error))));
    } else {
        wp_insert_user($info);
        echo json_encode(array('loggedin' => true, 'message' => __('Đăng ký thành công.')));
    }
    die;
}
开发者ID:vinhvv75,项目名称:tutannet,代码行数:31,代码来源:ajax-auth.php

示例4: ajax_register

 /**
  * AJAX Register.
  *
  * @since 1.0.0
  */
 public function ajax_register()
 {
     // First check the nonce, if it fails the function will break
     check_ajax_referer('vr-ajax-register-nonce', 'vr-secure-register');
     // Nonce is checked, Get to work
     $info = array();
     $info['user_nicename'] = $info['nickname'] = $info['display_name'] = $info['first_name'] = $info['user_login'] = sanitize_user($_POST['register_username']);
     $info['user_pass'] = sanitize_text_field($_POST['register_pwd']);
     $info['user_email'] = sanitize_email($_POST['register_email']);
     // Register the user
     $user_register = wp_insert_user($info);
     if (is_wp_error($user_register)) {
         $error = $user_register->get_error_codes();
         if (in_array('empty_user_login', $error)) {
             echo json_encode(array('success' => false, 'message' => __($user_register->get_error_message('empty_user_login'))));
         } elseif (in_array('existing_user_login', $error)) {
             echo json_encode(array('success' => false, 'message' => __('This username already exists.', 'VRC')));
         } elseif (in_array('existing_user_email', $error)) {
             echo json_encode(array('success' => false, 'message' => __('This email is already registered.', 'VRC')));
         }
     } else {
         /**
          * Object: VR_Member class.
          *
          * @since 1.0.0
          */
         $vr_member_object = new VR_Member();
         $vr_member_object->ajax_user_authenticate($info['user_login'], $info['user_pass'], __('Registration', 'VRC'));
     }
     die;
 }
开发者ID:WPTie,项目名称:VRCore,代码行数:36,代码来源:class-register.php

示例5: ajax_register

function ajax_register()
{
    // First check the nonce, if it fails the function will break
    check_ajax_referer('ajax-register-nonce', 'security');
    // Nonce is checked, get the POST data and sign user on
    $info = array();
    $info['user_nicename'] = $info['nickname'] = $info['display_name'] = $info['first_name'] = $info['user_login'] = sanitize_user($_POST['username']);
    $info['user_pass'] = sanitize_text_field($_POST['password']);
    $info['user_email'] = sanitize_email($_POST['email']);
    // Register the user
    $user_register = wp_insert_user($info);
    if (is_wp_error($user_register)) {
        $error = $user_register->get_error_codes();
        if (in_array('empty_user_login', $error)) {
            echo json_encode(array('loggedin' => false, 'message' => __($user_register->get_error_message('empty_user_login'))));
        } elseif (in_array('existing_user_login', $error)) {
            echo json_encode(array('loggedin' => false, 'message' => __('This username is already registered.')));
        } elseif (in_array('existing_user_email', $error)) {
            echo json_encode(array('loggedin' => false, 'message' => __('This email address is already registered.')));
        }
    } else {
        auth_user_login($info['nickname'], $info['user_pass'], 'Registration');
    }
    die;
}
开发者ID:Vatia13,项目名称:dancesport,代码行数:25,代码来源:functions.php

示例6: ins_oauth

function ins_oauth()
{
    $code = $_GET['code'];
    $url = "https://api.instagram.com/oauth/access_token";
    $data = array('client_id' => INS_APPID, 'client_secret' => INS_APPSECRET, 'grant_type' => 'authorization_code', 'redirect_uri' => home_url('/?type=instagram'), 'code' => $code);
    $response = wp_remote_post($url, array('method' => 'POST', 'body' => $data));
    $output = json_decode($response['body'], true);
    $token = $output['access_token'];
    $user = $output['user'];
    $ins_id = $user['id'];
    $name = $user['username'];
    if (!$ins_id) {
        wp_redirect(home_url('/?3' . $douban_id));
        exit;
    }
    if (is_user_logged_in()) {
        $this_user = wp_get_current_user();
        update_user_meta($this_user->ID, "instagram_id", $ins_id);
        ins_ouath_redirect();
    } else {
        $user_ins = get_users(array("meta_key " => "instagram_id", "meta_value" => $ins_id));
        if (is_wp_error($user_ins) || !count($user_ins)) {
            $login_name = wp_create_nonce($ins_id);
            $random_password = wp_generate_password($length = 12, $include_standard_special_chars = false);
            $userdata = array('user_login' => $login_name, 'display_name' => $name, 'user_email' => '', 'user_pass' => $random_password, 'nick_name' => $name);
            $user_id = wp_insert_user($userdata);
            wp_signon(array("user_login" => $login_name, "user_password" => $random_password), false);
            update_user_meta($user_id, "instagram_id", $ins_id);
            ins_ouath_redirect();
        } else {
            wp_set_auth_cookie($user_ins[0]->ID);
            ins_ouath_redirect();
        }
    }
}
开发者ID:AlwaysOnline,项目名称:wp-oauth,代码行数:35,代码来源:instagram.php

示例7: qq_oauth

function qq_oauth()
{
    $code = $_GET['code'];
    $token_url = "https://graph.qq.com/oauth2.0/token?client_id=" . QQ_APPID . "&client_secret=" . QQ_APPSECRET . "&grant_type=authorization_code&redirect_uri=" . urlencode(home_url()) . "&code=" . $code;
    $response = wp_remote_get($token_url);
    $response = $response['body'];
    if (strpos($response, "callback") !== false) {
        wp_redirect(home_url());
    }
    $params = array();
    parse_str($response, $params);
    $qq_access_token = $params["access_token"];
    $graph_url = "https://graph.qq.com/oauth2.0/me?access_token=" . $qq_access_token;
    $str = wp_remote_get($graph_url);
    $str = $str['body'];
    if (strpos($str, "callback") !== false) {
        $lpos = strpos($str, "(");
        $rpos = strrpos($str, ")");
        $str = substr($str, $lpos + 1, $rpos - $lpos - 1);
    }
    $user = json_decode($str, true);
    if (isset($user->error)) {
        echo "<h3>错误代码:</h3>" . $user->error;
        echo "<h3>信息  :</h3>" . $user->error_description;
        exit;
    }
    $qq_openid = $user['openid'];
    if (!$qq_openid) {
        wp_redirect(home_url());
        exit;
    }
    $get_user_info = "https://graph.qq.com/user/get_user_info?" . "access_token=" . $qq_access_token . "&oauth_consumer_key=" . QQ_APPID . "&openid=" . $qq_openid . "&format=json";
    $data = wp_remote_get($get_user_info);
    $data = $data['body'];
    $data = json_decode($data, true);
    $username = $data['nickname'];
    $avatar = $data['figureurl_2'];
    if (is_user_logged_in()) {
        $this_user = wp_get_current_user();
        update_user_meta($this_user->ID, "qq_openid", $qq_openid);
        update_user_meta($this_user->ID, "qq_avatar", $avatar);
        fa_qq_oauth_redirect();
    } else {
        $user_qq = get_users(array("meta_key " => "qq_openid", "meta_value" => $qq_openid));
        if (is_wp_error($user_qq) || !count($user_qq)) {
            $login_name = wp_create_nonce($qq_openid);
            $random_password = wp_generate_password($length = 12, $include_standard_special_chars = false);
            $userdata = array('user_login' => $login_name, 'display_name' => $username, 'user_pass' => $random_password, 'nick_name' => $username);
            $user_id = wp_insert_user($userdata);
            wp_signon(array("user_login" => $login_name, "user_password" => $random_password), false);
            update_user_meta($user_id, "qq_openid", $qq_openid);
            update_user_meta($user_id, "qq_avatar", $avatar);
            fa_qq_oauth_redirect();
        } else {
            wp_set_auth_cookie($user_qq[0]->ID);
            update_user_meta($user_qq[0]->ID, "qq_avatar", $avatar);
            fa_qq_oauth_redirect();
        }
    }
}
开发者ID:yarec,项目名称:wp-oauth,代码行数:60,代码来源:auth-qq.php

示例8: cr

function cr(&$fields, &$errors)
{
    // Check args and replace if necessary
    if (!is_array($fields)) {
        $fields = array();
    }
    if (!is_wp_error($errors)) {
        $errors = new WP_Error();
    }
    // Check for form submit
    if (isset($_POST['submit'])) {
        // Get fields from submitted form
        $fields = cr_get_fields();
        // Validate fields and produce errors
        if (cr_validate($fields, $errors)) {
            // If successful, register user
            wp_insert_user($fields);
            // And display a message
            echo 'Registration complete. Goto <a href="' . get_site_url() . '/wp-login.php">login page</a>.';
            // Clear field data
            $fields = array();
        }
    }
    // Santitize fields
    cr_sanitize($fields);
    // Generate form
    cr_display_form($fields, $errors);
}
开发者ID:anam5233,项目名称:wp_user_reg_plugin,代码行数:28,代码来源:first.php

示例9: testTwoUsersWithTheSameName

 function testTwoUsersWithTheSameName()
 {
     $user_id_1 = wp_insert_user(array('user_login' => 'mario_rossi', 'user_pass' => 'tmppass', 'first_name' => 'Mario', 'last_name' => 'Rossi'));
     $this->assertEquals($this->getURI('mario_rossi'), Wordlift_User_Service::get_instance()->get_uri($user_id_1));
     $user_id_2 = wp_insert_user(array('user_login' => 'mario_rossi_1', 'user_pass' => 'tmppass', 'first_name' => 'Mario', 'last_name' => 'Rossi'));
     $this->assertEquals($this->getURI('mario_rossi_1'), Wordlift_User_Service::get_instance()->get_uri($user_id_2));
 }
开发者ID:Byrlyne,项目名称:wordlift-plugin,代码行数:7,代码来源:test-user.php

示例10: userRegister

 function userRegister()
 {
     $this->verifyNonce('userRegister');
     $data = $_POST["data"];
     $userID = wp_insert_user(array('first_name' => $data["first_name"], 'last_name' => $data["last_name"], 'nickname' => $data["nickname"], 'user_email' => $data["user_email"], 'user_login' => $data["user_login"], 'user_pass' => $data["user_pass"]));
     /*
     	Add a custom capability to the user
     		$user = new WP_User($userID);
     		$user->add_cap("edit_posts");
     		$user->add_cap("delete_posts");
     */
     if (isset($userID->errors)) {
         echo json_encode($userID);
     } else {
         //Add USER INFO
         add_user_meta($userID, "adress", $data["adress"], true);
         add_user_meta($userID, "localidade", $data["localidade"], true);
         add_user_meta($userID, "codPostal", $data["codPostal"], true);
         add_user_meta($userID, "treinador", "Não atribuido", true);
         //Notify user and admin that a new user arrived
         wp_new_user_notification($userID, '', 'both');
         echo '{"userID": "' . $userID . '"}';
     }
     wp_die();
 }
开发者ID:eralha,项目名称:wp_angular_base,代码行数:25,代码来源:ajax__calls.php

示例11: registration

 public function registration($name, $pass, $email, $money)
 {
     $data = array('user_pass' => $pass, 'user_login' => $name, 'user_email' => $email, 'perfectmoney' => $money);
     #return ID new user
     $ret = wp_insert_user($data);
     #var_dump($ret);
 }
开发者ID:alexandrtkachuk,项目名称:arena,代码行数:7,代码来源:User.php

示例12: process_registration

 public function process_registration()
 {
     do_action('popmake_alm_ajax_override_registration');
     $user_login = $_POST['user_login'];
     $user_email = $_POST['user_email'];
     $user_pass = isset($_POST['user_pass']) ? $_POST['user_pass'] : wp_generate_password(12, false);
     $userdata = compact('user_login', 'user_email', 'user_pass');
     $user = wp_insert_user($userdata);
     if (!isset($_POST['user_pass'])) {
         update_user_option($user, 'default_password_nag', true, true);
         // Set up the Password change nag.
         wp_new_user_notification($user, $user_pass);
     }
     if (is_wp_error($user)) {
         $response = array('success' => false, 'message' => $user->get_error_message());
     } else {
         if (popmake_get_popup_ajax_registration($_POST['popup_id'], 'enable_autologin')) {
             $creds = array('user_login' => $user_login, 'user_password' => $user_pass, 'remember' => true);
             $user = wp_signon($creds);
         }
         $message = __('Registration complete.', 'popup-maker-ajax-login-modals');
         if (!isset($_POST['user_pass'])) {
             $message .= ' ' . __('Please check your e-mail.', 'popup-maker-ajax-login-modals');
         }
         $response = array('success' => true, 'message' => $message);
     }
     echo json_encode($response);
     die;
 }
开发者ID:eugene-gromky-co,项目名称:mindfulnesssummit,代码行数:29,代码来源:class-ajax.php

示例13: ucenter_oauth

function ucenter_oauth()
{
    //根据授权码获取access_token
    $url = UCENTER_API . '/oauth/accessToken';
    $data = array('client_id' => CLIENT_ID, 'client_secret' => CLIENT_SECRET, 'grant_type' => 'authorization_code', 'redirect_uri' => REDIRECT_URI, 'code' => $_GET['code']);
    $response = wp_remote_post($url, array('method' => 'POST', 'body' => $data));
    $data = json_decode($response['body'], true);
    if (1 !== $data['code']) {
        wp_die('授权失败');
    }
    $access_token = $data['data']['access_token'];
    //根据access_token获取用户信息
    $url = UCENTER_API . '/user/?access_token=' . $access_token;
    $data = wp_remote_get($url);
    $data = json_decode($data['body'], true);
    if (1 !== $data['code']) {
        wp_die('获取用户信息失败');
    }
    $username = $data['data']['username'];
    $user_id = $data['data']['user_id'];
    //根据返回的用户信息登录,用户还未存在时则插入
    $current_user = get_user_by('login', $username);
    if (is_wp_error($current_user) || !$current_user) {
        $random_password = wp_generate_password($length = 12, $include_standard_special_chars = false);
        $user_id = wp_insert_user(array('user_login' => $username, 'display_name' => $username, 'nick_name' => $username, 'user_pass' => $random_password));
        wp_set_auth_cookie($user_id);
    } else {
        wp_set_auth_cookie($current_user->ID);
    }
    header('Location: ' . home_url() . '/wp-admin');
    exit;
}
开发者ID:yaoshanliang,项目名称:WordPress,代码行数:32,代码来源:wp-ucenter-login.php

示例14: usersExist

 /**
  * @Given /^Users exist:$/
  */
 public function usersExist(TableNode $table)
 {
     $usersData = $table->getHash();
     add_filter('send_password_change_email', '__return_false');
     add_filter('send_email_change_email', '__return_false');
     foreach ($usersData as $userData) {
         if (empty($userData['login'])) {
             throw new \InvalidArgumentException('You must provide a user login!');
         }
         $user = get_user_by('login', $userData['login']);
         $data = $this->getUserDataFromTable($userData);
         if ($user) {
             $data['ID'] = $user->ID;
         }
         $result = $user ? wp_update_user($data) : wp_insert_user($data);
         if (is_wp_error($result)) {
             throw new \UnexpectedValueException('User could not be created: ' . $result->get_error_message());
         }
         foreach ($this->getUserMetaDataFromTable($userData) as $key => $value) {
             update_user_meta($user->ID, $key, $value);
         }
     }
     remove_filter('send_password_change_email', '__return_false');
     remove_filter('send_email_change_email', '__return_false');
 }
开发者ID:johnpbloch,项目名称:WpBehatExtension,代码行数:28,代码来源:UserContext.php

示例15: create

 /**
  * Create a user
  *
  * @param array $args
  * @param array $assoc_args
  **/
 public function create($args, $assoc_args)
 {
     global $blog_id;
     $user_login = $args[0];
     $user_email = $args[1];
     if (!$user_login || !$user_email) {
         WP_CLI::error("Login and email required (see 'wp user help').");
     }
     $defaults = array('role' => get_option('default_role'), 'user_pass' => wp_generate_password(), 'user_registered' => strftime("%F %T", time()), 'display_name' => false);
     extract(wp_parse_args($assoc_args, $defaults), EXTR_SKIP);
     if ('none' == $role) {
         $role = false;
     } elseif (is_null(get_role($role))) {
         WP_CLI::error("Invalid role.");
     }
     $user_id = wp_insert_user(array('user_email' => $user_email, 'user_login' => $user_login, 'user_pass' => $user_pass, 'user_registered' => $user_registered, 'display_name' => $display_name, 'role' => $role));
     if (is_wp_error($user_id)) {
         WP_CLI::error($user_id);
     } else {
         if (false === $role) {
             delete_user_option($user_id, 'capabilities');
             delete_user_option($user_id, 'user_level');
         }
     }
     WP_CLI::success("Created user {$user_id}.");
 }
开发者ID:bytewang,项目名称:wp-cli,代码行数:32,代码来源:user.php


注:本文中的wp_insert_user函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。