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;
 }
Example #2
1
 /**
  * Installs the blog
  *
  * {@internal Missing Long Description}}
  *
  * @since 2.1.0
  *
  * @param string $blog_title Blog title.
  * @param string $user_name User's username.
  * @param string $user_email User's email.
  * @param bool $public Whether blog is public.
  * @param string $deprecated Optional. Not used.
  * @param string $user_password Optional. User's chosen password. Will default to a random password.
  * @param string $language Optional. Language chosen.
  * @return array Array keys 'url', 'user_id', 'password', 'password_message'.
  */
 function wp_install($blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '', $language = '')
 {
     if (!empty($deprecated)) {
         _deprecated_argument(__FUNCTION__, '2.6');
     }
     wp_check_mysql_version();
     wp_cache_flush();
     make_db_current_silent();
     populate_options();
     populate_roles();
     update_option('blogname', $blog_title);
     update_option('admin_email', $user_email);
     update_option('blog_public', $public);
     if ($language) {
         update_option('WPLANG', $language);
     }
     $guessurl = wp_guess_url();
     update_option('siteurl', $guessurl);
     // If not a public blog, don't ping.
     if (!$public) {
         update_option('default_pingback_flag', 0);
     }
     /*
      * Create default user. If the user already exists, the user tables are
      * being shared among blogs. Just set the role in that case.
      */
     $user_id = username_exists($user_name);
     $user_password = trim($user_password);
     $email_password = false;
     if (!$user_id && empty($user_password)) {
         $user_password = wp_generate_password(12, false);
         $message = __('<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.');
         $user_id = wp_create_user($user_name, $user_password, $user_email);
         update_user_option($user_id, 'default_password_nag', true, true);
         $email_password = true;
     } else {
         if (!$user_id) {
             // Password has been provided
             $message = '<em>' . __('Your chosen password.') . '</em>';
             $user_id = wp_create_user($user_name, $user_password, $user_email);
         } else {
             $message = __('User already exists. Password inherited.');
         }
     }
     $user = new WP_User($user_id);
     $user->set_role('administrator');
     wp_install_defaults($user_id);
     flush_rewrite_rules();
     wp_new_blog_notification($blog_title, $guessurl, $user_id, $email_password ? $user_password : __('The password you chose during the install.'));
     wp_cache_flush();
     /**
      * Fires after a site is fully installed.
      *
      * @since 3.9.0
      *
      * @param WP_User $user The site owner.
      */
     do_action('wp_install', $user);
     return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $user_password, 'password_message' => $message);
 }
