WordPress.org

Ready to get started?Download WordPress

Forums

wp_create_user not working in my plugin (5 posts)

  1. pax2003
    Member
    Posted 7 years ago #

    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.

  2. pax2003
    Member
    Posted 7 years ago #

    dose any one know this

  3. pax2003
    Member
    Posted 7 years ago #

    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;
    }
  4. Rafael Dourado
    Member
    Posted 6 years ago #

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

  5. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic