21
21
if ( !function_exists('wp_install') ) :
25
* {@internal Missing Long Description}}
25
* Runs the required functions to set up and populate the database,
26
* including primary admin user and initial options.
29
* @param string $blog_title Blog title.
30
* @param string $user_name User's username.
31
* @param string $user_email User's email.
32
* @param bool $public Whether blog is public.
33
* @param string $deprecated Optional. Not used.
34
* @param string $user_password Optional. User's chosen password. Will default to a random password.
35
* @param string $language Optional. Language chosen.
36
* @return array Array keys 'url', 'user_id', 'password', 'password_message'.
30
* @param string $blog_title Blog title.
31
* @param string $user_name User's username.
32
* @param string $user_email User's email.
33
* @param bool $public Whether blog is public.
34
* @param string $deprecated Optional. Not used.
35
* @param string $user_password Optional. User's chosen password. Default empty (random password).
36
* @param string $language Optional. Language chosen. Default empty.
37
* @return array Array keys 'url', 'user_id', 'password', and 'password_message'.
38
39
function wp_install( $blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '', $language = '' ) {
39
40
if ( !empty( $deprecated ) )
74
75
$user_id = wp_create_user($user_name, $user_password, $user_email);
75
76
update_user_option($user_id, 'default_password_nag', true, true);
76
77
$email_password = true;
77
} else if ( !$user_id ) {
78
} elseif ( ! $user_id ) {
78
79
// Password has been provided
79
80
$message = '<em>'.__('Your chosen password.').'</em>';
80
81
$user_id = wp_create_user($user_name, $user_password, $user_email);
140
144
$cat_tt_id = $wpdb->insert_id;
143
$now = date('Y-m-d H:i:s');
144
$now_gmt = gmdate('Y-m-d H:i:s');
145
$first_post_guid = get_option('home') . '/?p=1';
147
$now = current_time( 'mysql' );
148
$now_gmt = current_time( 'mysql', 1 );
149
$first_post_guid = get_option( 'home' ) . '/?p=1';
147
151
if ( is_multisite() ) {
148
152
$first_post = get_site_option( 'first_post' );
268
* Maybe enable pretty permalinks on install.
270
* If after enabling pretty permalinks don't work, fallback to query-string permalinks.
274
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
276
* @return bool Whether pretty permalinks are enabled. False otherwise.
278
function wp_install_maybe_enable_pretty_permalinks() {
281
// Bail if a permalink structure is already enabled.
282
if ( get_option( 'permalink_structure' ) ) {
287
* The Permalink structures to attempt.
289
* The first is designed for mod_rewrite or nginx rewriting.
291
* The second is PATHINFO-based permalinks for web server configurations
292
* without a true rewrite module enabled.
294
$permalink_structures = array(
295
'/%year%/%monthnum%/%day%/%postname%/',
296
'/index.php/%year%/%monthnum%/%day%/%postname%/'
299
foreach ( (array) $permalink_structures as $permalink_structure ) {
300
$wp_rewrite->set_permalink_structure( $permalink_structure );
303
* Flush rules with the hard option to force refresh of the web-server's
304
* rewrite config file (e.g. .htaccess or web.config).
306
$wp_rewrite->flush_rules( true );
308
// Test against a real WordPress Post, or if none were created, a random 404 page.
309
$test_url = get_permalink( 1 );
312
$test_url = home_url( '/wordpress-check-for-rewrites/' );
316
* Send a request to the site, and check whether
317
* the 'x-pingback' header is returned as expected.
319
* Uses wp_remote_get() instead of wp_remote_head() because web servers
320
* can block head requests.
322
$response = wp_remote_get( $test_url, array( 'timeout' => 5 ) );
323
$x_pingback_header = wp_remote_retrieve_header( $response, 'x-pingback' );
324
$pretty_permalinks = $x_pingback_header && $x_pingback_header === get_bloginfo( 'pingback_url' );
326
if ( $pretty_permalinks ) {
332
* If it makes it this far, pretty permalinks failed.
333
* Fallback to query-string permalinks.
335
$wp_rewrite->set_permalink_structure( '' );
336
$wp_rewrite->flush_rules( true );
263
341
if ( !function_exists('wp_new_blog_notification') ) :
265
* {@internal Missing Short Description}}
343
* Notifies the site admin that the setup is complete.
267
* {@internal Missing Long Description}}
345
* Sends an email with wp_mail to the new administrator that the site setup is complete,
346
* and provides them with a record of their login credentials.
271
350
* @param string $blog_title Blog title.
272
* @param string $blog_url Blog url.
273
* @param int $user_id User ID.
274
* @param string $password User's Password.
351
* @param string $blog_url Blog url.
352
* @param int $user_id User ID.
353
* @param string $password User's Password.
276
355
function wp_new_blog_notification($blog_title, $blog_url, $user_id, $password) {
277
356
$user = new WP_User( $user_id );
301
380
if ( !function_exists('wp_upgrade') ) :
303
* Run WordPress Upgrade functions.
382
* Runs WordPress Upgrade functions.
305
* {@internal Missing Long Description}}
384
* Upgrades the database if needed during a site update.
388
* @return null If no update is necessary or site isn't completely installed, null.
311
390
function wp_upgrade() {
312
391
global $wp_current_db_version, $wp_db_version, $wpdb;
1332
* Execute network level changes
1418
* Execute changes made in WordPress 4.2.0.
1422
function upgrade_420() {
1423
global $wp_current_db_version, $wpdb;
1425
if ( $wp_current_db_version < 31351 && $wpdb->charset === 'utf8mb4' ) {
1426
if ( is_multisite() ) {
1427
$tables = $wpdb->tables( 'blog' );
1429
$tables = $wpdb->tables( 'all' );
1432
foreach ( $tables as $table ) {
1433
maybe_convert_table_to_utf8mb4( $table );
1439
* Executes network-level upgrade routines.
1424
1531
update_site_option( 'illegal_names', $illegal_names );
1536
if ( $wp_current_db_version < 31351 && $wpdb->charset === 'utf8mb4' ) {
1537
if ( ! ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) && DO_NOT_UPGRADE_GLOBAL_TABLES ) ) {
1538
$wpdb->query( "ALTER TABLE $wpdb->usermeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
1539
$wpdb->query( "ALTER TABLE $wpdb->site DROP INDEX domain, ADD INDEX domain(domain(140),path(51))" );
1540
$wpdb->query( "ALTER TABLE $wpdb->sitemeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
1541
$wpdb->query( "ALTER TABLE $wpdb->signups DROP INDEX domain, ADD INDEX domain(domain(140),path(51))" );
1543
$tables = $wpdb->tables( 'global' );
1545
foreach ( $tables as $table ) {
1546
maybe_convert_table_to_utf8mb4( $table );
1429
// The functions we use to actually do stuff
1553
// General functions we use to actually do stuff
1434
* {@internal Missing Short Description}}
1557
* Creates a table in the database if it doesn't already exist.
1436
* {@internal Missing Long Description}}
1559
* This method checks for an existing database and creates a new one if it's not
1560
* already present. It doesn't rely on MySQL's "IF NOT EXISTS" statement, but chooses
1561
* to query all tables first and then run the SQL statement creating the table.
1505
** maybe_add_column()
1506
** Add column to db table if it doesn't exist.
1507
** Returns: true if already exists or on successful completion
1626
* Adds column to a database table if it doesn't already exist.
1630
* @param string $table_name The table name to modify.
1631
* @param string $column_name The column name to add to the table.
1632
* @param string $create_ddl The SQL statement used to add the column.
1633
* @return True if already exists or on successful completion, false on error.
1510
1635
function maybe_add_column($table_name, $column_name, $create_ddl) {
1656
* If a table only contains utf8 or utf8mb4 columns, convert it to utf8mb4.
1660
* @param string $table The table to convert.
1661
* @return bool true if the table was converted, false if it wasn't.
1663
function maybe_convert_table_to_utf8mb4( $table ) {
1666
$results = $wpdb->get_results( "SHOW FULL COLUMNS FROM `$table`" );
1671
foreach ( $results as $column ) {
1672
if ( $column->Collation ) {
1673
list( $charset ) = explode( '_', $column->Collation );
1674
$charset = strtolower( $charset );
1675
if ( 'utf8' !== $charset && 'utf8mb4' !== $charset ) {
1676
// Don't upgrade tables that have non-utf8 columns.
1682
return $wpdb->query( "ALTER TABLE $table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci" );
1531
1686
* Retrieve all options as it was for 1.2.
1611
* {@internal Missing Short Description}}
1765
* Modifies the database based on specified SQL statements.
1613
* {@internal Missing Long Description}}
1767
* Useful for creating new tables and updating existing tables to a new structure.
1617
* @param string $queries
1618
* @param bool $execute
1771
* @param string|array $queries Optional. The query to run. Can be multiple queries
1772
* in an array, or a string of queries separated by
1773
* semicolons. Default empty.
1774
* @param bool $execute Optional. Whether or not to execute the query right away.
1776
* @return array Strings containing the results of the various update queries.
1621
1778
function dbDelta( $queries = '', $execute = true ) {
1646
1803
// Create a tablename index for an array ($cqueries) of queries
1647
1804
foreach($queries as $qry) {
1648
if (preg_match("|CREATE TABLE ([^ ]*)|", $qry, $matches)) {
1805
if ( preg_match( "|CREATE TABLE ([^ ]*)|", $qry, $matches ) ) {
1649
1806
$cqueries[ trim( $matches[1], '`' ) ] = $qry;
1650
1807
$for_update[$matches[1]] = 'Created table '.$matches[1];
1651
} else if (preg_match("|CREATE DATABASE ([^ ]*)|", $qry, $matches)) {
1652
array_unshift($cqueries, $qry);
1653
} else if (preg_match("|INSERT INTO ([^ ]*)|", $qry, $matches)) {
1808
} elseif ( preg_match( "|CREATE DATABASE ([^ ]*)|", $qry, $matches ) ) {
1809
array_unshift( $cqueries, $qry );
1810
} elseif ( preg_match( "|INSERT INTO ([^ ]*)|", $qry, $matches ) ) {
1654
1811
$iqueries[] = $qry;
1655
} else if (preg_match("|UPDATE ([^ ]*)|", $qry, $matches)) {
1812
} elseif ( preg_match( "|UPDATE ([^ ]*)|", $qry, $matches ) ) {
1656
1813
$iqueries[] = $qry;
1658
1815
// Unrecognized query type
1823
1980
$index_columns .= '('.$column_data['subpart'].')';
1984
// The alternative index string doesn't care about subparts
1985
$alt_index_columns = preg_replace( '/\([^)]*\)/', '', $index_columns );
1826
1987
// Add the column list to the index create string.
1827
$index_string .= ' ('.$index_columns.')';
1828
if (!(($aindex = array_search($index_string, $indices)) === false)) {
1829
unset($indices[$aindex]);
1830
// todo: Remove this?
1831
//echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">{$table}:<br />Found index:".$index_string."</pre>\n";
1988
$index_strings = array(
1989
"$index_string ($index_columns)",
1990
"$index_string ($alt_index_columns)",
1993
foreach( $index_strings as $index_string ) {
1994
if ( ! ( ( $aindex = array_search( $index_string, $indices ) ) === false ) ) {
1995
unset( $indices[ $aindex ] );
1997
// todo: Remove this?
1998
//echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">{$table}:<br />Found index:".$index_string."</pre>\n";
1833
2001
// todo: Remove this?
1834
2002
//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";
1862
* {@internal Missing Short Description}}
2030
* Updates the database tables to a new schema.
1864
* {@internal Missing Long Description}}
2032
* By default, updates all the tables to use the latest defined schema, but can also
2033
* be used to update a specific set of tables in wp_get_db_schema().
2039
* @param string $tables Optional. Which set of tables to update. Default is 'all'.
1868
2041
function make_db_current( $tables = 'all' ) {
1869
2042
$alterations = dbDelta( $tables );
1876
* {@internal Missing Short Description}}
2049
* Updates the database tables to a new schema, but without displaying results.
1878
* {@internal Missing Long Description}}
2051
* By default, updates all the tables to use the latest defined schema, but can
2052
* also be used to update a specific set of tables in wp_get_db_schema().
2056
* @see make_db_current()
2058
* @param string $tables Optional. Which set of tables to update. Default is 'all'.
1882
2060
function make_db_current_silent( $tables = 'all' ) {
1883
2061
dbDelta( $tables );
1887
* {@internal Missing Short Description}}
2065
* Creates a site theme from an existing theme.
1889
2067
* {@internal Missing Long Description}}
1893
* @param string $theme_name
1894
* @param string $template
2071
* @param string $theme_name The name of the theme.
2072
* @param string $template The directory name of the theme.
1897
2075
function make_site_theme_from_oldschool($theme_name, $template) {
1970
* {@internal Missing Short Description}}
2148
* Creates a site theme from the default theme.
1972
2150
* {@internal Missing Long Description}}
1976
* @param string $theme_name
1977
* @param string $template
2154
* @param string $theme_name The name of the theme.
2155
* @param string $template The directory name of the theme.
1978
2156
* @return null|false
1980
2158
function make_site_theme_from_default($theme_name, $template) {
2195
2370
// dbDelta() can recreate but can't drop the index.
2196
2371
$wpdb->query( "ALTER TABLE $wpdb->terms DROP INDEX slug" );
2374
// Upgrade versions prior to 4.2.
2375
if ( $wp_current_db_version < 31351 ) {
2376
if ( ! is_multisite() ) {
2377
$wpdb->query( "ALTER TABLE $wpdb->usermeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
2379
$wpdb->query( "ALTER TABLE $wpdb->terms DROP INDEX slug, ADD INDEX slug(slug(191))" );
2380
$wpdb->query( "ALTER TABLE $wpdb->terms DROP INDEX name, ADD INDEX name(name(191))" );
2381
$wpdb->query( "ALTER TABLE $wpdb->commentmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
2382
$wpdb->query( "ALTER TABLE $wpdb->postmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" );
2383
$wpdb->query( "ALTER TABLE $wpdb->posts DROP INDEX post_name, ADD INDEX post_name(post_name(191))" );