Forums

[resolved] wp_create_user() calling from an external script (4 posts)

  1. flamy
    Member
    Posted 2 years ago #

    I am building a script that creates new users and I need access to the functions within registration.php.

    I have tried just including this file, but then get undefinded function get_userdatabylogin() and it seems I need to include a whole load of other files. Is there just one file I can include so I can perform the functions within registration.php?

    The code I am trying to execute from my external script looks like this:

    <?php
    require_once('wp-includes/registration.php');
    
    $user_name = "new_user";
    $user_email = "email@email.com";
    
    $user_id = username_exists( $user_name );
    if ( !$user_id ) {
    	$random_password = wp_generate_password( 12, false );
    	$user_id = wp_create_user( $user_name, $random_password, $user_email );
    } else {
    	$random_password = __('User already exists.  Password inherited.');
    }
    ?>

    And I am using WordPress version 2.9.2.

  2. flamy
    Member
    Posted 2 years ago #

    I've also tried including wp-admin/admin.php to no avail.

  3. MichaelH
    Volunteer
    Posted 2 years ago #

  4. flamy
    Member
    Posted 2 years ago #

    Perfect, yes that did help thanks.

    require('/the/path/to/your/wp-blog-header.php');

    ..was the line of code I was looking for.

Topic Closed

This topic has been closed to new replies.

About this Topic