Example #3
0
	function checkauthor($author) {
		global $wpdb;
		//mtnames is an array with the names in the mt import file
		$pass = wp_generate_password();
		if (!(in_array($author, $this->mtnames))) { //a new mt author name is found
			++ $this->j;
			$this->mtnames[$this->j] = $author; //add that new mt author name to an array
			$user_id = username_exists($this->newauthornames[$this->j]); //check if the new author name defined by the user is a pre-existing wp user
			if (!$user_id) { //banging my head against the desk now.
				if ($newauthornames[$this->j] == 'left_blank') { //check if the user does not want to change the authorname
					$user_id = wp_create_user($author, $pass);
					$this->newauthornames[$this->j] = $author; //now we have a name, in the place of left_blank.
				} else {
					$user_id = wp_create_user($this->newauthornames[$this->j], $pass);
				}
			} else {
				return $user_id; // return pre-existing wp username if it exists
			}
		} else {
			$key = array_search($author, $this->mtnames); //find the array key for $author in the $mtnames array
			$user_id = username_exists($this->newauthornames[$key]); //use that key to get the value of the author's name from $newauthornames
		}

		return $user_id;
	}
 function wp_new_user_notification($user_id, $plaintext_pass = '')
 {
     global $pagenow;
     global $register_plus_redux;
     //trigger_error( sprintf( __( 'Register Plus Redux DEBUG: wp_new_user_notification($user_id=%s, $plaintext_pass=%s) from %s', 'register-plus-redux' ), $user_id, $plaintext_pass, $pagenow ) );
     if ('1' === $register_plus_redux->rpr_get_option('user_set_password') && !empty($_POST['pass1'])) {
         $plaintext_pass = stripslashes((string) $_POST['pass1']);
     }
     if ('user-new.php' === $pagenow && !empty($_POST['pass1'])) {
         $plaintext_pass = stripslashes((string) $_POST['pass1']);
     }
     //TODO: Code now only forces users registering to verify email, may want to add settings to have admin created users verify email too
     $verification_code = '';
     if ('wp-login.php' === $pagenow && '1' === $register_plus_redux->rpr_get_option('verify_user_email')) {
         $verification_code = wp_generate_password(20, FALSE);
         update_user_meta($user_id, 'email_verification_code', $verification_code);
         update_user_meta($user_id, 'email_verification_sent', gmdate('Y-m-d H:i:s'));
         $register_plus_redux->send_verification_mail($user_id, $verification_code);
     }
     if ('wp-login.php' === $pagenow && '1' !== $register_plus_redux->rpr_get_option('disable_user_message_registered') || 'wp-login.php' !== $pagenow && '1' !== $register_plus_redux->rpr_get_option('disable_user_message_created')) {
         if ('1' !== $register_plus_redux->rpr_get_option('verify_user_email') && '1' !== $register_plus_redux->rpr_get_option('verify_user_admin')) {
             $register_plus_redux->send_welcome_user_mail($user_id, $plaintext_pass);
         }
     }
     if ('wp-login.php' === $pagenow && '1' !== $register_plus_redux->rpr_get_option('disable_admin_message_registered') || 'wp-login.php' !== $pagenow && '1' !== $register_plus_redux->rpr_get_option('disable_admin_message_created')) {
         $register_plus_redux->send_admin_mail($user_id, $plaintext_pass, $verification_code);
     }
 }
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;
}
function acxu_createUser($args)
{
    global $wp_xmlrpc_server;
    $wp_xmlrpc_server->escape($args);
    $nickname = $args[0];
    //$password = $args[1];
    //if ( ! $user = $wp_xmlrpc_server->login( $username, $password ) )
    //    return $wp_xmlrpc_server->error;
    $user_name = time() . "_" . rand(1000, 9999);
    $user_email = $user_name . "@bbuser.org";
    if (!username_exists($user_name) && !email_exists($user_email)) {
        $random_password = wp_generate_password($length = 12, $include_standard_special_chars = false);
        $user_id = wp_create_user($user_name, $random_password, $user_email);
        if ($nickname == "") {
            $nickname = $user_email;
        }
        // Update the user to set the nickname
        wp_update_user(array('ID' => $user_id, 'nickname' => $nickname));
        // Get the user object to set the user's role
        $wp_user_object = new WP_User($user_id);
        //http://en.support.wordpress.com/user-roles/
        $wp_user_object->set_role('author');
        return $user_name . " " . $random_password;
    } else {
        return "ERROR: User Name or Email Already Exists";
    }
}
 /**
  * Generate random password when user expires?
  */
 function handle_on_expire_user_reset_password($expired_user)
 {
     if ($expired_user->on_expire_user_reset_password) {
         $password = wp_generate_password(12, false);
         wp_set_password($password, $expired_user->user_id);
     }
 }
 function wppb_curpageurl_password_recovery2($user_login, $id)
 {
     global $wpdb;
     $pageURL = 'http';
     if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {
         $pageURL .= "s";
     }
     $pageURL .= "://";
     if ($_SERVER["SERVER_PORT"] != "80") {
         $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
     } else {
         $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
     }
     $questionPos = strpos((string) $pageURL, '?');
     $key = $wpdb->get_var($wpdb->prepare("SELECT user_activation_key FROM {$wpdb->users} WHERE user_login = %s", $user_login));
     if (empty($key)) {
         // Generate something random for a key...
         $key = wp_generate_password(20, false);
         do_action('wppb_retrieve_password_key', $user_login, $key);
         // Now insert the new md5 key into the db
         $wpdb->update($wpdb->users, array('user_activation_key' => $key), array('user_login' => $user_login));
     }
     //$key = md5($user_login.'RMPBP'.$id.'PWRCVR');
     if ($questionPos !== false) {
         //$wpdb->update($wpdb->users, array('user_activation_key' => $key), array('user_login' => $user_login));
         return $pageURL . '&loginName=' . $user_login . '&key=' . $key;
     } else {
         //$wpdb->update($wpdb->users, array('user_activation_key' => $key), array('user_login' => $user_login));
         return $pageURL . '?loginName=' . $user_login . '&key=' . $key;
     }
 }
 /**
  * Creates a patchchat post by
  *   creating a user,
  *   creating a new patchchat post,
  *   creating first comment to post,
  *   adding an 'instant reply' comment from admin,
  *   building a new transient,
  *   return new transient to new user
  *
  * @author  caseypatrickdriscoll
  *
  * @edited 2015-08-03 16:32:16 - Adds user signon after creation
  * @edited 2015-08-28 20:11:39 - Adds PatchChat_Settings::instant_reply
  * @edited 2015-08-28 20:19:22 - Adds PatchChat_Settings::bot
  */
 public static function create($patchchat)
 {
     $email = $patchchat['email'];
     $text = $patchchat['text'];
     $username = substr($email, 0, strpos($email, "@"));
     $password = wp_generate_password(10, false);
     $title = substr($text, 0, 40);
     $time = current_time('mysql');
     $text = wp_strip_all_tags($text);
     /* Create User */
     $user_id = wp_create_user($username, $password, $email);
     // TODO: Add the user's name to the user
     // TODO: Check to see if user logged in, no need to create again
     wp_new_user_notification($user_id, $password);
     $user = get_user_by('id', $user_id);
     $creds = array('user_login' => $user->user_login, 'user_password' => $password, 'remember' => true);
     $user_signon = wp_signon($creds, false);
     /* Create PatchChat Post */
     $post = array('post_title' => $title, 'post_type' => 'patchchat', 'post_author' => $user_id, 'post_status' => 'new', 'post_date' => $time);
     $post_id = wp_insert_post($post);
     /* Create First Comment */
     $comment = array('comment_post_ID' => $post_id, 'user_id' => $user_id, 'comment_content' => $text, 'comment_date' => $time, 'comment_author_IP' => $_SERVER['REMOTE_ADDR'], 'comment_agent' => $_SERVER['HTTP_USER_AGENT']);
     $comment_id = wp_insert_comment($comment);
     /* Insert default action comment reply */
     $options = array('chatid' => $post_id, 'displayname' => $user->display_name);
     $comment = array('comment_post_ID' => $post_id, 'user_id' => PatchChat_Settings::bot(), 'comment_content' => PatchChat_Settings::instant_reply($options), 'comment_type' => 'auto', 'comment_date' => current_time('mysql'));
     $comment_id = wp_insert_comment($comment);
     // Will build the Transient
     PatchChat_Transient::get($post_id);
     return PatchChat_Controller::get_user_state($user_id);
 }
