Title: james108's Replies | WordPress.org

---

# james108

  [  ](https://wordpress.org/support/users/james108/)

 *   [Profile](https://wordpress.org/support/users/james108/)
 *   [Topics Started](https://wordpress.org/support/users/james108/topics/)
 *   [Replies Created](https://wordpress.org/support/users/james108/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/james108/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/james108/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/james108/engagements/)
 *   [Favorites](https://wordpress.org/support/users/james108/favorites/)

 Search replies:

## Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)

 *   Forum: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
   
   In reply to: [Hacked this morning](https://wordpress.org/support/topic/hacked-this-morning/)
 *  [james108](https://wordpress.org/support/users/james108/)
 * (@james108)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/hacked-this-morning/#post-2292159)
 * Just an FYI, your site has been cracked – not “hacked”. 🙂
    If someone cracked
   into your site, assuming that this is your own site (**not** a wordpress.com 
   site), you should first download a dump of all of the WP tables. To do this:
    1. Go to the PHPMyAdmin interface that your host has give you.
    2. Go to the DB you put WP in.
    3. Click “Export”.
    4. Choose the tables you want (or if you aren’t sure what tables WP is using, just
       select all of the tables). If you aren’t seeing an interface to choose which
       tables you want, choose the option that says “custom”.
    5. Click “Go” (or something similar), and you’ll have a backup of your DB in a 
       file (which can be saved to your desktop).
 * Next, get all of your files. FTP into your site and transfer all of the WP files
   to your computer.
 * When you want to get back your themes, copy the theme’s dir from _wp-content/
   themes/_ to your new site’s _wp-content/themes/_.
 * If you have some pics that you’ve uploaded to your website, search your WP dir
   for the pics.
 * When you want to get back something else, look through the DB (hint: the one 
   that ends in “posts” should be the most helpful, as it has both your blog posts
   and pages).
 *   Forum: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
   
   In reply to: [Add a site to WP from an external PHP script](https://wordpress.org/support/topic/add-a-site-to-wp-from-an-external-php-script/)
 *  Thread Starter [james108](https://wordpress.org/support/users/james108/)
 * (@james108)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/add-a-site-to-wp-from-an-external-php-script/#post-2235353)
 * I tried placing that code at the end of my current require_once section, and 
   it didn’t work for me. Could you tell me what code you used (so that I know the
   order of everything)?
 *   Forum: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
   
   In reply to: [Add a site to WP from an external PHP script](https://wordpress.org/support/topic/add-a-site-to-wp-from-an-external-php-script/)
 *  Thread Starter [james108](https://wordpress.org/support/users/james108/)
 * (@james108)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/add-a-site-to-wp-from-an-external-php-script/#post-2235282)
 * I found the main problem with the old code – my install was corrupt. I reinstalled
   WP (this time, I’m sure it’s **NOT** corrupt.), and the new site that was created
   told me
 * > Error establishing a database connection
 *  so I re-wrote the code (new code at the bottom). Just like the script before,
   everything worked, until I tried to view the site (and just like before, it told
   me it couldn’t connect to the DB). I took a look at the DB, and noticed that 
   all of my other sites had their own tables (in the format of (my prefix)_(site’s
   ID)_options, (my prefix)_(site’s ID)_posts, etc.), but the site I made with this
   script didn’t have it’s own tables with it’s ID. So, my problem now is that WP
   won’t make tables for my new site.
 *     ```
       <?php
           /* I have omitted the values of $title, $newSitePath, and $email.
            * If my WP installation was at example.com/mystuff and I wanted to make example.com/mystuff/something
            * and I wanted to assign administration rights to xyz@example.com then I'd type in:
            *     $email = 'james@jamescostian.com';
            *     $newSitePath = 'something';
            * I also need to add in a definition for $title. If I wanted to give this site the title "Randomness" then I'd type in:
            *     $title = 'Randomness';
            * This was made for the sub-dir install.
            * If you have the sub-domain install, then go to:
            * wp-admin/network/site-new.php
            * and use it to figure out how to make your own script.
            */
           require_once( 'wp-config.php' );
           require_once( 'wp-includes/ms-blogs.php' );
           require_once( 'wp-includes/functions.php' );
           require_once( 'wp-admin/includes/upgrade.php' );
           require_once( 'wp-includes/ms-functions.php' );
           $domain = strtolower( $domain );
           $email = sanitize_email( $email );
           $newdomain = $current_site->domain;
           $path = $base.$newSitePath.'/';
           $password = 'N/A';
           $user_id = email_exists( $email );
           $wpdb->hide_errors();
           wpmu_create_blog( $newdomain, $path, $title, $user_id, array( 'public' => 1 ), $current_site->id );
           $wpdb->show_errors();
           if ( !is_super_admin( $user_id ) && !get_user_option( 'primary_blog', $user_id ) )
               update_user_option( $user_id, 'primary_blog', $id, true );
       ?>
       ```
   
 *   Forum: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
   
   In reply to: [Add a site to WP from an external PHP script](https://wordpress.org/support/topic/add-a-site-to-wp-from-an-external-php-script/)
 *  Thread Starter [james108](https://wordpress.org/support/users/james108/)
 * (@james108)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/add-a-site-to-wp-from-an-external-php-script/#post-2235252)
 * This doesn’t make much sense to me. I copied ‘n pasted some PHP code (at the 
   bottom) from /wp-admin/network/site-new.php and it worked, without any output.
   I looked at the network admin interface, and it looked like everything was working.
   So I try to visit the site, and that’s when I get a 404. Anyone know a work around?
   Here’s the code (minus some details):
 *     ```
       <?php
           /* I have omitted the values of $domain, $sPath, $title, and $uuid.
            * For those who don't understand, $domain is the domain of the site (e.g. wordpress.org ),
            * $sPath is the new site's path, $title is for the website's title,
            * and $uuid is the user's ID from the DB. This was made for the sub-dir install. If you have the sub-domain install, then this script is not what you want.
            */
           require_once( 'wp-config.php' );
           require_once( 'wp-includes/ms-blogs.php' );
           require_once( 'wp-includes/functions.php' );
           require_once( 'wp-admin/includes/upgrade.php' );
           require_once( 'wp-includes/ms-functions.php' );
           wpmu_create_blog( $domain, $sPath, $title, intval( $uuid ), array( 'public' => 1 ) );
       ?>
       ```
   

Viewing 4 replies - 1 through 4 (of 4 total)