Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (6 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/ms-blogs.php

    r41918 r42343  
    5959function get_blogaddress_by_name( $blogname ) {
    6060    if ( is_subdomain_install() ) {
    61         if ( $blogname == 'main' )
     61        if ( $blogname == 'main' ) {
    6262            $blogname = 'www';
     63        }
    6364        $url = rtrim( network_home_url(), '/' );
    64         if ( !empty( $blogname ) )
    65             $url = preg_replace( '|^([^\.]+://)|', "\${1}" . $blogname . '.', $url );
     65        if ( ! empty( $blogname ) ) {
     66            $url = preg_replace( '|^([^\.]+://)|', '${1}' . $blogname . '.', $url );
     67        }
    6668    } else {
    6769        $url = network_home_url( $blogname );
     
    8183function get_id_from_blogname( $slug ) {
    8284    $current_network = get_network();
    83     $slug = trim( $slug, '/' );
     85    $slug            = trim( $slug, '/' );
    8486
    8587    if ( is_subdomain_install() ) {
    8688        $domain = $slug . '.' . preg_replace( '|^www\.|', '', $current_network->domain );
    87         $path = $current_network->path;
     89        $path   = $current_network->path;
    8890    } else {
    8991        $domain = $current_network->domain;
    90         $path = $current_network->path . $slug . '/';
    91     }
    92 
    93     $site_ids = get_sites( array(
    94         'number' => 1,
    95         'fields' => 'ids',
    96         'domain' => $domain,
    97         'path' => $path,
    98     ) );
     92        $path   = $current_network->path . $slug . '/';
     93    }
     94
     95    $site_ids = get_sites(
     96        array(
     97            'number' => 1,
     98            'fields' => 'ids',
     99            'domain' => $domain,
     100            'path'   => $path,
     101        )
     102    );
    99103
    100104    if ( empty( $site_ids ) ) {
     
    121125    global $wpdb;
    122126
    123     if ( is_array($fields ) ) {
    124         if ( isset($fields['blog_id']) ) {
     127    if ( is_array( $fields ) ) {
     128        if ( isset( $fields['blog_id'] ) ) {
    125129            $blog_id = $fields['blog_id'];
    126         } elseif ( isset($fields['domain']) && isset($fields['path']) ) {
    127             $key = md5( $fields['domain'] . $fields['path'] );
    128             $blog = wp_cache_get($key, 'blog-lookup');
    129             if ( false !== $blog )
     130        } elseif ( isset( $fields['domain'] ) && isset( $fields['path'] ) ) {
     131            $key  = md5( $fields['domain'] . $fields['path'] );
     132            $blog = wp_cache_get( $key, 'blog-lookup' );
     133            if ( false !== $blog ) {
    130134                return $blog;
     135            }
    131136            if ( substr( $fields['domain'], 0, 4 ) == 'www.' ) {
    132137                $nowww = substr( $fields['domain'], 4 );
    133                 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) AND path = %s ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'], $fields['path'] ) );
     138                $blog  = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) AND path = %s ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'], $fields['path'] ) );
    134139            } else {
    135140                $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $fields['domain'], $fields['path'] ) );
    136141            }
    137142            if ( $blog ) {
    138                 wp_cache_set($blog->blog_id . 'short', $blog, 'blog-details');
     143                wp_cache_set( $blog->blog_id . 'short', $blog, 'blog-details' );
    139144                $blog_id = $blog->blog_id;
    140145            } else {
    141146                return false;
    142147            }
    143         } elseif ( isset($fields['domain']) && is_subdomain_install() ) {
    144             $key = md5( $fields['domain'] );
    145             $blog = wp_cache_get($key, 'blog-lookup');
    146             if ( false !== $blog )
     148        } elseif ( isset( $fields['domain'] ) && is_subdomain_install() ) {
     149            $key  = md5( $fields['domain'] );
     150            $blog = wp_cache_get( $key, 'blog-lookup' );
     151            if ( false !== $blog ) {
    147152                return $blog;
     153            }
    148154            if ( substr( $fields['domain'], 0, 4 ) == 'www.' ) {
    149155                $nowww = substr( $fields['domain'], 4 );
    150                 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'] ) );
     156                $blog  = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'] ) );
    151157            } else {
    152158                $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s", $fields['domain'] ) );
    153159            }
    154160            if ( $blog ) {
    155                 wp_cache_set($blog->blog_id . 'short', $blog, 'blog-details');
     161                wp_cache_set( $blog->blog_id . 'short', $blog, 'blog-details' );
    156162                $blog_id = $blog->blog_id;
    157163            } else {
     
    162168        }
    163169    } else {
    164         if ( ! $fields )
     170        if ( ! $fields ) {
    165171            $blog_id = get_current_blog_id();
    166         elseif ( ! is_numeric( $fields ) )
     172        } elseif ( ! is_numeric( $fields ) ) {
    167173            $blog_id = get_id_from_blogname( $fields );
    168         else
     174        } else {
    169175            $blog_id = $fields;
     176        }
    170177    }
    171178
    172179    $blog_id = (int) $blog_id;
    173180
    174     $all = $get_all == true ? '' : 'short';
     181    $all     = $get_all == true ? '' : 'short';
    175182    $details = wp_cache_get( $blog_id . $all, 'blog-details' );
    176183
     
    182189                // Clear old pre-serialized objects. Cache clients do better with that.
    183190                wp_cache_delete( $blog_id . $all, 'blog-details' );
    184                 unset($details);
     191                unset( $details );
    185192            }
    186193        } else {
     
    202209                    // Clear old pre-serialized objects. Cache clients do better with that.
    203210                    wp_cache_delete( $blog_id, 'blog-details' );
    204                     unset($details);
     211                    unset( $details );
    205212                }
    206213            } else {
     
    210217    }
    211218
    212     if ( empty($details) ) {
     219    if ( empty( $details ) ) {
    213220        $details = WP_Site::get_instance( $blog_id );
    214221        if ( ! $details ) {
     
    283290    global $wpdb;
    284291
    285     if ( empty($details) )
     292    if ( empty( $details ) ) {
    286293        return false;
    287 
    288     if ( is_object($details) )
    289         $details = get_object_vars($details);
     294    }
     295
     296    if ( is_object( $details ) ) {
     297        $details = get_object_vars( $details );
     298    }
    290299
    291300    $current_details = get_site( $blog_id );
    292     if ( empty($current_details) )
     301    if ( empty( $current_details ) ) {
    293302        return false;
    294 
    295     $current_details = get_object_vars($current_details);
    296 
    297     $details = array_merge($current_details, $details);
    298     $details['last_updated'] = current_time('mysql', true);
     303    }
     304
     305    $current_details = get_object_vars( $current_details );
     306
     307    $details                 = array_merge( $current_details, $details );
     308    $details['last_updated'] = current_time( 'mysql', true );
    299309
    300310    $update_details = array();
    301     $fields = array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id');
     311    $fields         = array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id' );
    302312    foreach ( array_intersect( array_keys( $details ), $fields ) as $field ) {
    303313        if ( 'path' === $field ) {
     
    308318    }
    309319
    310     $result = $wpdb->update( $wpdb->blogs, $update_details, array('blog_id' => $blog_id) );
    311 
    312     if ( false === $result )
     320    $result = $wpdb->update( $wpdb->blogs, $update_details, array( 'blog_id' => $blog_id ) );
     321
     322    if ( false === $result ) {
    313323        return false;
     324    }
    314325
    315326    // If spam status changed, issue actions.
     
    437448
    438449    $blog_id = $blog;
    439     $blog = get_site( $blog_id );
     450    $blog    = get_site( $blog_id );
    440451    if ( ! $blog ) {
    441452        if ( ! is_numeric( $blog_id ) ) {
     
    444455
    445456        // Make sure a WP_Site object exists even when the site has been deleted.
    446         $blog = new WP_Site( (object) array(
    447             'blog_id' => $blog_id,
    448             'domain'  => null,
    449             'path'    => null,
    450         ) );
    451     }
    452 
    453     $blog_id = $blog->blog_id;
     457        $blog = new WP_Site(
     458            (object) array(
     459                'blog_id' => $blog_id,
     460                'domain'  => null,
     461                'path'    => null,
     462            )
     463        );
     464    }
     465
     466    $blog_id         = $blog->blog_id;
    454467    $domain_path_key = md5( $blog->domain . $blog->path );
    455468
     
    457470    wp_cache_delete( $blog_id, 'site-details' );
    458471    wp_cache_delete( $blog_id, 'blog-details' );
    459     wp_cache_delete( $blog_id . 'short' , 'blog-details' );
     472    wp_cache_delete( $blog_id . 'short', 'blog-details' );
    460473    wp_cache_delete( $domain_path_key, 'blog-lookup' );
    461474    wp_cache_delete( $domain_path_key, 'blog-id-cache' );
     
    560573    $non_cached_ids = _get_non_cached_ids( $ids, 'sites' );
    561574    if ( ! empty( $non_cached_ids ) ) {
    562         $fresh_sites = $wpdb->get_results( sprintf( "SELECT * FROM $wpdb->blogs WHERE blog_id IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) );
     575        $fresh_sites = $wpdb->get_results( sprintf( "SELECT * FROM $wpdb->blogs WHERE blog_id IN (%s)", join( ',', array_map( 'intval', $non_cached_ids ) ) ) );
    563576
    564577        update_site_cache( $fresh_sites );
     
    666679    $id = (int) $id;
    667680
    668     if ( empty( $id ) )
     681    if ( empty( $id ) ) {
    669682        $id = get_current_blog_id();
    670 
    671     if ( get_current_blog_id() == $id )
     683    }
     684
     685    if ( get_current_blog_id() == $id ) {
    672686        return get_option( $option, $default );
     687    }
    673688
    674689    switch_to_blog( $id );
     
    711726    $id = (int) $id;
    712727
    713     if ( empty( $id ) )
     728    if ( empty( $id ) ) {
    714729        $id = get_current_blog_id();
    715 
    716     if ( get_current_blog_id() == $id )
     730    }
     731
     732    if ( get_current_blog_id() == $id ) {
    717733        return add_option( $option, $value );
     734    }
    718735
    719736    switch_to_blog( $id );
     
    736753    $id = (int) $id;
    737754
    738     if ( empty( $id ) )
     755    if ( empty( $id ) ) {
    739756        $id = get_current_blog_id();
    740 
    741     if ( get_current_blog_id() == $id )
     757    }
     758
     759    if ( get_current_blog_id() == $id ) {
    742760        return delete_option( $option );
     761    }
    743762
    744763    switch_to_blog( $id );
     
    763782    $id = (int) $id;
    764783
    765     if ( null !== $deprecated  )
     784    if ( null !== $deprecated ) {
    766785        _deprecated_argument( __FUNCTION__, '3.1.0' );
    767 
    768     if ( get_current_blog_id() == $id )
     786    }
     787
     788    if ( get_current_blog_id() == $id ) {
    769789        return update_option( $option, $value );
     790    }
    770791
    771792    switch_to_blog( $id );
     
    830851    $wpdb->set_blog_id( $new_blog );
    831852    $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
    832     $prev_blog_id = $blog_id;
    833     $GLOBALS['blog_id'] = $new_blog;
     853    $prev_blog_id            = $blog_id;
     854    $GLOBALS['blog_id']      = $new_blog;
    834855
    835856    if ( function_exists( 'wp_cache_switch_to_blog' ) ) {
     
    884905    }
    885906
    886     $blog = array_pop( $GLOBALS['_wp_switched_stack'] );
     907    $blog    = array_pop( $GLOBALS['_wp_switched_stack'] );
    887908    $blog_id = get_current_blog_id();
    888909
     
    896917
    897918    $wpdb->set_blog_id( $blog );
    898     $prev_blog_id = $blog_id;
    899     $GLOBALS['blog_id'] = $blog;
     919    $prev_blog_id            = $blog_id;
     920    $GLOBALS['blog_id']      = $blog;
    900921    $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
    901922
     
    975996 */
    976997function is_archived( $id ) {
    977     return get_blog_status($id, 'archived');
     998    return get_blog_status( $id, 'archived' );
    978999}
    9791000
     
    9881009 */
    9891010function update_archived( $id, $archived ) {
    990     update_blog_status($id, 'archived', $archived);
     1011    update_blog_status( $id, 'archived', $archived );
    9911012    return $archived;
    9921013}
     
    10081029    global $wpdb;
    10091030
    1010     if ( null !== $deprecated  )
     1031    if ( null !== $deprecated ) {
    10111032        _deprecated_argument( __FUNCTION__, '3.1.0' );
    1012 
    1013     if ( ! in_array( $pref, array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id') ) )
     1033    }
     1034
     1035    if ( ! in_array( $pref, array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id' ) ) ) {
    10141036        return $value;
    1015 
    1016     $result = $wpdb->update( $wpdb->blogs, array($pref => $value, 'last_updated' => current_time('mysql', true)), array('blog_id' => $blog_id) );
    1017 
    1018     if ( false === $result )
     1037    }
     1038
     1039    $result = $wpdb->update(
     1040        $wpdb->blogs, array(
     1041            $pref          => $value,
     1042            'last_updated' => current_time( 'mysql', true ),
     1043        ), array( 'blog_id' => $blog_id )
     1044    );
     1045
     1046    if ( false === $result ) {
    10191047        return false;
     1048    }
    10201049
    10211050    clean_blog_cache( $blog_id );
     
    10611090         * @param int    $blog_id Blog ID.
    10621091         * @param string $value   The value of blog status.
    1063          */
     1092         */
    10641093        do_action( 'update_blog_public', $blog_id, $value ); // Moved here from update_blog_public().
    10651094    }
     
    10831112
    10841113    $details = get_site( $id );
    1085     if ( $details )
     1114    if ( $details ) {
    10861115        return $details->$pref;
    1087 
    1088     return $wpdb->get_var( $wpdb->prepare("SELECT %s FROM {$wpdb->blogs} WHERE blog_id = %d", $pref, $id) );
     1116    }
     1117
     1118    return $wpdb->get_var( $wpdb->prepare( "SELECT %s FROM {$wpdb->blogs} WHERE blog_id = %d", $pref, $id ) );
    10891119}
    10901120
     
    11041134    global $wpdb;
    11051135
    1106     if ( ! empty( $deprecated ) )
     1136    if ( ! empty( $deprecated ) ) {
    11071137        _deprecated_argument( __FUNCTION__, 'MU' ); // never used
     1138    }
    11081139
    11091140    return $wpdb->get_results( $wpdb->prepare( "SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' AND last_updated != '0000-00-00 00:00:00' ORDER BY last_updated DESC limit %d, %d", get_current_network_id(), $start, $quantity ), ARRAY_A );
     
    12331264
    12341265    $non_cached_ids = _get_non_cached_ids( $network_ids, 'networks' );
    1235     if ( !empty( $non_cached_ids ) ) {
    1236         $fresh_networks = $wpdb->get_results( sprintf( "SELECT $wpdb->site.* FROM $wpdb->site WHERE id IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) );
     1266    if ( ! empty( $non_cached_ids ) ) {
     1267        $fresh_networks = $wpdb->get_results( sprintf( "SELECT $wpdb->site.* FROM $wpdb->site WHERE id IN (%s)", join( ',', array_map( 'intval', $non_cached_ids ) ) ) );
    12371268
    12381269        update_network_cache( $fresh_networks );
Note: See TracChangeset for help on using the changeset viewer.