Make WordPress Core


Ignore:
Timestamp:
01/29/2020 12:43:23 AM (4 years ago)
Author:
SergeyBiryukov
Message:

Docs: Improve inline comments per the documentation standards.

Includes minor code layout fixes for better readability.

See #48303.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/upgrade.php

    r47060 r47122  
    155155        global $wpdb, $wp_rewrite, $table_prefix;
    156156
    157         // Default category
     157        // Default category.
    158158        $cat_name = __( 'Uncategorized' );
    159159        /* translators: Default category slug. */
     
    200200        $cat_tt_id = $wpdb->insert_id;
    201201
    202         // First post
     202        // First post.
    203203        $now             = current_time( 'mysql' );
    204204        $now_gmt         = current_time( 'mysql', 1 );
     
    220220            );
    221221
    222             // Back-compat for pre-4.4
     222            // Back-compat for pre-4.4.
    223223            $first_post = str_replace( 'SITE_URL', esc_url( network_home_url() ), $first_post );
    224224            $first_post = str_replace( 'SITE_NAME', get_network()->site_name, $first_post );
     
    258258        );
    259259
    260         // Default comment
     260        // Default comment.
    261261        if ( is_multisite() ) {
    262262            $first_comment_author = get_site_option( 'first_comment_author' );
     
    287287        );
    288288
    289         // First Page
     289        // First page.
    290290        if ( is_multisite() ) {
    291291            $first_page = get_site_option( 'first_page' );
     
    353353        );
    354354
    355         // Privacy Policy page
     355        // Privacy Policy page.
    356356        if ( is_multisite() ) {
    357357            // Disable by default unless the suggested content is provided.
     
    494494            $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix . 'capabilities' ) );
    495495
    496             // Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.) TODO: Get previous_blog_id.
     496            // Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.)
     497            // TODO: Get previous_blog_id.
    497498            if ( ! is_super_admin( $user_id ) && $user_id != 1 ) {
    498499                $wpdb->delete(
     
    551552        $test_url = '';
    552553
    553         // Test against a real WordPress Post
     554        // Test against a real WordPress post.
    554555        $first_post = get_page_by_path( sanitize_title( _x( 'hello-world', 'Default post slug' ) ), OBJECT, 'post' );
    555556        if ( $first_post ) {
     
    853854    global $wpdb;
    854855
    855     // Get the title and ID of every post, post_name to check if it already has a value
     856    // Get the title and ID of every post, post_name to check if it already has a value.
    856857    $posts = $wpdb->get_results( "SELECT ID, post_title, post_name FROM $wpdb->posts WHERE post_name = ''" );
    857858    if ( $posts ) {
     
    892893    if ( $allposts ) :
    893894        foreach ( $allposts as $post ) {
    894             // Check to see if it's already been imported
     895            // Check to see if it's already been imported.
    895896            $cat = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->post2cat WHERE post_id = %d AND category_id = %d", $post->ID, $post->post_category ) );
    896             if ( ! $cat && 0 != $post->post_category ) { // If there's no result
     897            if ( ! $cat && 0 != $post->post_category ) { // If there's no result.
    897898                $wpdb->insert(
    898899                    $wpdb->post2cat,
     
    918919    global $wpdb;
    919920
    920     // Clean up indices, add a few
     921    // Clean up indices, add a few.
    921922    add_clean_index( $wpdb->posts, 'post_name' );
    922923    add_clean_index( $wpdb->posts, 'post_status' );
     
    955956    }
    956957
    957     // Get the GMT offset, we'll use that later on
     958    // Get the GMT offset, we'll use that later on.
    958959    $all_options = get_alloptions_110();
    959960
     
    969970    $gmt_offset            = -$diff_gmt_weblogger;
    970971
    971     // Add a gmt_offset option, with value $gmt_offset
     972    // Add a gmt_offset option, with value $gmt_offset.
    972973    add_option( 'gmt_offset', $gmt_offset );
    973974
    974     // Check if we already set the GMT fields (if we did, then
    975     // MAX(post_date_gmt) can't be '0000-00-00 00:00:00'
    976     // <michel_v> I just slapped myself silly for not thinking about it earlier
     975    /*
     976     * Check if we already set the GMT fields. If we did, then
     977     * MAX(post_date_gmt) can't be '0000-00-00 00:00:00'.
     978     * <michel_v> I just slapped myself silly for not thinking about it earlier.
     979     */
    977980    $got_gmt_fields = ! ( $wpdb->get_var( "SELECT MAX(post_date_gmt) FROM $wpdb->posts" ) == '0000-00-00 00:00:00' );
    978981
    979982    if ( ! $got_gmt_fields ) {
    980983
    981         // Add or subtract time to all dates, to get GMT dates
     984        // Add or subtract time to all dates, to get GMT dates.
    982985        $add_hours   = intval( $diff_gmt_weblogger );
    983986        $add_minutes = intval( 60 * ( $diff_gmt_weblogger - $add_hours ) );
     
    10531056    }
    10541057
    1055     // Obsolete tables
     1058    // Obsolete tables.
    10561059    $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optionvalues' );
    10571060    $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiontypes' );
     
    10591062    $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroup_options' );
    10601063
    1061     // Update comments table to use comment_type
     1064    // Update comments table to use comment_type.
    10621065    $wpdb->query( "UPDATE $wpdb->comments SET comment_type='trackback', comment_content = REPLACE(comment_content, '<trackback />', '') WHERE comment_content LIKE '<trackback />%'" );
    10631066    $wpdb->query( "UPDATE $wpdb->comments SET comment_type='pingback', comment_content = REPLACE(comment_content, '<pingback />', '') WHERE comment_content LIKE '<pingback />%'" );
    10641067
    1065     // Some versions have multiple duplicate option_name rows with the same values
     1068    // Some versions have multiple duplicate option_name rows with the same values.
    10661069    $options = $wpdb->get_results( "SELECT option_name, COUNT(option_name) AS dupes FROM `$wpdb->options` GROUP BY option_name" );
    10671070    foreach ( $options as $option ) {
     
    13711374        /*
    13721375         * Create link_category terms for link categories. Create a map of link
    1373          * cat IDs to link_category terms.
     1376         * category IDs to link_category terms.
    13741377         */
    13751378        $link_cat_id_map  = array();
     
    14121415        }
    14131416
    1414         // Associate links to cats.
     1417        // Associate links to categories.
    14151418        $links = $wpdb->get_results( "SELECT link_id, link_category FROM $wpdb->links" );
    14161419        if ( ! empty( $links ) ) {
     
    14611464
    14621465    if ( $wp_current_db_version < 4772 ) {
    1463         // Obsolete linkcategories table
     1466        // Obsolete linkcategories table.
    14641467        $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'linkcategories' );
    14651468    }
    14661469
    1467     // Recalculate all counts
     1470    // Recalculate all counts.
    14681471    $terms = $wpdb->get_results( "SELECT term_taxonomy_id, taxonomy FROM $wpdb->term_taxonomy" );
    14691472    foreach ( (array) $terms as $term ) {
     
    15871590    }
    15881591
    1589     // Update post_date for unpublished posts with empty timestamp
     1592    // Update post_date for unpublished posts with empty timestamp.
    15901593    if ( $wp_current_db_version < 8921 ) {
    15911594        $wpdb->query( "UPDATE $wpdb->posts SET post_date = post_modified WHERE post_date = '0000-00-00 00:00:00'" );
     
    16381641
    16391642    if ( $wp_current_db_version < 11958 ) {
    1640         // Previously, setting depth to 1 would redundantly disable threading, but now 2 is the minimum depth to avoid confusion
     1643        // Previously, setting depth to 1 would redundantly disable threading,
     1644        // but now 2 is the minimum depth to avoid confusion.
    16411645        if ( get_option( 'thread_comments_depth' ) == '1' ) {
    16421646            update_option( 'thread_comments_depth', 2 );
     
    17701774            unset( $_sidebars_widgets );
    17711775
    1772             // intentional fall-through to upgrade to the next version.
     1776            // Intentional fall-through to upgrade to the next version.
    17731777        case 2:
    17741778            $sidebars_widgets                  = retrieve_widgets();
     
    18281832
    18291833    if ( $wp_current_db_version < 22006 && $wpdb->get_var( "SELECT link_id FROM $wpdb->links LIMIT 1" ) ) {
    1830         update_option( 'link_manager_enabled', 1 ); // Previously set to 0 by populate_options()
     1834        update_option( 'link_manager_enabled', 1 ); // Previously set to 0 by populate_options().
    18311835    }
    18321836
     
    20222026 */
    20232027function upgrade_431() {
    2024     // Fix incorrect cron entries for term splitting
     2028    // Fix incorrect cron entries for term splitting.
    20252029    $cron_array = _get_cron_array();
    20262030    if ( isset( $cron_array['wp_batch_split_terms'] ) ) {
     
    21392143 */
    21402144function upgrade_530() {
    2141     // The `admin_email_lifespan` option may have been set by an admin that just logged in,
    2142     // saw the verification screen, clicked on a button there, and is now upgrading the db,
    2143     // or by populate_options() that is called earlier in upgrade_all().
    2144     // In the second case `admin_email_lifespan` should be reset so the verification screen
    2145     // is shown next time an admin logs in.
     2145    /*
     2146     * The `admin_email_lifespan` option may have been set by an admin that just logged in,
     2147     * saw the verification screen, clicked on a button there, and is now upgrading the db,
     2148     * or by populate_options() that is called earlier in upgrade_all().
     2149     * In the second case `admin_email_lifespan` should be reset so the verification screen
     2150     * is shown next time an admin logs in.
     2151     */
    21462152    if ( function_exists( 'current_user_can' ) && ! current_user_can( 'manage_options' ) ) {
    21472153        update_option( 'admin_email_lifespan', 0 );
     
    21602166    global $wp_current_db_version, $wpdb;
    21612167
    2162     // Always clear expired transients
     2168    // Always clear expired transients.
    21632169    delete_expired_transients( true );
    21642170
    2165     // 2.8.
     2171    // 2.8
    21662172    if ( $wp_current_db_version < 11549 ) {
    21672173        $wpmu_sitewide_plugins   = get_site_option( 'wpmu_sitewide_plugins' );
     
    23022308
    23032309//
    2304 // General functions we use to actually do stuff
     2310// General functions we use to actually do stuff.
    23052311//
    23062312
     
    23292335    }
    23302336
    2331     // Didn't find it try to create it..
     2337    // Didn't find it, so try to create it.
    23322338    $wpdb->query( $create_ddl );
    23332339
     
    23542360    $wpdb->hide_errors();
    23552361    $wpdb->query( "ALTER TABLE `$table` DROP INDEX `$index`" );
    2356     // Now we need to take out all the extra ones we may have created
     2362    // Now we need to take out all the extra ones we may have created.
    23572363    for ( $i = 0; $i < 25; $i++ ) {
    23582364        $wpdb->query( "ALTER TABLE `$table` DROP INDEX `{$index}_$i`" );
     
    24002406    }
    24012407
    2402     // Didn't find it try to create it.
     2408    // Didn't find it, so try to create it.
    24032409    $wpdb->query( $create_ddl );
    24042410
     
    25672573    }
    25682574
    2569     // Separate individual queries into an array
     2575    // Separate individual queries into an array.
    25702576    if ( ! is_array( $queries ) ) {
    25712577        $queries = explode( ';', $queries );
     
    25822588    $queries = apply_filters( 'dbdelta_queries', $queries );
    25832589
    2584     $cqueries   = array(); // Creation Queries
    2585     $iqueries   = array(); // Insertion Queries
     2590    $cqueries   = array(); // Creation queries.
     2591    $iqueries   = array(); // Insertion queries.
    25862592    $for_update = array();
    25872593
    2588     // Create a tablename index for an array ($cqueries) of queries
     2594    // Create a tablename index for an array ($cqueries) of queries.
    25892595    foreach ( $queries as $qry ) {
    25902596        if ( preg_match( '|CREATE TABLE ([^ ]*)|', $qry, $matches ) ) {
     
    25982604            $iqueries[] = $qry;
    25992605        } else {
    2600             // Unrecognized query type
     2606            // Unrecognized query type.
    26012607        }
    26022608    }
     
    26352641        }
    26362642
    2637         // Fetch the table column structure from the database
     2643        // Fetch the table column structure from the database.
    26382644        $suppress    = $wpdb->suppress_errors();
    26392645        $tablefields = $wpdb->get_results( "DESCRIBE {$table};" );
     
    27832789            $tablefield_type_lowercased  = strtolower( $tablefield->Type );
    27842790
    2785             // If the table field exists in the field array ...
     2791            // If the table field exists in the field array...
    27862792            if ( array_key_exists( $tablefield_field_lowercased, $cfields ) ) {
    27872793
     
    28082814                    if ( $do_change ) {
    28092815                        // Add a query to change the column type.
    2810                         $cqueries[]                                      = "ALTER TABLE {$table} CHANGE COLUMN `{$tablefield->Field}` " . $cfields[ $tablefield_field_lowercased ];
     2816                        $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN `{$tablefield->Field}` " . $cfields[ $tablefield_field_lowercased ];
     2817
    28112818                        $for_update[ $table . '.' . $tablefield->Field ] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}";
    28122819                    }
     
    28182825                    if ( $tablefield->Default != $default_value ) {
    28192826                        // Add a query to change the column's default value
    2820                         $cqueries[]                                      = "ALTER TABLE {$table} ALTER COLUMN `{$tablefield->Field}` SET DEFAULT '{$default_value}'";
     2827                        $cqueries[] = "ALTER TABLE {$table} ALTER COLUMN `{$tablefield->Field}` SET DEFAULT '{$default_value}'";
     2828
    28212829                        $for_update[ $table . '.' . $tablefield->Field ] = "Changed default value of {$table}.{$tablefield->Field} from {$tablefield->Default} to {$default_value}";
    28222830                    }
     
    28332841        foreach ( $cfields as $fieldname => $fielddef ) {
    28342842            // Push a query line into $cqueries that adds the field to that table.
    2835             $cqueries[]                              = "ALTER TABLE {$table} ADD COLUMN $fielddef";
     2843            $cqueries[] = "ALTER TABLE {$table} ADD COLUMN $fielddef";
     2844
    28362845            $for_update[ $table . '.' . $fieldname ] = 'Added column ' . $table . '.' . $fieldname;
    28372846        }
     
    28462855            // For every index in the table.
    28472856            foreach ( $tableindices as $tableindex ) {
     2857                $keyname = strtolower( $tableindex->Key_name );
    28482858
    28492859                // Add the index to the index data array.
    2850                 $keyname                             = strtolower( $tableindex->Key_name );
    28512860                $index_ary[ $keyname ]['columns'][]  = array(
    28522861                    'fieldname' => $tableindex->Column_name,
     
    29052914        foreach ( (array) $indices as $index ) {
    29062915            // Push a query line into $cqueries that adds the index to that table.
    2907             $cqueries[]   = "ALTER TABLE {$table} ADD $index";
     2916            $cqueries[] = "ALTER TABLE {$table} ADD $index";
     2917
    29082918            $for_update[] = 'Added index ' . $table . ' ' . $index;
    29092919        }
     
    30693079
    30703080    // Copy files from the default theme to the site theme.
    3071     //$files = array('index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css');
     3081    // $files = array( 'index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css' );
    30723082
    30733083    $theme_dir = @opendir( $default_dir );
     
    32703280    global $wp_current_db_version, $wpdb;
    32713281
    3272     // Upgrade versions prior to 2.9
     3282    // Upgrade versions prior to 2.9.
    32733283    if ( $wp_current_db_version < 11557 ) {
    32743284        // Delete duplicate options. Keep the option with the highest option_id.
     
    32853295    if ( $wp_current_db_version < 25448 && is_multisite() && wp_should_upgrade_global_tables() ) {
    32863296
    3287         // Upgrade versions prior to 3.7
     3297        // Upgrade versions prior to 3.7.
    32883298        if ( $wp_current_db_version < 25179 ) {
    32893299            // New primary key for signups.
     
    33433353) $charset_collate;
    33443354";
    3345         // now create tables
     3355        // Now create tables.
    33463356        dbDelta( $ms_queries );
    33473357    }
     
    33683378function wp_should_upgrade_global_tables() {
    33693379
    3370     // Return false early if explicitly not upgrading
     3380    // Return false early if explicitly not upgrading.
    33713381    if ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) {
    33723382        return false;
    33733383    }
    33743384
    3375     // Assume global tables should be upgraded
     3385    // Assume global tables should be upgraded.
    33763386    $should_upgrade = true;
    33773387
    3378     // Set to false if not on main network (does not matter if not multi-network)
     3388    // Set to false if not on main network (does not matter if not multi-network).
    33793389    if ( ! is_main_network() ) {
    33803390        $should_upgrade = false;
    33813391    }
    33823392
    3383     // Set to false if not on main site of current network (does not matter if not multi-site)
     3393    // Set to false if not on main site of current network (does not matter if not multi-site).
    33843394    if ( ! is_main_site() ) {
    33853395        $should_upgrade = false;
Note: See TracChangeset for help on using the changeset viewer.