Make WordPress Core

Changeset 55688


Ignore:
Timestamp:
04/26/2023 03:08:35 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Remove an empty else statement in dbDelta().

Use continue to help separate each case for better readability, instead of having a wall of if/elseif.

Includes simplifying a similar fragment in make_site_theme_from_default().

Follow-up to [1575], [2037], [2040], [2044], [2346], [7999], [14080], [14485].

Props costdev, krunal265, hellofromTonya, brookedot, SergeyBiryukov.
Fixes #56982.

File:
1 edited

Legend:

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

    r55677 r55688  
    27432743        $for_update = array();
    27442744
    2745         // Create a tablename index for an array ($cqueries) of queries.
     2745        // Create a tablename index for an array ($cqueries) of recognized query types.
    27462746        foreach ( $queries as $qry ) {
    27472747                if ( preg_match( '|CREATE TABLE ([^ ]*)|', $qry, $matches ) ) {
    27482748                        $cqueries[ trim( $matches[1], '`' ) ] = $qry;
    27492749                        $for_update[ $matches[1] ]            = 'Created table ' . $matches[1];
    2750                 } elseif ( preg_match( '|CREATE DATABASE ([^ ]*)|', $qry, $matches ) ) {
     2750                        continue;
     2751                }
     2752
     2753                if ( preg_match( '|CREATE DATABASE ([^ ]*)|', $qry, $matches ) ) {
    27512754                        array_unshift( $cqueries, $qry );
    2752                 } elseif ( preg_match( '|INSERT INTO ([^ ]*)|', $qry, $matches ) ) {
     2755                        continue;
     2756                }
     2757
     2758                if ( preg_match( '|INSERT INTO ([^ ]*)|', $qry, $matches ) ) {
    27532759                        $iqueries[] = $qry;
    2754                 } elseif ( preg_match( '|UPDATE ([^ ]*)|', $qry, $matches ) ) {
     2760                        continue;
     2761                }
     2762
     2763                if ( preg_match( '|UPDATE ([^ ]*)|', $qry, $matches ) ) {
    27552764                        $iqueries[] = $qry;
    2756                 } else {
    2757                         // Unrecognized query type.
     2765                        continue;
    27582766                }
    27592767        }
     
    30743082                                        $index_string .= 'UNIQUE ';
    30753083                                }
     3084
    30763085                                if ( 'FULLTEXT' === strtoupper( $index_data['index_type'] ) ) {
    30773086                                        $index_string .= 'FULLTEXT ';
    30783087                                }
     3088
    30793089                                if ( 'SPATIAL' === strtoupper( $index_data['index_type'] ) ) {
    30803090                                        $index_string .= 'SPATIAL ';
    30813091                                }
     3092
    30823093                                $index_string .= 'KEY ';
    30833094                                if ( 'primary' !== $index_name ) {
    30843095                                        $index_string .= '`' . $index_name . '`';
    30853096                                }
     3097
    30863098                                $index_columns = '';
    30873099
     
    31803192 */
    31813193function make_site_theme_from_oldschool( $theme_name, $template ) {
    3182         $home_path = get_home_path();
    3183         $site_dir  = WP_CONTENT_DIR . "/themes/$template";
     3194        $home_path   = get_home_path();
     3195        $site_dir    = WP_CONTENT_DIR . "/themes/$template";
     3196        $default_dir = WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME;
    31843197
    31853198        if ( ! file_exists( "$home_path/index.php" ) ) {
     
    32093222                        $index = implode( '', file( "$oldpath/$oldfile" ) );
    32103223                        if ( strpos( $index, 'WP_USE_THEMES' ) !== false ) {
    3211                                 if ( ! copy( WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME . '/index.php', "$site_dir/$newfile" ) ) {
     3224                                if ( ! copy( "$default_dir/$oldfile", "$site_dir/$newfile" ) ) {
    32123225                                        return false;
    32133226                                }
     
    32353248
    32363249                                // Update stylesheet references.
    3237                                 $line = str_replace( "<?php echo __get_option('siteurl'); ?>/wp-layout.css", "<?php bloginfo('stylesheet_url'); ?>", $line );
     3250                                $line = str_replace(
     3251                                        "<?php echo __get_option('siteurl'); ?>/wp-layout.css",
     3252                                        "<?php bloginfo('stylesheet_url'); ?>",
     3253                                        $line
     3254                                );
    32383255
    32393256                                // Update comments template inclusion.
    3240                                 $line = str_replace( "<?php include(ABSPATH . 'wp-comments.php'); ?>", '<?php comments_template(); ?>', $line );
     3257                                $line = str_replace(
     3258                                        "<?php include(ABSPATH . 'wp-comments.php'); ?>",
     3259                                        '<?php comments_template(); ?>',
     3260                                        $line
     3261                                );
    32413262
    32423263                                fwrite( $f, "{$line}\n" );
     
    32473268
    32483269        // Add a theme header.
    3249         $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";
     3270        $header = "/*\n" .
     3271                "Theme Name: $theme_name\n" .
     3272                'Theme URI: ' . __get_option( 'siteurl' ) . "\n" .
     3273                "Description: A theme automatically created by the update.\n" .
     3274                "Version: 1.0\n" .
     3275                "Author: Moi\n" .
     3276                "*/\n";
    32503277
    32513278        $stylelines = file_get_contents( "$site_dir/style.css" );
     
    32853312                                continue;
    32863313                        }
     3314
    32873315                        if ( ! copy( "$default_dir/$theme_file", "$site_dir/$theme_file" ) ) {
    32883316                                return;
    32893317                        }
     3318
    32903319                        chmod( "$site_dir/$theme_file", 0777 );
    32913320                }
     
    32993328                $f = fopen( "$site_dir/style.css", 'w' );
    33003329
     3330                $headers = array(
     3331                        'Theme Name:'  => $theme_name,
     3332                        'Theme URI:'   => __get_option( 'url' ),
     3333                        'Description:' => 'Your theme.',
     3334                        'Version:'     => '1',
     3335                        'Author:'      => 'You',
     3336                );
     3337
    33013338                foreach ( $stylelines as $line ) {
    3302                         if ( strpos( $line, 'Theme Name:' ) !== false ) {
    3303                                 $line = 'Theme Name: ' . $theme_name;
    3304                         } elseif ( strpos( $line, 'Theme URI:' ) !== false ) {
    3305                                 $line = 'Theme URI: ' . __get_option( 'url' );
    3306                         } elseif ( strpos( $line, 'Description:' ) !== false ) {
    3307                                 $line = 'Description: Your theme.';
    3308                         } elseif ( strpos( $line, 'Version:' ) !== false ) {
    3309                                 $line = 'Version: 1';
    3310                         } elseif ( strpos( $line, 'Author:' ) !== false ) {
    3311                                 $line = 'Author: You';
    3312                         }
     3339                        foreach ( $headers as $header => $value ) {
     3340                                if ( strpos( $line, $header ) !== false ) {
     3341                                        $line = $header . ' ' . $value;
     3342                                }
     3343                        }
     3344
    33133345                        fwrite( $f, $line . "\n" );
    33143346                }
     3347
    33153348                fclose( $f );
    33163349        }
     
    33283361                                continue;
    33293362                        }
     3363
    33303364                        if ( ! copy( "$default_dir/images/$image", "$site_dir/images/$image" ) ) {
    33313365                                return;
    33323366                        }
     3367
    33333368                        chmod( "$site_dir/images/$image", 0777 );
    33343369                }
Note: See TracChangeset for help on using the changeset viewer.