Skip to main content
1 of 7
MikeSchinkel
  • 37.5k
  • 14
  • 116
  • 132

As I mentioned I was going to be working on this as immediately so I'm making headway. Given that I'm knocking these down I figured it best to start posting them.

Still, if someone else can post (some of) the parts I haven't done I'll be happy to let you copy whatever I'd done you haven't and select your answer as the best answer.

But until then I'm going to start posting the code:

Start with wp-load.php:

Since we're creating a standalone file in the root of the website to run initialization that will only be used to "bootstrap" a site (I called mine /my-init.php) we start by including /wp-load.php to load the WordPress API functions:

<?php
include "wp-load.php";

Create Users for the Site

We'll use the wp_insert_user() function located in /wp-includes/registration.php to create our users. This file is not loaded by default so we'll have to load it ourselves with a call to require_once().

We'll also use the get_user_by() function to first see if the user has already been created; no need to run the code twice if they haven't. NOTE: This is a pattern will follow; e.g. our script should not duplicate or overwrite anything if called multiple times, especially after users have added or changed data for any of the items we plan to initialize.

<?php
require_once( ABSPATH . WPINC . '/registration.php');

$user = get_user_by('slug','johnsmith');
if (!is_object($user)) {
  wp_insert_user(array(
    'user_login'        => 'johnsmith',
    'role'              => 'administrator',
    'user_email'        => '[email protected]',
    'user_url'          => 'http://example.com',
    'first_name'        => 'John',
    'last_name'         => 'Smith',
    'comment_shortcuts' => '',
    'use_ssl'           => '0',
    'user_pass'         => '12345',
  ));
}

I'll keep adding to this as I figure it out until I'm done or until someone else helps out.

MikeSchinkel
  • 37.5k
  • 14
  • 116
  • 132