Skip to:
Content

BuddyPress.org

Changeset 14010


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

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

See #9174
See #9173

Location:
trunk/src/bp-blogs/classes
Files:
4 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}
  • trunk/src/bp-blogs/classes/class-bp-blogs-component.php

    r13522 r14010  
    3535                        array(
    3636                                'adminbar_myaccount_order' => 30,
    37                                 'search_query_arg' => 'sites_search',
    38                                 'features' => array( 'site-icon' )
     37                                'search_query_arg'         => 'sites_search',
     38                                'features'                 => array( 'site-icon' ),
    3939                        )
    4040                );
     
    7474                // Fetch the default directory title.
    7575                $default_directory_titles = bp_core_get_directory_page_default_titles();
    76                 $default_directory_title  = $default_directory_titles[$this->id];
     76                $default_directory_title  = $default_directory_titles[ $this->id ];
    7777
    7878                // All globals for blogs component.
     
    8585                                'create_single_item'         => 'blog_create',
    8686                                'directory_action'           => 'blogs_action',
    87                                 'directory_action_variables' => 'blogs_action_variables'
     87                                'directory_action_variables' => 'blogs_action_variables',
    8888                        ),
    8989                        'directory_title'       => isset( $bp->pages->blogs->title ) ? $bp->pages->blogs->title : $default_directory_title,
     
    218218                 */
    219219                if ( ! is_multisite() ) {
    220                         return false;
     220                        return;
    221221                }
    222222
     
    229229                        'screen_function'     => 'bp_blogs_screen_my_blogs',
    230230                        'default_subnav_slug' => 'my-sites',
    231                         'item_css_id'         => $this->id
     231                        'item_css_id'         => $this->id,
    232232                );
    233233
     
    237237                        'parent_slug'     => $slug,
    238238                        'screen_function' => 'bp_blogs_screen_my_blogs',
    239                         'position'        => 10
     239                        'position'        => 10,
    240240                );
    241241
     
    334334                                        'title'    => __( 'Create a Site', 'buddypress' ),
    335335                                        'href'     => $url,
    336                                         'position' => 99
     336                                        'position' => 99,
    337337                                );
    338338                        }
     
    356356                                }
    357357
    358                         // If we are not viewing the logged in user, set up the current
    359                         // users avatar and name.
     358                                // If we are not viewing the logged in user, set up the current
     359                                // users avatar and name.
    360360                        } else {
    361                                 $bp->bp_options_avatar = bp_core_fetch_avatar( array(
    362                                         'item_id' => bp_displayed_user_id(),
    363                                         'type'    => 'thumb',
    364                                         'alt'     => sprintf(
     361                                $bp->bp_options_avatar = bp_core_fetch_avatar(
     362                                        array(
     363                                                'item_id' => bp_displayed_user_id(),
     364                                                'type'    => 'thumb',
     365                                                'alt'     => sprintf(
    365366                                                /* translators: %s: member name */
    366                                                 __( 'Profile picture of %s', 'buddypress' ),
    367                                                 bp_get_displayed_user_fullname()
    368                                         ),
    369                                 ) );
    370                                 $bp->bp_options_title = bp_get_displayed_user_fullname();
     367                                                        __( 'Profile picture of %s', 'buddypress' ),
     368                                                        bp_get_displayed_user_fullname()
     369                                                ),
     370                                        )
     371                                );
     372                                $bp->bp_options_title  = bp_get_displayed_user_fullname();
    371373                        }
    372374                }
     
    383385
    384386                // Global groups.
    385                 wp_cache_add_global_groups( array(
    386                         'bp_blog_meta'
    387                 ) );
     387                wp_cache_add_global_groups(
     388                        array(
     389                                'bp_blog_meta',
     390                        )
     391                );
    388392
    389393                parent::setup_cache_groups();
     
    430434                                'query' => 'index.php?' . $this->rewrite_ids['directory'] . '=1&' . $this->rewrite_ids['directory_action'] . '=$matches[1]',
    431435                        ),
    432                         'create_single_item' => array(
     436                        'create_single_item'         => array(
    433437                                'regex' => $this->root_slug . '/' . $create_slug . '/?$',
    434438                                'order' => 50,
     
    455459                 */
    456460                if ( ! is_multisite() || 'rewrites' !== bp_core_get_query_parser() ) {
    457                         return parent::parse_query( $query );
     461                        parent::parse_query( $query );
     462                        return;
    458463                }
    459464
     
    507512        public function rest_api_init( $controllers = array() ) {
    508513                if ( is_multisite() ) {
    509                         $controllers = array(
    510                                 'BP_REST_Blogs_Endpoint',
    511                         );
     514                        $controllers = array( 'BP_REST_Blogs_Endpoint' );
    512515
    513516                        // Support to Blog Avatar.
  • trunk/src/bp-blogs/classes/class-bp-blogs-template.php

    r13802 r14010  
    9696         * @see BP_Blogs_Blog::get() for a description of parameters.
    9797         *
    98          * @param array $args {
     98         * @param array ...$args {
    9999         *     Array of arguments. See {@link BP_Blogs_Blog::get()}.
    100100         * }
     
    103103                // Backward compatibility with old method of passing arguments.
    104104                if ( ! is_array( $args[0] ) || count( $args ) > 1 ) {
    105                         _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__ ) );
    106 
    107                         $old_args_keys = [
    108                                 0  => 'type',
    109                                 1  => 'page',
    110                                 2  => 'per_page',
    111                                 3  => 'max',
    112                                 4  => 'user_id',
    113                                 5  => 'search_terms',
    114                                 6  => 'page_arg',
    115                                 7  => 'update_meta_cache',
    116                                 8  => 'include_blog_ids',
    117                         ];
     105                        _deprecated_argument(
     106                                __METHOD__,
     107                                '10.0.0',
     108                                sprintf(
     109                                        // translators: 1: the name of the method. 2: the name of the file.
     110                                        esc_html__( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ),
     111                                        __METHOD__,
     112                                        __FILE__
     113                                )
     114                        );
     115
     116                        $old_args_keys = array(
     117                                0 => 'type',
     118                                1 => 'page',
     119                                2 => 'per_page',
     120                                3 => 'max',
     121                                4 => 'user_id',
     122                                5 => 'search_terms',
     123                                6 => 'page_arg',
     124                                7 => 'update_meta_cache',
     125                                8 => 'include_blog_ids',
     126                        );
    118127
    119128                        $args = bp_core_parse_args_array( $old_args_keys, $args );
     
    147156                        $this->blogs = BP_Blogs_Blog::get_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page );
    148157
    149                 // Typical blogs query.
     158                        // Typical blogs query.
    150159                } else {
    151                         $this->blogs = bp_blogs_get_blogs( array(
    152                                 'type'              => $r['type'],
    153                                 'per_page'          => $this->pag_num,
    154                                 'page'              => $this->pag_page,
    155                                 'user_id'           => $r['user_id'],
    156                                 'search_terms'      => $r['search_terms'],
    157                                 'update_meta_cache' => $r['update_meta_cache'],
    158                                 'include_blog_ids'  => $r['include_blog_ids'],
    159                                 'date_query'        => $r['date_query']
    160                         ) );
     160                        $this->blogs = bp_blogs_get_blogs(
     161                                array(
     162                                        'type'              => $r['type'],
     163                                        'per_page'          => $this->pag_num,
     164                                        'page'              => $this->pag_page,
     165                                        'user_id'           => $r['user_id'],
     166                                        'search_terms'      => $r['search_terms'],
     167                                        'update_meta_cache' => $r['update_meta_cache'],
     168                                        'include_blog_ids'  => $r['include_blog_ids'],
     169                                        'date_query'        => $r['date_query'],
     170                                )
     171                        );
    161172                }
    162173
     
    185196                // Build pagination links based on total blogs and current page number.
    186197                if ( ! empty( $this->total_blog_count ) && ! empty( $this->pag_num ) ) {
    187                         $this->pag_links = paginate_links( array(
    188                                 'base'      => add_query_arg( $this->pag_arg, '%#%' ),
    189                                 'format'    => '',
    190                                 'total'     => ceil( (int) $this->total_blog_count / (int) $this->pag_num ),
    191                                 'current'   => (int) $this->pag_page,
    192                                 'prev_text' => _x( '&larr;', 'Blog pagination previous text', 'buddypress' ),
    193                                 'next_text' => _x( '&rarr;', 'Blog pagination next text',     'buddypress' ),
    194                                 'mid_size'  => 1,
    195                                 'add_args'  => array(),
    196                         ) );
     198                        $this->pag_links = paginate_links(
     199                                array(
     200                                        'base'      => add_query_arg( $this->pag_arg, '%#%' ),
     201                                        'format'    => '',
     202                                        'total'     => ceil( (int) $this->total_blog_count / (int) $this->pag_num ),
     203                                        'current'   => (int) $this->pag_page,
     204                                        'prev_text' => _x( '&larr;', 'Blog pagination previous text', 'buddypress' ),
     205                                        'next_text' => _x( '&rarr;', 'Blog pagination next text', 'buddypress' ),
     206                                        'mid_size'  => 1,
     207                                        'add_args'  => array(),
     208                                )
     209                        );
    197210                }
    198211        }
     
    206219         */
    207220        public function has_blogs() {
    208                 return (bool) ! empty( $this->blog_count );
     221                return ! empty( $this->blog_count );
    209222        }
    210223
     
    215228         */
    216229        public function next_blog() {
    217                 $this->current_blog++;
     230                ++$this->current_blog;
    218231                $this->blog = $this->blogs[ $this->current_blog ];
    219232
     
    271284         */
    272285        public function the_blog() {
    273 
    274286                $this->in_the_loop = true;
    275287                $this->blog        = $this->next_blog();
  • trunk/src/bp-blogs/classes/class-bp-blogs-theme-compat.php

    r10517 r14010  
    3838
    3939                // Bail if not looking at a group.
    40                 if ( ! bp_is_blogs_component() )
     40                if ( ! bp_is_blogs_component() ) {
    4141                        return;
     42                }
    4243
    4344                // Bail if looking at a users sites.
    44                 if ( bp_is_user() )
     45                if ( bp_is_user() ) {
    4546                        return;
     47                }
    4648
    4749                // Blog Directory.
     
    5759                        do_action( 'bp_blogs_screen_index' );
    5860
    59                         add_filter( 'bp_get_buddypress_template',                array( $this, 'directory_template_hierarchy' ) );
     61                        add_filter( 'bp_get_buddypress_template', array( $this, 'directory_template_hierarchy' ) );
    6062                        add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'directory_dummy_post' ) );
    61                         add_filter( 'bp_replace_the_content',                    array( $this, 'directory_content'    ) );
    62 
    63                 // Create blog.
     63                        add_filter( 'bp_replace_the_content', array( $this, 'directory_content' ) );
     64
     65                        // Create blog.
    6466                } elseif ( is_user_logged_in() && bp_blog_signup_enabled() ) {
    65                         add_filter( 'bp_get_buddypress_template',                array( $this, 'create_template_hierarchy' ) );
     67                        add_filter( 'bp_get_buddypress_template', array( $this, 'create_template_hierarchy' ) );
    6668                        add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'create_dummy_post' ) );
    67                         add_filter( 'bp_replace_the_content',                    array( $this, 'create_content'    ) );
     69                        add_filter( 'bp_replace_the_content', array( $this, 'create_content' ) );
    6870                }
    6971        }
     
    7981         * @since 1.8.0
    8082         *
    81          * @param string $templates The templates from bp_get_theme_compat_templates().
     83         * @param array $templates The templates from bp_get_theme_compat_templates().
    8284         * @return array $templates Array of custom templates to look for.
    8385         */
    8486        public function directory_template_hierarchy( $templates ) {
     87
     88                if ( empty( $templates ) || ! is_array( $templates ) ) {
     89                        $templates = array();
     90                }
    8591
    8692                /**
     
    8995                 * @since 1.8.0
    9096                 *
    91                  * @param array $value Array of template paths to add to template list to look for.
     97                 * @param array $template_paths Array of template paths to add to template list to look for.
    9298                 */
    93                 $new_templates = apply_filters( 'bp_template_hierarchy_blogs_create', array(
    94                         'blogs/index-directory.php'
    95                 ) );
     99                $new_templates = apply_filters(
     100                        'bp_template_hierarchy_blogs_create',
     101                        array(
     102                                'blogs/index-directory.php',
     103                        )
     104                );
    96105
    97106                // Merge new templates with existing stack
    98107                // @see bp_get_theme_compat_templates().
    99                 $templates = array_merge( (array) $new_templates, $templates );
    100 
    101                 return $templates;
     108                return array_merge( $new_templates, $templates );
    102109        }
    103110
     
    108115         */
    109116        public function directory_dummy_post() {
    110 
    111                 bp_theme_compat_reset_post( array(
    112                         'ID'             => 0,
    113                         'post_title'     => __( 'Sites', 'buddypress' ),
    114                         'post_author'    => 0,
    115                         'post_date'      => 0,
    116                         'post_content'   => '',
    117                         'post_type'      => 'page',
    118                         'post_status'    => 'publish',
    119                         'is_page'        => true,
    120                         'comment_status' => 'closed'
    121                 ) );
     117                bp_theme_compat_reset_post(
     118                        array(
     119                                'ID'             => 0,
     120                                'post_title'     => __( 'Sites', 'buddypress' ),
     121                                'post_author'    => 0,
     122                                'post_date'      => 0,
     123                                'post_content'   => '',
     124                                'post_type'      => 'page',
     125                                'post_status'    => 'publish',
     126                                'is_page'        => true,
     127                                'comment_status' => 'closed',
     128                        )
     129                );
    122130        }
    123131
     
    126134         *
    127135         * @since 1.7.0
     136         *
     137         * @return string|null
    128138         */
    129139        public function directory_content() {
     
    141151         * @since 1.8.0
    142152         *
    143          * @param string $templates The templates from bp_get_theme_compat_templates().
     153         * @param array $templates The templates from bp_get_theme_compat_templates().
    144154         * @return array $templates Array of custom templates to look for.
    145155         */
    146156        public function create_template_hierarchy( $templates ) {
     157
     158                if ( empty( $templates ) || ! is_array( $templates ) ) {
     159                        $templates = array();
     160                }
    147161
    148162                /**
     
    151165                 * @since 1.8.0
    152166                 *
    153                  * @param array $value Array of template paths to add to template list to look for.
     167                 * @param array $template_paths Array of template paths to add to template list to look for.
    154168                 */
    155                 $new_templates = apply_filters( 'bp_template_hierarchy_blogs_create', array(
    156                         'blogs/index-create.php'
    157                 ) );
     169                $new_templates = apply_filters(
     170                        'bp_template_hierarchy_blogs_create',
     171                        array(
     172                                'blogs/index-create.php',
     173                        )
     174                );
    158175
    159176                // Merge new templates with existing stack
    160177                // @see bp_get_theme_compat_templates().
    161                 $templates = array_merge( (array) $new_templates, $templates );
    162 
    163                 return $templates;
     178                return array_merge( $new_templates, $templates );
    164179        }
    165180
     
    178193                }
    179194
    180                 bp_theme_compat_reset_post( array(
    181                         'ID'             => 0,
    182                         'post_title'     => $title,
    183                         'post_author'    => 0,
    184                         'post_date'      => 0,
    185                         'post_content'   => '',
    186                         'post_type'      => 'page',
    187                         'post_status'    => 'publish',
    188                         'is_page'        => true,
    189                         'comment_status' => 'closed'
    190                 ) );
     195                bp_theme_compat_reset_post(
     196                        array(
     197                                'ID'             => 0,
     198                                'post_title'     => $title,
     199                                'post_author'    => 0,
     200                                'post_date'      => 0,
     201                                'post_content'   => '',
     202                                'post_type'      => 'page',
     203                                'post_status'    => 'publish',
     204                                'is_page'        => true,
     205                                'comment_status' => 'closed',
     206                        )
     207                );
    191208        }
    192209
     
    195212         *
    196213         * @since 1.7.0
     214         *
     215         * @return string|null
    197216         */
    198217        public function create_content() {
Note: See TracChangeset for help on using the changeset viewer.