wp/wp-admin/includes/upgrade.php
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 11:14:17 +0000
changeset 6 490d5cc509ed
parent 5 5e2f62d02dcd
child 7 cf61fcea0001
permissions -rw-r--r--
update portfolio
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * WordPress Upgrade API
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     5
 * Most of the functions are pluggable and can be overwritten.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 * @subpackage Administration
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
/** Include user install customize script. */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
if ( file_exists(WP_CONTENT_DIR . '/install.php') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
	require (WP_CONTENT_DIR . '/install.php');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
/** WordPress Administration API */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
require_once(ABSPATH . 'wp-admin/includes/admin.php');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
/** WordPress Schema API */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
require_once(ABSPATH . 'wp-admin/includes/schema.php');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
if ( !function_exists('wp_install') ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    23
 * Installs the site.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    25
 * Runs the required functions to set up and populate the database,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    26
 * including primary admin user and initial options.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    30
 * @param string $blog_title    Blog title.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    31
 * @param string $user_name     User's username.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    32
 * @param string $user_email    User's email.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    33
 * @param bool   $public        Whether blog is public.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    34
 * @param string $deprecated    Optional. Not used.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    35
 * @param string $user_password Optional. User's chosen password. Default empty (random password).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    36
 * @param string $language      Optional. Language chosen. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    37
 * @return array Array keys 'url', 'user_id', 'password', and 'password_message'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    39
function wp_install( $blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '', $language = '' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
	if ( !empty( $deprecated ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
		_deprecated_argument( __FUNCTION__, '2.6' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
	wp_check_mysql_version();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
	wp_cache_flush();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
	make_db_current_silent();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
	populate_options();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
	populate_roles();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
	update_option('blogname', $blog_title);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
	update_option('admin_email', $user_email);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
	update_option('blog_public', $public);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    53
	if ( $language ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    54
		update_option( 'WPLANG', $language );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    55
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    56
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
	$guessurl = wp_guess_url();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
	update_option('siteurl', $guessurl);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
	// If not a public blog, don't ping.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
	if ( ! $public )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
		update_option('default_pingback_flag', 0);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    65
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    66
	 * Create default user. If the user already exists, the user tables are
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    67
	 * being shared among blogs. Just set the role in that case.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    68
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
	$user_id = username_exists($user_name);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
	$user_password = trim($user_password);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
	$email_password = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
	if ( !$user_id && empty($user_password) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
		$user_password = wp_generate_password( 12, false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
		$message = __('<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
		$user_id = wp_create_user($user_name, $user_password, $user_email);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
		update_user_option($user_id, 'default_password_nag', true, true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
		$email_password = true;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    78
	} elseif ( ! $user_id ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
		// Password has been provided
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
		$message = '<em>'.__('Your chosen password.').'</em>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
		$user_id = wp_create_user($user_name, $user_password, $user_email);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
		$message = __('User already exists. Password inherited.');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
	$user = new WP_User($user_id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
	$user->set_role('administrator');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
	wp_install_defaults($user_id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    91
	wp_install_maybe_enable_pretty_permalinks();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    92
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
	flush_rewrite_rules();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
	wp_new_blog_notification($blog_title, $guessurl, $user_id, ($email_password ? $user_password : __('The password you chose during the install.') ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
	wp_cache_flush();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    99
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   100
	 * Fires after a site is fully installed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   101
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   102
	 * @since 3.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   103
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   104
	 * @param WP_User $user The site owner.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   105
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   106
	do_action( 'wp_install', $user );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   107
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
	return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $user_password, 'password_message' => $message);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
endif;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
if ( !function_exists('wp_install_defaults') ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   114
 * Creates the initial content for a newly-installed site.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   116
 * Adds the default "Uncategorized" category, the first post (with comment),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   117
 * first page, and default widgets for default theme for the current version.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
 * @param int $user_id User ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   123
function wp_install_defaults( $user_id ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   124
	global $wpdb, $wp_rewrite, $table_prefix;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
	// Default category
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
	$cat_name = __('Uncategorized');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
	/* translators: Default category slug */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
	$cat_slug = sanitize_title(_x('Uncategorized', 'Default category slug'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
	if ( global_terms_enabled() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
		$cat_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
		if ( $cat_id == null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
			$wpdb->insert( $wpdb->sitecategories, array('cat_ID' => 0, 'cat_name' => $cat_name, 'category_nicename' => $cat_slug, 'last_updated' => current_time('mysql', true)) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
			$cat_id = $wpdb->insert_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
		update_option('default_category', $cat_id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
		$cat_id = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
	$wpdb->insert( $wpdb->terms, array('term_id' => $cat_id, 'name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
	$wpdb->insert( $wpdb->term_taxonomy, array('term_id' => $cat_id, 'taxonomy' => 'category', 'description' => '', 'parent' => 0, 'count' => 1));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
	$cat_tt_id = $wpdb->insert_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
	// First post
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   147
	$now = current_time( 'mysql' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   148
	$now_gmt = current_time( 'mysql', 1 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   149
	$first_post_guid = get_option( 'home' ) . '/?p=1';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
	if ( is_multisite() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
		$first_post = get_site_option( 'first_post' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
		if ( empty($first_post) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
			$first_post = __( 'Welcome to <a href="SITE_URL">SITE_NAME</a>. This is your first post. Edit or delete it, then start blogging!' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
		$first_post = str_replace( "SITE_URL", esc_url( network_home_url() ), $first_post );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   158
		$first_post = str_replace( "SITE_NAME", get_current_site()->site_name, $first_post );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
		$first_post = __('Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
	$wpdb->insert( $wpdb->posts, array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
								'post_author' => $user_id,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
								'post_date' => $now,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
								'post_date_gmt' => $now_gmt,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
								'post_content' => $first_post,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
								'post_excerpt' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
								'post_title' => __('Hello world!'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
								/* translators: Default post slug */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
								'post_name' => sanitize_title( _x('hello-world', 'Default post slug') ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
								'post_modified' => $now,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
								'post_modified_gmt' => $now_gmt,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
								'guid' => $first_post_guid,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
								'comment_count' => 1,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
								'to_ping' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
								'pinged' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
								'post_content_filtered' => ''
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
								));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
	$wpdb->insert( $wpdb->term_relationships, array('term_taxonomy_id' => $cat_tt_id, 'object_id' => 1) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
	// Default comment
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
	$first_comment_author = __('Mr WordPress');
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   184
	$first_comment_url = 'https://wordpress.org/';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
	$first_comment = __('Hi, this is a comment.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
To delete a comment, just log in and view the post&#039;s comments. There you will have the option to edit or delete them.');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
	if ( is_multisite() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
		$first_comment_author = get_site_option( 'first_comment_author', $first_comment_author );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
		$first_comment_url = get_site_option( 'first_comment_url', network_home_url() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
		$first_comment = get_site_option( 'first_comment', $first_comment );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
	$wpdb->insert( $wpdb->comments, array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
								'comment_post_ID' => 1,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
								'comment_author' => $first_comment_author,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
								'comment_author_email' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
								'comment_author_url' => $first_comment_url,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
								'comment_date' => $now,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
								'comment_date_gmt' => $now_gmt,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
								'comment_content' => $first_comment
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
								));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
	// First Page
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
	$first_page = sprintf( __( "This is an example page. It's different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site visitors. It might say something like this:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
<blockquote>Hi there! I'm a bike messenger by day, aspiring actor by night, and this is my blog. I live in Los Angeles, have a great dog named Jack, and I like pi&#241;a coladas. (And gettin' caught in the rain.)</blockquote>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
...or something like this:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
<blockquote>The XYZ Doohickey Company was founded in 1971, and has been providing quality doohickeys to the public ever since. Located in Gotham City, XYZ employs over 2,000 people and does all kinds of awesome things for the Gotham community.</blockquote>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
As a new WordPress user, you should go to <a href=\"%s\">your dashboard</a> to delete this page and create new pages for your content. Have fun!" ), admin_url() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
	if ( is_multisite() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
		$first_page = get_site_option( 'first_page', $first_page );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
	$first_post_guid = get_option('home') . '/?page_id=2';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
	$wpdb->insert( $wpdb->posts, array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
								'post_author' => $user_id,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
								'post_date' => $now,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
								'post_date_gmt' => $now_gmt,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
								'post_content' => $first_page,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
								'post_excerpt' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
								'post_title' => __( 'Sample Page' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
								/* translators: Default page slug */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
								'post_name' => __( 'sample-page' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
								'post_modified' => $now,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
								'post_modified_gmt' => $now_gmt,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
								'guid' => $first_post_guid,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
								'post_type' => 'page',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
								'to_ping' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
								'pinged' => '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
								'post_content_filtered' => ''
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
								));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
	$wpdb->insert( $wpdb->postmeta, array( 'post_id' => 2, 'meta_key' => '_wp_page_template', 'meta_value' => 'default' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
	// Set up default widgets for default theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
	update_option( 'widget_search', array ( 2 => array ( 'title' => '' ), '_multiwidget' => 1 ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
	update_option( 'widget_recent-posts', array ( 2 => array ( 'title' => '', 'number' => 5 ), '_multiwidget' => 1 ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
	update_option( 'widget_recent-comments', array ( 2 => array ( 'title' => '', 'number' => 5 ), '_multiwidget' => 1 ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
	update_option( 'widget_archives', array ( 2 => array ( 'title' => '', 'count' => 0, 'dropdown' => 0 ), '_multiwidget' => 1 ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
	update_option( 'widget_categories', array ( 2 => array ( 'title' => '', 'count' => 0, 'hierarchical' => 0, 'dropdown' => 0 ), '_multiwidget' => 1 ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
	update_option( 'widget_meta', array ( 2 => array ( 'title' => '' ), '_multiwidget' => 1 ) );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   241
	update_option( 'sidebars_widgets', array ( 'wp_inactive_widgets' => array (), 'sidebar-1' => array ( 0 => 'search-2', 1 => 'recent-posts-2', 2 => 'recent-comments-2', 3 => 'archives-2', 4 => 'categories-2', 5 => 'meta-2', ), 'array_version' => 3 ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
	if ( ! is_multisite() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
		update_user_meta( $user_id, 'show_welcome_panel', 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
	elseif ( ! is_super_admin( $user_id ) && ! metadata_exists( 'user', $user_id, 'show_welcome_panel' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
		update_user_meta( $user_id, 'show_welcome_panel', 2 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
	if ( is_multisite() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
		// Flush rules to pick up the new page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
		$wp_rewrite->init();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
		$wp_rewrite->flush_rules();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
		$user = new WP_User($user_id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
		$wpdb->update( $wpdb->options, array('option_value' => $user->user_email), array('option_name' => 'admin_email') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
		// Remove all perms except for the login user.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
		$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix.'user_level') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
		$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix.'capabilities') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
		// Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.) TODO: Get previous_blog_id.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
		if ( !is_super_admin( $user_id ) && $user_id != 1 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
			$wpdb->delete( $wpdb->usermeta, array( 'user_id' => $user_id , 'meta_key' => $wpdb->base_prefix.'1_capabilities' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
endif;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   267
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   268
 * Maybe enable pretty permalinks on install.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   269
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   270
 * If after enabling pretty permalinks don't work, fallback to query-string permalinks.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   271
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   272
 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   273
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   274
 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   275
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   276
 * @return bool Whether pretty permalinks are enabled. False otherwise.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   277
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   278
function wp_install_maybe_enable_pretty_permalinks() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   279
	global $wp_rewrite;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   280
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   281
	// Bail if a permalink structure is already enabled.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   282
	if ( get_option( 'permalink_structure' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   283
		return true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   284
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   285
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   286
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   287
	 * The Permalink structures to attempt.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   288
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   289
	 * The first is designed for mod_rewrite or nginx rewriting.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   290
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   291
	 * The second is PATHINFO-based permalinks for web server configurations
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   292
	 * without a true rewrite module enabled.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   293
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   294
	$permalink_structures = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   295
		'/%year%/%monthnum%/%day%/%postname%/',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   296
		'/index.php/%year%/%monthnum%/%day%/%postname%/'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   297
	);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   298
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   299
	foreach ( (array) $permalink_structures as $permalink_structure ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   300
		$wp_rewrite->set_permalink_structure( $permalink_structure );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   301
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   302
		/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   303
	 	 * Flush rules with the hard option to force refresh of the web-server's
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   304
	 	 * rewrite config file (e.g. .htaccess or web.config).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   305
	 	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   306
		$wp_rewrite->flush_rules( true );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   307
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   308
		// Test against a real WordPress Post, or if none were created, a random 404 page.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   309
		$test_url = get_permalink( 1 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   310
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   311
		if ( ! $test_url ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   312
			$test_url = home_url( '/wordpress-check-for-rewrites/' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   313
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   314
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   315
		/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   316
	 	 * Send a request to the site, and check whether
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   317
	 	 * the 'x-pingback' header is returned as expected.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   318
	 	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   319
	 	 * Uses wp_remote_get() instead of wp_remote_head() because web servers
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   320
	 	 * can block head requests.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   321
	 	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   322
		$response          = wp_remote_get( $test_url, array( 'timeout' => 5 ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   323
		$x_pingback_header = wp_remote_retrieve_header( $response, 'x-pingback' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   324
		$pretty_permalinks = $x_pingback_header && $x_pingback_header === get_bloginfo( 'pingback_url' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   325
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   326
		if ( $pretty_permalinks ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   327
			return true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   328
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   329
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   330
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   331
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   332
	 * If it makes it this far, pretty permalinks failed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   333
	 * Fallback to query-string permalinks.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   334
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   335
	$wp_rewrite->set_permalink_structure( '' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   336
	$wp_rewrite->flush_rules( true );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   337
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   338
	return false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   339
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   340
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
if ( !function_exists('wp_new_blog_notification') ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   343
 * Notifies the site admin that the setup is complete.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   345
 * Sends an email with wp_mail to the new administrator that the site setup is complete,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   346
 * and provides them with a record of their login credentials.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
 * @param string $blog_title Blog title.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   351
 * @param string $blog_url   Blog url.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   352
 * @param int    $user_id    User ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   353
 * @param string $password   User's Password.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
function wp_new_blog_notification($blog_title, $blog_url, $user_id, $password) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
	$user = new WP_User( $user_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
	$email = $user->user_email;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
	$name = $user->user_login;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   359
	$login_url = wp_login_url();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   360
	$message = sprintf( __( "Your new WordPress site has been successfully set up at:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
%1\$s
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
You can log in to the administrator account with the following information:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
Username: %2\$s
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
Password: %3\$s
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   368
Log in here: %4\$s
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
We hope you enjoy your new site. Thanks!
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
--The WordPress Team
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   373
https://wordpress.org/
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   374
"), $blog_url, $name, $password, $login_url );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
	@wp_mail($email, __('New WordPress Site'), $message);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
endif;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
if ( !function_exists('wp_upgrade') ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   382
 * Runs WordPress Upgrade functions.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   384
 * Upgrades the database if needed during a site update.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   388
 * @return null If no update is necessary or site isn't completely installed, null.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
function wp_upgrade() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
	global $wp_current_db_version, $wp_db_version, $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
	$wp_current_db_version = __get_option('db_version');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
	// We are up-to-date. Nothing to do.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
	if ( $wp_db_version == $wp_current_db_version )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
	if ( ! is_blog_installed() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
	wp_check_mysql_version();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
	wp_cache_flush();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
	pre_schema_upgrade();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
	make_db_current_silent();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
	upgrade_all();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
	if ( is_multisite() && is_main_site() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
		upgrade_network();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
	wp_cache_flush();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
	if ( is_multisite() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
		if ( $wpdb->get_row( "SELECT blog_id FROM {$wpdb->blog_versions} WHERE blog_id = '{$wpdb->blogid}'" ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
			$wpdb->query( "UPDATE {$wpdb->blog_versions} SET db_version = '{$wp_db_version}' WHERE blog_id = '{$wpdb->blogid}'" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
			$wpdb->query( "INSERT INTO {$wpdb->blog_versions} ( `blog_id` , `db_version` , `last_updated` ) VALUES ( '{$wpdb->blogid}', '{$wp_db_version}', NOW());" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   417
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   418
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   419
	 * Fires after a site is fully upgraded.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   420
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   421
	 * @since 3.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   422
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   423
	 * @param int $wp_db_version         The new $wp_db_version.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   424
	 * @param int $wp_current_db_version The old (current) $wp_db_version.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   425
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   426
	do_action( 'wp_upgrade', $wp_db_version, $wp_current_db_version );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
endif;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
 * Functions to be called in install and upgrade scripts.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   433
 * Contains conditional checks to determine which upgrade scripts to run,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   434
 * based on database version and WP version being updated-to.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
 * @since 1.0.1
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   437
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   438
 * @return null If no update is necessary, null.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
function upgrade_all() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
	global $wp_current_db_version, $wp_db_version;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
	$wp_current_db_version = __get_option('db_version');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
	// We are up-to-date. Nothing to do.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
	if ( $wp_db_version == $wp_current_db_version )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
	// If the version is not set in the DB, try to guess the version.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
	if ( empty($wp_current_db_version) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
		$wp_current_db_version = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
		// If the template option exists, we have 1.5.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
		$template = __get_option('template');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
		if ( !empty($template) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
			$wp_current_db_version = 2541;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
	if ( $wp_current_db_version < 6039 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
		upgrade_230_options_table();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
	populate_options();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
	if ( $wp_current_db_version < 2541 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
		upgrade_100();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
		upgrade_101();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
		upgrade_110();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
		upgrade_130();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
	if ( $wp_current_db_version < 3308 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
		upgrade_160();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   473
	if ( $wp_current_db_version < 4772 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
		upgrade_210();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
	if ( $wp_current_db_version < 4351 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
		upgrade_old_slugs();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
	if ( $wp_current_db_version < 5539 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
		upgrade_230();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
	if ( $wp_current_db_version < 6124 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   483
		upgrade_230_old_tables();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
	if ( $wp_current_db_version < 7499 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
		upgrade_250();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
	if ( $wp_current_db_version < 7935 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
		upgrade_252();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   491
	if ( $wp_current_db_version < 8201 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
		upgrade_260();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
	if ( $wp_current_db_version < 8989 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
		upgrade_270();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   496
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
	if ( $wp_current_db_version < 10360 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
		upgrade_280();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
	if ( $wp_current_db_version < 11958 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   501
		upgrade_290();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
	if ( $wp_current_db_version < 15260 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
		upgrade_300();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
	if ( $wp_current_db_version < 19389 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
		upgrade_330();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
	if ( $wp_current_db_version < 20080 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
		upgrade_340();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
	if ( $wp_current_db_version < 22422 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
		upgrade_350();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
	if ( $wp_current_db_version < 25824 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
		upgrade_370();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   518
	if ( $wp_current_db_version < 26148 )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   519
		upgrade_372();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   520
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   521
	if ( $wp_current_db_version < 26691 )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   522
		upgrade_380();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   523
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   524
	if ( $wp_current_db_version < 29630 )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   525
		upgrade_400();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   526
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   527
	// Don't harsh my mellow. upgrade_422() must be called before
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   528
	// upgrade_420() to catch bad comments prior to any auto-expansion of
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   529
	// MySQL column widths.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   530
	if ( $wp_current_db_version < 31534 )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   531
		upgrade_422();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   532
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   533
	if ( $wp_current_db_version < 31351 )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   534
		upgrade_420();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   535
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
	maybe_disable_link_manager();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
	maybe_disable_automattic_widgets();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
	update_option( 'db_version', $wp_db_version );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
	update_option( 'db_upgraded', true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
 * Execute changes made in WordPress 1.0.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
 * @since 1.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
function upgrade_100() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
	// Get the title and ID of every post, post_name to check if it already has a value
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
	$posts = $wpdb->get_results("SELECT ID, post_title, post_name FROM $wpdb->posts WHERE post_name = ''");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
	if ($posts) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
		foreach($posts as $post) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
			if ('' == $post->post_name) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
				$newtitle = sanitize_title($post->post_title);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   558
				$wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_name = %s WHERE ID = %d", $newtitle, $post->ID) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
	$categories = $wpdb->get_results("SELECT cat_ID, cat_name, category_nicename FROM $wpdb->categories");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
	foreach ($categories as $category) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
		if ('' == $category->category_nicename) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
			$newtitle = sanitize_title($category->cat_name);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
			$wpdb->update( $wpdb->categories, array('category_nicename' => $newtitle), array('cat_ID' => $category->cat_ID) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   571
	$sql = "UPDATE $wpdb->options
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   572
		SET option_value = REPLACE(option_value, 'wp-links/links-images/', 'wp-images/links/')
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   573
		WHERE option_name LIKE %s
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   574
		AND option_value LIKE %s";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   575
	$wpdb->query( $wpdb->prepare( $sql, $wpdb->esc_like( 'links_rating_image' ) . '%', $wpdb->esc_like( 'wp-links/links-images/' ) . '%' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
	$done_ids = $wpdb->get_results("SELECT DISTINCT post_id FROM $wpdb->post2cat");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   578
	if ($done_ids) :
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   579
		$done_posts = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
		foreach ($done_ids as $done_id) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   581
			$done_posts[] = $done_id->post_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
		endforeach;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
		$catwhere = ' AND ID NOT IN (' . implode(',', $done_posts) . ')';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   584
	else:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   585
		$catwhere = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
	endif;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   587
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
	$allposts = $wpdb->get_results("SELECT ID, post_category FROM $wpdb->posts WHERE post_category != '0' $catwhere");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
	if ($allposts) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
		foreach ($allposts as $post) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
			// Check to see if it's already been imported
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
			$cat = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->post2cat WHERE post_id = %d AND category_id = %d", $post->ID, $post->post_category) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
			if (!$cat && 0 != $post->post_category) { // If there's no result
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
				$wpdb->insert( $wpdb->post2cat, array('post_id' => $post->ID, 'category_id' => $post->post_category) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   595
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   597
	endif;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   599
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   600
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   601
 * Execute changes made in WordPress 1.0.1.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   603
 * @since 1.0.1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   605
function upgrade_101() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
	// Clean up indices, add a few
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
	add_clean_index($wpdb->posts, 'post_name');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
	add_clean_index($wpdb->posts, 'post_status');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
	add_clean_index($wpdb->categories, 'category_nicename');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
	add_clean_index($wpdb->comments, 'comment_approved');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
	add_clean_index($wpdb->comments, 'comment_post_ID');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
	add_clean_index($wpdb->links , 'link_category');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
	add_clean_index($wpdb->links , 'link_visible');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
 * Execute changes made in WordPress 1.2.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   621
 * @since 1.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   622
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   623
function upgrade_110() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   624
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   625
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
	// Set user_nicename.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
	$users = $wpdb->get_results("SELECT ID, user_nickname, user_nicename FROM $wpdb->users");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
	foreach ($users as $user) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
		if ('' == $user->user_nicename) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
			$newname = sanitize_title($user->user_nickname);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
			$wpdb->update( $wpdb->users, array('user_nicename' => $newname), array('ID' => $user->ID) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
	$users = $wpdb->get_results("SELECT ID, user_pass from $wpdb->users");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   636
	foreach ($users as $row) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   637
		if (!preg_match('/^[A-Fa-f0-9]{32}$/', $row->user_pass)) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   638
			$wpdb->update( $wpdb->users, array('user_pass' => md5($row->user_pass)), array('ID' => $row->ID) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   639
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
	// Get the GMT offset, we'll use that later on
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
	$all_options = get_alloptions_110();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
	$time_difference = $all_options->time_difference;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
		$server_time = time()+date('Z');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
	$weblogger_time = $server_time + $time_difference * HOUR_IN_SECONDS;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   649
	$gmt_time = time();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   650
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   651
	$diff_gmt_server = ($gmt_time - $server_time) / HOUR_IN_SECONDS;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   652
	$diff_weblogger_server = ($weblogger_time - $server_time) / HOUR_IN_SECONDS;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
	$diff_gmt_weblogger = $diff_gmt_server - $diff_weblogger_server;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
	$gmt_offset = -$diff_gmt_weblogger;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   655
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
	// Add a gmt_offset option, with value $gmt_offset
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
	add_option('gmt_offset', $gmt_offset);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
	// Check if we already set the GMT fields (if we did, then
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
	// MAX(post_date_gmt) can't be '0000-00-00 00:00:00'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
	// <michel_v> I just slapped myself silly for not thinking about it earlier
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
	$got_gmt_fields = ! ($wpdb->get_var("SELECT MAX(post_date_gmt) FROM $wpdb->posts") == '0000-00-00 00:00:00');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
	if (!$got_gmt_fields) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
		// Add or subtract time to all dates, to get GMT dates
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
		$add_hours = intval($diff_gmt_weblogger);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
		$add_minutes = intval(60 * ($diff_gmt_weblogger - $add_hours));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
		$wpdb->query("UPDATE $wpdb->posts SET post_date_gmt = DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   670
		$wpdb->query("UPDATE $wpdb->posts SET post_modified = post_date");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
		$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'");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
		$wpdb->query("UPDATE $wpdb->comments SET comment_date_gmt = DATE_ADD(comment_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
		$wpdb->query("UPDATE $wpdb->users SET user_registered = DATE_ADD(user_registered, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   676
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   677
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   678
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   679
 * Execute changes made in WordPress 1.5.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   680
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   681
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   682
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   683
function upgrade_130() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
	// Remove extraneous backslashes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
	$posts = $wpdb->get_results("SELECT ID, post_title, post_content, post_excerpt, guid, post_date, post_name, post_status, post_author FROM $wpdb->posts");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
	if ($posts) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
		foreach($posts as $post) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   690
			$post_content = addslashes(deslash($post->post_content));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   691
			$post_title = addslashes(deslash($post->post_title));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
			$post_excerpt = addslashes(deslash($post->post_excerpt));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
			if ( empty($post->guid) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
				$guid = get_permalink($post->ID);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   695
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
				$guid = $post->guid;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   697
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
			$wpdb->update( $wpdb->posts, compact('post_title', 'post_content', 'post_excerpt', 'guid'), array('ID' => $post->ID) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
	// Remove extraneous backslashes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
	$comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_content FROM $wpdb->comments");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
	if ($comments) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
		foreach($comments as $comment) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
			$comment_content = deslash($comment->comment_content);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
			$comment_author = deslash($comment->comment_author);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
			$wpdb->update($wpdb->comments, compact('comment_content', 'comment_author'), array('comment_ID' => $comment->comment_ID) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   714
	// Remove extraneous backslashes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
	$links = $wpdb->get_results("SELECT link_id, link_name, link_description FROM $wpdb->links");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   716
	if ($links) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   717
		foreach($links as $link) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   718
			$link_name = deslash($link->link_name);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   719
			$link_description = deslash($link->link_description);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   720
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   721
			$wpdb->update( $wpdb->links, compact('link_name', 'link_description'), array('link_id' => $link->link_id) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   722
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   723
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   724
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   725
	$active_plugins = __get_option('active_plugins');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   726
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   727
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   728
	 * If plugins are not stored in an array, they're stored in the old
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   729
	 * newline separated format. Convert to new format.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   730
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   731
	if ( !is_array( $active_plugins ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   732
		$active_plugins = explode("\n", trim($active_plugins));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   733
		update_option('active_plugins', $active_plugins);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   734
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   736
	// Obsolete tables
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   737
	$wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optionvalues');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   738
	$wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiontypes');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   739
	$wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroups');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
	$wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroup_options');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   741
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   742
	// Update comments table to use comment_type
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   743
	$wpdb->query("UPDATE $wpdb->comments SET comment_type='trackback', comment_content = REPLACE(comment_content, '<trackback />', '') WHERE comment_content LIKE '<trackback />%'");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   744
	$wpdb->query("UPDATE $wpdb->comments SET comment_type='pingback', comment_content = REPLACE(comment_content, '<pingback />', '') WHERE comment_content LIKE '<pingback />%'");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   745
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   746
	// Some versions have multiple duplicate option_name rows with the same values
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   747
	$options = $wpdb->get_results("SELECT option_name, COUNT(option_name) AS dupes FROM `$wpdb->options` GROUP BY option_name");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   748
	foreach ( $options as $option ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   749
		if ( 1 != $option->dupes ) { // Could this be done in the query?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   750
			$limit = $option->dupes - 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   751
			$dupe_ids = $wpdb->get_col( $wpdb->prepare("SELECT option_id FROM $wpdb->options WHERE option_name = %s LIMIT %d", $option->option_name, $limit) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   752
			if ( $dupe_ids ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   753
				$dupe_ids = join($dupe_ids, ',');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   754
				$wpdb->query("DELETE FROM $wpdb->options WHERE option_id IN ($dupe_ids)");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   755
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   756
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   757
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   758
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   759
	make_site_theme();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   760
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   761
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   762
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   763
 * Execute changes made in WordPress 2.0.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   764
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   765
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   766
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   767
function upgrade_160() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   768
	global $wpdb, $wp_current_db_version;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   769
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   770
	populate_roles_160();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   771
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   772
	$users = $wpdb->get_results("SELECT * FROM $wpdb->users");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   773
	foreach ( $users as $user ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   774
		if ( !empty( $user->user_firstname ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   775
			update_user_meta( $user->ID, 'first_name', wp_slash($user->user_firstname) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   776
		if ( !empty( $user->user_lastname ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   777
			update_user_meta( $user->ID, 'last_name', wp_slash($user->user_lastname) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   778
		if ( !empty( $user->user_nickname ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   779
			update_user_meta( $user->ID, 'nickname', wp_slash($user->user_nickname) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   780
		if ( !empty( $user->user_level ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   781
			update_user_meta( $user->ID, $wpdb->prefix . 'user_level', $user->user_level );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   782
		if ( !empty( $user->user_icq ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   783
			update_user_meta( $user->ID, 'icq', wp_slash($user->user_icq) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   784
		if ( !empty( $user->user_aim ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   785
			update_user_meta( $user->ID, 'aim', wp_slash($user->user_aim) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   786
		if ( !empty( $user->user_msn ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   787
			update_user_meta( $user->ID, 'msn', wp_slash($user->user_msn) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   788
		if ( !empty( $user->user_yim ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   789
			update_user_meta( $user->ID, 'yim', wp_slash($user->user_icq) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   790
		if ( !empty( $user->user_description ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   791
			update_user_meta( $user->ID, 'description', wp_slash($user->user_description) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   792
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   793
		if ( isset( $user->user_idmode ) ):
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   794
			$idmode = $user->user_idmode;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   795
			if ($idmode == 'nickname') $id = $user->user_nickname;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   796
			if ($idmode == 'login') $id = $user->user_login;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   797
			if ($idmode == 'firstname') $id = $user->user_firstname;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   798
			if ($idmode == 'lastname') $id = $user->user_lastname;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   799
			if ($idmode == 'namefl') $id = $user->user_firstname.' '.$user->user_lastname;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   800
			if ($idmode == 'namelf') $id = $user->user_lastname.' '.$user->user_firstname;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   801
			if (!$idmode) $id = $user->user_nickname;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   802
			$wpdb->update( $wpdb->users, array('display_name' => $id), array('ID' => $user->ID) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   803
		endif;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   804
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   805
		// FIXME: RESET_CAPS is temporary code to reset roles and caps if flag is set.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   806
		$caps = get_user_meta( $user->ID, $wpdb->prefix . 'capabilities');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   807
		if ( empty($caps) || defined('RESET_CAPS') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   808
			$level = get_user_meta($user->ID, $wpdb->prefix . 'user_level', true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   809
			$role = translate_level_to_role($level);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   810
			update_user_meta( $user->ID, $wpdb->prefix . 'capabilities', array($role => true) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   811
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   812
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   813
	endforeach;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   814
	$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' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   815
	$wpdb->hide_errors();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   816
	foreach ( $old_user_fields as $old )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   817
		$wpdb->query("ALTER TABLE $wpdb->users DROP $old");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   818
	$wpdb->show_errors();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   819
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   820
	// Populate comment_count field of posts table.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   821
	$comments = $wpdb->get_results( "SELECT comment_post_ID, COUNT(*) as c FROM $wpdb->comments WHERE comment_approved = '1' GROUP BY comment_post_ID" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   822
	if ( is_array( $comments ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   823
		foreach ($comments as $comment)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   824
			$wpdb->update( $wpdb->posts, array('comment_count' => $comment->c), array('ID' => $comment->comment_post_ID) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   825
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   826
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   827
	 * Some alpha versions used a post status of object instead of attachment
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   828
	 * and put the mime type in post_type instead of post_mime_type.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   829
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   830
	if ( $wp_current_db_version > 2541 && $wp_current_db_version <= 3091 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   831
		$objects = $wpdb->get_results("SELECT ID, post_type FROM $wpdb->posts WHERE post_status = 'object'");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   832
		foreach ($objects as $object) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   833
			$wpdb->update( $wpdb->posts, array(	'post_status' => 'attachment',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   834
												'post_mime_type' => $object->post_type,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   835
												'post_type' => ''),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   836
										 array( 'ID' => $object->ID ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   837
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   838
			$meta = get_post_meta($object->ID, 'imagedata', true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   839
			if ( ! empty($meta['file']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   840
				update_attached_file( $object->ID, $meta['file'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   841
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   842
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   843
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   844
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   845
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   846
 * Execute changes made in WordPress 2.1.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   847
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   848
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   849
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   850
function upgrade_210() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   851
	global $wpdb, $wp_current_db_version;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   852
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   853
	if ( $wp_current_db_version < 3506 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   854
		// Update status and type.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   855
		$posts = $wpdb->get_results("SELECT ID, post_status FROM $wpdb->posts");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   856
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   857
		if ( ! empty($posts) ) foreach ($posts as $post) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   858
			$status = $post->post_status;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   859
			$type = 'post';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   860
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   861
			if ( 'static' == $status ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   862
				$status = 'publish';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   863
				$type = 'page';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   864
			} elseif ( 'attachment' == $status ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   865
				$status = 'inherit';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   866
				$type = 'attachment';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   867
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   868
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   869
			$wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_status = %s, post_type = %s WHERE ID = %d", $status, $type, $post->ID) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   870
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   871
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   872
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   873
	if ( $wp_current_db_version < 3845 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   874
		populate_roles_210();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   875
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   876
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   877
	if ( $wp_current_db_version < 3531 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   878
		// Give future posts a post_status of future.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   879
		$now = gmdate('Y-m-d H:i:59');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   880
		$wpdb->query ("UPDATE $wpdb->posts SET post_status = 'future' WHERE post_status = 'publish' AND post_date_gmt > '$now'");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   881
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   882
		$posts = $wpdb->get_results("SELECT ID, post_date FROM $wpdb->posts WHERE post_status ='future'");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   883
		if ( !empty($posts) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   884
			foreach ( $posts as $post )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   885
				wp_schedule_single_event(mysql2date('U', $post->post_date, false), 'publish_future_post', array($post->ID));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   886
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   887
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   888
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   889
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   890
 * Execute changes made in WordPress 2.3.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   891
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   892
 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   893
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   894
function upgrade_230() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   895
	global $wp_current_db_version, $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   896
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   897
	if ( $wp_current_db_version < 5200 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   898
		populate_roles_230();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   899
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   900
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   901
	// Convert categories to terms.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   902
	$tt_ids = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   903
	$have_tags = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   904
	$categories = $wpdb->get_results("SELECT * FROM $wpdb->categories ORDER BY cat_ID");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   905
	foreach ($categories as $category) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   906
		$term_id = (int) $category->cat_ID;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   907
		$name = $category->cat_name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   908
		$description = $category->category_description;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   909
		$slug = $category->category_nicename;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   910
		$parent = $category->category_parent;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   911
		$term_group = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   912
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   913
		// Associate terms with the same slug in a term group and make slugs unique.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   914
		if ( $exists = $wpdb->get_results( $wpdb->prepare("SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $slug) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   915
			$term_group = $exists[0]->term_group;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   916
			$id = $exists[0]->term_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   917
			$num = 2;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   918
			do {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   919
				$alt_slug = $slug . "-$num";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   920
				$num++;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   921
				$slug_check = $wpdb->get_var( $wpdb->prepare("SELECT slug FROM $wpdb->terms WHERE slug = %s", $alt_slug) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   922
			} while ( $slug_check );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   923
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   924
			$slug = $alt_slug;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   925
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   926
			if ( empty( $term_group ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   927
				$term_group = $wpdb->get_var("SELECT MAX(term_group) FROM $wpdb->terms GROUP BY term_group") + 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   928
				$wpdb->query( $wpdb->prepare("UPDATE $wpdb->terms SET term_group = %d WHERE term_id = %d", $term_group, $id) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   929
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   930
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   931
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   932
		$wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->terms (term_id, name, slug, term_group) VALUES
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   933
		(%d, %s, %s, %d)", $term_id, $name, $slug, $term_group) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   934
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   935
		$count = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   936
		if ( !empty($category->category_count) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   937
			$count = (int) $category->category_count;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   938
			$taxonomy = 'category';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   939
			$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) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   940
			$tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   941
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   942
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   943
		if ( !empty($category->link_count) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   944
			$count = (int) $category->link_count;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   945
			$taxonomy = 'link_category';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   946
			$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) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   947
			$tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   948
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   949
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   950
		if ( !empty($category->tag_count) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   951
			$have_tags = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   952
			$count = (int) $category->tag_count;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   953
			$taxonomy = 'post_tag';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   954
			$wpdb->insert( $wpdb->term_taxonomy, compact('term_id', 'taxonomy', 'description', 'parent', 'count') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   955
			$tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   956
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   957
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   958
		if ( empty($count) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   959
			$count = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   960
			$taxonomy = 'category';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   961
			$wpdb->insert( $wpdb->term_taxonomy, compact('term_id', 'taxonomy', 'description', 'parent', 'count') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   962
			$tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   963
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   964
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   965
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   966
	$select = 'post_id, category_id';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   967
	if ( $have_tags )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   968
		$select .= ', rel_type';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   969
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   970
	$posts = $wpdb->get_results("SELECT $select FROM $wpdb->post2cat GROUP BY post_id, category_id");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   971
	foreach ( $posts as $post ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   972
		$post_id = (int) $post->post_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   973
		$term_id = (int) $post->category_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   974
		$taxonomy = 'category';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   975
		if ( !empty($post->rel_type) && 'tag' == $post->rel_type)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   976
			$taxonomy = 'tag';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   977
		$tt_id = $tt_ids[$term_id][$taxonomy];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   978
		if ( empty($tt_id) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   979
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   980
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   981
		$wpdb->insert( $wpdb->term_relationships, array('object_id' => $post_id, 'term_taxonomy_id' => $tt_id) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   982
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   983
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   984
	// < 3570 we used linkcategories. >= 3570 we used categories and link2cat.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   985
	if ( $wp_current_db_version < 3570 ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   986
		/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   987
		 * Create link_category terms for link categories. Create a map of link
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   988
		 * cat IDs to link_category terms.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   989
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   990
		$link_cat_id_map = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   991
		$default_link_cat = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   992
		$tt_ids = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   993
		$link_cats = $wpdb->get_results("SELECT cat_id, cat_name FROM " . $wpdb->prefix . 'linkcategories');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   994
		foreach ( $link_cats as $category) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   995
			$cat_id = (int) $category->cat_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   996
			$term_id = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   997
			$name = wp_slash($category->cat_name);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   998
			$slug = sanitize_title($name);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   999
			$term_group = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1000
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1001
			// Associate terms with the same slug in a term group and make slugs unique.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1002
			if ( $exists = $wpdb->get_results( $wpdb->prepare("SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $slug) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1003
				$term_group = $exists[0]->term_group;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1004
				$term_id = $exists[0]->term_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1005
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1006
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1007
			if ( empty($term_id) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1008
				$wpdb->insert( $wpdb->terms, compact('name', 'slug', 'term_group') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1009
				$term_id = (int) $wpdb->insert_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1010
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1011
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1012
			$link_cat_id_map[$cat_id] = $term_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1013
			$default_link_cat = $term_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1014
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1015
			$wpdb->insert( $wpdb->term_taxonomy, array('term_id' => $term_id, 'taxonomy' => 'link_category', 'description' => '', 'parent' => 0, 'count' => 0) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1016
			$tt_ids[$term_id] = (int) $wpdb->insert_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1017
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1018
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1019
		// Associate links to cats.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1020
		$links = $wpdb->get_results("SELECT link_id, link_category FROM $wpdb->links");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1021
		if ( !empty($links) ) foreach ( $links as $link ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1022
			if ( 0 == $link->link_category )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1023
				continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1024
			if ( ! isset($link_cat_id_map[$link->link_category]) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1025
				continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1026
			$term_id = $link_cat_id_map[$link->link_category];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1027
			$tt_id = $tt_ids[$term_id];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1028
			if ( empty($tt_id) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1029
				continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1030
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1031
			$wpdb->insert( $wpdb->term_relationships, array('object_id' => $link->link_id, 'term_taxonomy_id' => $tt_id) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1032
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1033
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1034
		// Set default to the last category we grabbed during the upgrade loop.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1035
		update_option('default_link_category', $default_link_cat);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1036
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1037
		$links = $wpdb->get_results("SELECT link_id, category_id FROM $wpdb->link2cat GROUP BY link_id, category_id");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1038
		foreach ( $links as $link ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1039
			$link_id = (int) $link->link_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1040
			$term_id = (int) $link->category_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1041
			$taxonomy = 'link_category';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1042
			$tt_id = $tt_ids[$term_id][$taxonomy];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1043
			if ( empty($tt_id) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1044
				continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1045
			$wpdb->insert( $wpdb->term_relationships, array('object_id' => $link_id, 'term_taxonomy_id' => $tt_id) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1046
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1047
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1048
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1049
	if ( $wp_current_db_version < 4772 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1050
		// Obsolete linkcategories table
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1051
		$wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'linkcategories');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1052
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1053
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1054
	// Recalculate all counts
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1055
	$terms = $wpdb->get_results("SELECT term_taxonomy_id, taxonomy FROM $wpdb->term_taxonomy");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1056
	foreach ( (array) $terms as $term ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1057
		if ( ('post_tag' == $term->taxonomy) || ('category' == $term->taxonomy) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1058
			$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) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1059
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1060
			$count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term->term_taxonomy_id) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1061
		$wpdb->update( $wpdb->term_taxonomy, array('count' => $count), array('term_taxonomy_id' => $term->term_taxonomy_id) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1062
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1063
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1064
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1065
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1066
 * Remove old options from the database.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1067
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1068
 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1069
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1070
function upgrade_230_options_table() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1071
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1072
	$old_options_fields = array( 'option_can_override', 'option_type', 'option_width', 'option_height', 'option_description', 'option_admin_level' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1073
	$wpdb->hide_errors();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1074
	foreach ( $old_options_fields as $old )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1075
		$wpdb->query("ALTER TABLE $wpdb->options DROP $old");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1076
	$wpdb->show_errors();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1077
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1078
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1079
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1080
 * Remove old categories, link2cat, and post2cat database tables.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1081
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1082
 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1083
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1084
function upgrade_230_old_tables() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1085
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1086
	$wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'categories');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1087
	$wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'link2cat');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1088
	$wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'post2cat');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1089
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1090
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1091
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1092
 * Upgrade old slugs made in version 2.2.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1093
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1094
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1095
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1096
function upgrade_old_slugs() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1097
	// Upgrade people who were using the Redirect Old Slugs plugin.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1098
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1099
	$wpdb->query("UPDATE $wpdb->postmeta SET meta_key = '_wp_old_slug' WHERE meta_key = 'old_slug'");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1100
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1101
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1102
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1103
 * Execute changes made in WordPress 2.5.0.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1104
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1105
 * @since 2.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1106
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1107
function upgrade_250() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1108
	global $wp_current_db_version;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1109
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1110
	if ( $wp_current_db_version < 6689 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1111
		populate_roles_250();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1112
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1113
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1114
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1115
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1116
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1117
 * Execute changes made in WordPress 2.5.2.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1118
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1119
 * @since 2.5.2
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1120
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1121
function upgrade_252() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1122
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1123
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1124
	$wpdb->query("UPDATE $wpdb->users SET user_activation_key = ''");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1125
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1126
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1127
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1128
 * Execute changes made in WordPress 2.6.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1129
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1130
 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1131
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1132
function upgrade_260() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1133
	global $wp_current_db_version;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1134
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1135
	if ( $wp_current_db_version < 8000 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1136
		populate_roles_260();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1137
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1138
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1139
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1140
 * Execute changes made in WordPress 2.7.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1141
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1142
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1143
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1144
function upgrade_270() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1145
	global $wpdb, $wp_current_db_version;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1146
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1147
	if ( $wp_current_db_version < 8980 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1148
		populate_roles_270();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1149
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1150
	// Update post_date for unpublished posts with empty timestamp
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1151
	if ( $wp_current_db_version < 8921 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1152
		$wpdb->query( "UPDATE $wpdb->posts SET post_date = post_modified WHERE post_date = '0000-00-00 00:00:00'" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1153
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1154
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1155
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1156
 * Execute changes made in WordPress 2.8.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1157
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1158
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1159
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1160
function upgrade_280() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1161
	global $wp_current_db_version, $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1162
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1163
	if ( $wp_current_db_version < 10360 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1164
		populate_roles_280();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1165
	if ( is_multisite() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1166
		$start = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1167
		while( $rows = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options ORDER BY option_id LIMIT $start, 20" ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1168
			foreach( $rows as $row ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1169
				$value = $row->option_value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1170
				if ( !@unserialize( $value ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1171
					$value = stripslashes( $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1172
				if ( $value !== $row->option_value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1173
					update_option( $row->option_name, $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1174
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1175
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1176
			$start += 20;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1177
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1178
		refresh_blog_details( $wpdb->blogid );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1179
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1180
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1181
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1182
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1183
 * Execute changes made in WordPress 2.9.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1184
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1185
 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1186
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1187
function upgrade_290() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1188
	global $wp_current_db_version;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1189
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1190
	if ( $wp_current_db_version < 11958 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1191
		// Previously, setting depth to 1 would redundantly disable threading, but now 2 is the minimum depth to avoid confusion
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1192
		if ( get_option( 'thread_comments_depth' ) == '1' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1193
			update_option( 'thread_comments_depth', 2 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1194
			update_option( 'thread_comments', 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1195
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1196
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1197
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1198
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1199
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1200
 * Execute changes made in WordPress 3.0.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1201
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1202
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1203
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1204
function upgrade_300() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1205
	global $wp_current_db_version, $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1206
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1207
	if ( $wp_current_db_version < 15093 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1208
		populate_roles_300();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1209
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1210
	if ( $wp_current_db_version < 14139 && is_multisite() && is_main_site() && ! defined( 'MULTISITE' ) && get_site_option( 'siteurl' ) === false )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1211
		add_site_option( 'siteurl', '' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1212
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1213
	// 3.0 screen options key name changes.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1214
	if ( is_main_site() && !defined('DO_NOT_UPGRADE_GLOBAL_TABLES') ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1215
		$sql = "DELETE FROM $wpdb->usermeta
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1216
			WHERE meta_key LIKE %s
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1217
			OR meta_key LIKE %s
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1218
			OR meta_key LIKE %s
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1219
			OR meta_key LIKE %s
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1220
			OR meta_key LIKE %s
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1221
			OR meta_key LIKE %s
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1222
			OR meta_key = 'manageedittagscolumnshidden'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1223
			OR meta_key = 'managecategoriescolumnshidden'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1224
			OR meta_key = 'manageedit-tagscolumnshidden'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1225
			OR meta_key = 'manageeditcolumnshidden'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1226
			OR meta_key = 'categories_per_page'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1227
			OR meta_key = 'edit_tags_per_page'";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1228
		$prefix = $wpdb->esc_like( $wpdb->base_prefix );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1229
		$wpdb->query( $wpdb->prepare( $sql,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1230
			$prefix . '%' . $wpdb->esc_like( 'meta-box-hidden' ) . '%',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1231
			$prefix . '%' . $wpdb->esc_like( 'closedpostboxes' ) . '%',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1232
			$prefix . '%' . $wpdb->esc_like( 'manage-'	   ) . '%' . $wpdb->esc_like( '-columns-hidden' ) . '%',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1233
			$prefix . '%' . $wpdb->esc_like( 'meta-box-order'  ) . '%',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1234
			$prefix . '%' . $wpdb->esc_like( 'metaboxorder'    ) . '%',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1235
			$prefix . '%' . $wpdb->esc_like( 'screen_layout'   ) . '%'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1236
		) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1237
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1238
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1239
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1240
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1241
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1242
 * Execute changes made in WordPress 3.3.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1243
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1244
 * @since 3.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1245
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1246
function upgrade_330() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1247
	global $wp_current_db_version, $wpdb, $wp_registered_widgets, $sidebars_widgets;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1248
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1249
	if ( $wp_current_db_version < 19061 && is_main_site() && ! defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1250
		$wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key IN ('show_admin_bar_admin', 'plugins_last_view')" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1251
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1252
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1253
	if ( $wp_current_db_version >= 11548 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1254
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1255
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1256
	$sidebars_widgets = get_option( 'sidebars_widgets', array() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1257
	$_sidebars_widgets = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1258
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1259
	if ( isset($sidebars_widgets['wp_inactive_widgets']) || empty($sidebars_widgets) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1260
		$sidebars_widgets['array_version'] = 3;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1261
	elseif ( !isset($sidebars_widgets['array_version']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1262
		$sidebars_widgets['array_version'] = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1263
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1264
	switch ( $sidebars_widgets['array_version'] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1265
		case 1 :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1266
			foreach ( (array) $sidebars_widgets as $index => $sidebar )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1267
			if ( is_array($sidebar) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1268
			foreach ( (array) $sidebar as $i => $name ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1269
				$id = strtolower($name);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1270
				if ( isset($wp_registered_widgets[$id]) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1271
					$_sidebars_widgets[$index][$i] = $id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1272
					continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1273
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1274
				$id = sanitize_title($name);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1275
				if ( isset($wp_registered_widgets[$id]) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1276
					$_sidebars_widgets[$index][$i] = $id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1277
					continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1278
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1279
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1280
				$found = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1281
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1282
				foreach ( $wp_registered_widgets as $widget_id => $widget ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1283
					if ( strtolower($widget['name']) == strtolower($name) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1284
						$_sidebars_widgets[$index][$i] = $widget['id'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1285
						$found = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1286
						break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1287
					} elseif ( sanitize_title($widget['name']) == sanitize_title($name) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1288
						$_sidebars_widgets[$index][$i] = $widget['id'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1289
						$found = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1290
						break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1291
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1292
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1293
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1294
				if ( $found )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1295
					continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1296
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1297
				unset($_sidebars_widgets[$index][$i]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1298
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1299
			$_sidebars_widgets['array_version'] = 2;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1300
			$sidebars_widgets = $_sidebars_widgets;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1301
			unset($_sidebars_widgets);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1302
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1303
		case 2 :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1304
			$sidebars_widgets = retrieve_widgets();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1305
			$sidebars_widgets['array_version'] = 3;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1306
			update_option( 'sidebars_widgets', $sidebars_widgets );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1307
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1308
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1309
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1310
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1311
 * Execute changes made in WordPress 3.4.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1312
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1313
 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1314
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1315
function upgrade_340() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1316
	global $wp_current_db_version, $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1317
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1318
	if ( $wp_current_db_version < 19798 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1319
		$wpdb->hide_errors();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1320
		$wpdb->query( "ALTER TABLE $wpdb->options DROP COLUMN blog_id" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1321
		$wpdb->show_errors();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1322
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1323
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1324
	if ( $wp_current_db_version < 19799 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1325
		$wpdb->hide_errors();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1326
		$wpdb->query("ALTER TABLE $wpdb->comments DROP INDEX comment_approved");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1327
		$wpdb->show_errors();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1328
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1329
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1330
	if ( $wp_current_db_version < 20022 && is_main_site() && ! defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1331
		$wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key = 'themes_last_view'" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1332
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1333
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1334
	if ( $wp_current_db_version < 20080 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1335
		if ( 'yes' == $wpdb->get_var( "SELECT autoload FROM $wpdb->options WHERE option_name = 'uninstall_plugins'" ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1336
			$uninstall_plugins = get_option( 'uninstall_plugins' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1337
			delete_option( 'uninstall_plugins' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1338
			add_option( 'uninstall_plugins', $uninstall_plugins, null, 'no' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1339
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1340
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1341
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1342
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1343
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1344
 * Execute changes made in WordPress 3.5.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1345
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1346
 * @since 3.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1347
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1348
function upgrade_350() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1349
	global $wp_current_db_version, $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1350
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1351
	if ( $wp_current_db_version < 22006 && $wpdb->get_var( "SELECT link_id FROM $wpdb->links LIMIT 1" ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1352
		update_option( 'link_manager_enabled', 1 ); // Previously set to 0 by populate_options()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1353
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1354
	if ( $wp_current_db_version < 21811 && is_main_site() && ! defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1355
		$meta_keys = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1356
		foreach ( array_merge( get_post_types(), get_taxonomies() ) as $name ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1357
			if ( false !== strpos( $name, '-' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1358
			$meta_keys[] = 'edit_' . str_replace( '-', '_', $name ) . '_per_page';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1359
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1360
		if ( $meta_keys ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1361
			$meta_keys = implode( "', '", $meta_keys );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1362
			$wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key IN ('$meta_keys')" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1363
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1364
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1365
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1366
	if ( $wp_current_db_version < 22422 && $term = get_term_by( 'slug', 'post-format-standard', 'post_format' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1367
		wp_delete_term( $term->term_id, 'post_format' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1368
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1369
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1370
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1371
 * Execute changes made in WordPress 3.7.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1372
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1373
 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1374
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1375
function upgrade_370() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1376
	global $wp_current_db_version;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1377
	if ( $wp_current_db_version < 25824 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1378
		wp_clear_scheduled_hook( 'wp_auto_updates_maybe_update' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1379
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1380
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1381
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1382
 * Execute changes made in WordPress 3.7.2.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1383
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1384
 * @since 3.7.2
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1385
 * @since 3.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1386
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1387
function upgrade_372() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1388
	global $wp_current_db_version;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1389
	if ( $wp_current_db_version < 26148 )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1390
		wp_clear_scheduled_hook( 'wp_maybe_auto_update' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1391
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1392
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1393
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1394
 * Execute changes made in WordPress 3.8.0.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1395
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1396
 * @since 3.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1397
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1398
function upgrade_380() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1399
	global $wp_current_db_version;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1400
	if ( $wp_current_db_version < 26691 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1401
		deactivate_plugins( array( 'mp6/mp6.php' ), true );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1402
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1403
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1404
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1405
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1406
 * Execute changes made in WordPress 4.0.0.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1407
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1408
 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1409
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1410
function upgrade_400() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1411
	global $wp_current_db_version;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1412
	if ( $wp_current_db_version < 29630 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1413
		if ( ! is_multisite() && false === get_option( 'WPLANG' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1414
			if ( defined( 'WPLANG' ) && ( '' !== WPLANG ) && in_array( WPLANG, get_available_languages() ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1415
				update_option( 'WPLANG', WPLANG );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1416
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1417
				update_option( 'WPLANG', '' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1418
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1419
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1420
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1421
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1422
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1423
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1424
 * Execute changes made in WordPress 4.2.0.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1425
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1426
 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1427
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1428
function upgrade_420() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1429
	global $wp_current_db_version, $wpdb;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1430
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1431
	if ( $wp_current_db_version < 31351 && $wpdb->charset === 'utf8mb4' ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1432
		if ( is_multisite() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1433
			$tables = $wpdb->tables( 'blog' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1434
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1435
			$tables = $wpdb->tables( 'all' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1436
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1437
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1438
		foreach ( $tables as $table ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1439
			maybe_convert_table_to_utf8mb4( $table );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1440
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1441
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1442
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1443
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1444
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1445
 * Execute changes made in WordPress 4.2.1.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1446
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1447
 * @since 4.2.1
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1448
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1449
function upgrade_421() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1450
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1451
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1452
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1453
 * Execute changes made in WordPress 4.2.2.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1454
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1455
 * @since 4.2.2
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1456
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1457
function upgrade_422() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1458
	global $wp_current_db_version, $wpdb;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1459
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1460
	if ( $wp_current_db_version < 31534 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1461
		$content_length = $wpdb->get_col_length( $wpdb->comments, 'comment_content' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1462
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1463
		if ( is_wp_error( $content_length ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1464
			return;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1465
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1466
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1467
		if ( false === $content_length ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1468
			$content_length = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1469
				'type'   => 'byte',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1470
				'length' => 65535,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1471
			);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1472
		} elseif ( ! is_array( $content_length ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1473
			$length = (int) $content_length > 0 ? (int) $content_length : 65535;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1474
			$content_length = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1475
				'type'	 => 'byte',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1476
				'length' => $length
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1477
			);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1478
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1479
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1480
		if ( 'byte' !== $content_length['type'] || 0 === $content_length['length'] ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1481
			// Sites with malformed DB schemas are on their own.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1482
			return;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1483
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1484
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1485
		$allowed_length = intval( $content_length['length'] ) - 10;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1486
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1487
		$comments = $wpdb->get_results(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1488
			"SELECT `comment_ID` FROM `{$wpdb->comments}`
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1489
				WHERE `comment_date_gmt` > '2015-04-26'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1490
				AND LENGTH( `comment_content` ) >= {$allowed_length}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1491
				AND ( `comment_content` LIKE '%<%' OR `comment_content` LIKE '%>%' )"
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1492
		);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1493
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1494
		foreach ( $comments as $comment ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1495
			wp_delete_comment( $comment->comment_ID, true );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1496
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1497
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1498
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1499
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1500
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1501
 * Executes network-level upgrade routines.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1502
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1503
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1504
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1505
function upgrade_network() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1506
	global $wp_current_db_version, $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1507
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1508
	// Always.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1509
	if ( is_main_network() ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1510
		/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1511
		 * Deletes all expired transients. The multi-table delete syntax is used
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1512
		 * to delete the transient record from table a, and the corresponding
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1513
		 * transient_timeout record from table b.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1514
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1515
		$time = time();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1516
		$sql = "DELETE a, b FROM $wpdb->sitemeta a, $wpdb->sitemeta b
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1517
			WHERE a.meta_key LIKE %s
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1518
			AND a.meta_key NOT LIKE %s
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1519
			AND b.meta_key = CONCAT( '_site_transient_timeout_', SUBSTRING( a.meta_key, 17 ) )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1520
			AND b.meta_value < %d";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1521
		$wpdb->query( $wpdb->prepare( $sql, $wpdb->esc_like( '_site_transient_' ) . '%', $wpdb->esc_like ( '_site_transient_timeout_' ) . '%', $time ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1522
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1523
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1524
	// 2.8.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1525
	if ( $wp_current_db_version < 11549 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1526
		$wpmu_sitewide_plugins = get_site_option( 'wpmu_sitewide_plugins' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1527
		$active_sitewide_plugins = get_site_option( 'active_sitewide_plugins' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1528
		if ( $wpmu_sitewide_plugins ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1529
			if ( !$active_sitewide_plugins )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1530
				$sitewide_plugins = (array) $wpmu_sitewide_plugins;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1531
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1532
				$sitewide_plugins = array_merge( (array) $active_sitewide_plugins, (array) $wpmu_sitewide_plugins );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1533
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1534
			update_site_option( 'active_sitewide_plugins', $sitewide_plugins );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1535
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1536
		delete_site_option( 'wpmu_sitewide_plugins' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1537
		delete_site_option( 'deactivated_sitewide_plugins' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1538
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1539
		$start = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1540
		while( $rows = $wpdb->get_results( "SELECT meta_key, meta_value FROM {$wpdb->sitemeta} ORDER BY meta_id LIMIT $start, 20" ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1541
			foreach( $rows as $row ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1542
				$value = $row->meta_value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1543
				if ( !@unserialize( $value ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1544
					$value = stripslashes( $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1545
				if ( $value !== $row->meta_value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1546
					update_site_option( $row->meta_key, $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1547
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1548
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1549
			$start += 20;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1550
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1551
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1552
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1553
	// 3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1554
	if ( $wp_current_db_version < 13576 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1555
		update_site_option( 'global_terms_enabled', '1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1556
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1557
	// 3.3
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1558
	if ( $wp_current_db_version < 19390 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1559
		update_site_option( 'initial_db_version', $wp_current_db_version );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1560
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1561
	if ( $wp_current_db_version < 19470 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1562
		if ( false === get_site_option( 'active_sitewide_plugins' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1563
			update_site_option( 'active_sitewide_plugins', array() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1564
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1565
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1566
	// 3.4
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1567
	if ( $wp_current_db_version < 20148 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1568
		// 'allowedthemes' keys things by stylesheet. 'allowed_themes' keyed things by name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1569
		$allowedthemes  = get_site_option( 'allowedthemes'  );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1570
		$allowed_themes = get_site_option( 'allowed_themes' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1571
		if ( false === $allowedthemes && is_array( $allowed_themes ) && $allowed_themes ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1572
			$converted = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1573
			$themes = wp_get_themes();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1574
			foreach ( $themes as $stylesheet => $theme_data ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1575
				if ( isset( $allowed_themes[ $theme_data->get('Name') ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1576
					$converted[ $stylesheet ] = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1577
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1578
			update_site_option( 'allowedthemes', $converted );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1579
			delete_site_option( 'allowed_themes' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1580
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1581
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1582
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1583
	// 3.5
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1584
	if ( $wp_current_db_version < 21823 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1585
		update_site_option( 'ms_files_rewriting', '1' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1586
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1587
	// 3.5.2
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1588
	if ( $wp_current_db_version < 24448 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1589
		$illegal_names = get_site_option( 'illegal_names' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1590
		if ( is_array( $illegal_names ) && count( $illegal_names ) === 1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1591
			$illegal_name = reset( $illegal_names );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1592
			$illegal_names = explode( ' ', $illegal_name );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1593
			update_site_option( 'illegal_names', $illegal_names );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1594
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1595
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1596
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1597
	// 4.2
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1598
	if ( $wp_current_db_version < 31351 && $wpdb->charset === 'utf8mb4' ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1599
		if ( ! ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) && DO_NOT_UPGRADE_GLOBAL_TABLES ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1600
			$wpdb->query( "ALTER TABLE $wpdb->usermeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1601
			$wpdb->query( "ALTER TABLE $wpdb->site DROP INDEX domain, ADD INDEX domain(domain(140),path(51))" );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1602
			$wpdb->query( "ALTER TABLE $wpdb->sitemeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1603
			$wpdb->query( "ALTER TABLE $wpdb->signups DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))" );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1604
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1605
			$tables = $wpdb->tables( 'global' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1606
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1607
			foreach ( $tables as $table ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1608
				maybe_convert_table_to_utf8mb4( $table );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1609
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1610
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1611
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1612
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1613
	// 4.2.2
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1614
	if ( $wp_current_db_version < 31535 && 'utf8mb4' === $wpdb->charset ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1615
		if ( ! ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) && DO_NOT_UPGRADE_GLOBAL_TABLES ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1616
			$upgrade = false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1617
			$indexes = $wpdb->get_results( "SHOW INDEXES FROM $wpdb->signups" );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1618
			foreach( $indexes as $index ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1619
				if ( 'domain_path' == $index->Key_name && 'domain' == $index->Column_name && 140 != $index->Sub_part ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1620
					$upgrade = true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1621
					break;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1622
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1623
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1624
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1625
			if ( $upgrade ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1626
				$wpdb->query( "ALTER TABLE $wpdb->signups DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))" );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1627
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1628
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1629
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1630
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1631
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1632
//
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1633
// General functions we use to actually do stuff
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1634
//
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1635
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1636
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1637
 * Creates a table in the database if it doesn't already exist.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1638
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1639
 * This method checks for an existing database and creates a new one if it's not
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1640
 * already present. It doesn't rely on MySQL's "IF NOT EXISTS" statement, but chooses
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1641
 * to query all tables first and then run the SQL statement creating the table.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1642
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1643
 * @since 1.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1644
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1645
 * @param string $table_name Database table name to create.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1646
 * @param string $create_ddl SQL statement to create table.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1647
 * @return bool If table already exists or was created by function.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1648
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1649
function maybe_create_table($table_name, $create_ddl) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1650
	global $wpdb;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1651
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1652
	$query = $wpdb->prepare( "SHOW TABLES LIKE %s", $wpdb->esc_like( $table_name ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1653
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1654
	if ( $wpdb->get_var( $query ) == $table_name ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1655
		return true;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1656
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1657
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1658
	// Didn't find it try to create it..
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1659
	$wpdb->query($create_ddl);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1660
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1661
	// We cannot directly tell that whether this succeeded!
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1662
	if ( $wpdb->get_var( $query ) == $table_name ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1663
		return true;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1664
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1665
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1666
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1667
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1668
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1669
 * Drops a specified index from a table.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1670
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1671
 * @since 1.0.1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1672
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1673
 * @param string $table Database table name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1674
 * @param string $index Index name to drop.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1675
 * @return bool True, when finished.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1676
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1677
function drop_index($table, $index) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1678
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1679
	$wpdb->hide_errors();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1680
	$wpdb->query("ALTER TABLE `$table` DROP INDEX `$index`");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1681
	// Now we need to take out all the extra ones we may have created
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1682
	for ($i = 0; $i < 25; $i++) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1683
		$wpdb->query("ALTER TABLE `$table` DROP INDEX `{$index}_$i`");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1684
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1685
	$wpdb->show_errors();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1686
	return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1687
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1688
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1689
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1690
 * Adds an index to a specified table.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1691
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1692
 * @since 1.0.1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1693
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1694
 * @param string $table Database table name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1695
 * @param string $index Database table index column.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1696
 * @return bool True, when done with execution.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1697
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1698
function add_clean_index($table, $index) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1699
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1700
	drop_index($table, $index);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1701
	$wpdb->query("ALTER TABLE `$table` ADD INDEX ( `$index` )");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1702
	return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1703
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1704
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1705
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1706
 * Adds column to a database table if it doesn't already exist.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1707
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1708
 * @since 1.3.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1709
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1710
 * @param string $table_name  The table name to modify.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1711
 * @param string $column_name The column name to add to the table.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1712
 * @param string $create_ddl  The SQL statement used to add the column.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1713
 * @return True if already exists or on successful completion, false on error.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1714
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1715
function maybe_add_column($table_name, $column_name, $create_ddl) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1716
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1717
	foreach ($wpdb->get_col("DESC $table_name", 0) as $column ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1718
		if ($column == $column_name) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1719
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1720
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1721
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1722
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1723
	// Didn't find it try to create it.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1724
	$wpdb->query($create_ddl);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1725
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1726
	// We cannot directly tell that whether this succeeded!
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1727
	foreach ($wpdb->get_col("DESC $table_name", 0) as $column ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1728
		if ($column == $column_name) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1729
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1730
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1731
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1732
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1733
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1734
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1735
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1736
 * If a table only contains utf8 or utf8mb4 columns, convert it to utf8mb4.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1737
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1738
 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1739
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1740
 * @param string $table The table to convert.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1741
 * @return bool true if the table was converted, false if it wasn't.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1742
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1743
function maybe_convert_table_to_utf8mb4( $table ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1744
	global $wpdb;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1745
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1746
	$results = $wpdb->get_results( "SHOW FULL COLUMNS FROM `$table`" );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1747
	if ( ! $results ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1748
		return false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1749
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1750
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1751
	foreach ( $results as $column ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1752
		if ( $column->Collation ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1753
			list( $charset ) = explode( '_', $column->Collation );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1754
			$charset = strtolower( $charset );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1755
			if ( 'utf8' !== $charset && 'utf8mb4' !== $charset ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1756
				// Don't upgrade tables that have non-utf8 columns.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1757
				return false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1758
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1759
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1760
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1761
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1762
	return $wpdb->query( "ALTER TABLE $table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci" );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1763
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1764
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1765
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1766
 * Retrieve all options as it was for 1.2.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1767
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1768
 * @since 1.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1769
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1770
 * @return stdClass List of options.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1771
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1772
function get_alloptions_110() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1773
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1774
	$all_options = new stdClass;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1775
	if ( $options = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1776
		foreach ( $options as $option ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1777
			if ( 'siteurl' == $option->option_name || 'home' == $option->option_name || 'category_base' == $option->option_name )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1778
				$option->option_value = untrailingslashit( $option->option_value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1779
			$all_options->{$option->option_name} = stripslashes( $option->option_value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1780
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1781
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1782
	return $all_options;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1783
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1784
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1785
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1786
 * Utility version of get_option that is private to install/upgrade.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1787
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1788
 * @ignore
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1789
 * @since 1.5.1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1790
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1791
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1792
 * @param string $setting Option name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1793
 * @return mixed
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1794
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1795
function __get_option($setting) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1796
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1797
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1798
	if ( $setting == 'home' && defined( 'WP_HOME' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1799
		return untrailingslashit( WP_HOME );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1800
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1801
	if ( $setting == 'siteurl' && defined( 'WP_SITEURL' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1802
		return untrailingslashit( WP_SITEURL );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1803
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1804
	$option = $wpdb->get_var( $wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = %s", $setting ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1805
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1806
	if ( 'home' == $setting && '' == $option )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1807
		return __get_option( 'siteurl' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1808
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1809
	if ( 'siteurl' == $setting || 'home' == $setting || 'category_base' == $setting || 'tag_base' == $setting )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1810
		$option = untrailingslashit( $option );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1811
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1812
	return maybe_unserialize( $option );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1813
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1814
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1815
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1816
 * Filters for content to remove unnecessary slashes.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1817
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1818
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1819
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1820
 * @param string $content The content to modify.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1821
 * @return string The de-slashed content.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1822
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1823
function deslash($content) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1824
	// Note: \\\ inside a regex denotes a single backslash.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1825
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1826
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1827
	 * Replace one or more backslashes followed by a single quote with
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1828
	 * a single quote.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1829
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1830
	$content = preg_replace("/\\\+'/", "'", $content);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1831
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1832
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1833
	 * Replace one or more backslashes followed by a double quote with
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1834
	 * a double quote.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1835
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1836
	$content = preg_replace('/\\\+"/', '"', $content);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1837
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1838
	// Replace one or more backslashes with one backslash.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1839
	$content = preg_replace("/\\\+/", "\\", $content);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1840
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1841
	return $content;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1842
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1843
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1844
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1845
 * Modifies the database based on specified SQL statements.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1846
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1847
 * Useful for creating new tables and updating existing tables to a new structure.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1848
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1849
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1850
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1851
 * @param string|array $queries Optional. The query to run. Can be multiple queries
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1852
 *                              in an array, or a string of queries separated by
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1853
 *                              semicolons. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1854
 * @param bool         $execute Optional. Whether or not to execute the query right away.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1855
 *                              Default true.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1856
 * @return array Strings containing the results of the various update queries.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1857
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1858
function dbDelta( $queries = '', $execute = true ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1859
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1860
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1861
	if ( in_array( $queries, array( '', 'all', 'blog', 'global', 'ms_global' ), true ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1862
	    $queries = wp_get_db_schema( $queries );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1863
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1864
	// Separate individual queries into an array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1865
	if ( !is_array($queries) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1866
		$queries = explode( ';', $queries );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1867
		$queries = array_filter( $queries );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1868
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1869
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1870
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1871
	 * Filter the dbDelta SQL queries.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1872
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1873
	 * @since 3.3.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1874
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1875
	 * @param array $queries An array of dbDelta SQL queries.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1876
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1877
	$queries = apply_filters( 'dbdelta_queries', $queries );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1878
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1879
	$cqueries = array(); // Creation Queries
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1880
	$iqueries = array(); // Insertion Queries
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1881
	$for_update = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1882
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1883
	// Create a tablename index for an array ($cqueries) of queries
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1884
	foreach($queries as $qry) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1885
		if ( preg_match( "|CREATE TABLE ([^ ]*)|", $qry, $matches ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1886
			$cqueries[ trim( $matches[1], '`' ) ] = $qry;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1887
			$for_update[$matches[1]] = 'Created table '.$matches[1];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1888
		} elseif ( preg_match( "|CREATE DATABASE ([^ ]*)|", $qry, $matches ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1889
			array_unshift( $cqueries, $qry );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1890
		} elseif ( preg_match( "|INSERT INTO ([^ ]*)|", $qry, $matches ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1891
			$iqueries[] = $qry;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1892
		} elseif ( preg_match( "|UPDATE ([^ ]*)|", $qry, $matches ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1893
			$iqueries[] = $qry;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1894
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1895
			// Unrecognized query type
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1896
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1897
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1898
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1899
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1900
	 * Filter the dbDelta SQL queries for creating tables and/or databases.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1901
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1902
	 * Queries filterable via this hook contain "CREATE TABLE" or "CREATE DATABASE".
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1903
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1904
	 * @since 3.3.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1905
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1906
	 * @param array $cqueries An array of dbDelta create SQL queries.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1907
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1908
	$cqueries = apply_filters( 'dbdelta_create_queries', $cqueries );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1909
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1910
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1911
	 * Filter the dbDelta SQL queries for inserting or updating.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1912
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1913
	 * Queries filterable via this hook contain "INSERT INTO" or "UPDATE".
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1914
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1915
	 * @since 3.3.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1916
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1917
	 * @param array $iqueries An array of dbDelta insert or update SQL queries.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1918
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1919
	$iqueries = apply_filters( 'dbdelta_insert_queries', $iqueries );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1920
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1921
	$global_tables = $wpdb->tables( 'global' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1922
	foreach ( $cqueries as $table => $qry ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1923
		// Upgrade global tables only for the main site. Don't upgrade at all if DO_NOT_UPGRADE_GLOBAL_TABLES is defined.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1924
		if ( in_array( $table, $global_tables ) && ( !is_main_site() || defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1925
			unset( $cqueries[ $table ], $for_update[ $table ] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1926
			continue;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1927
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1928
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1929
		// Fetch the table column structure from the database
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1930
		$suppress = $wpdb->suppress_errors();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1931
		$tablefields = $wpdb->get_results("DESCRIBE {$table};");
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1932
		$wpdb->suppress_errors( $suppress );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1933
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1934
		if ( ! $tablefields )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1935
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1936
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1937
		// Clear the field and index arrays.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1938
		$cfields = $indices = array();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1939
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1940
		// Get all of the field names in the query from between the parentheses.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1941
		preg_match("|\((.*)\)|ms", $qry, $match2);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1942
		$qryline = trim($match2[1]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1943
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1944
		// Separate field lines into an array.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1945
		$flds = explode("\n", $qryline);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1946
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1947
		// todo: Remove this?
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1948
		//echo "<hr/><pre>\n".print_r(strtolower($table), true).":\n".print_r($cqueries, true)."</pre><hr/>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1949
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1950
		// For every field line specified in the query.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1951
		foreach ($flds as $fld) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1952
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1953
			// Extract the field name.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1954
			preg_match("|^([^ ]*)|", trim($fld), $fvals);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1955
			$fieldname = trim( $fvals[1], '`' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1956
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1957
			// Verify the found field name.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1958
			$validfield = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1959
			switch (strtolower($fieldname)) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1960
			case '':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1961
			case 'primary':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1962
			case 'index':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1963
			case 'fulltext':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1964
			case 'unique':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1965
			case 'key':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1966
				$validfield = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1967
				$indices[] = trim(trim($fld), ", \n");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1968
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1969
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1970
			$fld = trim($fld);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1971
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1972
			// If it's a valid field, add it to the field array.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1973
			if ($validfield) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1974
				$cfields[strtolower($fieldname)] = trim($fld, ", \n");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1975
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1976
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1977
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1978
		// For every field in the table.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1979
		foreach ($tablefields as $tablefield) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1980
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1981
			// If the table field exists in the field array ...
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1982
			if (array_key_exists(strtolower($tablefield->Field), $cfields)) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1983
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1984
				// Get the field type from the query.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1985
				preg_match("|".$tablefield->Field." ([^ ]*( unsigned)?)|i", $cfields[strtolower($tablefield->Field)], $matches);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1986
				$fieldtype = $matches[1];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1987
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1988
				// Is actual field type different from the field type in query?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1989
				if ($tablefield->Type != $fieldtype) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1990
					// Add a query to change the column type
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1991
					$cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN {$tablefield->Field} " . $cfields[strtolower($tablefield->Field)];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1992
					$for_update[$table.'.'.$tablefield->Field] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1993
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1994
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1995
				// Get the default value from the array
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1996
					// todo: Remove this?
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1997
					//echo "{$cfields[strtolower($tablefield->Field)]}<br>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1998
				if (preg_match("| DEFAULT '(.*?)'|i", $cfields[strtolower($tablefield->Field)], $matches)) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1999
					$default_value = $matches[1];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2000
					if ($tablefield->Default != $default_value) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2001
						// Add a query to change the column's default value
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2002
						$cqueries[] = "ALTER TABLE {$table} ALTER COLUMN {$tablefield->Field} SET DEFAULT '{$default_value}'";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2003
						$for_update[$table.'.'.$tablefield->Field] = "Changed default value of {$table}.{$tablefield->Field} from {$tablefield->Default} to {$default_value}";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2004
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2005
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2006
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2007
				// Remove the field from the array (so it's not added).
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2008
				unset($cfields[strtolower($tablefield->Field)]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2009
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2010
				// This field exists in the table, but not in the creation queries?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2011
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2012
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2013
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2014
		// For every remaining field specified for the table.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2015
		foreach ($cfields as $fieldname => $fielddef) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2016
			// Push a query line into $cqueries that adds the field to that table.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2017
			$cqueries[] = "ALTER TABLE {$table} ADD COLUMN $fielddef";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2018
			$for_update[$table.'.'.$fieldname] = 'Added column '.$table.'.'.$fieldname;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2019
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2020
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2021
		// Index stuff goes here. Fetch the table index structure from the database.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2022
		$tableindices = $wpdb->get_results("SHOW INDEX FROM {$table};");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2023
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2024
		if ($tableindices) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2025
			// Clear the index array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2026
			$index_ary = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2027
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2028
			// For every index in the table.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2029
			foreach ($tableindices as $tableindex) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2030
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2031
				// Add the index to the index data array.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2032
				$keyname = $tableindex->Key_name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2033
				$index_ary[$keyname]['columns'][] = array('fieldname' => $tableindex->Column_name, 'subpart' => $tableindex->Sub_part);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2034
				$index_ary[$keyname]['unique'] = ($tableindex->Non_unique == 0)?true:false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2035
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2036
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2037
			// For each actual index in the index array.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2038
			foreach ($index_ary as $index_name => $index_data) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2039
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2040
				// Build a create string to compare to the query.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2041
				$index_string = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2042
				if ($index_name == 'PRIMARY') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2043
					$index_string .= 'PRIMARY ';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2044
				} elseif ( $index_data['unique'] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2045
					$index_string .= 'UNIQUE ';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2046
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2047
				$index_string .= 'KEY ';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2048
				if ($index_name != 'PRIMARY') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2049
					$index_string .= $index_name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2050
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2051
				$index_columns = '';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2052
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2053
				// For each column in the index.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2054
				foreach ($index_data['columns'] as $column_data) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2055
					if ($index_columns != '') $index_columns .= ',';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2056
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2057
					// Add the field to the column list string.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2058
					$index_columns .= $column_data['fieldname'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2059
					if ($column_data['subpart'] != '') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2060
						$index_columns .= '('.$column_data['subpart'].')';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2061
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2062
				}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2063
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2064
				// The alternative index string doesn't care about subparts
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2065
				$alt_index_columns = preg_replace( '/\([^)]*\)/', '', $index_columns );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2066
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2067
				// Add the column list to the index create string.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2068
				$index_strings = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2069
					"$index_string ($index_columns)",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2070
					"$index_string ($alt_index_columns)",
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2071
				);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2072
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2073
				foreach( $index_strings as $index_string ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2074
					if ( ! ( ( $aindex = array_search( $index_string, $indices ) ) === false ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2075
						unset( $indices[ $aindex ] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2076
						break;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2077
						// todo: Remove this?
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2078
						//echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">{$table}:<br />Found index:".$index_string."</pre>\n";
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2079
					}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2080
				}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2081
				// todo: Remove this?
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2082
				//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";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2083
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2084
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2085
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2086
		// For every remaining index specified for the table.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2087
		foreach ( (array) $indices as $index ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2088
			// Push a query line into $cqueries that adds the index to that table.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2089
			$cqueries[] = "ALTER TABLE {$table} ADD $index";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2090
			$for_update[] = 'Added index ' . $table . ' ' . $index;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2091
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2092
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2093
		// Remove the original table creation query from processing.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2094
		unset( $cqueries[ $table ], $for_update[ $table ] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2095
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2096
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2097
	$allqueries = array_merge($cqueries, $iqueries);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2098
	if ($execute) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2099
		foreach ($allqueries as $query) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2100
			// todo: Remove this?
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2101
			//echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">".print_r($query, true)."</pre>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2102
			$wpdb->query($query);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2103
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2104
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2105
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2106
	return $for_update;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2107
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2108
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2109
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2110
 * Updates the database tables to a new schema.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2111
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2112
 * By default, updates all the tables to use the latest defined schema, but can also
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2113
 * be used to update a specific set of tables in wp_get_db_schema().
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2114
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2115
 * @since 1.5.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2116
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2117
 * @uses dbDelta
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2118
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2119
 * @param string $tables Optional. Which set of tables to update. Default is 'all'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2120
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2121
function make_db_current( $tables = 'all' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2122
	$alterations = dbDelta( $tables );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2123
	echo "<ol>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2124
	foreach($alterations as $alteration) echo "<li>$alteration</li>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2125
	echo "</ol>\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2126
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2127
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2128
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2129
 * Updates the database tables to a new schema, but without displaying results.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2130
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2131
 * By default, updates all the tables to use the latest defined schema, but can
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2132
 * also be used to update a specific set of tables in wp_get_db_schema().
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2133
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2134
 * @since 1.5.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2135
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2136
 * @see make_db_current()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2137
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2138
 * @param string $tables Optional. Which set of tables to update. Default is 'all'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2139
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2140
function make_db_current_silent( $tables = 'all' ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2141
	dbDelta( $tables );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2142
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2143
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2144
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2145
 * Creates a site theme from an existing theme.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2146
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2147
 * {@internal Missing Long Description}}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2148
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2149
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2150
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2151
 * @param string $theme_name The name of the theme.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2152
 * @param string $template   The directory name of the theme.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2153
 * @return bool
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2154
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2155
function make_site_theme_from_oldschool($theme_name, $template) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2156
	$home_path = get_home_path();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2157
	$site_dir = WP_CONTENT_DIR . "/themes/$template";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2158
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2159
	if (! file_exists("$home_path/index.php"))
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2160
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2161
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2162
	/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2163
	 * Copy files from the old locations to the site theme.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2164
	 * TODO: This does not copy arbitrary include dependencies. Only the standard WP files are copied.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2165
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2166
	$files = array('index.php' => 'index.php', 'wp-layout.css' => 'style.css', 'wp-comments.php' => 'comments.php', 'wp-comments-popup.php' => 'comments-popup.php');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2167
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2168
	foreach ($files as $oldfile => $newfile) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2169
		if ($oldfile == 'index.php')
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2170
			$oldpath = $home_path;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2171
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2172
			$oldpath = ABSPATH;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2173
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2174
		// Check to make sure it's not a new index.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2175
		if ($oldfile == 'index.php') {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2176
			$index = implode('', file("$oldpath/$oldfile"));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2177
			if (strpos($index, 'WP_USE_THEMES') !== false) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2178
				if (! @copy(WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME . '/index.php', "$site_dir/$newfile"))
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2179
					return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2180
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2181
				// Don't copy anything.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2182
				continue;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2183
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2184
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2185
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2186
		if (! @copy("$oldpath/$oldfile", "$site_dir/$newfile"))
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2187
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2188
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2189
		chmod("$site_dir/$newfile", 0777);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2190
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2191
		// Update the blog header include in each file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2192
		$lines = explode("\n", implode('', file("$site_dir/$newfile")));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2193
		if ($lines) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2194
			$f = fopen("$site_dir/$newfile", 'w');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2195
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2196
			foreach ($lines as $line) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2197
				if (preg_match('/require.*wp-blog-header/', $line))
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2198
					$line = '//' . $line;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2199
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2200
				// Update stylesheet references.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2201
				$line = str_replace("<?php echo __get_option('siteurl'); ?>/wp-layout.css", "<?php bloginfo('stylesheet_url'); ?>", $line);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2202
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2203
				// Update comments template inclusion.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2204
				$line = str_replace("<?php include(ABSPATH . 'wp-comments.php'); ?>", "<?php comments_template(); ?>", $line);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2205
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2206
				fwrite($f, "{$line}\n");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2207
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2208
			fclose($f);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2209
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2210
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2211
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2212
	// Add a theme header.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2213
	$header = "/*\nTheme Name: $theme_name\nTheme URI: " . __get_option('siteurl') . "\nDescription: A theme automatically created by the update.\nVersion: 1.0\nAuthor: Moi\n*/\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2214
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2215
	$stylelines = file_get_contents("$site_dir/style.css");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2216
	if ($stylelines) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2217
		$f = fopen("$site_dir/style.css", 'w');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2218
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2219
		fwrite($f, $header);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2220
		fwrite($f, $stylelines);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2221
		fclose($f);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2222
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2223
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2224
	return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2225
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2226
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2227
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2228
 * Creates a site theme from the default theme.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2229
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2230
 * {@internal Missing Long Description}}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2231
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2232
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2233
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2234
 * @param string $theme_name The name of the theme.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2235
 * @param string $template   The directory name of the theme.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2236
 * @return null|false
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2237
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2238
function make_site_theme_from_default($theme_name, $template) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2239
	$site_dir = WP_CONTENT_DIR . "/themes/$template";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2240
	$default_dir = WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2241
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2242
	// Copy files from the default theme to the site theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2243
	//$files = array('index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2244
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2245
	$theme_dir = @ opendir($default_dir);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2246
	if ($theme_dir) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2247
		while(($theme_file = readdir( $theme_dir )) !== false) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2248
			if (is_dir("$default_dir/$theme_file"))
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2249
				continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2250
			if (! @copy("$default_dir/$theme_file", "$site_dir/$theme_file"))
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2251
				return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2252
			chmod("$site_dir/$theme_file", 0777);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2253
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2254
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2255
	@closedir($theme_dir);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2256
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2257
	// Rewrite the theme header.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2258
	$stylelines = explode("\n", implode('', file("$site_dir/style.css")));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2259
	if ($stylelines) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2260
		$f = fopen("$site_dir/style.css", 'w');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2261
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2262
		foreach ($stylelines as $line) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2263
			if (strpos($line, 'Theme Name:') !== false) $line = 'Theme Name: ' . $theme_name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2264
			elseif (strpos($line, 'Theme URI:') !== false) $line = 'Theme URI: ' . __get_option('url');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2265
			elseif (strpos($line, 'Description:') !== false) $line = 'Description: Your theme.';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2266
			elseif (strpos($line, 'Version:') !== false) $line = 'Version: 1';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2267
			elseif (strpos($line, 'Author:') !== false) $line = 'Author: You';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2268
			fwrite($f, $line . "\n");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2269
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2270
		fclose($f);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2271
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2272
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2273
	// Copy the images.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2274
	umask(0);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2275
	if (! mkdir("$site_dir/images", 0777)) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2276
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2277
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2278
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2279
	$images_dir = @ opendir("$default_dir/images");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2280
	if ($images_dir) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2281
		while(($image = readdir($images_dir)) !== false) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2282
			if (is_dir("$default_dir/images/$image"))
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2283
				continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2284
			if (! @copy("$default_dir/images/$image", "$site_dir/images/$image"))
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2285
				return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2286
			chmod("$site_dir/images/$image", 0777);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2287
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2288
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2289
	@closedir($images_dir);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2290
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2291
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2292
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2293
 * Creates a site theme.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2294
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2295
 * {@internal Missing Long Description}}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2296
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2297
 * @since 1.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2298
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2299
 * @return false|string
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2300
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2301
function make_site_theme() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2302
	// Name the theme after the blog.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2303
	$theme_name = __get_option('blogname');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2304
	$template = sanitize_title($theme_name);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2305
	$site_dir = WP_CONTENT_DIR . "/themes/$template";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2306
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2307
	// If the theme already exists, nothing to do.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2308
	if ( is_dir($site_dir)) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2309
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2310
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2311
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2312
	// We must be able to write to the themes dir.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2313
	if (! is_writable(WP_CONTENT_DIR . "/themes")) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2314
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2315
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2316
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2317
	umask(0);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2318
	if (! mkdir($site_dir, 0777)) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2319
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2320
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2321
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2322
	if (file_exists(ABSPATH . 'wp-layout.css')) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2323
		if (! make_site_theme_from_oldschool($theme_name, $template)) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2324
			// TODO: rm -rf the site theme directory.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2325
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2326
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2327
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2328
		if (! make_site_theme_from_default($theme_name, $template))
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2329
			// TODO: rm -rf the site theme directory.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2330
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2331
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2332
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2333
	// Make the new site theme active.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2334
	$current_template = __get_option('template');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2335
	if ($current_template == WP_DEFAULT_THEME) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2336
		update_option('template', $template);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2337
		update_option('stylesheet', $template);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2338
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2339
	return $template;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2340
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2341
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2342
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2343
 * Translate user level to user role name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2344
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2345
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2346
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2347
 * @param int $level User level.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2348
 * @return string User role name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2349
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2350
function translate_level_to_role($level) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2351
	switch ($level) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2352
	case 10:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2353
	case 9:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2354
	case 8:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2355
		return 'administrator';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2356
	case 7:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2357
	case 6:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2358
	case 5:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2359
		return 'editor';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2360
	case 4:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2361
	case 3:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2362
	case 2:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2363
		return 'author';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2364
	case 1:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2365
		return 'contributor';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2366
	case 0:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2367
		return 'subscriber';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2368
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2369
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2370
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2371
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2372
 * Checks the version of the installed MySQL binary.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2373
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2374
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2375
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2376
function wp_check_mysql_version() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2377
	global $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2378
	$result = $wpdb->check_database_version();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2379
	if ( is_wp_error( $result ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2380
		die( $result->get_error_message() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2381
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2382
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2383
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2384
 * Disables the Automattic widgets plugin, which was merged into core.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2385
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2386
 * @since 2.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2387
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2388
function maybe_disable_automattic_widgets() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2389
	$plugins = __get_option( 'active_plugins' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2390
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2391
	foreach ( (array) $plugins as $plugin ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2392
		if ( basename( $plugin ) == 'widgets.php' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2393
			array_splice( $plugins, array_search( $plugin, $plugins ), 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2394
			update_option( 'active_plugins', $plugins );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2395
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2396
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2397
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2398
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2399
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2400
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2401
 * Disables the Link Manager on upgrade if, at the time of upgrade, no links exist in the DB.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2402
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2403
 * @since 3.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2404
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2405
function maybe_disable_link_manager() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2406
	global $wp_current_db_version, $wpdb;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2407
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2408
	if ( $wp_current_db_version >= 22006 && get_option( 'link_manager_enabled' ) && ! $wpdb->get_var( "SELECT link_id FROM $wpdb->links LIMIT 1" ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2409
		update_option( 'link_manager_enabled', 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2410
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2411
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2412
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2413
 * Runs before the schema is upgraded.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2414
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2415
 * @since 2.9.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2416
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2417
function pre_schema_upgrade() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2418
	global $wp_current_db_version, $wpdb;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2419
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2420
	// Upgrade versions prior to 2.9
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2421
	if ( $wp_current_db_version < 11557 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2422
		// Delete duplicate options. Keep the option with the highest option_id.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2423
		$wpdb->query("DELETE o1 FROM $wpdb->options AS o1 JOIN $wpdb->options AS o2 USING (`option_name`) WHERE o2.option_id > o1.option_id");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2424
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2425
		// Drop the old primary key and add the new.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2426
		$wpdb->query("ALTER TABLE $wpdb->options DROP PRIMARY KEY, ADD PRIMARY KEY(option_id)");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2427
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2428
		// Drop the old option_name index. dbDelta() doesn't do the drop.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2429
		$wpdb->query("ALTER TABLE $wpdb->options DROP INDEX option_name");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2430
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2431
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2432
	// Multisite schema upgrades.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2433
	if ( $wp_current_db_version < 25448 && is_multisite() && ! defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) && is_main_network() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2434
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2435
		// Upgrade verions prior to 3.7
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2436
		if ( $wp_current_db_version < 25179 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2437
			// New primary key for signups.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2438
			$wpdb->query( "ALTER TABLE $wpdb->signups ADD signup_id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2439
			$wpdb->query( "ALTER TABLE $wpdb->signups DROP INDEX domain" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2440
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2441
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2442
		if ( $wp_current_db_version < 25448 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2443
			// Convert archived from enum to tinyint.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2444
			$wpdb->query( "ALTER TABLE $wpdb->blogs CHANGE COLUMN archived archived varchar(1) NOT NULL default '0'" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2445
			$wpdb->query( "ALTER TABLE $wpdb->blogs CHANGE COLUMN archived archived tinyint(2) NOT NULL default 0" );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2446
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2447
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2448
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2449
	if ( $wp_current_db_version < 30133 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2450
		// dbDelta() can recreate but can't drop the index.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2451
		$wpdb->query( "ALTER TABLE $wpdb->terms DROP INDEX slug" );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2452
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2453
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2454
	// Upgrade versions prior to 4.2.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2455
	if ( $wp_current_db_version < 31351 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2456
		if ( ! is_multisite() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2457
			$wpdb->query( "ALTER TABLE $wpdb->usermeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2458
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2459
		$wpdb->query( "ALTER TABLE $wpdb->terms DROP INDEX slug, ADD INDEX slug(slug(191))" );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2460
		$wpdb->query( "ALTER TABLE $wpdb->terms DROP INDEX name, ADD INDEX name(name(191))" );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2461
		$wpdb->query( "ALTER TABLE $wpdb->commentmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2462
		$wpdb->query( "ALTER TABLE $wpdb->postmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2463
		$wpdb->query( "ALTER TABLE $wpdb->posts DROP INDEX post_name, ADD INDEX post_name(post_name(191))" );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  2464
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2465
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2466
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2467
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2468
 * Install global terms.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2469
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2470
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2471
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2472
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2473
if ( !function_exists( 'install_global_terms' ) ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2474
function install_global_terms() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2475
	global $wpdb, $charset_collate;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2476
	$ms_queries = "
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2477
CREATE TABLE $wpdb->sitecategories (
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2478
  cat_ID bigint(20) NOT NULL auto_increment,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2479
  cat_name varchar(55) NOT NULL default '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2480
  category_nicename varchar(200) NOT NULL default '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2481
  last_updated timestamp NOT NULL,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2482
  PRIMARY KEY  (cat_ID),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2483
  KEY category_nicename (category_nicename),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2484
  KEY last_updated (last_updated)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2485
) $charset_collate;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2486
";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2487
// now create tables
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2488
	dbDelta( $ms_queries );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2489
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2490
endif;