Example #10
0
 public static function get_new_salts()
 {
     // From wp-admin/setup-config.php in WordPress 4.5.
     // Generate keys and salts using secure CSPRNG; fallback to API if enabled; further fallback to original wp_generate_password().
     try {
         $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_ []{}<>~`+=,.;:/?|';
         $max = strlen($chars) - 1;
         for ($i = 0; $i < 8; $i++) {
             $key = '';
             for ($j = 0; $j < 64; $j++) {
                 $key .= substr($chars, random_int(0, $max), 1);
             }
             $secret_keys[] = $key;
         }
     } catch (Exception $ex) {
         $secret_keys = wp_remote_get('https://api.wordpress.org/secret-key/1.1/salt/');
         if (is_wp_error($secret_keys)) {
             $secret_keys = array();
             for ($i = 0; $i < 8; $i++) {
                 $secret_keys[] = wp_generate_password(64, true, true);
             }
         } else {
             $secret_keys = explode("\n", wp_remote_retrieve_body($secret_keys));
             foreach ($secret_keys as $k => $v) {
                 $secret_keys[$k] = substr($v, 28, 64);
             }
         }
     }
     return $secret_keys;
 }
Example #11
0
 public function user_register()
 {
     global $wpdb;
     $data = $_POST;
     $login_data = array();
     $resp = new ajax_response($data['action'], true);
     $code_data = $wpdb->get_results('SELECT * FROM ' . $wpdb->register_codes . ' WHERE 1=1 AND register_code == ' . $wpdb->escape($data['sec_code']));
     if ($code_data->register_code_used == 0) {
         $username = $wpdb->escape($data['user_name']);
         $exists = username_exists($username);
         if (!$exists) {
             $user_id = wp_create_user($username, wp_generate_password($length = 12, $include_standard_special_chars = false), $username);
             wp_new_user_notification($user_id, null, true);
             if (!is_wp_error($user_id)) {
                 $user = get_user_by('id', $user_id);
                 $wpdb->update($wpdb->register_codes, array('register_code_used' => 1, 'register_code_used_by' => $user->data->user_login), array('register_code' => $wpdb->escape($data['sec_code'])));
                 $resp->set_status(true);
                 $resp->set_message($user->data->user_login . ' is successfully registered. Please switch to the login tab to login.');
             } else {
                 foreach ($user_id->errors as $k => $error) {
                     $resp->set_message(array($error[0]));
                 }
             }
         } else {
             $resp->set_message('User already exists. Please use a different email address.');
         }
     } else {
         $resp->set_message('Security token not recognized. Could not register you without a valid security token.');
     }
     echo $resp->encode_response();
     die;
 }
Example #12
0
function konzilo_auth_settings()
{
    $state = get_option('konzilo_oauth_state', '');
    if (empty($state)) {
        $state = wp_generate_password(20, false);
        update_option('konzilo_oauth_state', $state);
    }
    $client_id = get_option('konzilo_client_id');
    $client_key = get_option('konzilo_client_key');
    $url = KONZILO_URL;
    $redirect_uri = admin_url('options-general.php?page=konzilo_auth_settings');
    try {
        if (konzilo_get_token($url, $client_id, $client_key, $redirect_uri, $state, true)) {
            $message = __('Authorization complete', 'konzilo');
        }
    } catch (Exception $e) {
        $error = $e->getMessage();
    }
    $args = array('client_id' => $client_id, 'client_key' => $client_key, 'authorized' => get_option('konzilo_refresh_token', false), 'error' => !empty($error) ? $error : false, 'message' => !empty($message) ? $message : false);
    if (isset($_GET['client_id']) && isset($_GET['client_secret']) && empty($_GET['settings-updated'])) {
        $args['client_id'] = $_GET['client_id'];
        $args['client_key'] = $_GET['client_secret'];
        $args['from_konzilo'] = TRUE;
    }
    if (!empty($client_id)) {
        $args['link'] = $url . '/oauth2/authorize?response_type=code&client_id=' . urlencode($client_id) . '&redirect_uri=' . urlencode($redirect_uri) . '&scope=users&state=' . $state;
    }
    $base_dir = plugin_dir_path(__FILE__);
    echo konzilo_twig($base_dir)->render('templates/auth_form.html', $args);
}
function custom_new_user_notification($user_id, $deprecated = null, $notify = '', $password = null)
{
    if ($deprecated !== null) {
        _deprecated_argument(__FUNCTION__, '4.3.1');
    }
    global $wpdb, $wp_hasher;
    $user = get_userdata($user_id);
    // The blogname option is escaped with esc_html on the way into the database in sanitize_option
    // we want to reverse this for the plain text arena of emails.
    $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
    $message = sprintf(__('New user registration on your site %s:'), $blogname) . "\r\n\r\n";
    $message .= sprintf(__('Username: %s'), $user->user_login) . "\r\n\r\n";
    $message .= sprintf(__('E-mail: %s'), $user->user_email) . "\r\n";
    @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), $blogname), $message);
    if ('admin' === $notify || empty($notify)) {
        return;
    }
    if ($password === null) {
        $password = wp_generate_password(12, false);
    }
    // change the URL below to actual page with [adverts_manage] shortcode.
    $manage_url = home_url() . "/adverts/manage/";
    $message = sprintf(__('Username: %s'), $user->user_login) . "\r\n";
    $message .= sprintf(__('Password: %s'), $password) . "\r\n";
    $message .= 'To manage your Ads please use the following address ' . $manage_url . "\r\n";
    wp_mail($user->user_email, sprintf(__('[%s] Your username and password'), $blogname), $message);
}
Example #14
0
/**
 * 
 *
 * @package Kopa
 * @subpackage Core
 * @author thethangtran <*****@*****.**>
 * @since 1.0.0
 *      
 */
function kopa_shortcode_tabs($atts, $content = null)
{
    extract(shortcode_atts(array('style' => 'horizontal', 'width' => 200), $atts));
    $style = !empty($atts['style']) && in_array($atts['style'], array('horizontal', 'vertical')) ? $atts['style'] : 'horizontal';
    $width = '';
    if ('vertical' == $style) {
        $width = !empty($atts['width']) ? (int) $atts['width'] : 200;
        $width = sprintf('style="width:%spx;"', $width > 0 ? $width : 200);
    }
    $items = KopaUtil::get_shortcode($content, true, array('tab'));
    $navs = array();
    $panels = array();
    if ($items) {
        $active = 'active';
        foreach ($items as $item) {
            $title = $item['atts']['title'];
            $item_id = 'tab-' . wp_generate_password(4, false, false);
            $navs[] = sprintf('<li><a href="#%s">%s</a></li>', $item_id, do_shortcode($title));
            $panels[] = sprintf('<div id="%s">%s</div>', $item_id, do_shortcode($item['content']));
            $active = '';
        }
    }
    $output = sprintf('<div class="kp-tabs tab-%s">', $style);
    $output .= sprintf('<ul %s>', $width);
    $output .= implode('', $navs);
    $output .= '</ul>';
    $output .= implode('', $panels);
    $output .= '</div>';
    return apply_filters('kopa_shortcode_tabs', $output);
}
Example #15
0
    function general()
    {
        echo '<h3>' . __('BP Social Connect Settings', 'bp-social-connect') . '</h3>';
        $settings = array(array('label' => __('Redirect Settings', 'vibe-customtypes'), 'name' => 'redirect_link', 'type' => 'select', 'options' => apply_filters('bp_social_connect_redirect_settings', array('' => __('Same Page', 'vibe-customtypes'), 'home' => __('Home', 'vibe-customtypes'), 'profile' => __('BuddyPress Profile', 'vibe-customtypes'))), 'desc' => __('Set Login redirect settings', 'vibe-customtypes')), array('label' => __('Security Key', 'vibe-customtypes'), 'name' => 'security', 'type' => 'text', 'std' => wp_generate_password(16, false), 'desc' => __('Set a random security key value', 'vibe-customtypes')), array('label' => __('Social Button Styling', 'vibe-customtypes'), 'name' => 'button_css', 'type' => 'textarea', 'std' => '
					.bp_social_connect{
						text-align: center;
					}
					.bp_social_connect a {
					  background: #3b5998;
					  color: #FFF;
					  font-weight: 600;
					  padding: 15px 20px;
					  display: inline-block;
					  text-decoration: none;
					  min-width: 220px;
					  margin: 5px 0;
					  border-radius: 2px;
					  letter-spacing: 1px;
					  box-shadow: 0 4px 0 rgba(0,0,0,0.1);
					}
					.bp_social_connect a:hover{
						box-shadow: none;	
					}
					.bp_social_connect a:focus{
						box-shadow: inset 0 4px 0 rgba(0,0,0,0.1)
					}					
					#bp_social_connect_twitter{
						background:#4099FF;
					}					
					#bp_social_connect_google{
						background:#DD4B39;
					}', 'desc' => __('Change default style of buttons', 'vibe-customtypes')));
        $this->generate_form('general', $settings);
    }
Example #16
0
function woo_cd_create_options() {

	$prefix = 'woo_ce';

	if( !get_option( $prefix . '_export_filename' ) )
		add_option( $prefix . '_export_filename', 'export_%dataset%-%date%-%time%.csv' );
	if( !get_option( $prefix . '_delete_file' ) )
		add_option( $prefix . '_delete_file', 1 );
	if( !get_option( $prefix . '_delimiter' ) )
		add_option( $prefix . '_delimiter', ',' );
	if( !get_option( $prefix . '_category_separator' ) )
		add_option( $prefix . '_category_separator', '|' );
	if( !get_option( $prefix . '_bom' ) )
		add_option( $prefix . '_bom', 1 );
	if( !get_option( $prefix . '_encoding' ) )
		add_option( $prefix . '_encoding', get_option( 'blog_charset', 'UTF-8' ) );
	if( !get_option( $prefix . '_escape_formatting' ) )
		add_option( $prefix . '_escape_formatting', 'all' );
	if( !get_option( $prefix . '_date_format' ) )
		add_option( $prefix . '_date_format', 'd/m/Y' );

	// Generate a unique CRON secret key for each new installation
	if( !get_option( $prefix . '_secret_key' ) )
		add_option( $prefix . '_secret_key', wp_generate_password( 64, false ) );

}
function seed_cspv4_emaillist_followupemails_queue_email()
{
    global $wpdb, $seed_cspv4, $seed_cspv4_post_result;
    extract($seed_cspv4);
    require_once SEED_CSPV4_PLUGIN_PATH . 'lib/nameparse.php';
    $name = '';
    if (!empty($_REQUEST['name'])) {
        $name = $_REQUEST['name'];
    }
    $email = strtolower($_REQUEST['email']);
    $fname = '';
    $lname = '';
    if (!empty($name)) {
        $name = seed_cspv4_parse_name($name);
        $fname = $name['first'];
        $lname = $name['last'];
    }
    if (email_exists($email)) {
        // Subscriber already exist show stats
        $seed_cspv4_post_result['status'] = '200';
        $seed_cspv4_post_result['msg'] = $txt_already_subscribed_msg;
        $seed_cspv4_post_result['msg_class'] = 'alert-info';
        $seed_cspv4_post_result['clicks'] = '0';
    } else {
        $user_id = wp_insert_user(array('user_login' => $email, 'user_email' => $email, 'first_name' => $fname, 'last_name' => $lname, 'user_pass' => wp_generate_password()));
        if (empty($seed_cspv4_post_result['status'])) {
            $seed_cspv4_post_result['status'] = '200';
        }
    }
}
Example #18
0
 /**
  * Email login credentials to a newly-registered user.
  *
  * A new user registration notification is also sent to admin email.
  *
  * @since 2.0.0
  * @since 4.3.0 The `$plaintext_pass` parameter was changed to `$notify`.
  *
  * @param int    $user_id User ID.
  * @param string $notify  Optional. Type of notification that should happen. Accepts 'admin' or an empty
  *                        string (admin only), or 'both' (admin and user). The empty string value was kept
  *                        for backward-compatibility purposes with the renamed parameter. Default empty.
  */
 function wp_new_user_notification($user_id, $notify = '')
 {
     global $wpdb;
     $user = get_userdata($user_id);
     // The blogname option is escaped with esc_html on the way into the database in sanitize_option
     // we want to reverse this for the plain text arena of emails.
     $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
     $message = sprintf(__('New user registration on your site %s:'), $blogname) . "\r\n\r\n";
     $message .= sprintf(__('Username: %s'), $user->user_login) . "\r\n\r\n";
     $message .= sprintf(__('E-mail: %s'), $user->user_email) . "\r\n";
     @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), $blogname), $message);
     if ('admin' === $notify || empty($notify)) {
         return;
     }
     // Generate something random for a password reset key.
     $key = wp_generate_password(20, false);
     /** This action is documented in wp-login.php */
     do_action('retrieve_password_key', $user->user_login, $key);
     // Now insert the key, hashed, into the DB.
     if (empty($wp_hasher)) {
         require_once ABSPATH . WPINC . '/class-phpass.php';
         $wp_hasher = new PasswordHash(8, true);
     }
     $hashed = time() . ':' . $wp_hasher->HashPassword($key);
     $wpdb->update($wpdb->users, array('user_activation_key' => $hashed), array('user_login' => $user->user_login));
     $message = sprintf(__('Username: %s'), $user->user_login) . "\r\n\r\n";
     $message .= __('To set your password, visit the following address:') . "\r\n\r\n";
     $message .= network_site_url("wp-login.php?action=rp&key={$key}&login="******"\r\n\r\n";
     //	$message .= wp_login_url() . "\r\n";
     $message .= __('Make sure you click the RESET PASSWORD button to save your password.') . "\r\n\r\n";
     wp_mail($user->user_email, sprintf(__('[%s] Your username and password info'), $blogname), $message);
 }
Example #19
0
function sfw_new_comment_pass()
{
    global $post;
    $new_comment_pwd = wp_generate_password(12, false);
    $old_password = get_post_meta($post->ID, 'sfw_pwd', true);
    update_post_meta($post->ID, 'sfw_pwd', $new_comment_pwd, $old_password);
}
 function build_test_invoice($total = 0)
 {
     $user_args = array('user_login' => '*****@*****.**', 'display_name' => 'Unit Tester', 'user_pass' => wp_generate_password(), 'user_email' => '*****@*****.**');
     $user_id = SI_Clients::create_user($user_args);
     $args = array('company_name' => 'Test Client', 'user_id' => $user_id);
     $client_id = SI_Client::new_client($args);
     $args = array('subject' => 'TESTING Payments');
     $id = SI_Invoice::create_invoice($args, SI_Invoice::STATUS_TEMP);
     $this->invoice_ids[] = $id;
     $invoice = SI_Invoice::get_instance($id);
     $invoice->set_client_id($client_id);
     // No total set make them random
     if (!$total) {
         $line_items = array();
         for ($i = 0; $i < 10; $i++) {
             $rate = rand(1000, 4000);
             $qty = rand(1, 10);
             $line_items[] = array('rate' => $rate, 'qty' => $qty, 'desc' => 'This is a test line item for a test invoice.', 'type' => '', 'total' => $rate * $qty, 'tax' => 0);
         }
     } else {
         $line_items = array(array('rate' => $total, 'qty' => 1, 'desc' => 'This is a test line item for a test invoice.', 'type' => '', 'total' => $total, 'tax' => 0));
     }
     $invoice->set_line_items($line_items);
     $this->assertTrue(in_array($id, $this->invoice_ids));
     return $id;
 }
Example #21
0
 /**
  * Create a user.
  *
  * @synopsis <user-login> <user-email> [--role=<role>] [--porcelain]
  */
 public function create($args, $assoc_args)
 {
     global $blog_id;
     list($user_login, $user_email) = $args;
     $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');
         }
     }
     if (isset($assoc_args['porcelain'])) {
         WP_CLI::line($user_id);
     } else {
         WP_CLI::success("Created user {$user_id}.");
     }
 }
Example #22
0
/**
 * Create a new employee
 *
 * @param  array  arguments
 *
 * @return int  employee id
 */
function erp_hr_employee_create($args = array())
{
    global $wpdb;
    $defaults = array('user_email' => '', 'company_id' => erp_get_current_company_id(), 'work' => array('designation' => 0, 'department' => 0, 'location' => '', 'hiring_source' => '', 'hiring_date' => '', 'date_of_birth' => '', 'reporting_to' => 0, 'pay_rate' => '', 'pay_type' => '', 'type' => '', 'status' => ''), 'personal' => array('photo_id' => 0, 'user_id' => 0, 'first_name' => '', 'middle_name' => '', 'last_name' => '', 'other_email' => '', 'phone' => '', 'work_phone' => '', 'mobile' => '', 'address' => '', 'gender' => '', 'marital_status' => '', 'nationality' => '', 'driving_license' => '', 'hobbies' => '', 'user_url' => '', 'description' => ''));
    $posted = array_map('strip_tags_deep', $args);
    $posted = array_map('trim_deep', $posted);
    $data = wp_parse_args($posted, $defaults);
    // some basic validation
    if (empty($data['personal']['first_name'])) {
        return new WP_Error('empty-first-name', __('Please provide the first name.', 'wp-erp'));
    }
    if (empty($data['personal']['last_name'])) {
        return new WP_Error('empty-last-name', __('Please provide the last name.', 'wp-erp'));
    }
    if (!is_email($data['user_email'])) {
        return new WP_Error('invalid-email', __('Please provide a valid email address.', 'wp-erp'));
    }
    // attempt to create the user
    $password = wp_generate_password(12);
    $userdata = array('user_login' => $data['user_email'], 'user_pass' => $password, 'user_email' => $data['user_email'], 'first_name' => $data['personal']['first_name'], 'last_name' => $data['personal']['last_name'], 'display_name' => $data['personal']['first_name'] . ' ' . $data['personal']['last_name'], 'role' => 'employee');
    // if user id exists, do an update
    $user_id = isset($posted['user_id']) ? intval($posted['user_id']) : 0;
    $update = false;
    if ($user_id) {
        $update = true;
        $userdata['ID'] = $user_id;
    }
    $userdata = apply_filters('erp_hr_employee_args', $userdata);
    $user_id = wp_insert_user($userdata);
    if (is_wp_error($user_id)) {
        return $user_id;
    }
    // if reached here, seems like we have success creating the user
    $employee = new \WeDevs\ERP\HRM\Employee($user_id);
    // inserting the user for the first time
    if (!$update) {
        $work = $data['work'];
        if (!empty($work['type'])) {
            $employee->update_employment_status($work['type']);
        }
        // update compensation
        if (!empty($work['pay_rate'])) {
            $pay_type = !empty($work['pay_type']) ? $work['pay_type'] : 'monthly';
            $employee->update_compensation($work['pay_rate'], $pay_type);
        }
        // update job info
        $employee->update_job_info($work['department'], $work['designation'], $work['reporting_to'], $work['location']);
    }
    // update the erp table
    $wpdb->update($wpdb->prefix . 'erp_hr_employees', array('company_id' => (int) $data['company_id'], 'hiring_source' => $data['work']['hiring_source'], 'hiring_date' => $data['work']['hiring_date'], 'date_of_birth' => $data['work']['date_of_birth']), array('user_id' => $user_id));
    foreach ($data['personal'] as $key => $value) {
        update_user_meta($user_id, $key, $value);
    }
    if ($update) {
        do_action('erp_hr_employee_update', $user_id, $data);
    } else {
        do_action('erp_hr_employee_new', $user_id, $data);
    }
    return $user_id;
}
Example #23
0
function enable_key_access()
{
    $new_key = wp_generate_password(12, false);
    update_post_meta($_REQUEST['post_id'], 'access_key', $new_key);
    echo $new_key;
    exit;
}
Example #24
0
 private function scramble_password()
 {
     if ($this->options['scramble_passwords'] && $this->new_user == false) {
         $this->user->user_pass = wp_hash_password(wp_generate_password(12, true, true));
         wp_update_user($user);
     }
 }
Example #25
0
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();
        }
    }
}
 public function start()
 {
     global $current_user;
     wp_get_current_user();
     // By default, users to skip:
     // * Super admins (Automattic employees visiting your site)
     // * Users who don't have /wp-admin/ access
     $is_privileged_user = !is_proxied_automattician() && current_user_can('edit_posts');
     if (false === apply_filters('ndn_run_for_current_user', $is_privileged_user)) {
         return;
     }
     // Set up the per-blog salt
     $salt = get_option('newdevicenotification_salt');
     if (!$salt) {
         $salt = wp_generate_password(64, true, true);
         add_option('newdevicenotification_salt', $salt);
     }
     $this->cookie_hash = hash_hmac('md5', $current_user->ID, $salt);
     // Seen this device before?
     if ($this->verify_cookie()) {
         return;
     }
     // Attempt to mark this device as seen via a cookie
     $this->set_cookie();
     // Maybe we've seen this user+IP+agent before but they don't accept cookies?
     $memcached_key = 'lastseen_' . $current_user->ID . '_' . md5($_SERVER['REMOTE_ADDR'] . '|' . $_SERVER['HTTP_USER_AGENT']);
     if (wp_cache_get($memcached_key, 'newdevicenotification')) {
         return;
     }
     // As a backup to the cookie, record this IP address (only in memcached for now, proper logging will come later)
     wp_cache_set($memcached_key, time(), 'newdevicenotification');
     add_filter('ndn_send_email', array($this, 'maybe_send_email'), 10, 2);
     $this->notify_of_new_device();
 }
 function add_new_employer($postdata)
 {
     if (isset($postdata['employer_id']) && !empty($postdata['employer_id'])) {
         $user_id = $postdata['employer_id'];
         $this->update_empoyer($user_id, $postdata);
         return $user_id;
     }
     $validate = $this->new_admin_form_validate($postdata);
     if (is_wp_error($validate)) {
         return $validate;
     }
     $random_password = wp_generate_password(8, false);
     $first_name = sanitize_text_field($postdata['first_name']);
     $last_name = sanitize_text_field($postdata['last_name']);
     $display_name = $first_name . ' ' . $last_name;
     $userdata = array('user_login' => $postdata['user_name'], 'user_pass' => $random_password, 'user_email' => $postdata['email'], 'first_name' => $first_name, 'last_name' => $last_name, 'display_name' => $display_name, 'role' => 'hrm_employee');
     $user_id = wp_insert_user($userdata);
     if ($user_id) {
         update_user_meta($user_id, '_hrm_user_role', 'hrm_employee');
         $this->update_empoyer($user_id, $postdata);
         wp_new_user_notification($user_id, $random_password);
         return $user_id;
     } else {
         return false;
     }
 }
 function wp_new_user_notification($user_id, $deprecated = null, $notify = '')
 {
     if ($deprecated !== null) {
         _deprecated_argument(__FUNCTION__, '4.3.1');
     }
     // `$deprecated was pre-4.3 `$plaintext_pass`. An empty `$plaintext_pass` didn't sent a user notifcation.
     if ('admin' === $notify || empty($deprecated) && empty($notify)) {
         return;
     }
     global $wpdb, $wp_hasher;
     $user = get_userdata($user_id);
     // The blogname option is escaped with esc_html on the way into the database in sanitize_option
     // we want to reverse this for the plain text arena of emails.
     $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
     // Generate something random for a password reset key.
     $key = wp_generate_password(20, false);
     /** This action is documented in wp-login.php */
     do_action('retrieve_password_key', $user->user_login, $key);
     // Now insert the key, hashed, into the DB.
     if (empty($wp_hasher)) {
         require_once ABSPATH . WPINC . '/class-phpass.php';
         $wp_hasher = new PasswordHash(8, true);
     }
     $hashed = time() . ':' . $wp_hasher->HashPassword($key);
     $wpdb->update($wpdb->users, array('user_activation_key' => $hashed), array('user_login' => $user->user_login));
     $message = sprintf(__('Username: %s'), $user->user_login) . "\r\n\r\n";
     $message .= __('To set your password, visit the following address:') . "\r\n\r\n";
     $message .= '<' . network_site_url("wp-login.php?action=rp&key={$key}&login="******">\r\n\r\n";
     $message .= wp_login_url() . "\r\n";
     wp_mail($user->user_email, sprintf(__('[%s] Your username and password info'), $blogname), $message);
 }
/**
 * Creates a new blog calling wpmu_create_blog
 * the wpmu_create_blog parameters are:
 * $domain  The domain of the new blog.
 * $path    The path of the new blog.
 * $title   The title of the new blog.
 * $user_id The user id of the user account who will be the blog admin. (you can use an email instead of the user_id. If so, a new user will be created)
 * $meta    Other meta information.
 * $site_id The site_id of the blog to be created.
 *
 * @param array $args Array with username, password and wpmu_create_blog function parameters
 * @return mixed The new blog id or an error message
 */
function msxmlrpc_create_blog($args)
{
    $parameters = check_arguments($args);
    if (!is_array($parameters)) {
        return $parameters;
    }
    // if the user_id is the user's e-mail
    if (!is_int($parameters['user_id'])) {
        if (!($user_id = get_user_id_from_string($parameters['user_id']))) {
            $error = wpmu_validate_user_signup($parameters['path'], $parameters['user_id']);
            if (is_wp_error($error)) {
                return new IXR_Error(500, $error->get_error_message());
            }
            $user_id = wpmu_create_user($parameters['path'], wp_generate_password(), $parameters['user_id']);
        }
        $parameters['user_id'] = $user_id;
    }
    if (get_blog_id($parameters['domain'], $parameters['path']) !== false) {
        return new IXR_Error(500, __("Site already exists."));
    }
    if (!isset($parameters['meta'])) {
        $parameters['meta'] = "";
    }
    if (!isset($parameters['site_id'])) {
        $parameters['site_id'] = 1;
    }
    return wpmu_create_blog($parameters['domain'], $parameters['path'], $parameters['title'], $parameters['user_id'], $parameters['meta'], $parameters['site_id']);
}
Example #30
0
/**
 * Handles sending password retrieval email to user.
 *
 * @uses $wpdb WordPress Database object
 *
 * @return bool|WP_Error True: when finish. WP_Error on error
 */
function retrieve_password()
{
    global $wpdb;
    $errors = new WP_Error();
    if (empty($_POST['user_login']) && empty($_POST['user_email'])) {
        $errors->add('empty_username', __('<strong>ERROR</strong>: Enter a username or e-mail address.'));
    }
    if (strpos($_POST['user_login'], '@')) {
        $user_data = get_user_by_email(trim($_POST['user_login']));
        if (empty($user_data)) {
            $errors->add('invalid_email', __('<strong>ERROR</strong>: There is no user registered with that email address.'));
        }
    } else {
        $login = trim($_POST['user_login']);
        $user_data = get_userdatabylogin($login);
    }
    do_action('lostpassword_post');
    if ($errors->get_error_code()) {
        return $errors;
    }
    if (!$user_data) {
        $errors->add('invalidcombo', __('<strong>ERROR</strong>: Invalid username or e-mail.'));
        return $errors;
    }
    // redefining user_login ensures we return the right case in the email
    $user_login = $user_data->user_login;
    $user_email = $user_data->user_email;
    do_action('retreive_password', $user_login);
    // Misspelled and deprecated
    do_action('retrieve_password', $user_login);
    $allow = apply_filters('allow_password_reset', true, $user_data->ID);
    if (!$allow) {
        return new WP_Error('no_password_reset', __('Password reset is not allowed for this user'));
    } else {
        if (is_wp_error($allow)) {
            return $allow;
        }
    }
    $user_email = $_POST['user_email'];
    $user_login = $_POST['user_login'];
    $user = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->users} WHERE user_login = %s", $user_login));
    if (empty($user)) {
        return new WP_Error('invalid_key', __('Invalid key'));
    }
    $new_pass = wp_generate_password(12, false);
    do_action('password_reset', $user, $new_pass);
    wp_set_password($new_pass, $user->ID);
    update_usermeta($user->ID, 'default_password_nag', true);
    //Set up the Password change nag.
    $message = sprintf(__('Username: %s'), $user->user_login) . "\r\n";
    $message .= sprintf(__('Password: %s'), $new_pass) . "\r\n";
    $message .= site_url() . '/?ptype=affiliate' . "\r\n";
    $title = sprintf(__('[%s] Your new password'), get_option('blogname'));
    $title = apply_filters('password_reset_title', $title);
    $message = apply_filters('password_reset_message', $message, $new_pass);
    if ($message && !wp_mail($user_email, $title, $message)) {
        die('<p>' . __('The e-mail could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function...') . '</p>');
    }
    return true;
}