'meta_key' => $wpdb->base_prefix . '1_capabilities',
* Maybe enable pretty permalinks on installation.
* If after enabling pretty permalinks don't work, fallback to query-string permalinks.
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
* @return bool Whether pretty permalinks are enabled. False otherwise.
function wp_install_maybe_enable_pretty_permalinks() {
// Bail if a permalink structure is already enabled.
if ( get_option( 'permalink_structure' ) ) {
* The Permalink structures to attempt.
* The first is designed for mod_rewrite or nginx rewriting.
* The second is PATHINFO-based permalinks for web server configurations
* without a true rewrite module enabled.
$permalink_structures = array(
'/%year%/%monthnum%/%day%/%postname%/',
'/index.php/%year%/%monthnum%/%day%/%postname%/',
foreach ( (array) $permalink_structures as $permalink_structure ) {
$wp_rewrite->set_permalink_structure( $permalink_structure );
* Flush rules with the hard option to force refresh of the web-server's
* rewrite config file (e.g. .htaccess or web.config).
$wp_rewrite->flush_rules( true );
// Test against a real WordPress post.
$first_post = get_page_by_path( sanitize_title( _x( 'hello-world', 'Default post slug' ) ), OBJECT, 'post' );
$test_url = get_permalink( $first_post->ID );
* Send a request to the site, and check whether
* the 'x-pingback' header is returned as expected.
* Uses wp_remote_get() instead of wp_remote_head() because web servers
* can block head requests.
$response = wp_remote_get( $test_url, array( 'timeout' => 5 ) );
$x_pingback_header = wp_remote_retrieve_header( $response, 'x-pingback' );
$pretty_permalinks = $x_pingback_header && get_bloginfo( 'pingback_url' ) === $x_pingback_header;
if ( $pretty_permalinks ) {
* If it makes it this far, pretty permalinks failed.
* Fallback to query-string permalinks.
$wp_rewrite->set_permalink_structure( '' );
$wp_rewrite->flush_rules( true );
if ( ! function_exists( 'wp_new_blog_notification' ) ) :
* Notifies the site admin that the installation of WordPress is complete.
* Sends an email to the new administrator that the installation is complete
* and provides them with a record of their login credentials.
* @param string $blog_title Site title.
* @param string $blog_url Site URL.
* @param int $user_id Administrator's user ID.
* @param string $password Administrator's password. Note that a placeholder message is
* usually passed instead of the actual password.
function wp_new_blog_notification( $blog_title, $blog_url, $user_id, $password ) {
$user = new WP_User( $user_id );
$email = $user->user_email;
$name = $user->user_login;
$login_url = wp_login_url();
/* translators: New site notification email. 1: New site URL, 2: User login, 3: User password or password reset link, 4: Login URL. */
'Your new WordPress site has been successfully set up at:
You can log in to the administrator account with the following information:
We hope you enjoy your new site. Thanks!
$installed_email = array(
'subject' => __( 'New WordPress Site' ),
* Filters the contents of the email sent to the site administrator when WordPress is installed.
* @param array $installed_email {
* Used to build wp_mail().
* @type string $to The email address of the recipient.
* @type string $subject The subject of the email.
* @type string $message The content of the email.
* @type string $headers Headers.
* @param WP_User $user The site administrator user object.
* @param string $blog_title The site title.
* @param string $blog_url The site URL.
* @param string $password The site administrator's password. Note that a placeholder message
* is usually passed instead of the user's actual password.
$installed_email = apply_filters( 'wp_installed_email', $installed_email, $user, $blog_title, $blog_url, $password );
$installed_email['subject'],
$installed_email['message'],
$installed_email['headers']
if ( ! function_exists( 'wp_upgrade' ) ) :
* Runs WordPress Upgrade functions.
* Upgrades the database if needed during a site update.
* @global int $wp_current_db_version The old (current) database version.
* @global int $wp_db_version The new database version.
* @global wpdb $wpdb WordPress database abstraction object.
global $wp_current_db_version, $wp_db_version, $wpdb;
$wp_current_db_version = __get_option( 'db_version' );
// We are up to date. Nothing to do.
if ( $wp_db_version == $wp_current_db_version ) {
if ( ! is_blog_installed() ) {
wp_check_mysql_version();
make_db_current_silent();
if ( is_multisite() && is_main_site() ) {
update_site_meta( get_current_blog_id(), 'db_version', $wp_db_version );
update_site_meta( get_current_blog_id(), 'db_last_updated', microtime() );
* Fires after a site is fully upgraded.
* @param int $wp_db_version The new $wp_db_version.
* @param int $wp_current_db_version The old (current) $wp_db_version.
do_action( 'wp_upgrade', $wp_db_version, $wp_current_db_version );
* Functions to be called in installation and upgrade scripts.
* Contains conditional checks to determine which upgrade scripts to run,
* based on database version and WP version being updated-to.
* @global int $wp_current_db_version The old (current) database version.
* @global int $wp_db_version The new database version.
global $wp_current_db_version, $wp_db_version;
$wp_current_db_version = __get_option( 'db_version' );
// We are up to date. Nothing to do.
if ( $wp_db_version == $wp_current_db_version ) {
// If the version is not set in the DB, try to guess the version.
if ( empty( $wp_current_db_version ) ) {
$wp_current_db_version = 0;
// If the template option exists, we have 1.5.
$template = __get_option( 'template' );
if ( ! empty( $template ) ) {
$wp_current_db_version = 2541;
if ( $wp_current_db_version < 6039 ) {
upgrade_230_options_table();
if ( $wp_current_db_version < 2541 ) {
if ( $wp_current_db_version < 3308 ) {
if ( $wp_current_db_version < 4772 ) {
if ( $wp_current_db_version < 4351 ) {
if ( $wp_current_db_version < 5539 ) {
if ( $wp_current_db_version < 6124 ) {
upgrade_230_old_tables();
if ( $wp_current_db_version < 7499 ) {
if ( $wp_current_db_version < 7935 ) {
if ( $wp_current_db_version < 8201 ) {
if ( $wp_current_db_version < 8989 ) {
if ( $wp_current_db_version < 10360 ) {
if ( $wp_current_db_version < 11958 ) {
if ( $wp_current_db_version < 15260 ) {
if ( $wp_current_db_version < 19389 ) {
if ( $wp_current_db_version < 20080 ) {
if ( $wp_current_db_version < 22422 ) {
if ( $wp_current_db_version < 25824 ) {
if ( $wp_current_db_version < 26148 ) {
if ( $wp_current_db_version < 26691 ) {
if ( $wp_current_db_version < 29630 ) {
if ( $wp_current_db_version < 33055 ) {
if ( $wp_current_db_version < 33056 ) {
if ( $wp_current_db_version < 35700 ) {
if ( $wp_current_db_version < 36686 ) {
if ( $wp_current_db_version < 37965 ) {
if ( $wp_current_db_version < 44719 ) {
if ( $wp_current_db_version < 45744 ) {
if ( $wp_current_db_version < 48575 ) {
if ( $wp_current_db_version < 49752 ) {
maybe_disable_link_manager();
maybe_disable_automattic_widgets();
update_option( 'db_version', $wp_db_version );
update_option( 'db_upgraded', true );
* Execute changes made in WordPress 1.0.
* @global wpdb $wpdb WordPress database abstraction object.
// Get the title and ID of every post, post_name to check if it already has a value.
$posts = $wpdb->get_results( "SELECT ID, post_title, post_name FROM $wpdb->posts WHERE post_name = ''" );
foreach ( $posts as $post ) {
if ( '' === $post->post_name ) {
$newtitle = sanitize_title( $post->post_title );
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_name = %s WHERE ID = %d", $newtitle, $post->ID ) );
$categories = $wpdb->get_results( "SELECT cat_ID, cat_name, category_nicename FROM $wpdb->categories" );
foreach ( $categories as $category ) {
if ( '' === $category->category_nicename ) {
$newtitle = sanitize_title( $category->cat_name );
$wpdb->update( $wpdb->categories, array( 'category_nicename' => $newtitle ), array( 'cat_ID' => $category->cat_ID ) );
$sql = "UPDATE $wpdb->options
SET option_value = REPLACE(option_value, 'wp-links/links-images/', 'wp-images/links/')
WHERE option_name LIKE %s
AND option_value LIKE %s";
$wpdb->query( $wpdb->prepare( $sql, $wpdb->esc_like( 'links_rating_image' ) . '%', $wpdb->esc_like( 'wp-links/links-images/' ) . '%' ) );
$done_ids = $wpdb->get_results( "SELECT DISTINCT post_id FROM $wpdb->post2cat" );
foreach ( $done_ids as $done_id ) :
$done_posts[] = $done_id->post_id;
$catwhere = ' AND ID NOT IN (' . implode( ',', $done_posts ) . ')';
$allposts = $wpdb->get_results( "SELECT ID, post_category FROM $wpdb->posts WHERE post_category != '0' $catwhere" );
foreach ( $allposts as $post ) {
// Check to see if it's already been imported.
$cat = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->post2cat WHERE post_id = %d AND category_id = %d", $post->ID, $post->post_category ) );
if ( ! $cat && 0 != $post->post_category ) { // If there's no result.
'category_id' => $post->post_category,
* Execute changes made in WordPress 1.0.1.
* @global wpdb $wpdb WordPress database abstraction object.
// Clean up indices, add a few.
add_clean_index( $wpdb->posts, 'post_name' );
add_clean_index( $wpdb->posts, 'post_status' );
add_clean_index( $wpdb->categories, 'category_nicename' );
add_clean_index( $wpdb->comments, 'comment_approved' );
add_clean_index( $wpdb->comments, 'comment_post_ID' );
add_clean_index( $wpdb->links, 'link_category' );
add_clean_index( $wpdb->links, 'link_visible' );
* Execute changes made in WordPress 1.2.
* @global wpdb $wpdb WordPress database abstraction object.
$users = $wpdb->get_results( "SELECT ID, user_nickname, user_nicename FROM $wpdb->users" );
foreach ( $users as $user ) {
if ( '' === $user->user_nicename ) {
$newname = sanitize_title( $user->user_nickname );
$wpdb->update( $wpdb->users, array( 'user_nicename' => $newname ), array( 'ID' => $user->ID ) );
$users = $wpdb->get_results( "SELECT ID, user_pass from $wpdb->users" );
foreach ( $users as $row ) {
if ( ! preg_match( '/^[A-Fa-f0-9]{32}$/', $row->user_pass ) ) {
$wpdb->update( $wpdb->users, array( 'user_pass' => md5( $row->user_pass ) ), array( 'ID' => $row->ID ) );