Support » Plugins » wp_create_user not working in my plugin

  • hello.
    I am making a plugin that overides the wp_login function.
    and so far it is working.

    I am using another method of authentication. if the user is in the wordpress database then it logs in with that. if not, then it uses my alterntave method of authentication. if the other method check out, then i want to create that new user with wp_create_user.

    but it fails when i use it.

    i did a function_exists(“wp_create_user”) witch returns false.

Viewing 4 replies - 1 through 4 (of 4 total)
  • dose any one know this

    here is the code:

    function wp_login($username, $password, $already_md5 = false) {
    	global $wpdb, $error;
    	if ( '' == $username )
    		return false;
    
    	if ( '' == $password ) {
    		$error = __('<strong>Error</strong>: The password field is empty.');
    		return false;
    	}
    
    	$auth = true;#ldap_auth($username, $password);
    	$login = get_userdatabylogin($username);
    	#
    	if($auth and $login){
    		#print "return true r2";
    		return true;
    	}
    	if(! $auth and $login){
    		if($login->user_pass==$password){
    			#print "return true r1";
    			return true;
    		}
    		$error = __('<strong>Error</strong>: Login error.');
    		return false;
    	}
    
    	# if auth is true but login is false, make new user
    	if($auth and ! $login){
    		if(! function_exists("wp_create_user"))print "before";
    
    		$userid = 23 ;#wp_create_user($username, $password, $username."@njit.edu");
    		#print "created new user";
    		$login = get_userdata($userid);
    		print_r($login);
    		if(! $login) {
    			#print "error getting info from new user";
    			$error = __("error getting info from new user");
    			return false;
    		}
    		else{
    			return true;
    		}
    	}
    
    	return false;
    }

    Just add this on first line:
    require_once(ABSPATH . WPINC . ‘/registration.php’);

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Should probably do this instead:
    include_once(ABSPATH . 'wp-admin/includes/admin.php');

    Also, you should not do it every time the plugin runs, but only when you need to access admin functions.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘wp_create_user not working in my plugin’ is closed to new replies.