mp-wp_genesis 1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * WordPress Upgrade API
mp-wp_genesis 4 *
mp-wp_genesis 5 * Most of the functions are pluggable and can be overwritten
mp-wp_genesis 6 *
mp-wp_genesis 7 * @package WordPress
mp-wp_genesis 8 * @subpackage Administration
mp-wp_genesis 9 */
mp-wp_genesis 10
mp-wp_genesis 11 /** Include user install customize script. */
mp-wp_genesis 12 if ( file_exists(WP_CONTENT_DIR . '/install.php') )
mp-wp_genesis 13 require (WP_CONTENT_DIR . '/install.php');
mp-wp_genesis 14
mp-wp_genesis 15 /** WordPress Administration API */
mp-wp_genesis 16 require_once(ABSPATH . 'wp-admin/includes/admin.php');
mp-wp_genesis 17
mp-wp_genesis 18 /** WordPress Schema API */
mp-wp_genesis 19 require_once(ABSPATH . 'wp-admin/includes/schema.php');
mp-wp_genesis 20
mp-wp_genesis 21 if ( !function_exists('wp_install') ) :
mp-wp_genesis 22 /**
mp-wp_genesis 23 * {@internal Missing Short Description}}
mp-wp_genesis 24 *
mp-wp_genesis 25 * {@internal Missing Long Description}}
mp-wp_genesis 26 *
mp-wp_genesis 27 * @since unknown
mp-wp_genesis 28 *
mp-wp_genesis 29 * @param string $blog_title Blog title.
mp-wp_genesis 30 * @param string $user_name User's username.
mp-wp_genesis 31 * @param string $user_email User's email.
mp-wp_genesis 32 * @param bool $public Whether blog is public.
mp-wp_genesis 33 * @param null $deprecated Optional. Not used.
mp-wp_genesis 34 * @return array Array keys 'url', 'user_id', 'password'.
mp-wp_genesis 35 */
mp-wp_genesis 36 function wp_install($blog_title, $user_name, $user_email, $public, $deprecated='') {
mp-wp_genesis 37 global $wp_rewrite;
mp-wp_genesis 38
mp-wp_genesis 39 wp_check_mysql_version();
mp-wp_genesis 40 wp_cache_flush();
mp-wp_genesis 41 make_db_current_silent();
mp-wp_genesis 42 populate_options();
mp-wp_genesis 43 populate_roles();
mp-wp_genesis 44
mp-wp_genesis 45 update_option('blogname', $blog_title);
mp-wp_genesis 46 update_option('admin_email', $user_email);
mp-wp_genesis 47 update_option('blog_public', $public);
mp-wp_genesis 48
mp-wp_genesis 49 $guessurl = wp_guess_url();
mp-wp_genesis 50
mp-wp_genesis 51 update_option('siteurl', $guessurl);
mp-wp_genesis 52
mp-wp_genesis 53 // If not a public blog, don't ping.
mp-wp_genesis 54 if ( ! $public )
mp-wp_genesis 55 update_option('default_pingback_flag', 0);
mp-wp_genesis 56
mp-wp_genesis 57 // Create default user. If the user already exists, the user tables are
mp-wp_genesis 58 // being shared among blogs. Just set the role in that case.
mp-wp_genesis 59 $user_id = username_exists($user_name);
mp-wp_genesis 60 if ( !$user_id ) {
mp-wp_genesis 61 $random_password = wp_generate_password();
mp-wp_genesis 62 $user_id = wp_create_user($user_name, $random_password, $user_email);
mp-wp_genesis 63 } else {
mp-wp_genesis 64 $random_password = __('User already exists. Password inherited.');
mp-wp_genesis 65 }
mp-wp_genesis 66
mp-wp_genesis 67 $user = new WP_User($user_id);
mp-wp_genesis 68 $user->set_role('administrator');
mp-wp_genesis 69
mp-wp_genesis 70 wp_install_defaults($user_id);
mp-wp_genesis 71
mp-wp_genesis 72 $wp_rewrite->flush_rules();
mp-wp_genesis 73
mp-wp_genesis 74 wp_new_blog_notification($blog_title, $guessurl, $user_id, $random_password);
mp-wp_genesis 75
mp-wp_genesis 76 wp_cache_flush();
mp-wp_genesis 77
mp-wp_genesis 78 return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $random_password);
mp-wp_genesis 79 }
mp-wp_genesis 80 endif;
mp-wp_genesis 81
mp-wp_genesis 82 if ( !function_exists('wp_install_defaults') ) :
mp-wp_genesis 83 /**
mp-wp_genesis 84 * {@internal Missing Short Description}}
mp-wp_genesis 85 *
mp-wp_genesis 86 * {@internal Missing Long Description}}
mp-wp_genesis 87 *
mp-wp_genesis 88 * @since unknown
mp-wp_genesis 89 *
mp-wp_genesis 90 * @param int $user_id User ID.
mp-wp_genesis 91 */
mp-wp_genesis 92 function wp_install_defaults($user_id) {
mp-wp_genesis 93 global $wpdb;
mp-wp_genesis 94
mp-wp_genesis 95 // Default category
mp-wp_genesis 96 $cat_name = $wpdb->escape(__('Uncategorized'));
mp-wp_genesis 97 $cat_slug = sanitize_title(_c('Uncategorized|Default category slug'));
mp-wp_genesis 98 $wpdb->query("INSERT INTO $wpdb->terms (name, slug, term_group) VALUES ('$cat_name', '$cat_slug', '0')");
mp-wp_genesis 99 $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('1', 'category', '', '0', '1')");
mp-wp_genesis 100
mp-wp_genesis 101 // Default link category
mp-wp_genesis 102 $cat_name = $wpdb->escape(__('Blogroll'));
mp-wp_genesis 103 $cat_slug = sanitize_title(_c('Blogroll|Default link category slug'));
mp-wp_genesis 104 $wpdb->query("INSERT INTO $wpdb->terms (name, slug, term_group) VALUES ('$cat_name', '$cat_slug', '0')");
mp-wp_genesis 105 $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('2', 'link_category', '', '0', '7')");
mp-wp_genesis 106
mp-wp_genesis 107 // Now drop in some default links
mp-wp_genesis 108 $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://codex.wordpress.org/', 'Documentation', 0, '', '');");
mp-wp_genesis 109 $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (1, 2)" );
mp-wp_genesis 110
mp-wp_genesis 111 $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://wordpress.org/development/', 'Development Blog', 0, 'http://wordpress.org/development/feed/', '');");
mp-wp_genesis 112 $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (2, 2)" );
mp-wp_genesis 113
mp-wp_genesis 114 $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://wordpress.org/extend/ideas/', 'Suggest Ideas', 0, '', '');");
mp-wp_genesis 115 $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (3, 2)" );
mp-wp_genesis 116
mp-wp_genesis 117 $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://wordpress.org/support/', 'Support Forum', 0, '', '');");
mp-wp_genesis 118 $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (4, 2)" );
mp-wp_genesis 119
mp-wp_genesis 120 $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://wordpress.org/extend/plugins/', 'Plugins', 0, '', '');");
mp-wp_genesis 121 $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (5, 2)" );
mp-wp_genesis 122
mp-wp_genesis 123 $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://wordpress.org/extend/themes/', 'Themes', 0, '', '');");
mp-wp_genesis 124 $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (6, 2)" );
mp-wp_genesis 125
mp-wp_genesis 126 $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://planet.wordpress.org/', 'WordPress Planet', 0, '', '');");
mp-wp_genesis 127 $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (7, 2)" );
mp-wp_genesis 128
mp-wp_genesis 129 // First post
mp-wp_genesis 130 $now = date('Y-m-d H:i:s');
mp-wp_genesis 131 $now_gmt = gmdate('Y-m-d H:i:s');
mp-wp_genesis 132 $first_post_guid = get_option('home') . '/?p=1';
mp-wp_genesis 133 $wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, guid, comment_count, to_ping, pinged, post_content_filtered) VALUES ($user_id, '$now', '$now_gmt', '".$wpdb->escape(__('Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!'))."', '', '".$wpdb->escape(__('Hello world!'))."', '0', '".$wpdb->escape(_c('hello-world|Default post slug'))."', '$now', '$now_gmt', '$first_post_guid', '1', '', '', '')");
mp-wp_genesis 134 $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (1, 1)" );
mp-wp_genesis 135
mp-wp_genesis 136 // Default comment
mp-wp_genesis 137 $wpdb->query("INSERT INTO $wpdb->comments (comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_date, comment_date_gmt, comment_content) VALUES ('1', '".$wpdb->escape(__('Mr WordPress'))."', '', 'http://wordpress.org/', '$now', '$now_gmt', '".$wpdb->escape(__('Hi, this is a comment.<br />To delete a comment, just log in and view the post's comments. There you will have the option to edit or delete them.'))."')");
mp-wp_genesis 138
mp-wp_genesis 139 // First Page
mp-wp_genesis 140 $first_post_guid = get_option('home') . '/?page_id=2';
mp-wp_genesis 141 $wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, guid, post_status, post_type, to_ping, pinged, post_content_filtered) VALUES ($user_id, '$now', '$now_gmt', '".$wpdb->escape(__('This is an example of a WordPress page, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many pages like this one or sub-pages as you like and manage all of your content inside of WordPress.'))."', '', '".$wpdb->escape(__('About'))."', '0', '".$wpdb->escape(_c('about|Default page slug'))."', '$now', '$now_gmt','$first_post_guid', 'publish', 'page', '', '', '')");
mp-wp_genesis 142 }
mp-wp_genesis 143 endif;
mp-wp_genesis 144
mp-wp_genesis 145 if ( !function_exists('wp_new_blog_notification') ) :
mp-wp_genesis 146 /**
mp-wp_genesis 147 * {@internal Missing Short Description}}
mp-wp_genesis 148 *
mp-wp_genesis 149 * {@internal Missing Long Description}}
mp-wp_genesis 150 *
mp-wp_genesis 151 * @since unknown
mp-wp_genesis 152 *
mp-wp_genesis 153 * @param string $blog_title Blog title.
mp-wp_genesis 154 * @param string $blog_url Blog url.
mp-wp_genesis 155 * @param int $user_id User ID.
mp-wp_genesis 156 * @param string $password User's Password.
mp-wp_genesis 157 */
mp-wp_genesis 158 function wp_new_blog_notification($blog_title, $blog_url, $user_id, $password) {
mp-wp_genesis 159 $user = new WP_User($user_id);
mp-wp_genesis 160 $email = $user->user_email;
mp-wp_genesis 161 $name = $user->user_login;
mp-wp_genesis 162 $message_headers = 'From: "' . $blog_title . '" <wordpress@' . $_SERVER['SERVER_NAME'] . '>';
mp-wp_genesis 163 $message = sprintf(__("Your new WordPress blog has been successfully set up at:
mp-wp_genesis 164
mp-wp_genesis 165 %1\$s
mp-wp_genesis 166
mp-wp_genesis 167 You can log in to the administrator account with the following information:
mp-wp_genesis 168
mp-wp_genesis 169 Username: %2\$s
mp-wp_genesis 170 Password: %3\$s
mp-wp_genesis 171
mp-wp_genesis 172 We hope you enjoy your new blog. Thanks!
mp-wp_genesis 173
mp-wp_genesis 174 --The WordPress Team
mp-wp_genesis 175 http://wordpress.org/
mp-wp_genesis 176 "), $blog_url, $name, $password);
mp-wp_genesis 177
mp-wp_genesis 178 @wp_mail($email, __('New WordPress Blog'), $message, $message_headers);
mp-wp_genesis 179 }
mp-wp_genesis 180 endif;
mp-wp_genesis 181
mp-wp_genesis 182 if ( !function_exists('wp_upgrade') ) :
mp-wp_genesis 183 /**
mp-wp_genesis 184 * Run WordPress Upgrade functions.
mp-wp_genesis 185 *
mp-wp_genesis 186 * {@internal Missing Long Description}}
mp-wp_genesis 187 *
mp-wp_genesis 188 * @since unknown
mp-wp_genesis 189 *
mp-wp_genesis 190 * @return null
mp-wp_genesis 191 */
mp-wp_genesis 192 function wp_upgrade() {
mp-wp_genesis 193 global $wp_current_db_version, $wp_db_version;
mp-wp_genesis 194
mp-wp_genesis 195 $wp_current_db_version = __get_option('db_version');
mp-wp_genesis 196
mp-wp_genesis 197 // We are up-to-date. Nothing to do.
mp-wp_genesis 198 if ( $wp_db_version == $wp_current_db_version )
mp-wp_genesis 199 return;
mp-wp_genesis 200
mp-wp_genesis 201 if( ! is_blog_installed() )
mp-wp_genesis 202 return;
mp-wp_genesis 203
mp-wp_genesis 204 wp_check_mysql_version();
mp-wp_genesis 205 wp_cache_flush();
mp-wp_genesis 206 make_db_current_silent();
mp-wp_genesis 207 upgrade_all();
mp-wp_genesis 208 wp_cache_flush();
mp-wp_genesis 209 }
mp-wp_genesis 210 endif;
mp-wp_genesis 211
mp-wp_genesis 212 /**
mp-wp_genesis 213 * Functions to be called in install and upgrade scripts.
mp-wp_genesis 214 *
mp-wp_genesis 215 * {@internal Missing Long Description}}
mp-wp_genesis 216 *
mp-wp_genesis 217 * @since unknown
mp-wp_genesis 218 */
mp-wp_genesis 219 function upgrade_all() {
mp-wp_genesis 220 global $wp_current_db_version, $wp_db_version, $wp_rewrite;
mp-wp_genesis 221 $wp_current_db_version = __get_option('db_version');
mp-wp_genesis 222
mp-wp_genesis 223 // We are up-to-date. Nothing to do.
mp-wp_genesis 224 if ( $wp_db_version == $wp_current_db_version )
mp-wp_genesis 225 return;
mp-wp_genesis 226
mp-wp_genesis 227 // If the version is not set in the DB, try to guess the version.
mp-wp_genesis 228 if ( empty($wp_current_db_version) ) {
mp-wp_genesis 229 $wp_current_db_version = 0;
mp-wp_genesis 230
mp-wp_genesis 231 // If the template option exists, we have 1.5.
mp-wp_genesis 232 $template = __get_option('template');
mp-wp_genesis 233 if ( !empty($template) )
mp-wp_genesis 234 $wp_current_db_version = 2541;
mp-wp_genesis 235 }
mp-wp_genesis 236
mp-wp_genesis 237 if ( $wp_current_db_version < 6039 )
mp-wp_genesis 238 upgrade_230_options_table();
mp-wp_genesis 239
mp-wp_genesis 240 populate_options();
mp-wp_genesis 241
mp-wp_genesis 242 if ( $wp_current_db_version < 2541 ) {
mp-wp_genesis 243 upgrade_100();
mp-wp_genesis 244 upgrade_101();
mp-wp_genesis 245 upgrade_110();
mp-wp_genesis 246 upgrade_130();
mp-wp_genesis 247 }
mp-wp_genesis 248
mp-wp_genesis 249 if ( $wp_current_db_version < 3308 )
mp-wp_genesis 250 upgrade_160();
mp-wp_genesis 251
mp-wp_genesis 252 if ( $wp_current_db_version < 4772 )
mp-wp_genesis 253 upgrade_210();
mp-wp_genesis 254
mp-wp_genesis 255 if ( $wp_current_db_version < 4351 )
mp-wp_genesis 256 upgrade_old_slugs();
mp-wp_genesis 257
mp-wp_genesis 258 if ( $wp_current_db_version < 5539 )
mp-wp_genesis 259 upgrade_230();
mp-wp_genesis 260
mp-wp_genesis 261 if ( $wp_current_db_version < 6124 )
mp-wp_genesis 262 upgrade_230_old_tables();
mp-wp_genesis 263
mp-wp_genesis 264 if ( $wp_current_db_version < 7499 )
mp-wp_genesis 265 upgrade_250();
mp-wp_genesis 266
mp-wp_genesis 267 if ( $wp_current_db_version < 7796 )
mp-wp_genesis 268 upgrade_251();
mp-wp_genesis 269
mp-wp_genesis 270 if ( $wp_current_db_version < 7935 )
mp-wp_genesis 271 upgrade_252();
mp-wp_genesis 272
mp-wp_genesis 273 if ( $wp_current_db_version < 8201 )
mp-wp_genesis 274 upgrade_260();
mp-wp_genesis 275
mp-wp_genesis 276 if ( $wp_current_db_version < 8989 )
mp-wp_genesis 277 upgrade_270();
mp-wp_genesis 278
mp-wp_genesis 279 maybe_disable_automattic_widgets();
mp-wp_genesis 280
mp-wp_genesis 281 $wp_rewrite->flush_rules();
mp-wp_genesis 282
mp-wp_genesis 283 update_option('db_version', $wp_db_version);
mp-wp_genesis 284 }
mp-wp_genesis 285
mp-wp_genesis 286 /**
mp-wp_genesis 287 * Execute changes made in WordPress 1.0.
mp-wp_genesis 288 *
mp-wp_genesis 289 * @since 1.0.0
mp-wp_genesis 290 */
mp-wp_genesis 291 function upgrade_100() {
mp-wp_genesis 292 global $wpdb;
mp-wp_genesis 293
mp-wp_genesis 294 // Get the title and ID of every post, post_name to check if it already has a value
mp-wp_genesis 295 $posts = $wpdb->get_results("SELECT ID, post_title, post_name FROM $wpdb->posts WHERE post_name = ''");
mp-wp_genesis 296 if ($posts) {
mp-wp_genesis 297 foreach($posts as $post) {
mp-wp_genesis 298 if ('' == $post->post_name) {
mp-wp_genesis 299 $newtitle = sanitize_title($post->post_title);
mp-wp_genesis 300 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_name = %s WHERE ID = %d", $newtitle, $post->ID) );
mp-wp_genesis 301 }
mp-wp_genesis 302 }
mp-wp_genesis 303 }
mp-wp_genesis 304
mp-wp_genesis 305 $categories = $wpdb->get_results("SELECT cat_ID, cat_name, category_nicename FROM $wpdb->categories");
mp-wp_genesis 306 foreach ($categories as $category) {
mp-wp_genesis 307 if ('' == $category->category_nicename) {
mp-wp_genesis 308 $newtitle = sanitize_title($category->cat_name);
mp-wp_genesis 309 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->categories SET category_nicename = %s WHERE cat_ID = %d", $newtitle, $category->cat_ID) );
mp-wp_genesis 310 }
mp-wp_genesis 311 }
mp-wp_genesis 312
mp-wp_genesis 313 $wpdb->query("UPDATE $wpdb->options SET option_value = REPLACE(option_value, 'wp-links/links-images/', 'wp-images/links/')
mp-wp_genesis 314 WHERE option_name LIKE 'links_rating_image%'
mp-wp_genesis 315 AND option_value LIKE 'wp-links/links-images/%'");
mp-wp_genesis 316
mp-wp_genesis 317 $done_ids = $wpdb->get_results("SELECT DISTINCT post_id FROM $wpdb->post2cat");
mp-wp_genesis 318 if ($done_ids) :
mp-wp_genesis 319 foreach ($done_ids as $done_id) :
mp-wp_genesis 320 $done_posts[] = $done_id->post_id;
mp-wp_genesis 321 endforeach;
mp-wp_genesis 322 $catwhere = ' AND ID NOT IN (' . implode(',', $done_posts) . ')';
mp-wp_genesis 323 else:
mp-wp_genesis 324 $catwhere = '';
mp-wp_genesis 325 endif;
mp-wp_genesis 326
mp-wp_genesis 327 $allposts = $wpdb->get_results("SELECT ID, post_category FROM $wpdb->posts WHERE post_category != '0' $catwhere");
mp-wp_genesis 328 if ($allposts) :
mp-wp_genesis 329 foreach ($allposts as $post) {
mp-wp_genesis 330 // Check to see if it's already been imported
mp-wp_genesis 331 $cat = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->post2cat WHERE post_id = %d AND category_id = %d", $post->ID, $post->post_category) );
mp-wp_genesis 332 if (!$cat && 0 != $post->post_category) { // If there's no result
mp-wp_genesis 333 $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->post2cat
mp-wp_genesis 334 (post_id, category_id)
mp-wp_genesis 335 VALUES (%s, %s)
mp-wp_genesis 336 ", $post->ID, $post->post_category) );
mp-wp_genesis 337 }
mp-wp_genesis 338 }
mp-wp_genesis 339 endif;
mp-wp_genesis 340 }
mp-wp_genesis 341
mp-wp_genesis 342 /**
mp-wp_genesis 343 * Execute changes made in WordPress 1.0.1.
mp-wp_genesis 344 *
mp-wp_genesis 345 * @since 1.0.1
mp-wp_genesis 346 */
mp-wp_genesis 347 function upgrade_101() {
mp-wp_genesis 348 global $wpdb;
mp-wp_genesis 349
mp-wp_genesis 350 // Clean up indices, add a few
mp-wp_genesis 351 add_clean_index($wpdb->posts, 'post_name');
mp-wp_genesis 352 add_clean_index($wpdb->posts, 'post_status');
mp-wp_genesis 353 add_clean_index($wpdb->categories, 'category_nicename');
mp-wp_genesis 354 add_clean_index($wpdb->comments, 'comment_approved');
mp-wp_genesis 355 add_clean_index($wpdb->comments, 'comment_post_ID');
mp-wp_genesis 356 add_clean_index($wpdb->links , 'link_category');
mp-wp_genesis 357 add_clean_index($wpdb->links , 'link_visible');
mp-wp_genesis 358 }
mp-wp_genesis 359
mp-wp_genesis 360 /**
mp-wp_genesis 361 * Execute changes made in WordPress 1.2.
mp-wp_genesis 362 *
mp-wp_genesis 363 * @since 1.2.0
mp-wp_genesis 364 */
mp-wp_genesis 365 function upgrade_110() {
mp-wp_genesis 366 global $wpdb;
mp-wp_genesis 367
mp-wp_genesis 368 // Set user_nicename.
mp-wp_genesis 369 $users = $wpdb->get_results("SELECT ID, user_nickname, user_nicename FROM $wpdb->users");
mp-wp_genesis 370 foreach ($users as $user) {
mp-wp_genesis 371 if ('' == $user->user_nicename) {
mp-wp_genesis 372 $newname = sanitize_title($user->user_nickname);
mp-wp_genesis 373 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->users SET user_nicename = %s WHERE ID = %d", $newname, $user->ID) );
mp-wp_genesis 374 }
mp-wp_genesis 375 }
mp-wp_genesis 376
mp-wp_genesis 377 $users = $wpdb->get_results("SELECT ID, user_pass from $wpdb->users");
mp-wp_genesis 378 foreach ($users as $row) {
mp-wp_genesis 379 if (!preg_match('/^[A-Fa-f0-9]{32}$/', $row->user_pass)) {
mp-wp_genesis 380 $wpdb->query('UPDATE '.$wpdb->users.' SET user_pass = MD5(\''.$row->user_pass.'\') WHERE ID = \''.$row->ID.'\'');
mp-wp_genesis 381 }
mp-wp_genesis 382 }
mp-wp_genesis 383
mp-wp_genesis 384 // Get the GMT offset, we'll use that later on
mp-wp_genesis 385 $all_options = get_alloptions_110();
mp-wp_genesis 386
mp-wp_genesis 387 $time_difference = $all_options->time_difference;
mp-wp_genesis 388
mp-wp_genesis 389 $server_time = time()+date('Z');
mp-wp_genesis 390 $weblogger_time = $server_time + $time_difference*3600;
mp-wp_genesis 391 $gmt_time = time();
mp-wp_genesis 392
mp-wp_genesis 393 $diff_gmt_server = ($gmt_time - $server_time) / 3600;
mp-wp_genesis 394 $diff_weblogger_server = ($weblogger_time - $server_time) / 3600;
mp-wp_genesis 395 $diff_gmt_weblogger = $diff_gmt_server - $diff_weblogger_server;
mp-wp_genesis 396 $gmt_offset = -$diff_gmt_weblogger;
mp-wp_genesis 397
mp-wp_genesis 398 // Add a gmt_offset option, with value $gmt_offset
mp-wp_genesis 399 add_option('gmt_offset', $gmt_offset);
mp-wp_genesis 400
mp-wp_genesis 401 // Check if we already set the GMT fields (if we did, then
mp-wp_genesis 402 // MAX(post_date_gmt) can't be '0000-00-00 00:00:00'
mp-wp_genesis 403 // <michel_v> I just slapped myself silly for not thinking about it earlier
mp-wp_genesis 404 $got_gmt_fields = ($wpdb->get_var("SELECT MAX(post_date_gmt) FROM $wpdb->posts") == '0000-00-00 00:00:00') ? false : true;
mp-wp_genesis 405
mp-wp_genesis 406 if (!$got_gmt_fields) {
mp-wp_genesis 407
mp-wp_genesis 408 // Add or substract time to all dates, to get GMT dates
mp-wp_genesis 409 $add_hours = intval($diff_gmt_weblogger);
mp-wp_genesis 410 $add_minutes = intval(60 * ($diff_gmt_weblogger - $add_hours));
mp-wp_genesis 411 $wpdb->query("UPDATE $wpdb->posts SET post_date_gmt = DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)");
mp-wp_genesis 412 $wpdb->query("UPDATE $wpdb->posts SET post_modified = post_date");
mp-wp_genesis 413 $wpdb->query("UPDATE $wpdb->posts SET post_modified_gmt = DATE_ADD(post_modified, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE) WHERE post_modified != '0000-00-00 00:00:00'");
mp-wp_genesis 414 $wpdb->query("UPDATE $wpdb->comments SET comment_date_gmt = DATE_ADD(comment_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)");
mp-wp_genesis 415 $wpdb->query("UPDATE $wpdb->users SET user_registered = DATE_ADD(user_registered, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)");
mp-wp_genesis 416 }
mp-wp_genesis 417
mp-wp_genesis 418 }
mp-wp_genesis 419
mp-wp_genesis 420 /**
mp-wp_genesis 421 * Execute changes made in WordPress 1.5.
mp-wp_genesis 422 *
mp-wp_genesis 423 * @since 1.5.0
mp-wp_genesis 424 */
mp-wp_genesis 425 function upgrade_130() {
mp-wp_genesis 426 global $wpdb;
mp-wp_genesis 427
mp-wp_genesis 428 // Remove extraneous backslashes.
mp-wp_genesis 429 $posts = $wpdb->get_results("SELECT ID, post_title, post_content, post_excerpt, guid, post_date, post_name, post_status, post_author FROM $wpdb->posts");
mp-wp_genesis 430 if ($posts) {
mp-wp_genesis 431 foreach($posts as $post) {
mp-wp_genesis 432 $post_content = addslashes(deslash($post->post_content));
mp-wp_genesis 433 $post_title = addslashes(deslash($post->post_title));
mp-wp_genesis 434 $post_excerpt = addslashes(deslash($post->post_excerpt));
mp-wp_genesis 435 if ( empty($post->guid) )
mp-wp_genesis 436 $guid = get_permalink($post->ID);
mp-wp_genesis 437 else
mp-wp_genesis 438 $guid = $post->guid;
mp-wp_genesis 439
mp-wp_genesis 440 $wpdb->query("UPDATE $wpdb->posts SET post_title = '$post_title', post_content = '$post_content', post_excerpt = '$post_excerpt', guid = '$guid' WHERE ID = '$post->ID'");
mp-wp_genesis 441 }
mp-wp_genesis 442 }
mp-wp_genesis 443
mp-wp_genesis 444 // Remove extraneous backslashes.
mp-wp_genesis 445 $comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_content FROM $wpdb->comments");
mp-wp_genesis 446 if ($comments) {
mp-wp_genesis 447 foreach($comments as $comment) {
mp-wp_genesis 448 $comment_content = addslashes(deslash($comment->comment_content));
mp-wp_genesis 449 $comment_author = addslashes(deslash($comment->comment_author));
mp-wp_genesis 450 $wpdb->query("UPDATE $wpdb->comments SET comment_content = '$comment_content', comment_author = '$comment_author' WHERE comment_ID = '$comment->comment_ID'");
mp-wp_genesis 451 }
mp-wp_genesis 452 }
mp-wp_genesis 453
mp-wp_genesis 454 // Remove extraneous backslashes.
mp-wp_genesis 455 $links = $wpdb->get_results("SELECT link_id, link_name, link_description FROM $wpdb->links");
mp-wp_genesis 456 if ($links) {
mp-wp_genesis 457 foreach($links as $link) {
mp-wp_genesis 458 $link_name = addslashes(deslash($link->link_name));
mp-wp_genesis 459 $link_description = addslashes(deslash($link->link_description));
mp-wp_genesis 460 $wpdb->query("UPDATE $wpdb->links SET link_name = '$link_name', link_description = '$link_description' WHERE link_id = '$link->link_id'");
mp-wp_genesis 461 }
mp-wp_genesis 462 }
mp-wp_genesis 463
mp-wp_genesis 464 // The "paged" option for what_to_show is no more.
mp-wp_genesis 465 if ($wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = 'what_to_show'") == 'paged') {
mp-wp_genesis 466 $wpdb->query("UPDATE $wpdb->options SET option_value = 'posts' WHERE option_name = 'what_to_show'");
mp-wp_genesis 467 }
mp-wp_genesis 468
mp-wp_genesis 469 $active_plugins = __get_option('active_plugins');
mp-wp_genesis 470
mp-wp_genesis 471 // If plugins are not stored in an array, they're stored in the old
mp-wp_genesis 472 // newline separated format. Convert to new format.
mp-wp_genesis 473 if ( !is_array( $active_plugins ) ) {
mp-wp_genesis 474 $active_plugins = explode("\n", trim($active_plugins));
mp-wp_genesis 475 update_option('active_plugins', $active_plugins);
mp-wp_genesis 476 }
mp-wp_genesis 477
mp-wp_genesis 478 // Obsolete tables
mp-wp_genesis 479 $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optionvalues');
mp-wp_genesis 480 $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiontypes');
mp-wp_genesis 481 $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroups');
mp-wp_genesis 482 $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroup_options');
mp-wp_genesis 483
mp-wp_genesis 484 // Update comments table to use comment_type
mp-wp_genesis 485 $wpdb->query("UPDATE $wpdb->comments SET comment_type='trackback', comment_content = REPLACE(comment_content, '<trackback />', '') WHERE comment_content LIKE '<trackback />%'");
mp-wp_genesis 486 $wpdb->query("UPDATE $wpdb->comments SET comment_type='pingback', comment_content = REPLACE(comment_content, '<pingback />', '') WHERE comment_content LIKE '<pingback />%'");
mp-wp_genesis 487
mp-wp_genesis 488 // Some versions have multiple duplicate option_name rows with the same values
mp-wp_genesis 489 $options = $wpdb->get_results("SELECT option_name, COUNT(option_name) AS dupes FROM `$wpdb->options` GROUP BY option_name");
mp-wp_genesis 490 foreach ( $options as $option ) {
mp-wp_genesis 491 if ( 1 != $option->dupes ) { // Could this be done in the query?
mp-wp_genesis 492 $limit = $option->dupes - 1;
mp-wp_genesis 493 $dupe_ids = $wpdb->get_col( $wpdb->prepare("SELECT option_id FROM $wpdb->options WHERE option_name = %s LIMIT %d", $option->option_name, $limit) );
mp-wp_genesis 494 $dupe_ids = join($dupe_ids, ',');
mp-wp_genesis 495 $wpdb->query("DELETE FROM $wpdb->options WHERE option_id IN ($dupe_ids)");
mp-wp_genesis 496 }
mp-wp_genesis 497 }
mp-wp_genesis 498
mp-wp_genesis 499 make_site_theme();
mp-wp_genesis 500 }
mp-wp_genesis 501
mp-wp_genesis 502 /**
mp-wp_genesis 503 * Execute changes made in WordPress 2.0.
mp-wp_genesis 504 *
mp-wp_genesis 505 * @since 2.0.0
mp-wp_genesis 506 */
mp-wp_genesis 507 function upgrade_160() {
mp-wp_genesis 508 global $wpdb, $wp_current_db_version;
mp-wp_genesis 509
mp-wp_genesis 510 populate_roles_160();
mp-wp_genesis 511
mp-wp_genesis 512 $users = $wpdb->get_results("SELECT * FROM $wpdb->users");
mp-wp_genesis 513 foreach ( $users as $user ) :
mp-wp_genesis 514 if ( !empty( $user->user_firstname ) )
mp-wp_genesis 515 update_usermeta( $user->ID, 'first_name', $wpdb->escape($user->user_firstname) );
mp-wp_genesis 516 if ( !empty( $user->user_lastname ) )
mp-wp_genesis 517 update_usermeta( $user->ID, 'last_name', $wpdb->escape($user->user_lastname) );
mp-wp_genesis 518 if ( !empty( $user->user_nickname ) )
mp-wp_genesis 519 update_usermeta( $user->ID, 'nickname', $wpdb->escape($user->user_nickname) );
mp-wp_genesis 520 if ( !empty( $user->user_level ) )
mp-wp_genesis 521 update_usermeta( $user->ID, $wpdb->prefix . 'user_level', $user->user_level );
mp-wp_genesis 522 if ( !empty( $user->user_icq ) )
mp-wp_genesis 523 update_usermeta( $user->ID, 'icq', $wpdb->escape($user->user_icq) );
mp-wp_genesis 524 if ( !empty( $user->user_aim ) )
mp-wp_genesis 525 update_usermeta( $user->ID, 'aim', $wpdb->escape($user->user_aim) );
mp-wp_genesis 526 if ( !empty( $user->user_msn ) )
mp-wp_genesis 527 update_usermeta( $user->ID, 'msn', $wpdb->escape($user->user_msn) );
mp-wp_genesis 528 if ( !empty( $user->user_yim ) )
mp-wp_genesis 529 update_usermeta( $user->ID, 'yim', $wpdb->escape($user->user_icq) );
mp-wp_genesis 530 if ( !empty( $user->user_description ) )
mp-wp_genesis 531 update_usermeta( $user->ID, 'description', $wpdb->escape($user->user_description) );
mp-wp_genesis 532
mp-wp_genesis 533 if ( isset( $user->user_idmode ) ):
mp-wp_genesis 534 $idmode = $user->user_idmode;
mp-wp_genesis 535 if ($idmode == 'nickname') $id = $user->user_nickname;
mp-wp_genesis 536 if ($idmode == 'login') $id = $user->user_login;
mp-wp_genesis 537 if ($idmode == 'firstname') $id = $user->user_firstname;
mp-wp_genesis 538 if ($idmode == 'lastname') $id = $user->user_lastname;
mp-wp_genesis 539 if ($idmode == 'namefl') $id = $user->user_firstname.' '.$user->user_lastname;
mp-wp_genesis 540 if ($idmode == 'namelf') $id = $user->user_lastname.' '.$user->user_firstname;
mp-wp_genesis 541 if (!$idmode) $id = $user->user_nickname;
mp-wp_genesis 542 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->users SET display_name = %s WHERE ID = %d", $id, $user->ID) );
mp-wp_genesis 543 endif;
mp-wp_genesis 544
mp-wp_genesis 545 // FIXME: RESET_CAPS is temporary code to reset roles and caps if flag is set.
mp-wp_genesis 546 $caps = get_usermeta( $user->ID, $wpdb->prefix . 'capabilities');
mp-wp_genesis 547 if ( empty($caps) || defined('RESET_CAPS') ) {
mp-wp_genesis 548 $level = get_usermeta($user->ID, $wpdb->prefix . 'user_level');
mp-wp_genesis 549 $role = translate_level_to_role($level);
mp-wp_genesis 550 update_usermeta( $user->ID, $wpdb->prefix . 'capabilities', array($role => true) );
mp-wp_genesis 551 }
mp-wp_genesis 552
mp-wp_genesis 553 endforeach;
mp-wp_genesis 554 $old_user_fields = array( 'user_firstname', 'user_lastname', 'user_icq', 'user_aim', 'user_msn', 'user_yim', 'user_idmode', 'user_ip', 'user_domain', 'user_browser', 'user_description', 'user_nickname', 'user_level' );
mp-wp_genesis 555 $wpdb->hide_errors();
mp-wp_genesis 556 foreach ( $old_user_fields as $old )
mp-wp_genesis 557 $wpdb->query("ALTER TABLE $wpdb->users DROP $old");
mp-wp_genesis 558 $wpdb->show_errors();
mp-wp_genesis 559
mp-wp_genesis 560 // populate comment_count field of posts table
mp-wp_genesis 561 $comments = $wpdb->get_results( "SELECT comment_post_ID, COUNT(*) as c FROM $wpdb->comments WHERE comment_approved = '1' GROUP BY comment_post_ID" );
mp-wp_genesis 562 if( is_array( $comments ) ) {
mp-wp_genesis 563 foreach ($comments as $comment) {
mp-wp_genesis 564 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET comment_count = %d WHERE ID = %d", $comment->c, $comment->comment_post_ID) );
mp-wp_genesis 565 }
mp-wp_genesis 566 }
mp-wp_genesis 567
mp-wp_genesis 568 // Some alpha versions used a post status of object instead of attachment and put
mp-wp_genesis 569 // the mime type in post_type instead of post_mime_type.
mp-wp_genesis 570 if ( $wp_current_db_version > 2541 && $wp_current_db_version <= 3091 ) {
mp-wp_genesis 571 $objects = $wpdb->get_results("SELECT ID, post_type FROM $wpdb->posts WHERE post_status = 'object'");
mp-wp_genesis 572 foreach ($objects as $object) {
mp-wp_genesis 573 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_status = 'attachment',
mp-wp_genesis 574 post_mime_type = %s,
mp-wp_genesis 575 post_type = ''
mp-wp_genesis 576 WHERE ID = %d", $object->post_type, $object->ID) );
mp-wp_genesis 577
mp-wp_genesis 578 $meta = get_post_meta($object->ID, 'imagedata', true);
mp-wp_genesis 579 if ( ! empty($meta['file']) )
mp-wp_genesis 580 update_attached_file( $object->ID, $meta['file'] );
mp-wp_genesis 581 }
mp-wp_genesis 582 }
mp-wp_genesis 583 }
mp-wp_genesis 584
mp-wp_genesis 585 /**
mp-wp_genesis 586 * Execute changes made in WordPress 2.1.
mp-wp_genesis 587 *
mp-wp_genesis 588 * @since 2.1.0
mp-wp_genesis 589 */
mp-wp_genesis 590 function upgrade_210() {
mp-wp_genesis 591 global $wpdb, $wp_current_db_version;
mp-wp_genesis 592
mp-wp_genesis 593 if ( $wp_current_db_version < 3506 ) {
mp-wp_genesis 594 // Update status and type.
mp-wp_genesis 595 $posts = $wpdb->get_results("SELECT ID, post_status FROM $wpdb->posts");
mp-wp_genesis 596
mp-wp_genesis 597 if ( ! empty($posts) ) foreach ($posts as $post) {
mp-wp_genesis 598 $status = $post->post_status;
mp-wp_genesis 599 $type = 'post';
mp-wp_genesis 600
mp-wp_genesis 601 if ( 'static' == $status ) {
mp-wp_genesis 602 $status = 'publish';
mp-wp_genesis 603 $type = 'page';
mp-wp_genesis 604 } else if ( 'attachment' == $status ) {
mp-wp_genesis 605 $status = 'inherit';
mp-wp_genesis 606 $type = 'attachment';
mp-wp_genesis 607 }
mp-wp_genesis 608
mp-wp_genesis 609 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_status = %s, post_type = %s WHERE ID = %d", $status, $type, $post->ID) );
mp-wp_genesis 610 }
mp-wp_genesis 611 }
mp-wp_genesis 612
mp-wp_genesis 613 if ( $wp_current_db_version < 3845 ) {
mp-wp_genesis 614 populate_roles_210();
mp-wp_genesis 615 }
mp-wp_genesis 616
mp-wp_genesis 617 if ( $wp_current_db_version < 3531 ) {
mp-wp_genesis 618 // Give future posts a post_status of future.
mp-wp_genesis 619 $now = gmdate('Y-m-d H:i:59');
mp-wp_genesis 620 $wpdb->query ("UPDATE $wpdb->posts SET post_status = 'future' WHERE post_status = 'publish' AND post_date_gmt > '$now'");
mp-wp_genesis 621
mp-wp_genesis 622 $posts = $wpdb->get_results("SELECT ID, post_date FROM $wpdb->posts WHERE post_status ='future'");
mp-wp_genesis 623 if ( !empty($posts) )
mp-wp_genesis 624 foreach ( $posts as $post )
mp-wp_genesis 625 wp_schedule_single_event(mysql2date('U', $post->post_date), 'publish_future_post', array($post->ID));
mp-wp_genesis 626 }
mp-wp_genesis 627 }
mp-wp_genesis 628
mp-wp_genesis 629 /**
mp-wp_genesis 630 * Execute changes made in WordPress 2.3.
mp-wp_genesis 631 *
mp-wp_genesis 632 * @since 2.3.0
mp-wp_genesis 633 */
mp-wp_genesis 634 function upgrade_230() {
mp-wp_genesis 635 global $wp_current_db_version, $wpdb;
mp-wp_genesis 636
mp-wp_genesis 637 if ( $wp_current_db_version < 5200 ) {
mp-wp_genesis 638 populate_roles_230();
mp-wp_genesis 639 }
mp-wp_genesis 640
mp-wp_genesis 641 // Convert categories to terms.
mp-wp_genesis 642 $tt_ids = array();
mp-wp_genesis 643 $have_tags = false;
mp-wp_genesis 644 $categories = $wpdb->get_results("SELECT * FROM $wpdb->categories ORDER BY cat_ID");
mp-wp_genesis 645 foreach ($categories as $category) {
mp-wp_genesis 646 $term_id = (int) $category->cat_ID;
mp-wp_genesis 647 $name = $category->cat_name;
mp-wp_genesis 648 $description = $category->category_description;
mp-wp_genesis 649 $slug = $category->category_nicename;
mp-wp_genesis 650 $parent = $category->category_parent;
mp-wp_genesis 651 $term_group = 0;
mp-wp_genesis 652
mp-wp_genesis 653 // Associate terms with the same slug in a term group and make slugs unique.
mp-wp_genesis 654 if ( $exists = $wpdb->get_results( $wpdb->prepare("SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $slug) ) ) {
mp-wp_genesis 655 $term_group = $exists[0]->term_group;
mp-wp_genesis 656 $id = $exists[0]->term_id;
mp-wp_genesis 657 $num = 2;
mp-wp_genesis 658 do {
mp-wp_genesis 659 $alt_slug = $slug . "-$num";
mp-wp_genesis 660 $num++;
mp-wp_genesis 661 $slug_check = $wpdb->get_var( $wpdb->prepare("SELECT slug FROM $wpdb->terms WHERE slug = %s", $alt_slug) );
mp-wp_genesis 662 } while ( $slug_check );
mp-wp_genesis 663
mp-wp_genesis 664 $slug = $alt_slug;
mp-wp_genesis 665
mp-wp_genesis 666 if ( empty( $term_group ) ) {
mp-wp_genesis 667 $term_group = $wpdb->get_var("SELECT MAX(term_group) FROM $wpdb->terms GROUP BY term_group") + 1;
mp-wp_genesis 668 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->terms SET term_group = %d WHERE term_id = %d", $term_group, $id) );
mp-wp_genesis 669 }
mp-wp_genesis 670 }
mp-wp_genesis 671
mp-wp_genesis 672 $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->terms (term_id, name, slug, term_group) VALUES
mp-wp_genesis 673 (%d, %s, %s, %d)", $term_id, $name, $slug, $term_group) );
mp-wp_genesis 674
mp-wp_genesis 675 $count = 0;
mp-wp_genesis 676 if ( !empty($category->category_count) ) {
mp-wp_genesis 677 $count = (int) $category->category_count;
mp-wp_genesis 678 $taxonomy = 'category';
mp-wp_genesis 679 $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ( %d, %s, %s, %d, %d)", $term_id, $taxonomy, $description, $parent, $count) );
mp-wp_genesis 680 $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id;
mp-wp_genesis 681 }
mp-wp_genesis 682
mp-wp_genesis 683 if ( !empty($category->link_count) ) {
mp-wp_genesis 684 $count = (int) $category->link_count;
mp-wp_genesis 685 $taxonomy = 'link_category';
mp-wp_genesis 686 $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ( %d, %s, %s, %d, %d)", $term_id, $taxonomy, $description, $parent, $count) );
mp-wp_genesis 687 $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id;
mp-wp_genesis 688 }
mp-wp_genesis 689
mp-wp_genesis 690 if ( !empty($category->tag_count) ) {
mp-wp_genesis 691 $have_tags = true;
mp-wp_genesis 692 $count = (int) $category->tag_count;
mp-wp_genesis 693 $taxonomy = 'post_tag';
mp-wp_genesis 694 $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ( %d, %s, %s, %d, %d)", $term_id, $taxonomy, $description, $parent, $count) );
mp-wp_genesis 695 $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id;
mp-wp_genesis 696 }
mp-wp_genesis 697
mp-wp_genesis 698 if ( empty($count) ) {
mp-wp_genesis 699 $count = 0;
mp-wp_genesis 700 $taxonomy = 'category';
mp-wp_genesis 701 $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ( %d, %s, %s, %d, %d)", $term_id, $taxonomy, $description, $parent, $count) );
mp-wp_genesis 702 $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id;
mp-wp_genesis 703 }
mp-wp_genesis 704 }
mp-wp_genesis 705
mp-wp_genesis 706 $select = 'post_id, category_id';
mp-wp_genesis 707 if ( $have_tags )
mp-wp_genesis 708 $select .= ', rel_type';
mp-wp_genesis 709
mp-wp_genesis 710 $posts = $wpdb->get_results("SELECT $select FROM $wpdb->post2cat GROUP BY post_id, category_id");
mp-wp_genesis 711 foreach ( $posts as $post ) {
mp-wp_genesis 712 $post_id = (int) $post->post_id;
mp-wp_genesis 713 $term_id = (int) $post->category_id;
mp-wp_genesis 714 $taxonomy = 'category';
mp-wp_genesis 715 if ( !empty($post->rel_type) && 'tag' == $post->rel_type)
mp-wp_genesis 716 $taxonomy = 'tag';
mp-wp_genesis 717 $tt_id = $tt_ids[$term_id][$taxonomy];
mp-wp_genesis 718 if ( empty($tt_id) )
mp-wp_genesis 719 continue;
mp-wp_genesis 720
mp-wp_genesis 721 $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ( %d, %d)", $post_id, $tt_id) );
mp-wp_genesis 722 }
mp-wp_genesis 723
mp-wp_genesis 724 // < 3570 we used linkcategories. >= 3570 we used categories and link2cat.
mp-wp_genesis 725 if ( $wp_current_db_version < 3570 ) {
mp-wp_genesis 726 // Create link_category terms for link categories. Create a map of link cat IDs
mp-wp_genesis 727 // to link_category terms.
mp-wp_genesis 728 $link_cat_id_map = array();
mp-wp_genesis 729 $default_link_cat = 0;
mp-wp_genesis 730 $tt_ids = array();
mp-wp_genesis 731 $link_cats = $wpdb->get_results("SELECT cat_id, cat_name FROM " . $wpdb->prefix . 'linkcategories');
mp-wp_genesis 732 foreach ( $link_cats as $category) {
mp-wp_genesis 733 $cat_id = (int) $category->cat_id;
mp-wp_genesis 734 $term_id = 0;
mp-wp_genesis 735 $name = $wpdb->escape($category->cat_name);
mp-wp_genesis 736 $slug = sanitize_title($name);
mp-wp_genesis 737 $term_group = 0;
mp-wp_genesis 738
mp-wp_genesis 739 // Associate terms with the same slug in a term group and make slugs unique.
mp-wp_genesis 740 if ( $exists = $wpdb->get_results( $wpdb->prepare("SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $slug) ) ) {
mp-wp_genesis 741 $term_group = $exists[0]->term_group;
mp-wp_genesis 742 $term_id = $exists[0]->term_id;
mp-wp_genesis 743 }
mp-wp_genesis 744
mp-wp_genesis 745 if ( empty($term_id) ) {
mp-wp_genesis 746 $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->terms (name, slug, term_group) VALUES (%s, %s, %d)", $name, $slug, $term_group) );
mp-wp_genesis 747 $term_id = (int) $wpdb->insert_id;
mp-wp_genesis 748 }
mp-wp_genesis 749
mp-wp_genesis 750 $link_cat_id_map[$cat_id] = $term_id;
mp-wp_genesis 751 $default_link_cat = $term_id;
mp-wp_genesis 752
mp-wp_genesis 753 $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES (%d, 'link_category', '', '0', '0')", $term_id) );
mp-wp_genesis 754 $tt_ids[$term_id] = (int) $wpdb->insert_id;
mp-wp_genesis 755 }
mp-wp_genesis 756
mp-wp_genesis 757 // Associate links to cats.
mp-wp_genesis 758 $links = $wpdb->get_results("SELECT link_id, link_category FROM $wpdb->links");
mp-wp_genesis 759 if ( !empty($links) ) foreach ( $links as $link ) {
mp-wp_genesis 760 if ( 0 == $link->link_category )
mp-wp_genesis 761 continue;
mp-wp_genesis 762 if ( ! isset($link_cat_id_map[$link->link_category]) )
mp-wp_genesis 763 continue;
mp-wp_genesis 764 $term_id = $link_cat_id_map[$link->link_category];
mp-wp_genesis 765 $tt_id = $tt_ids[$term_id];
mp-wp_genesis 766 if ( empty($tt_id) )
mp-wp_genesis 767 continue;
mp-wp_genesis 768
mp-wp_genesis 769 $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ( %d, %d)", $link->link_id, $tt_id) );
mp-wp_genesis 770 }
mp-wp_genesis 771
mp-wp_genesis 772 // Set default to the last category we grabbed during the upgrade loop.
mp-wp_genesis 773 update_option('default_link_category', $default_link_cat);
mp-wp_genesis 774 } else {
mp-wp_genesis 775 $links = $wpdb->get_results("SELECT link_id, category_id FROM $wpdb->link2cat GROUP BY link_id, category_id");
mp-wp_genesis 776 foreach ( $links as $link ) {
mp-wp_genesis 777 $link_id = (int) $link->link_id;
mp-wp_genesis 778 $term_id = (int) $link->category_id;
mp-wp_genesis 779 $taxonomy = 'link_category';
mp-wp_genesis 780 $tt_id = $tt_ids[$term_id][$taxonomy];
mp-wp_genesis 781 if ( empty($tt_id) )
mp-wp_genesis 782 continue;
mp-wp_genesis 783
mp-wp_genesis 784 $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ( %d, %d)", $link_id, $tt_id) );
mp-wp_genesis 785 }
mp-wp_genesis 786 }
mp-wp_genesis 787
mp-wp_genesis 788 if ( $wp_current_db_version < 4772 ) {
mp-wp_genesis 789 // Obsolete linkcategories table
mp-wp_genesis 790 $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'linkcategories');
mp-wp_genesis 791 }
mp-wp_genesis 792
mp-wp_genesis 793 // Recalculate all counts
mp-wp_genesis 794 $terms = $wpdb->get_results("SELECT term_taxonomy_id, taxonomy FROM $wpdb->term_taxonomy");
mp-wp_genesis 795 foreach ( (array) $terms as $term ) {
mp-wp_genesis 796 if ( ('post_tag' == $term->taxonomy) || ('category' == $term->taxonomy) )
mp-wp_genesis 797 $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type = 'post' AND term_taxonomy_id = %d", $term->term_taxonomy_id) );
mp-wp_genesis 798 else
mp-wp_genesis 799 $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term->term_taxonomy_id) );
mp-wp_genesis 800 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET count = %d WHERE term_taxonomy_id = %d", $count, $term->term_taxonomy_id) );
mp-wp_genesis 801 }
mp-wp_genesis 802 }
mp-wp_genesis 803
mp-wp_genesis 804 /**
mp-wp_genesis 805 * Remove old options from the database.
mp-wp_genesis 806 *
mp-wp_genesis 807 * @since 2.3.0
mp-wp_genesis 808 */
mp-wp_genesis 809 function upgrade_230_options_table() {
mp-wp_genesis 810 global $wpdb;
mp-wp_genesis 811 $old_options_fields = array( 'option_can_override', 'option_type', 'option_width', 'option_height', 'option_description', 'option_admin_level' );
mp-wp_genesis 812 $wpdb->hide_errors();
mp-wp_genesis 813 foreach ( $old_options_fields as $old )
mp-wp_genesis 814 $wpdb->query("ALTER TABLE $wpdb->options DROP $old");
mp-wp_genesis 815 $wpdb->show_errors();
mp-wp_genesis 816 }
mp-wp_genesis 817
mp-wp_genesis 818 /**
mp-wp_genesis 819 * Remove old categories, link2cat, and post2cat database tables.
mp-wp_genesis 820 *
mp-wp_genesis 821 * @since 2.3.0
mp-wp_genesis 822 */
mp-wp_genesis 823 function upgrade_230_old_tables() {
mp-wp_genesis 824 global $wpdb;
mp-wp_genesis 825 $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'categories');
mp-wp_genesis 826 $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'link2cat');
mp-wp_genesis 827 $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'post2cat');
mp-wp_genesis 828 }
mp-wp_genesis 829
mp-wp_genesis 830 /**
mp-wp_genesis 831 * Upgrade old slugs made in version 2.2.
mp-wp_genesis 832 *
mp-wp_genesis 833 * @since 2.2.0
mp-wp_genesis 834 */
mp-wp_genesis 835 function upgrade_old_slugs() {
mp-wp_genesis 836 // upgrade people who were using the Redirect Old Slugs plugin
mp-wp_genesis 837 global $wpdb;
mp-wp_genesis 838 $wpdb->query("UPDATE $wpdb->postmeta SET meta_key = '_wp_old_slug' WHERE meta_key = 'old_slug'");
mp-wp_genesis 839 }
mp-wp_genesis 840
mp-wp_genesis 841 /**
mp-wp_genesis 842 * Execute changes made in WordPress 2.5.0.
mp-wp_genesis 843 *
mp-wp_genesis 844 * @since 2.5.0
mp-wp_genesis 845 */
mp-wp_genesis 846 function upgrade_250() {
mp-wp_genesis 847 global $wp_current_db_version;
mp-wp_genesis 848
mp-wp_genesis 849 if ( $wp_current_db_version < 6689 ) {
mp-wp_genesis 850 populate_roles_250();
mp-wp_genesis 851 }
mp-wp_genesis 852
mp-wp_genesis 853 }
mp-wp_genesis 854
mp-wp_genesis 855 /**
mp-wp_genesis 856 * Execute changes made in WordPress 2.5.1.
mp-wp_genesis 857 *
mp-wp_genesis 858 * @since 2.5.1
mp-wp_genesis 859 */
mp-wp_genesis 860 function upgrade_251() {
mp-wp_genesis 861 global $wp_current_db_version;
mp-wp_genesis 862
mp-wp_genesis 863 // Make the secret longer
mp-wp_genesis 864 update_option('secret', wp_generate_password(64));
mp-wp_genesis 865 }
mp-wp_genesis 866
mp-wp_genesis 867 /**
mp-wp_genesis 868 * Execute changes made in WordPress 2.5.2.
mp-wp_genesis 869 *
mp-wp_genesis 870 * @since 2.5.2
mp-wp_genesis 871 */
mp-wp_genesis 872 function upgrade_252() {
mp-wp_genesis 873 global $wpdb;
mp-wp_genesis 874
mp-wp_genesis 875 $wpdb->query("UPDATE $wpdb->users SET user_activation_key = ''");
mp-wp_genesis 876 }
mp-wp_genesis 877
mp-wp_genesis 878 /**
mp-wp_genesis 879 * Execute changes made in WordPress 2.6.
mp-wp_genesis 880 *
mp-wp_genesis 881 * @since 2.6.0
mp-wp_genesis 882 */
mp-wp_genesis 883 function upgrade_260() {
mp-wp_genesis 884 global $wp_current_db_version;
mp-wp_genesis 885
mp-wp_genesis 886 if ( $wp_current_db_version < 8000 )
mp-wp_genesis 887 populate_roles_260();
mp-wp_genesis 888
mp-wp_genesis 889 if ( $wp_current_db_version < 8201 ) {
mp-wp_genesis 890 update_option('enable_app', 1);
mp-wp_genesis 891 update_option('enable_xmlrpc', 1);
mp-wp_genesis 892 }
mp-wp_genesis 893 }
mp-wp_genesis 894
mp-wp_genesis 895 /**
mp-wp_genesis 896 * Execute changes made in WordPress 2.7.
mp-wp_genesis 897 *
mp-wp_genesis 898 * @since 2.7.0
mp-wp_genesis 899 */
mp-wp_genesis 900 function upgrade_270() {
mp-wp_genesis 901 global $wpdb, $wp_current_db_version;
mp-wp_genesis 902
mp-wp_genesis 903 if ( $wp_current_db_version < 8980 )
mp-wp_genesis 904 populate_roles_270();
mp-wp_genesis 905
mp-wp_genesis 906 // Update post_date for unpublished posts with empty timestamp
mp-wp_genesis 907 if ( $wp_current_db_version < 8921 )
mp-wp_genesis 908 $wpdb->query( "UPDATE $wpdb->posts SET post_date = post_modified WHERE post_date = '0000-00-00 00:00:00'" );
mp-wp_genesis 909 }
mp-wp_genesis 910
mp-wp_genesis 911
mp-wp_genesis 912 // The functions we use to actually do stuff
mp-wp_genesis 913
mp-wp_genesis 914 // General
mp-wp_genesis 915
mp-wp_genesis 916 /**
mp-wp_genesis 917 * {@internal Missing Short Description}}
mp-wp_genesis 918 *
mp-wp_genesis 919 * {@internal Missing Long Description}}
mp-wp_genesis 920 *
mp-wp_genesis 921 * @since unknown
mp-wp_genesis 922 *
mp-wp_genesis 923 * @param string $table_name Database table name to create.
mp-wp_genesis 924 * @param string $create_ddl SQL statement to create table.
mp-wp_genesis 925 * @return bool If table already exists or was created by function.
mp-wp_genesis 926 */
mp-wp_genesis 927 function maybe_create_table($table_name, $create_ddl) {
mp-wp_genesis 928 global $wpdb;
mp-wp_genesis 929 foreach ($wpdb->get_col("SHOW TABLES",0) as $table ) {
mp-wp_genesis 930 if ($table == $table_name) {
mp-wp_genesis 931 return true;
mp-wp_genesis 932 }
mp-wp_genesis 933 }
mp-wp_genesis 934 //didn't find it try to create it.
mp-wp_genesis 935 $q = $wpdb->query($create_ddl);
mp-wp_genesis 936 // we cannot directly tell that whether this succeeded!
mp-wp_genesis 937 foreach ($wpdb->get_col("SHOW TABLES",0) as $table ) {
mp-wp_genesis 938 if ($table == $table_name) {
mp-wp_genesis 939 return true;
mp-wp_genesis 940 }
mp-wp_genesis 941 }
mp-wp_genesis 942 return false;
mp-wp_genesis 943 }
mp-wp_genesis 944
mp-wp_genesis 945 /**
mp-wp_genesis 946 * {@internal Missing Short Description}}
mp-wp_genesis 947 *
mp-wp_genesis 948 * {@internal Missing Long Description}}
mp-wp_genesis 949 *
mp-wp_genesis 950 * @since unknown
mp-wp_genesis 951 *
mp-wp_genesis 952 * @param string $table Database table name.
mp-wp_genesis 953 * @param string $index Index name to drop.
mp-wp_genesis 954 * @return bool True, when finished.
mp-wp_genesis 955 */
mp-wp_genesis 956 function drop_index($table, $index) {
mp-wp_genesis 957 global $wpdb;
mp-wp_genesis 958 $wpdb->hide_errors();
mp-wp_genesis 959 $wpdb->query("ALTER TABLE `$table` DROP INDEX `$index`");
mp-wp_genesis 960 // Now we need to take out all the extra ones we may have created
mp-wp_genesis 961 for ($i = 0; $i < 25; $i++) {
mp-wp_genesis 962 $wpdb->query("ALTER TABLE `$table` DROP INDEX `{$index}_$i`");
mp-wp_genesis 963 }
mp-wp_genesis 964 $wpdb->show_errors();
mp-wp_genesis 965 return true;
mp-wp_genesis 966 }
mp-wp_genesis 967
mp-wp_genesis 968 /**
mp-wp_genesis 969 * {@internal Missing Short Description}}
mp-wp_genesis 970 *
mp-wp_genesis 971 * {@internal Missing Long Description}}
mp-wp_genesis 972 *
mp-wp_genesis 973 * @since unknown
mp-wp_genesis 974 *
mp-wp_genesis 975 * @param string $table Database table name.
mp-wp_genesis 976 * @param string $index Database table index column.
mp-wp_genesis 977 * @return bool True, when done with execution.
mp-wp_genesis 978 */
mp-wp_genesis 979 function add_clean_index($table, $index) {
mp-wp_genesis 980 global $wpdb;
mp-wp_genesis 981 drop_index($table, $index);
mp-wp_genesis 982 $wpdb->query("ALTER TABLE `$table` ADD INDEX ( `$index` )");
mp-wp_genesis 983 return true;
mp-wp_genesis 984 }
mp-wp_genesis 985
mp-wp_genesis 986 /**
mp-wp_genesis 987 ** maybe_add_column()
mp-wp_genesis 988 ** Add column to db table if it doesn't exist.
mp-wp_genesis 989 ** Returns: true if already exists or on successful completion
mp-wp_genesis 990 ** false on error
mp-wp_genesis 991 */
mp-wp_genesis 992 function maybe_add_column($table_name, $column_name, $create_ddl) {
mp-wp_genesis 993 global $wpdb, $debug;
mp-wp_genesis 994 foreach ($wpdb->get_col("DESC $table_name", 0) as $column ) {
mp-wp_genesis 995 if ($debug) echo("checking $column == $column_name<br />");
mp-wp_genesis 996 if ($column == $column_name) {
mp-wp_genesis 997 return true;
mp-wp_genesis 998 }
mp-wp_genesis 999 }
mp-wp_genesis 1000 //didn't find it try to create it.
mp-wp_genesis 1001 $q = $wpdb->query($create_ddl);
mp-wp_genesis 1002 // we cannot directly tell that whether this succeeded!
mp-wp_genesis 1003 foreach ($wpdb->get_col("DESC $table_name", 0) as $column ) {
mp-wp_genesis 1004 if ($column == $column_name) {
mp-wp_genesis 1005 return true;
mp-wp_genesis 1006 }
mp-wp_genesis 1007 }
mp-wp_genesis 1008 return false;
mp-wp_genesis 1009 }
mp-wp_genesis 1010
mp-wp_genesis 1011 /**
mp-wp_genesis 1012 * Retrieve all options as it was for 1.2.
mp-wp_genesis 1013 *
mp-wp_genesis 1014 * @since 1.2.0
mp-wp_genesis 1015 *
mp-wp_genesis 1016 * @return array List of options.
mp-wp_genesis 1017 */
mp-wp_genesis 1018 function get_alloptions_110() {
mp-wp_genesis 1019 global $wpdb;
mp-wp_genesis 1020 if ($options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options")) {
mp-wp_genesis 1021 foreach ($options as $option) {
mp-wp_genesis 1022 // "When trying to design a foolproof system,
mp-wp_genesis 1023 // never underestimate the ingenuity of the fools :)" -- Dougal
mp-wp_genesis 1024 if ('siteurl' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value);
mp-wp_genesis 1025 if ('home' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value);
mp-wp_genesis 1026 if ('category_base' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value);
mp-wp_genesis 1027 $all_options->{$option->option_name} = stripslashes($option->option_value);
mp-wp_genesis 1028 }
mp-wp_genesis 1029 }
mp-wp_genesis 1030 return $all_options;
mp-wp_genesis 1031 }
mp-wp_genesis 1032
mp-wp_genesis 1033 /**
mp-wp_genesis 1034 * Version of get_option that is private to install/upgrade.
mp-wp_genesis 1035 *
mp-wp_genesis 1036 * @since unknown
mp-wp_genesis 1037 * @access private
mp-wp_genesis 1038 *
mp-wp_genesis 1039 * @param string $setting Option name.
mp-wp_genesis 1040 * @return mixed
mp-wp_genesis 1041 */
mp-wp_genesis 1042 function __get_option($setting) {
mp-wp_genesis 1043 global $wpdb;
mp-wp_genesis 1044
mp-wp_genesis 1045 if ( $setting == 'home' && defined( 'WP_HOME' ) ) {
mp-wp_genesis 1046 return preg_replace( '|/+$|', '', constant( 'WP_HOME' ) );
mp-wp_genesis 1047 }
mp-wp_genesis 1048
mp-wp_genesis 1049 if ( $setting == 'siteurl' && defined( 'WP_SITEURL' ) ) {
mp-wp_genesis 1050 return preg_replace( '|/+$|', '', constant( 'WP_SITEURL' ) );
mp-wp_genesis 1051 }
mp-wp_genesis 1052
mp-wp_genesis 1053 $option = $wpdb->get_var( $wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = %s", $setting) );
mp-wp_genesis 1054
mp-wp_genesis 1055 if ( 'home' == $setting && '' == $option )
mp-wp_genesis 1056 return __get_option('siteurl');
mp-wp_genesis 1057
mp-wp_genesis 1058 if ( 'siteurl' == $setting || 'home' == $setting || 'category_base' == $setting )
mp-wp_genesis 1059 $option = preg_replace('|/+$|', '', $option);
mp-wp_genesis 1060
mp-wp_genesis 1061 @ $kellogs = unserialize($option);
mp-wp_genesis 1062 if ($kellogs !== FALSE)
mp-wp_genesis 1063 return $kellogs;
mp-wp_genesis 1064 else
mp-wp_genesis 1065 return $option;
mp-wp_genesis 1066 }
mp-wp_genesis 1067
mp-wp_genesis 1068 /**
mp-wp_genesis 1069 * {@internal Missing Short Description}}
mp-wp_genesis 1070 *
mp-wp_genesis 1071 * {@internal Missing Long Description}}
mp-wp_genesis 1072 *
mp-wp_genesis 1073 * @since unknown
mp-wp_genesis 1074 *
mp-wp_genesis 1075 * @param string $content
mp-wp_genesis 1076 * @return string
mp-wp_genesis 1077 */
mp-wp_genesis 1078 function deslash($content) {
mp-wp_genesis 1079 // Note: \\\ inside a regex denotes a single backslash.
mp-wp_genesis 1080
mp-wp_genesis 1081 // Replace one or more backslashes followed by a single quote with
mp-wp_genesis 1082 // a single quote.
mp-wp_genesis 1083 $content = preg_replace("/\\\+'/", "'", $content);
mp-wp_genesis 1084
mp-wp_genesis 1085 // Replace one or more backslashes followed by a double quote with
mp-wp_genesis 1086 // a double quote.
mp-wp_genesis 1087 $content = preg_replace('/\\\+"/', '"', $content);
mp-wp_genesis 1088
mp-wp_genesis 1089 // Replace one or more backslashes with one backslash.
mp-wp_genesis 1090 $content = preg_replace("/\\\+/", "\\", $content);
mp-wp_genesis 1091
mp-wp_genesis 1092 return $content;
mp-wp_genesis 1093 }
mp-wp_genesis 1094
mp-wp_genesis 1095 /**
mp-wp_genesis 1096 * {@internal Missing Short Description}}
mp-wp_genesis 1097 *
mp-wp_genesis 1098 * {@internal Missing Long Description}}
mp-wp_genesis 1099 *
mp-wp_genesis 1100 * @since unknown
mp-wp_genesis 1101 *
mp-wp_genesis 1102 * @param unknown_type $queries
mp-wp_genesis 1103 * @param unknown_type $execute
mp-wp_genesis 1104 * @return unknown
mp-wp_genesis 1105 */
mp-wp_genesis 1106 function dbDelta($queries, $execute = true) {
mp-wp_genesis 1107 global $wpdb;
mp-wp_genesis 1108
mp-wp_genesis 1109 // Separate individual queries into an array
mp-wp_genesis 1110 if( !is_array($queries) ) {
mp-wp_genesis 1111 $queries = explode( ';', $queries );
mp-wp_genesis 1112 if('' == $queries[count($queries) - 1]) array_pop($queries);
mp-wp_genesis 1113 }
mp-wp_genesis 1114
mp-wp_genesis 1115 $cqueries = array(); // Creation Queries
mp-wp_genesis 1116 $iqueries = array(); // Insertion Queries
mp-wp_genesis 1117 $for_update = array();
mp-wp_genesis 1118
mp-wp_genesis 1119 // Create a tablename index for an array ($cqueries) of queries
mp-wp_genesis 1120 foreach($queries as $qry) {
mp-wp_genesis 1121 if(preg_match("|CREATE TABLE ([^ ]*)|", $qry, $matches)) {
mp-wp_genesis 1122 $cqueries[strtolower($matches[1])] = $qry;
mp-wp_genesis 1123 $for_update[$matches[1]] = 'Created table '.$matches[1];
mp-wp_genesis 1124 }
mp-wp_genesis 1125 else if(preg_match("|CREATE DATABASE ([^ ]*)|", $qry, $matches)) {
mp-wp_genesis 1126 array_unshift($cqueries, $qry);
mp-wp_genesis 1127 }
mp-wp_genesis 1128 else if(preg_match("|INSERT INTO ([^ ]*)|", $qry, $matches)) {
mp-wp_genesis 1129 $iqueries[] = $qry;
mp-wp_genesis 1130 }
mp-wp_genesis 1131 else if(preg_match("|UPDATE ([^ ]*)|", $qry, $matches)) {
mp-wp_genesis 1132 $iqueries[] = $qry;
mp-wp_genesis 1133 }
mp-wp_genesis 1134 else {
mp-wp_genesis 1135 // Unrecognized query type
mp-wp_genesis 1136 }
mp-wp_genesis 1137 }
mp-wp_genesis 1138
mp-wp_genesis 1139 // Check to see which tables and fields exist
mp-wp_genesis 1140 if($tables = $wpdb->get_col('SHOW TABLES;')) {
mp-wp_genesis 1141 // For every table in the database
mp-wp_genesis 1142 foreach($tables as $table) {
mp-wp_genesis 1143 // If a table query exists for the database table...
mp-wp_genesis 1144 if( array_key_exists(strtolower($table), $cqueries) ) {
mp-wp_genesis 1145 // Clear the field and index arrays
mp-wp_genesis 1146 unset($cfields);
mp-wp_genesis 1147 unset($indices);
mp-wp_genesis 1148 // Get all of the field names in the query from between the parens
mp-wp_genesis 1149 preg_match("|\((.*)\)|ms", $cqueries[strtolower($table)], $match2);
mp-wp_genesis 1150 $qryline = trim($match2[1]);
mp-wp_genesis 1151
mp-wp_genesis 1152 // Separate field lines into an array
mp-wp_genesis 1153 $flds = explode("\n", $qryline);
mp-wp_genesis 1154
mp-wp_genesis 1155 //echo "<hr/><pre>\n".print_r(strtolower($table), true).":\n".print_r($cqueries, true)."</pre><hr/>";
mp-wp_genesis 1156
mp-wp_genesis 1157 // For every field line specified in the query
mp-wp_genesis 1158 foreach($flds as $fld) {
mp-wp_genesis 1159 // Extract the field name
mp-wp_genesis 1160 preg_match("|^([^ ]*)|", trim($fld), $fvals);
mp-wp_genesis 1161 $fieldname = $fvals[1];
mp-wp_genesis 1162
mp-wp_genesis 1163 // Verify the found field name
mp-wp_genesis 1164 $validfield = true;
mp-wp_genesis 1165 switch(strtolower($fieldname))
mp-wp_genesis 1166 {
mp-wp_genesis 1167 case '':
mp-wp_genesis 1168 case 'primary':
mp-wp_genesis 1169 case 'index':
mp-wp_genesis 1170 case 'fulltext':
mp-wp_genesis 1171 case 'unique':
mp-wp_genesis 1172 case 'key':
mp-wp_genesis 1173 $validfield = false;
mp-wp_genesis 1174 $indices[] = trim(trim($fld), ", \n");
mp-wp_genesis 1175 break;
mp-wp_genesis 1176 }
mp-wp_genesis 1177 $fld = trim($fld);
mp-wp_genesis 1178
mp-wp_genesis 1179 // If it's a valid field, add it to the field array
mp-wp_genesis 1180 if($validfield) {
mp-wp_genesis 1181 $cfields[strtolower($fieldname)] = trim($fld, ", \n");
mp-wp_genesis 1182 }
mp-wp_genesis 1183 }
mp-wp_genesis 1184
mp-wp_genesis 1185 // Fetch the table column structure from the database
mp-wp_genesis 1186 $tablefields = $wpdb->get_results("DESCRIBE {$table};");
mp-wp_genesis 1187
mp-wp_genesis 1188 // For every field in the table
mp-wp_genesis 1189 foreach($tablefields as $tablefield) {
mp-wp_genesis 1190 // If the table field exists in the field array...
mp-wp_genesis 1191 if(array_key_exists(strtolower($tablefield->Field), $cfields)) {
mp-wp_genesis 1192 // Get the field type from the query
mp-wp_genesis 1193 preg_match("|".$tablefield->Field." ([^ ]*( unsigned)?)|i", $cfields[strtolower($tablefield->Field)], $matches);
mp-wp_genesis 1194 $fieldtype = $matches[1];
mp-wp_genesis 1195
mp-wp_genesis 1196 // Is actual field type different from the field type in query?
mp-wp_genesis 1197 if($tablefield->Type != $fieldtype) {
mp-wp_genesis 1198 // Add a query to change the column type
mp-wp_genesis 1199 $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN {$tablefield->Field} " . $cfields[strtolower($tablefield->Field)];
mp-wp_genesis 1200 $for_update[$table.'.'.$tablefield->Field] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}";
mp-wp_genesis 1201 }
mp-wp_genesis 1202
mp-wp_genesis 1203 // Get the default value from the array
mp-wp_genesis 1204 //echo "{$cfields[strtolower($tablefield->Field)]}<br>";
mp-wp_genesis 1205 if(preg_match("| DEFAULT '(.*)'|i", $cfields[strtolower($tablefield->Field)], $matches)) {
mp-wp_genesis 1206 $default_value = $matches[1];
mp-wp_genesis 1207 if($tablefield->Default != $default_value)
mp-wp_genesis 1208 {
mp-wp_genesis 1209 // Add a query to change the column's default value
mp-wp_genesis 1210 $cqueries[] = "ALTER TABLE {$table} ALTER COLUMN {$tablefield->Field} SET DEFAULT '{$default_value}'";
mp-wp_genesis 1211 $for_update[$table.'.'.$tablefield->Field] = "Changed default value of {$table}.{$tablefield->Field} from {$tablefield->Default} to {$default_value}";
mp-wp_genesis 1212 }
mp-wp_genesis 1213 }
mp-wp_genesis 1214
mp-wp_genesis 1215 // Remove the field from the array (so it's not added)
mp-wp_genesis 1216 unset($cfields[strtolower($tablefield->Field)]);
mp-wp_genesis 1217 }
mp-wp_genesis 1218 else {
mp-wp_genesis 1219 // This field exists in the table, but not in the creation queries?
mp-wp_genesis 1220 }
mp-wp_genesis 1221 }
mp-wp_genesis 1222
mp-wp_genesis 1223 // For every remaining field specified for the table
mp-wp_genesis 1224 foreach($cfields as $fieldname => $fielddef) {
mp-wp_genesis 1225 // Push a query line into $cqueries that adds the field to that table
mp-wp_genesis 1226 $cqueries[] = "ALTER TABLE {$table} ADD COLUMN $fielddef";
mp-wp_genesis 1227 $for_update[$table.'.'.$fieldname] = 'Added column '.$table.'.'.$fieldname;
mp-wp_genesis 1228 }
mp-wp_genesis 1229
mp-wp_genesis 1230 // Index stuff goes here
mp-wp_genesis 1231 // Fetch the table index structure from the database
mp-wp_genesis 1232 $tableindices = $wpdb->get_results("SHOW INDEX FROM {$table};");
mp-wp_genesis 1233
mp-wp_genesis 1234 if($tableindices) {
mp-wp_genesis 1235 // Clear the index array
mp-wp_genesis 1236 unset($index_ary);
mp-wp_genesis 1237
mp-wp_genesis 1238 // For every index in the table
mp-wp_genesis 1239 foreach($tableindices as $tableindex) {
mp-wp_genesis 1240 // Add the index to the index data array
mp-wp_genesis 1241 $keyname = $tableindex->Key_name;
mp-wp_genesis 1242 $index_ary[$keyname]['columns'][] = array('fieldname' => $tableindex->Column_name, 'subpart' => $tableindex->Sub_part);
mp-wp_genesis 1243 $index_ary[$keyname]['unique'] = ($tableindex->Non_unique == 0)?true:false;
mp-wp_genesis 1244 }
mp-wp_genesis 1245
mp-wp_genesis 1246 // For each actual index in the index array
mp-wp_genesis 1247 foreach($index_ary as $index_name => $index_data) {
mp-wp_genesis 1248 // Build a create string to compare to the query
mp-wp_genesis 1249 $index_string = '';
mp-wp_genesis 1250 if($index_name == 'PRIMARY') {
mp-wp_genesis 1251 $index_string .= 'PRIMARY ';
mp-wp_genesis 1252 }
mp-wp_genesis 1253 else if($index_data['unique']) {
mp-wp_genesis 1254 $index_string .= 'UNIQUE ';
mp-wp_genesis 1255 }
mp-wp_genesis 1256 $index_string .= 'KEY ';
mp-wp_genesis 1257 if($index_name != 'PRIMARY') {
mp-wp_genesis 1258 $index_string .= $index_name;
mp-wp_genesis 1259 }
mp-wp_genesis 1260 $index_columns = '';
mp-wp_genesis 1261 // For each column in the index
mp-wp_genesis 1262 foreach($index_data['columns'] as $column_data) {
mp-wp_genesis 1263 if($index_columns != '') $index_columns .= ',';
mp-wp_genesis 1264 // Add the field to the column list string
mp-wp_genesis 1265 $index_columns .= $column_data['fieldname'];
mp-wp_genesis 1266 if($column_data['subpart'] != '') {
mp-wp_genesis 1267 $index_columns .= '('.$column_data['subpart'].')';
mp-wp_genesis 1268 }
mp-wp_genesis 1269 }
mp-wp_genesis 1270 // Add the column list to the index create string
mp-wp_genesis 1271 $index_string .= ' ('.$index_columns.')';
mp-wp_genesis 1272 if(!(($aindex = array_search($index_string, $indices)) === false)) {
mp-wp_genesis 1273 unset($indices[$aindex]);
mp-wp_genesis 1274 //echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">{$table}:<br />Found index:".$index_string."</pre>\n";
mp-wp_genesis 1275 }
mp-wp_genesis 1276 //else echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">{$table}:<br /><b>Did not find index:</b>".$index_string."<br />".print_r($indices, true)."</pre>\n";
mp-wp_genesis 1277 }
mp-wp_genesis 1278 }
mp-wp_genesis 1279
mp-wp_genesis 1280 // For every remaining index specified for the table
mp-wp_genesis 1281 foreach ( (array) $indices as $index ) {
mp-wp_genesis 1282 // Push a query line into $cqueries that adds the index to that table
mp-wp_genesis 1283 $cqueries[] = "ALTER TABLE {$table} ADD $index";
mp-wp_genesis 1284 $for_update[$table.'.'.$fieldname] = 'Added index '.$table.' '.$index;
mp-wp_genesis 1285 }
mp-wp_genesis 1286
mp-wp_genesis 1287 // Remove the original table creation query from processing
mp-wp_genesis 1288 unset($cqueries[strtolower($table)]);
mp-wp_genesis 1289 unset($for_update[strtolower($table)]);
mp-wp_genesis 1290 } else {
mp-wp_genesis 1291 // This table exists in the database, but not in the creation queries?
mp-wp_genesis 1292 }
mp-wp_genesis 1293 }
mp-wp_genesis 1294 }
mp-wp_genesis 1295
mp-wp_genesis 1296 $allqueries = array_merge($cqueries, $iqueries);
mp-wp_genesis 1297 if($execute) {
mp-wp_genesis 1298 foreach($allqueries as $query) {
mp-wp_genesis 1299 //echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">".print_r($query, true)."</pre>\n";
mp-wp_genesis 1300 $wpdb->query($query);
mp-wp_genesis 1301 }
mp-wp_genesis 1302 }
mp-wp_genesis 1303
mp-wp_genesis 1304 return $for_update;
mp-wp_genesis 1305 }
mp-wp_genesis 1306
mp-wp_genesis 1307 /**
mp-wp_genesis 1308 * {@internal Missing Short Description}}
mp-wp_genesis 1309 *
mp-wp_genesis 1310 * {@internal Missing Long Description}}
mp-wp_genesis 1311 *
mp-wp_genesis 1312 * @since unknown
mp-wp_genesis 1313 */
mp-wp_genesis 1314 function make_db_current() {
mp-wp_genesis 1315 global $wp_queries;
mp-wp_genesis 1316
mp-wp_genesis 1317 $alterations = dbDelta($wp_queries);
mp-wp_genesis 1318 echo "<ol>\n";
mp-wp_genesis 1319 foreach($alterations as $alteration) echo "<li>$alteration</li>\n";
mp-wp_genesis 1320 echo "</ol>\n";
mp-wp_genesis 1321 }
mp-wp_genesis 1322
mp-wp_genesis 1323 /**
mp-wp_genesis 1324 * {@internal Missing Short Description}}
mp-wp_genesis 1325 *
mp-wp_genesis 1326 * {@internal Missing Long Description}}
mp-wp_genesis 1327 *
mp-wp_genesis 1328 * @since unknown
mp-wp_genesis 1329 */
mp-wp_genesis 1330 function make_db_current_silent() {
mp-wp_genesis 1331 global $wp_queries;
mp-wp_genesis 1332
mp-wp_genesis 1333 $alterations = dbDelta($wp_queries);
mp-wp_genesis 1334 }
mp-wp_genesis 1335
mp-wp_genesis 1336 /**
mp-wp_genesis 1337 * {@internal Missing Short Description}}
mp-wp_genesis 1338 *
mp-wp_genesis 1339 * {@internal Missing Long Description}}
mp-wp_genesis 1340 *
mp-wp_genesis 1341 * @since unknown
mp-wp_genesis 1342 *
mp-wp_genesis 1343 * @param unknown_type $theme_name
mp-wp_genesis 1344 * @param unknown_type $template
mp-wp_genesis 1345 * @return unknown
mp-wp_genesis 1346 */
mp-wp_genesis 1347 function make_site_theme_from_oldschool($theme_name, $template) {
mp-wp_genesis 1348 $home_path = get_home_path();
mp-wp_genesis 1349 $site_dir = WP_CONTENT_DIR . "/themes/$template";
mp-wp_genesis 1350
mp-wp_genesis 1351 if (! file_exists("$home_path/index.php"))
mp-wp_genesis 1352 return false;
mp-wp_genesis 1353
mp-wp_genesis 1354 // Copy files from the old locations to the site theme.
mp-wp_genesis 1355 // TODO: This does not copy arbitarary include dependencies. Only the
mp-wp_genesis 1356 // standard WP files are copied.
mp-wp_genesis 1357 $files = array('index.php' => 'index.php', 'wp-layout.css' => 'style.css', 'wp-comments.php' => 'comments.php', 'wp-comments-popup.php' => 'comments-popup.php');
mp-wp_genesis 1358
mp-wp_genesis 1359 foreach ($files as $oldfile => $newfile) {
mp-wp_genesis 1360 if ($oldfile == 'index.php')
mp-wp_genesis 1361 $oldpath = $home_path;
mp-wp_genesis 1362 else
mp-wp_genesis 1363 $oldpath = ABSPATH;
mp-wp_genesis 1364
mp-wp_genesis 1365 if ($oldfile == 'index.php') { // Check to make sure it's not a new index
mp-wp_genesis 1366 $index = implode('', file("$oldpath/$oldfile"));
mp-wp_genesis 1367 if (strpos($index, 'WP_USE_THEMES') !== false) {
mp-wp_genesis 1368 if (! @copy(WP_CONTENT_DIR . '/themes/default/index.php', "$site_dir/$newfile"))
mp-wp_genesis 1369 return false;
mp-wp_genesis 1370 continue; // Don't copy anything
mp-wp_genesis 1371 }
mp-wp_genesis 1372 }
mp-wp_genesis 1373
mp-wp_genesis 1374 if (! @copy("$oldpath/$oldfile", "$site_dir/$newfile"))
mp-wp_genesis 1375 return false;
mp-wp_genesis 1376
mp-wp_genesis 1377 chmod("$site_dir/$newfile", 0777);
mp-wp_genesis 1378
mp-wp_genesis 1379 // Update the blog header include in each file.
mp-wp_genesis 1380 $lines = explode("\n", implode('', file("$site_dir/$newfile")));
mp-wp_genesis 1381 if ($lines) {
mp-wp_genesis 1382 $f = fopen("$site_dir/$newfile", 'w');
mp-wp_genesis 1383
mp-wp_genesis 1384 foreach ($lines as $line) {
mp-wp_genesis 1385 if (preg_match('/require.*wp-blog-header/', $line))
mp-wp_genesis 1386 $line = '//' . $line;
mp-wp_genesis 1387
mp-wp_genesis 1388 // Update stylesheet references.
mp-wp_genesis 1389 $line = str_replace("<?php echo __get_option('siteurl'); ?>/wp-layout.css", "<?php bloginfo('stylesheet_url'); ?>", $line);
mp-wp_genesis 1390
mp-wp_genesis 1391 // Update comments template inclusion.
mp-wp_genesis 1392 $line = str_replace("<?php include(ABSPATH . 'wp-comments.php'); ?>", "<?php comments_template(); ?>", $line);
mp-wp_genesis 1393
mp-wp_genesis 1394 fwrite($f, "{$line}\n");
mp-wp_genesis 1395 }
mp-wp_genesis 1396 fclose($f);
mp-wp_genesis 1397 }
mp-wp_genesis 1398 }
mp-wp_genesis 1399
mp-wp_genesis 1400 // Add a theme header.
mp-wp_genesis 1401 $header = "/*\nTheme Name: $theme_name\nTheme URI: " . __get_option('siteurl') . "\nDescription: A theme automatically created by the upgrade.\nVersion: 1.0\nAuthor: Moi\n*/\n";
mp-wp_genesis 1402
mp-wp_genesis 1403 $stylelines = file_get_contents("$site_dir/style.css");
mp-wp_genesis 1404 if ($stylelines) {
mp-wp_genesis 1405 $f = fopen("$site_dir/style.css", 'w');
mp-wp_genesis 1406
mp-wp_genesis 1407 fwrite($f, $header);
mp-wp_genesis 1408 fwrite($f, $stylelines);
mp-wp_genesis 1409 fclose($f);
mp-wp_genesis 1410 }
mp-wp_genesis 1411
mp-wp_genesis 1412 return true;
mp-wp_genesis 1413 }
mp-wp_genesis 1414
mp-wp_genesis 1415 /**
mp-wp_genesis 1416 * {@internal Missing Short Description}}
mp-wp_genesis 1417 *
mp-wp_genesis 1418 * {@internal Missing Long Description}}
mp-wp_genesis 1419 *
mp-wp_genesis 1420 * @since unknown
mp-wp_genesis 1421 *
mp-wp_genesis 1422 * @param unknown_type $theme_name
mp-wp_genesis 1423 * @param unknown_type $template
mp-wp_genesis 1424 * @return unknown
mp-wp_genesis 1425 */
mp-wp_genesis 1426 function make_site_theme_from_default($theme_name, $template) {
mp-wp_genesis 1427 $site_dir = WP_CONTENT_DIR . "/themes/$template";
mp-wp_genesis 1428 $default_dir = WP_CONTENT_DIR . '/themes/default';
mp-wp_genesis 1429
mp-wp_genesis 1430 // Copy files from the default theme to the site theme.
mp-wp_genesis 1431 //$files = array('index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css');
mp-wp_genesis 1432
mp-wp_genesis 1433 $theme_dir = @ opendir("$default_dir");
mp-wp_genesis 1434 if ($theme_dir) {
mp-wp_genesis 1435 while(($theme_file = readdir( $theme_dir )) !== false) {
mp-wp_genesis 1436 if (is_dir("$default_dir/$theme_file"))
mp-wp_genesis 1437 continue;
mp-wp_genesis 1438 if (! @copy("$default_dir/$theme_file", "$site_dir/$theme_file"))
mp-wp_genesis 1439 return;
mp-wp_genesis 1440 chmod("$site_dir/$theme_file", 0777);
mp-wp_genesis 1441 }
mp-wp_genesis 1442 }
mp-wp_genesis 1443 @closedir($theme_dir);
mp-wp_genesis 1444
mp-wp_genesis 1445 // Rewrite the theme header.
mp-wp_genesis 1446 $stylelines = explode("\n", implode('', file("$site_dir/style.css")));
mp-wp_genesis 1447 if ($stylelines) {
mp-wp_genesis 1448 $f = fopen("$site_dir/style.css", 'w');
mp-wp_genesis 1449
mp-wp_genesis 1450 foreach ($stylelines as $line) {
mp-wp_genesis 1451 if (strpos($line, 'Theme Name:') !== false) $line = 'Theme Name: ' . $theme_name;
mp-wp_genesis 1452 elseif (strpos($line, 'Theme URI:') !== false) $line = 'Theme URI: ' . __get_option('url');
mp-wp_genesis 1453 elseif (strpos($line, 'Description:') !== false) $line = 'Description: Your theme.';
mp-wp_genesis 1454 elseif (strpos($line, 'Version:') !== false) $line = 'Version: 1';
mp-wp_genesis 1455 elseif (strpos($line, 'Author:') !== false) $line = 'Author: You';
mp-wp_genesis 1456 fwrite($f, $line . "\n");
mp-wp_genesis 1457 }
mp-wp_genesis 1458 fclose($f);
mp-wp_genesis 1459 }
mp-wp_genesis 1460
mp-wp_genesis 1461 // Copy the images.
mp-wp_genesis 1462 umask(0);
mp-wp_genesis 1463 if (! mkdir("$site_dir/images", 0777)) {
mp-wp_genesis 1464 return false;
mp-wp_genesis 1465 }
mp-wp_genesis 1466
mp-wp_genesis 1467 $images_dir = @ opendir("$default_dir/images");
mp-wp_genesis 1468 if ($images_dir) {
mp-wp_genesis 1469 while(($image = readdir($images_dir)) !== false) {
mp-wp_genesis 1470 if (is_dir("$default_dir/images/$image"))
mp-wp_genesis 1471 continue;
mp-wp_genesis 1472 if (! @copy("$default_dir/images/$image", "$site_dir/images/$image"))
mp-wp_genesis 1473 return;
mp-wp_genesis 1474 chmod("$site_dir/images/$image", 0777);
mp-wp_genesis 1475 }
mp-wp_genesis 1476 }
mp-wp_genesis 1477 @closedir($images_dir);
mp-wp_genesis 1478 }
mp-wp_genesis 1479
mp-wp_genesis 1480 // Create a site theme from the default theme.
mp-wp_genesis 1481 /**
mp-wp_genesis 1482 * {@internal Missing Short Description}}
mp-wp_genesis 1483 *
mp-wp_genesis 1484 * {@internal Missing Long Description}}
mp-wp_genesis 1485 *
mp-wp_genesis 1486 * @since unknown
mp-wp_genesis 1487 *
mp-wp_genesis 1488 * @return unknown
mp-wp_genesis 1489 */
mp-wp_genesis 1490 function make_site_theme() {
mp-wp_genesis 1491 // Name the theme after the blog.
mp-wp_genesis 1492 $theme_name = __get_option('blogname');
mp-wp_genesis 1493 $template = sanitize_title($theme_name);
mp-wp_genesis 1494 $site_dir = WP_CONTENT_DIR . "/themes/$template";
mp-wp_genesis 1495
mp-wp_genesis 1496 // If the theme already exists, nothing to do.
mp-wp_genesis 1497 if ( is_dir($site_dir)) {
mp-wp_genesis 1498 return false;
mp-wp_genesis 1499 }
mp-wp_genesis 1500
mp-wp_genesis 1501 // We must be able to write to the themes dir.
mp-wp_genesis 1502 if (! is_writable(WP_CONTENT_DIR . "/themes")) {
mp-wp_genesis 1503 return false;
mp-wp_genesis 1504 }
mp-wp_genesis 1505
mp-wp_genesis 1506 umask(0);
mp-wp_genesis 1507 if (! mkdir($site_dir, 0777)) {
mp-wp_genesis 1508 return false;
mp-wp_genesis 1509 }
mp-wp_genesis 1510
mp-wp_genesis 1511 if (file_exists(ABSPATH . 'wp-layout.css')) {
mp-wp_genesis 1512 if (! make_site_theme_from_oldschool($theme_name, $template)) {
mp-wp_genesis 1513 // TODO: rm -rf the site theme directory.
mp-wp_genesis 1514 return false;
mp-wp_genesis 1515 }
mp-wp_genesis 1516 } else {
mp-wp_genesis 1517 if (! make_site_theme_from_default($theme_name, $template))
mp-wp_genesis 1518 // TODO: rm -rf the site theme directory.
mp-wp_genesis 1519 return false;
mp-wp_genesis 1520 }
mp-wp_genesis 1521
mp-wp_genesis 1522 // Make the new site theme active.
mp-wp_genesis 1523 $current_template = __get_option('template');
mp-wp_genesis 1524 if ($current_template == 'default') {
mp-wp_genesis 1525 update_option('template', $template);
mp-wp_genesis 1526 update_option('stylesheet', $template);
mp-wp_genesis 1527 }
mp-wp_genesis 1528 return $template;
mp-wp_genesis 1529 }
mp-wp_genesis 1530
mp-wp_genesis 1531 /**
mp-wp_genesis 1532 * Translate user level to user role name.
mp-wp_genesis 1533 *
mp-wp_genesis 1534 * @since unknown
mp-wp_genesis 1535 *
mp-wp_genesis 1536 * @param int $level User level.
mp-wp_genesis 1537 * @return string User role name.
mp-wp_genesis 1538 */
mp-wp_genesis 1539 function translate_level_to_role($level) {
mp-wp_genesis 1540 switch ($level) {
mp-wp_genesis 1541 case 10:
mp-wp_genesis 1542 case 9:
mp-wp_genesis 1543 case 8:
mp-wp_genesis 1544 return 'administrator';
mp-wp_genesis 1545 case 7:
mp-wp_genesis 1546 case 6:
mp-wp_genesis 1547 case 5:
mp-wp_genesis 1548 return 'editor';
mp-wp_genesis 1549 case 4:
mp-wp_genesis 1550 case 3:
mp-wp_genesis 1551 case 2:
mp-wp_genesis 1552 return 'author';
mp-wp_genesis 1553 case 1:
mp-wp_genesis 1554 return 'contributor';
mp-wp_genesis 1555 case 0:
mp-wp_genesis 1556 return 'subscriber';
mp-wp_genesis 1557 }
mp-wp_genesis 1558 }
mp-wp_genesis 1559
mp-wp_genesis 1560 /**
mp-wp_genesis 1561 * {@internal Missing Short Description}}
mp-wp_genesis 1562 *
mp-wp_genesis 1563 * {@internal Missing Long Description}}
mp-wp_genesis 1564 *
mp-wp_genesis 1565 * @since unknown
mp-wp_genesis 1566 */
mp-wp_genesis 1567 function wp_check_mysql_version() {
mp-wp_genesis 1568 global $wpdb;
mp-wp_genesis 1569 $result = $wpdb->check_database_version();
mp-wp_genesis 1570 if ( is_wp_error( $result ) )
mp-wp_genesis 1571 die( $result->get_error_message() );
mp-wp_genesis 1572 }
mp-wp_genesis 1573
mp-wp_genesis 1574 /**
mp-wp_genesis 1575 * {@internal Missing Short Description}}
mp-wp_genesis 1576 *
mp-wp_genesis 1577 * {@internal Missing Long Description}}
mp-wp_genesis 1578 *
mp-wp_genesis 1579 * @since unknown
mp-wp_genesis 1580 */
mp-wp_genesis 1581 function maybe_disable_automattic_widgets() {
mp-wp_genesis 1582 $plugins = __get_option( 'active_plugins' );
mp-wp_genesis 1583
mp-wp_genesis 1584 foreach ( (array) $plugins as $plugin ) {
mp-wp_genesis 1585 if ( basename( $plugin ) == 'widgets.php' ) {
mp-wp_genesis 1586 array_splice( $plugins, array_search( $plugin, $plugins ), 1 );
mp-wp_genesis 1587 update_option( 'active_plugins', $plugins );
mp-wp_genesis 1588 break;
mp-wp_genesis 1589 }
mp-wp_genesis 1590 }
mp-wp_genesis 1591 }
mp-wp_genesis 1592
mp-wp_genesis 1593 ?>