WordPress blog to MU
Upgrading to wordpress MU manually from an old blog.
At work I had to update an old wordpress installation from 2.3.2 all the way up to the latest version of WordPress Mu (Multi User).
I documented the method I used and placed it below here.
If you do decide to do this it is done entirely at your own risk.
ALWAYS MAKE A BACKUP FIRST
Stage 1
Install Mu on its own database alongside your existing installation and database, within its own directory in the normal way.
Stage 2
Move the data across from Mu performing an upgrade, keeping all the data intact and wordpress Mu functioning correctly.
How this is done
1. On your old blog`s database rename the following tables
1 2 3 4 5 6 7 8 9 10 | from to ----------------------------------------------------------------- wp_comments wp_1_comments wp_links wp_1_links wp_options wp_1_options wp_postmeta wp_1_postmeta wp_posts wp_1_posts wp_terms wp_1_terms wp_term_relationships wp_1_term_relationships wp_term_taxonomy wp_1_term_taxonomy |
2. Copy only these tables across from the MU database to the old blog database.
1 2 3 4 5 6 7 | wp_blogs wp_blog_versions --> wp_posts (THIS CAN BE OVER WRITTEN BECAREFULL) wp_registration_log wp_signups wp_site wp_site_categories |
3. Alter the table wp_users in the old database by adding the following fields to its structure
1 2 3 4 | Field Type Collation Attributes Null default Extra ---------------------------------------------------------------------------------------------------------------------- spam tinyint(2) No 0 deleted tinyint(2) No 0 |
4. Add the following information into the table wp_1_options in the old database
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | option_id blog_id option_name option_value autoload -------------------------------------------------------------------------------------------------------------------------------------------- 75 0 avatar_default mystery yes 68 0 avatar_rating G yes 84 0 close_comments_days_old 14 yes 83 0 close_comments_for_old_posts 0 yes 88 0 comments_per_page 50 yes 116 0 current_theme (the value from the database) yes 107 0 dashboard_widget_options (the value from the database) yes 97 0 dismissed_update_core a:0:{} yes 76 0 enable_app 0 yes 77 0 enable_xmlrpc 0 yes 99 0 fileupload_url (the value from the database) yes 82 0 image_default_align yes 80 0 image_default_link_type file yes 81 0 image_default_size yes 79 0 large_size_h 1024 yes 78 0 large_size_w 1024 yes 74 0 medium_size_h 300 yes 73 0 medium_size_w 300 yes 108 0 nonce_salt (the value from the database) yes 87 0 page_comments 1 yes 100 0 post_count 1 yes 61 0 random_seed (the value from the database) yes 67 0 show_avatars 1 yes 92 0 sticky_posts a:0:{} yes 85 0 thread_comments 0 yes 86 0 thread_comments_depth 5 yes 72 0 thumbnail_crop 1 yes 71 0 thumbnail_size_h 150 yes 70 0 thumbnail_size_w 150 yes 106 0 update_themes (the value from the database) yes 69 0 upload_url_path yes 91 0 use_ssl 0 yes 95 0 widget_rss a:0:{} yes 94 0 widget_text a:0:{} yes 102 0 WPLANG yes 98 0 wp_1_user_roles (the value from the database) yes |
5. alter the value of upload_path in wp_1_options in the old database to wp-content/blogs.dir/1/files
The blog will now be active
…but the back office is broken!, to fix this….
6. in wp_usermeta change every entry of wp_capabilities to wp_1_capabilities (use the mysql below)
1 | UPDATE wp_usermeta SET meta_key='wp_1_capabilities' WHERE meta_key='wp_capabilities' |
7. create some extra fields based upon the user (run the php code below)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | // custom code for upgrade list($maxId) = $wpdb->get_results( 'SELECT max(umeta_id) AS startPoint FROM wp_usermeta', ARRAY_A); foreach ($wpdb->get_results( 'SELECT ID FROM wp_users', ARRAY_A) AS $userId){ echo '<h3>Updating user: '.$userId['ID'].'</h3><p>'; // execute all the querys for ($queryNumber=0; $queryNumber<3;){ switch ($queryNumber){ case 0: $SQL1 = "INSERT INTO wp_usermeta (umeta_id, user_id, meta_key, meta_value) VALUES ("; $SQL2 = ", ".$userId['ID'].", 'comment_shortcuts', 'false');"; $queryNumber++; break; case 1: $SQL1 = "INSERT INTO wp_usermeta (umeta_id, user_id, meta_key, meta_value) VALUES ("; $SQL2 = ", ".$userId['ID'].", 'admin_color', 'fresh');"; $queryNumber++; break; case 2: $SQL1 = "INSERT INTO wp_usermeta (umeta_id, user_id, meta_key, meta_value) VALUES ("; $SQL2 = ", ".$userId['ID'].", 'source_domain', 'YOURBLOGDOMAIN');"; $queryNumber++; break; default: die('Query out of bounds exception: '.$queryNumber); } // check the slot is available $check = $wpdb->get_results('SELECT * FROM wp_usermeta WHERE umeta_id='.$maxId['startPoint'], ARRAY_A); while (!empty($check)) { $maxId['startPoint']++; echo 'Incrementing to: '.$maxId['startPoint'].'<br />'; $check = $wpdb->get_results('SELECT * FROM wp_usermeta WHERE umeta_id='.$maxId['startPoint'], ARRAY_A); } $SQL = $SQL1.$maxId['startPoint'].$SQL2; echo 'Executing query '.$queryNumber.' : '; echo $wpdb->query($SQL) ? 'Success': 'Failed'; echo '<br />'; } echo '</p>'; } |
8. point the MU config.php to the old database, you will need to change the permissions from 644 to 666 use CHMOD
or duplicate the config file, alter it, rename the old config file, and then rename the new file as config.php
9. Log into the back office goto to settings->permalinks and click save, your posts/pages can now be found
Your upgrade should now be complete and you can go ahead and delete the MU database installation, not your old but now upgraded database.
I will be happy to answer any questions, and comments as always, are welcome
Additionally:
Ensure that both the field umeta_id in table wp_usermeta and the field ID in table wp_users are set to auto_increment.
49,963 views
This entry was posted on Thursday, April 16th, 2009 at 3:39 pm and is filed under Programming, Wordpress. You can follow any responses to this entry through the RSS 2.0 feed.
Thanks, I’m gonna give this a go!
You may want to compare with this:
http://bavatuesdays.com/importing-a-single-wp-blog-to-a-wpmu-installation/
I am very interested in this
I think you love dark color
it’s too difficult sir. i’ll find the easier one. thank you anyway