WordPress.org

Support

Support » How-To and Troubleshooting » Problem with wp_create_user

Problem with wp_create_user

  • fancymyreality
    Member

    @fancymyreality

    Please be a little patient as I’m fairly new to wordpress architecture. I’m having an issue with the wp_create_user() function. I’m trying to create a custom registration form page for my site.

    This code is what should execute after submit:

    <?php
    	include('./wp-blog-header.php');
    
    	$theUser = $_POST['theUser'];
    	$theEmail = $_POST['theEmail'];
    	$random_password = generate_random_password(12, false, false);
    
    	$user_id = username_exists( $theUser );
    
    	if ( !$user_id ) {
    		$user_id = wp_create_user( $theUser, $random_password, $theEmail );
    	} else {
    		$random_password = __('User already exists.  Password inherited.');
    	}
    }

    Most of the code was copied from the wp_create_user() function reference page.

    I get this error:

    Fatal error: call to member function get_row() on a non-object in wp-includes/capabilities.php on line 530

    Removing the whole username_exist code creates this error:

    Fatal error: call to member function escape() on a non-object in wp-includes/formatting.php on line 2295

    I’m not sure what my error is. Everything I find says there’s a problem with my $wpdb but whether I use global $wpdb in any area of the code above it still doesn’t work.

    Any help is greatly appreciated. Thanks.

  • The topic ‘Problem with wp_create_user’ is closed to new replies.