Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/26/2024 11:10:35 PM (3 months ago)
Author:
espellcaste
Message:

WPCS: Part I: miscellaneous fixes for some of the files of the blogs component.

See #9174
See #9173

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-blogs/classes/class-bp-blogs-blog.php

    r13902 r14010  
    4949     */
    5050    public function __construct( $id = null ) {
    51         if ( !empty( $id ) ) {
     51        if ( ! empty( $id ) ) {
    5252            $this->id = (int) $id;
    5353            $this->populate();
     
    7171    /**
    7272     * Save the BP blog data to the database.
     73     *
     74     * @global wpdb $wpdb WordPress database object.
    7375     *
    7476     * @return bool
     
    109111
    110112        // Don't try and save if there is no user ID or blog ID set.
    111         if ( !$this->user_id || !$this->blog_id )
     113        if ( ! $this->user_id || ! $this->blog_id ) {
    112114            return false;
     115        }
    113116
    114117        // Don't save if this blog has already been recorded for the user.
    115         if ( !$this->id && $this->exists() )
     118        if ( ! $this->id && $this->exists() ) {
    116119            return false;
     120        }
    117121
    118122        $bp = buddypress();
     
    126130        }
    127131
    128         if ( !$wpdb->query($sql) )
     132        if ( ! $wpdb->query( $sql ) ) {
    129133            return false;
     134        }
    130135
    131136        /**
     
    140145        do_action_ref_array( 'bp_blogs_blog_after_save', array( &$this ) );
    141146
    142         if ( $this->id )
     147        if ( $this->id ) {
    143148            return $this->id;
    144         else
    145             return $wpdb->insert_id;
     149        }
     150
     151        return $wpdb->insert_id;
    146152    }
    147153
     
    149155     * Check whether an association between this user and this blog exists.
    150156     *
    151      * @return int $value The number of associations between the user and blog
    152      *                    saved in the blog component tables.
     157     * @global wpdb $wpdb WordPress database object.
     158     *
     159     * @return string|null The number of associations between the user and blog.
    153160     */
    154161    public function exists() {
     
    166173     *
    167174     * @since 1.2.0
    168      * @since 10.0.0 Converted to array as main function argument. Added `$date_query` parameter.
    169      *
    170      * @param array $data {
     175     * @since 10.0.0 Converted to `array` as main function argument. Added `$date_query` parameter.
     176     *
     177     * @global wpdb $wpdb WordPress database object.
     178     *
     179     * @param array ...$args {
    171180     *     Array of site data to query for.
     181     *
    172182     *     @type string      $type              The order in which results should be returned.
    173183     *                                          'active', 'alphabetical', 'newest', or 'random'.
     
    184194     *     @type array|bool  $include_blog_ids  Optional. Array of blog IDs to include.
    185195     *     @type array       $date_query        Optional. Filter results by site last activity date. See first
    186      *                                          paramter of {@link WP_Date_Query::__construct()} for syntax. Only
    187      *                                          applicable if $type is either 'newest' or 'active'.
     196     *                                          parameter of {@link WP_Date_Query::__construct()} for syntax. Only
     197     *                                          applicable if `$type` is either 'newest' or 'active'.
    188198     * }
    189199     * @return array Multidimensional results array, structured as follows:
     
    194204        global $wpdb;
    195205
    196         $bp = buddypress();
    197 
    198206        // Backward compatibility with old method of passing arguments.
    199207        if ( ! is_array( $args[0] ) || count( $args ) > 1 ) {
    200             _deprecated_argument( __METHOD__, '10.0.0', sprintf( esc_html__( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
    201 
    202             $old_args_keys = [
    203                 0  => 'type',
    204                 1  => 'per_page',
    205                 2  => 'page',
    206                 3  => 'user_id',
    207                 4  => 'search_terms',
    208                 5  => 'update_meta_cache',
    209                 6  => 'include_blog_ids',
    210             ];
     208            _deprecated_argument(
     209                __METHOD__,
     210                '10.0.0',
     211                sprintf(
     212                    // translators: 1: the name of the method. 2: the name of the file.
     213                    esc_html__( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ),
     214                    __METHOD__,
     215                    __FILE__
     216                )
     217            );
     218
     219            $old_args_keys = array(
     220                0 => 'type',
     221                1 => 'per_page',
     222                2 => 'page',
     223                3 => 'user_id',
     224                4 => 'search_terms',
     225                5 => 'update_meta_cache',
     226                6 => 'include_blog_ids',
     227            );
    211228
    212229            $args = bp_core_parse_args_array( $old_args_keys, $args );
     
    215232        }
    216233
    217         $r = wp_parse_args(
     234        $bp = buddypress();
     235        $r  = wp_parse_args(
    218236            $args,
    219237            array(
     
    230248
    231249        if ( ! is_user_logged_in() || ( ! bp_current_user_can( 'bp_moderate' ) && ( $r['user_id'] != bp_loggedin_user_id() ) ) ) {
    232             $hidden_sql = "AND wb.public = 1";
     250            $hidden_sql = 'AND wb.public = 1';
    233251        } else {
    234252            $hidden_sql = '';
    235253        }
    236254
    237         $pag_sql = ( $r['per_page'] && $r['page'] ) ? $wpdb->prepare( " LIMIT %d, %d", intval( ( $r['page'] - 1 ) * $r['per_page']), intval( $r['per_page'] ) ) : '';
    238 
    239         $user_sql = ! empty( $r['user_id'] ) ? $wpdb->prepare( " AND b.user_id = %d", $r['user_id'] ) : '';
     255        $pag_sql = ( $r['per_page'] && $r['page'] ) ? $wpdb->prepare( ' LIMIT %d, %d', intval( ( $r['page'] - 1 ) * $r['per_page'] ), intval( $r['per_page'] ) ) : '';
     256
     257        $user_sql = ! empty( $r['user_id'] ) ? $wpdb->prepare( ' AND b.user_id = %d', $r['user_id'] ) : '';
    240258
    241259        $date_query_sql = '';
    242260
    243261        switch ( $r['type'] ) {
    244             case 'active': default:
     262            case 'active':
     263            default:
    245264                $date_query_sql = BP_Date_Query::get_where_sql( $r['date_query'], 'bm.meta_value', true );
    246                 $order_sql      = "ORDER BY bm.meta_value DESC";
     265                $order_sql      = 'ORDER BY bm.meta_value DESC';
    247266                break;
    248267            case 'alphabetical':
    249                 $order_sql = "ORDER BY bm_name.meta_value ASC";
     268                $order_sql = 'ORDER BY bm_name.meta_value ASC';
    250269                break;
    251270            case 'newest':
    252271                $date_query_sql = BP_Date_Query::get_where_sql( $r['date_query'], 'wb.registered', true );
    253                 $order_sql      = "ORDER BY wb.registered DESC";
     272                $order_sql      = 'ORDER BY wb.registered DESC';
    254273                break;
    255274            case 'random':
    256                 $order_sql = "ORDER BY RAND()";
     275                $order_sql = 'ORDER BY RAND()';
    257276                break;
    258277        }
    259278
    260         $include_sql = '';
     279        $include_sql      = '';
    261280        $include_blog_ids = array_filter( wp_parse_id_list( $r['include_blog_ids'] ) );
    262281        if ( ! empty( $include_blog_ids ) ) {
     
    278297        }
    279298
    280         $paged_blogs = $wpdb->get_results( "
     299        $paged_blogs = $wpdb->get_results(
     300            "
    281301            SELECT b.blog_id, b.user_id as admin_user_id, u.user_email as admin_user_email, wb.domain, wb.path, bm.meta_value as last_activity, bm_name.meta_value as name
    282302            FROM
     
    292312              {$search_terms_sql} {$user_sql} {$include_sql} {$date_query_sql}
    293313            GROUP BY b.blog_id {$order_sql} {$pag_sql}
    294         " );
    295 
    296         $total_blogs = $wpdb->get_var( "
     314        "
     315        );
     316
     317        $total_blogs = $wpdb->get_var(
     318            "
    297319            SELECT COUNT(DISTINCT b.blog_id)
    298320            FROM
     
    306328              AND bm.meta_key = 'last_activity' AND bm_name.meta_key = 'name'
    307329              {$search_terms_sql} {$user_sql} {$include_sql} {$date_query_sql}
    308         " );
     330        "
     331        );
    309332
    310333        $blog_ids = array();
     
    313336        }
    314337
    315         $paged_blogs = BP_Blogs_Blog::get_blog_extras( $paged_blogs, $blog_ids, $r['type'] );
     338        $paged_blogs = self::get_blog_extras( $paged_blogs, $blog_ids, $r['type'] );
    316339
    317340        // Integer casting.
     
    325348        }
    326349
    327         return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
     350        return array(
     351            'blogs' => $paged_blogs,
     352            'total' => $total_blogs,
     353        );
    328354    }
    329355
    330356    /**
    331357     * Delete the record of a given blog for all users.
     358     *
     359     * @global wpdb $wpdb WordPress database object.
    332360     *
    333361     * @param int $blog_id The blog being removed from all users.
     
    346374    /**
    347375     * Delete the record of a given blog for a specific user.
     376     *
     377     * @global wpdb $wpdb WordPress database object.
    348378     *
    349379     * @param int      $blog_id The blog being removed.
     
    355385        global $wpdb;
    356386
    357         if ( !$user_id )
     387        if ( ! $user_id ) {
    358388            $user_id = bp_loggedin_user_id();
     389        }
    359390
    360391        $bp = buddypress();
     
    365396    /**
    366397     * Delete all of a user's blog associations in the BP tables.
     398     *
     399     * @global wpdb $wpdb WordPress database object.
    367400     *
    368401     * @param int|null $user_id Optional. The ID of the user whose blog associations
     
    373406        global $wpdb;
    374407
    375         if ( !$user_id )
     408        if ( ! $user_id ) {
    376409            $user_id = bp_loggedin_user_id();
     410        }
    377411
    378412        $bp = buddypress();
     
    388422     * blogs that have been recorded by BuddyPress, while the WP function
    389423     * does a true query of a user's blog capabilities.
     424     *
     425     * @global wpdb $wpdb WordPress database object.
    390426     *
    391427     * @param int  $user_id     Optional. ID of the user whose blogs are being
     
    402438        $bp = buddypress();
    403439
    404         if ( !$user_id )
     440        if ( ! $user_id ) {
    405441            $user_id = bp_displayed_user_id();
     442        }
    406443
    407444        // Show logged in users their hidden blogs.
    408         if ( !bp_is_my_profile() && !$show_hidden )
     445        if ( ! bp_is_my_profile() && ! $show_hidden ) {
    409446            $blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.blog_id, b.id, bm1.meta_value as name, wb.domain, wb.path FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name_blogmeta} bm1 WHERE b.blog_id = wb.blog_id AND b.blog_id = bm1.blog_id AND bm1.meta_key = 'name' AND wb.public = 1 AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ORDER BY b.blog_id", $user_id ) );
    410         else
     447        } else {
    411448            $blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.blog_id, b.id, bm1.meta_value as name, wb.domain, wb.path FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name_blogmeta} bm1 WHERE b.blog_id = wb.blog_id AND b.blog_id = bm1.blog_id AND bm1.meta_key = 'name' AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ORDER BY b.blog_id", $user_id ) );
    412 
    413         $total_blog_count = BP_Blogs_Blog::total_blog_count_for_user( $user_id );
     449        }
     450
     451        $total_blog_count = self::total_blog_count_for_user( $user_id );
    414452
    415453        $user_blogs = array();
    416454        foreach ( (array) $blogs as $blog ) {
    417             $user_blogs[$blog->blog_id] = new stdClass;
    418             $user_blogs[$blog->blog_id]->id = (int) $blog->id;
    419             $user_blogs[$blog->blog_id]->blog_id = (int) $blog->blog_id;
    420             $user_blogs[$blog->blog_id]->siteurl = ( is_ssl() ) ? 'https://' . $blog->domain . $blog->path : 'http://' . $blog->domain . $blog->path;
    421             $user_blogs[$blog->blog_id]->name = $blog->name;
    422         }
    423 
    424         return array( 'blogs' => $user_blogs, 'count' => $total_blog_count );
     455            $user_blogs[ $blog->blog_id ]          = new stdClass();
     456            $user_blogs[ $blog->blog_id ]->id      = (int) $blog->id;
     457            $user_blogs[ $blog->blog_id ]->blog_id = (int) $blog->blog_id;
     458            $user_blogs[ $blog->blog_id ]->siteurl = ( is_ssl() ) ? 'https://' . $blog->domain . $blog->path : 'http://' . $blog->domain . $blog->path;
     459            $user_blogs[ $blog->blog_id ]->name    = $blog->name;
     460        }
     461
     462        return array(
     463            'blogs' => $user_blogs,
     464            'count' => $total_blog_count,
     465        );
    425466    }
    426467
     
    429470     *
    430471     * This method always includes hidden blogs.
     472     *
     473     * @global wpdb $wpdb WordPress database object.
    431474     *
    432475     * @param int $user_id Optional. ID of the user whose blogs are being
    433476     *                     queried. Defaults to logged-in user.
    434      * @return int The number of blogs associated with the user.
     477     * @return int[]
    435478     */
    436479    public static function get_blog_ids_for_user( $user_id = 0 ) {
     
    439482        $bp = buddypress();
    440483
    441         if ( !$user_id )
     484        if ( ! $user_id ) {
    442485            $user_id = bp_displayed_user_id();
    443 
    444         return array_map( 'intval', $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM {$bp->blogs->table_name} WHERE user_id = %d", $user_id ) ) );
     486        }
     487
     488        $blog_ids = $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM {$bp->blogs->table_name} WHERE user_id = %d", $user_id ) );
     489
     490        return wp_parse_id_list( $blog_ids );
    445491    }
    446492
    447493    /**
    448494     * Check whether a blog has been recorded by BuddyPress.
     495     *
     496     * @global wpdb $wpdb WordPress database object.
    449497     *
    450498     * @param int $blog_id ID of the blog being queried.
     
    469517     * cap.
    470518     *
     519     * @global wpdb $wpdb WordPress database object.
     520     *
    471521     * @param int|null $user_id Optional. ID of the user whose blogs are being
    472522     *                          queried. Defaults to logged-in user.
    473      * @return int Blog count for the user.
     523     * @return string|null Blog count for the user.
    474524     */
    475525    public static function total_blog_count_for_user( $user_id = null ) {
     
    478528        $bp = buddypress();
    479529
    480         if ( !$user_id )
     530        if ( ! $user_id ) {
    481531            $user_id = bp_displayed_user_id();
     532        }
    482533
    483534        // If the user is logged in return the blog count including their hidden blogs.
    484         if ( ( is_user_logged_in() && $user_id == bp_loggedin_user_id() ) || bp_current_user_can( 'bp_moderate' ) ) {
     535        if ( ( is_user_logged_in() && $user_id === bp_loggedin_user_id() ) || bp_current_user_can( 'bp_moderate' ) ) {
    485536            return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND user_id = %d", $user_id ) );
    486         } else {
    487             return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND user_id = %d", $user_id ) );
    488         }
     537        }
     538
     539        return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND user_id = %d", $user_id ) );
    489540    }
    490541
     
    494545     * Matches against blog names and descriptions, as stored in the BP
    495546     * blogmeta table.
     547     *
     548     * @global wpdb $wpdb WordPress database object.
    496549     *
    497550     * @param string   $filter The search term.
     
    511564
    512565        $hidden_sql = '';
    513         if ( !bp_current_user_can( 'bp_moderate' ) )
    514             $hidden_sql = "AND wb.public = 1";
     566        if ( ! bp_current_user_can( 'bp_moderate' ) ) {
     567            $hidden_sql = 'AND wb.public = 1';
     568        }
    515569
    516570        $pag_sql = '';
    517571        if ( $limit && $page ) {
    518             $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
     572            $pag_sql = $wpdb->prepare( ' LIMIT %d, %d', intval( ( $page - 1 ) * $limit ), intval( $limit ) );
    519573        }
    520574
     
    529583        }
    530584
    531         return array( 'blogs' => $paged_blogs, 'total' => (int) $total_blogs );
     585        return array(
     586            'blogs' => $paged_blogs,
     587            'total' => (int) $total_blogs,
     588        );
    532589    }
    533590
     
    537594     * Query will include hidden blogs if the logged-in user has the
    538595     * 'bp_moderate' cap.
     596     *
     597     * @global wpdb $wpdb WordPress database object.
    539598     *
    540599     * @param int|null $limit Optional. The maximum number of items to return.
     
    551610        $bp = buddypress();
    552611
    553         $hidden_sql = !bp_current_user_can( 'bp_moderate' ) ? "AND wb.public = 1" : '';
    554         $pag_sql    = ( $limit && $page ) ? $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ) : '';
     612        $hidden_sql = ! bp_current_user_can( 'bp_moderate' ) ? 'AND wb.public = 1' : '';
     613        $pag_sql    = ( $limit && $page ) ? $wpdb->prepare( ' LIMIT %d, %d', intval( ( $page - 1 ) * $limit ), intval( $limit ) ) : '';
    555614
    556615        $paged_blogs = $wpdb->get_results( "SELECT DISTINCT b.blog_id FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 {$hidden_sql} {$pag_sql}" );
     
    562621        }
    563622
    564         return array( 'blogs' => $paged_blogs, 'total' => (int) $total_blogs );
     623        return array(
     624            'blogs' => $paged_blogs,
     625            'total' => (int) $total_blogs,
     626        );
    565627    }
    566628
     
    570632     * Query will include hidden blogs if the logged-in user has the
    571633     * 'bp_moderate' cap.
     634     *
     635     * @global wpdb $wpdb WordPress database object.
    572636     *
    573637     * @param string   $letter The letter you're looking for.
     
    589653
    590654        $hidden_sql = '';
    591         if ( !bp_current_user_can( 'bp_moderate' ) )
    592             $hidden_sql = "AND wb.public = 1";
     655        if ( ! bp_current_user_can( 'bp_moderate' ) ) {
     656            $hidden_sql = 'AND wb.public = 1';
     657        }
    593658
    594659        $pag_sql = '';
    595         if ( $limit && $page )
    596             $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
     660        if ( $limit && $page ) {
     661            $pag_sql = $wpdb->prepare( ' LIMIT %d, %d', intval( ( $page - 1 ) * $limit ), intval( $limit ) );
     662        }
    597663
    598664        $paged_blogs = $wpdb->get_results( "SELECT DISTINCT bm.blog_id FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE bm.meta_key = 'name' AND {$letter_sql} {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY bm.meta_value ASC{$pag_sql}" );
     
    604670        }
    605671
    606         return array( 'blogs' => $paged_blogs, 'total' => (int) $total_blogs );
     672        return array(
     673            'blogs' => $paged_blogs,
     674            'total' => (int) $total_blogs,
     675        );
    607676    }
    608677
     
    616685     *   - The blog description
    617686     *
     687     * @global wpdb $wpdb WordPress database object.
     688     *
    618689     * @param array       $paged_blogs Array of results from the original query.
    619690     * @param array       $blog_ids    Array of IDs returned from the original query.
     
    626697        $bp = buddypress();
    627698
    628         if ( empty( $blog_ids ) )
     699        if ( empty( $blog_ids ) ) {
    629700            return $paged_blogs;
     701        }
    630702
    631703        $blog_ids = implode( ',', wp_parse_id_list( $blog_ids ) );
    632704
    633705        for ( $i = 0, $count = count( $paged_blogs ); $i < $count; ++$i ) {
    634             $blog_prefix = $wpdb->get_blog_prefix( $paged_blogs[$i]->blog_id );
    635             $paged_blogs[$i]->latest_post = $wpdb->get_row( "SELECT ID, post_content, post_title, post_excerpt, guid FROM {$blog_prefix}posts WHERE post_status = 'publish' AND post_type = 'post' AND id != 1 ORDER BY id DESC LIMIT 1" );
     706            $blog_prefix                    = $wpdb->get_blog_prefix( $paged_blogs[ $i ]->blog_id );
     707            $paged_blogs[ $i ]->latest_post = $wpdb->get_row( "SELECT ID, post_content, post_title, post_excerpt, guid FROM {$blog_prefix}posts WHERE post_status = 'publish' AND post_type = 'post' AND id != 1 ORDER BY id DESC LIMIT 1" );
    636708
    637709            /**
     
    649721
    650722                // Add URLs to any Featured Image this post might have.
    651                 if ( ! empty( $paged_blogs[$i]->latest_post ) && has_post_thumbnail( $paged_blogs[$i]->latest_post->ID ) ) {
     723                if ( ! empty( $paged_blogs[ $i ]->latest_post ) && has_post_thumbnail( $paged_blogs[ $i ]->latest_post->ID ) ) {
    652724
    653725                    // Grab 4 sizes of the image. Thumbnail.
    654                     $image = wp_get_attachment_image_src( get_post_thumbnail_id( $paged_blogs[$i]->latest_post->ID ), 'thumbnail', false );
    655                     if ( ! empty( $image ) )
     726                    $image = wp_get_attachment_image_src( get_post_thumbnail_id( $paged_blogs[ $i ]->latest_post->ID ), 'thumbnail', false );
     727                    if ( ! empty( $image ) ) {
    656728                        $images['thumbnail'] = $image[0];
     729                    }
    657730
    658731                    // Medium.
    659                     $image = wp_get_attachment_image_src( get_post_thumbnail_id( $paged_blogs[$i]->latest_post->ID ), 'medium', false );
    660                     if ( ! empty( $image ) )
     732                    $image = wp_get_attachment_image_src( get_post_thumbnail_id( $paged_blogs[ $i ]->latest_post->ID ), 'medium', false );
     733                    if ( ! empty( $image ) ) {
    661734                        $images['medium'] = $image[0];
     735                    }
    662736
    663737                    // Large.
    664                     $image = wp_get_attachment_image_src( get_post_thumbnail_id( $paged_blogs[$i]->latest_post->ID ), 'large', false );
    665                     if ( ! empty( $image ) )
     738                    $image = wp_get_attachment_image_src( get_post_thumbnail_id( $paged_blogs[ $i ]->latest_post->ID ), 'large', false );
     739                    if ( ! empty( $image ) ) {
    666740                        $images['large'] = $image[0];
     741                    }
    667742
    668743                    // Post thumbnail.
    669                     $image = wp_get_attachment_image_src( get_post_thumbnail_id( $paged_blogs[$i]->latest_post->ID ), 'post-thumbnail', false );
    670                     if ( ! empty( $image ) )
     744                    $image = wp_get_attachment_image_src( get_post_thumbnail_id( $paged_blogs[ $i ]->latest_post->ID ), 'post-thumbnail', false );
     745                    if ( ! empty( $image ) ) {
    671746                        $images['post-thumbnail'] = $image[0];
     747                    }
    672748
    673749                    // Add the images to the latest_post object.
    674                     $paged_blogs[$i]->latest_post->images = $images;
     750                    $paged_blogs[ $i ]->latest_post->images = $images;
    675751                }
    676752
     
    684760        for ( $i = 0, $count = count( $paged_blogs ); $i < $count; ++$i ) {
    685761            foreach ( (array) $blog_descs as $desc ) {
    686                 if ( $desc->blog_id == $paged_blogs[$i]->blog_id )
    687                     $paged_blogs[$i]->description = $desc->description;
     762                if ( $desc->blog_id === $paged_blogs[ $i ]->blog_id ) {
     763                    $paged_blogs[ $i ]->description = $desc->description;
     764                }
    688765            }
    689766        }
     
    696773     *
    697774     * Checks the 'public' column in the wp_blogs table.
     775     *
     776     * @global wpdb $wpdb WordPress database object.
    698777     *
    699778     * @param int $blog_id The ID of the blog being checked.
     
    703782        global $wpdb;
    704783
    705         if ( !(int) $wpdb->get_var( $wpdb->prepare( "SELECT public FROM {$wpdb->base_prefix}blogs WHERE blog_id = %d", $blog_id ) ) ) {
     784        if ( ! (int) $wpdb->get_var( $wpdb->prepare( "SELECT public FROM {$wpdb->base_prefix}blogs WHERE blog_id = %d", $blog_id ) ) ) {
    706785            return true;
    707786        }
     
    712791    /**
    713792     * Get ID of user-blog link.
     793     *
     794     * @global wpdb $wpdb WordPress database object.
    714795     *
    715796     * @param int $user_id ID of user.
     
    725806
    726807        if ( empty( $user_blog ) ) {
    727             $user_blog = false;
    728         } else {
    729             $user_blog = intval( $user_blog );
    730         }
    731 
    732         return $user_blog;
     808            return false;
     809        }
     810
     811        return intval( $user_blog );
    733812    }
    734813}
Note: See TracChangeset for help on using the changeset viewer.