Changeset 14010
- Timestamp:
- 08/26/2024 11:10:35 PM (7 months ago)
- 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 49 49 */ 50 50 public function __construct( $id = null ) { 51 if ( ! empty( $id ) ) {51 if ( ! empty( $id ) ) { 52 52 $this->id = (int) $id; 53 53 $this->populate(); … … 71 71 /** 72 72 * Save the BP blog data to the database. 73 * 74 * @global wpdb $wpdb WordPress database object. 73 75 * 74 76 * @return bool … … 109 111 110 112 // 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 ) { 112 114 return false; 115 } 113 116 114 117 // 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() ) { 116 119 return false; 120 } 117 121 118 122 $bp = buddypress(); … … 126 130 } 127 131 128 if ( ! $wpdb->query($sql) )132 if ( ! $wpdb->query( $sql ) ) { 129 133 return false; 134 } 130 135 131 136 /** … … 140 145 do_action_ref_array( 'bp_blogs_blog_after_save', array( &$this ) ); 141 146 142 if ( $this->id ) 147 if ( $this->id ) { 143 148 return $this->id; 144 else 145 return $wpdb->insert_id; 149 } 150 151 return $wpdb->insert_id; 146 152 } 147 153 … … 149 155 * Check whether an association between this user and this blog exists. 150 156 * 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. 153 160 */ 154 161 public function exists() { … … 166 173 * 167 174 * @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 { 171 180 * Array of site data to query for. 181 * 172 182 * @type string $type The order in which results should be returned. 173 183 * 'active', 'alphabetical', 'newest', or 'random'. … … 184 194 * @type array|bool $include_blog_ids Optional. Array of blog IDs to include. 185 195 * @type array $date_query Optional. Filter results by site last activity date. See first 186 * param ter of {@link WP_Date_Query::__construct()} for syntax. Only187 * applicable if $typeis either 'newest' or 'active'.196 * parameter of {@link WP_Date_Query::__construct()} for syntax. Only 197 * applicable if `$type` is either 'newest' or 'active'. 188 198 * } 189 199 * @return array Multidimensional results array, structured as follows: … … 194 204 global $wpdb; 195 205 196 $bp = buddypress();197 198 206 // Backward compatibility with old method of passing arguments. 199 207 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 ); 211 228 212 229 $args = bp_core_parse_args_array( $old_args_keys, $args ); … … 215 232 } 216 233 217 $r = wp_parse_args( 234 $bp = buddypress(); 235 $r = wp_parse_args( 218 236 $args, 219 237 array( … … 230 248 231 249 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'; 233 251 } else { 234 252 $hidden_sql = ''; 235 253 } 236 254 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'] ) : ''; 240 258 241 259 $date_query_sql = ''; 242 260 243 261 switch ( $r['type'] ) { 244 case 'active': default: 262 case 'active': 263 default: 245 264 $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'; 247 266 break; 248 267 case 'alphabetical': 249 $order_sql = "ORDER BY bm_name.meta_value ASC";268 $order_sql = 'ORDER BY bm_name.meta_value ASC'; 250 269 break; 251 270 case 'newest': 252 271 $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'; 254 273 break; 255 274 case 'random': 256 $order_sql = "ORDER BY RAND()";275 $order_sql = 'ORDER BY RAND()'; 257 276 break; 258 277 } 259 278 260 $include_sql = '';279 $include_sql = ''; 261 280 $include_blog_ids = array_filter( wp_parse_id_list( $r['include_blog_ids'] ) ); 262 281 if ( ! empty( $include_blog_ids ) ) { … … 278 297 } 279 298 280 $paged_blogs = $wpdb->get_results( " 299 $paged_blogs = $wpdb->get_results( 300 " 281 301 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 282 302 FROM … … 292 312 {$search_terms_sql} {$user_sql} {$include_sql} {$date_query_sql} 293 313 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 " 297 319 SELECT COUNT(DISTINCT b.blog_id) 298 320 FROM … … 306 328 AND bm.meta_key = 'last_activity' AND bm_name.meta_key = 'name' 307 329 {$search_terms_sql} {$user_sql} {$include_sql} {$date_query_sql} 308 " ); 330 " 331 ); 309 332 310 333 $blog_ids = array(); … … 313 336 } 314 337 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'] ); 316 339 317 340 // Integer casting. … … 325 348 } 326 349 327 return array( 'blogs' => $paged_blogs, 'total' => $total_blogs ); 350 return array( 351 'blogs' => $paged_blogs, 352 'total' => $total_blogs, 353 ); 328 354 } 329 355 330 356 /** 331 357 * Delete the record of a given blog for all users. 358 * 359 * @global wpdb $wpdb WordPress database object. 332 360 * 333 361 * @param int $blog_id The blog being removed from all users. … … 346 374 /** 347 375 * Delete the record of a given blog for a specific user. 376 * 377 * @global wpdb $wpdb WordPress database object. 348 378 * 349 379 * @param int $blog_id The blog being removed. … … 355 385 global $wpdb; 356 386 357 if ( ! $user_id )387 if ( ! $user_id ) { 358 388 $user_id = bp_loggedin_user_id(); 389 } 359 390 360 391 $bp = buddypress(); … … 365 396 /** 366 397 * Delete all of a user's blog associations in the BP tables. 398 * 399 * @global wpdb $wpdb WordPress database object. 367 400 * 368 401 * @param int|null $user_id Optional. The ID of the user whose blog associations … … 373 406 global $wpdb; 374 407 375 if ( ! $user_id )408 if ( ! $user_id ) { 376 409 $user_id = bp_loggedin_user_id(); 410 } 377 411 378 412 $bp = buddypress(); … … 388 422 * blogs that have been recorded by BuddyPress, while the WP function 389 423 * does a true query of a user's blog capabilities. 424 * 425 * @global wpdb $wpdb WordPress database object. 390 426 * 391 427 * @param int $user_id Optional. ID of the user whose blogs are being … … 402 438 $bp = buddypress(); 403 439 404 if ( ! $user_id )440 if ( ! $user_id ) { 405 441 $user_id = bp_displayed_user_id(); 442 } 406 443 407 444 // Show logged in users their hidden blogs. 408 if ( ! bp_is_my_profile() && !$show_hidden )445 if ( ! bp_is_my_profile() && ! $show_hidden ) { 409 446 $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 else447 } else { 411 448 $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 ); 414 452 415 453 $user_blogs = array(); 416 454 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 ); 425 466 } 426 467 … … 429 470 * 430 471 * This method always includes hidden blogs. 472 * 473 * @global wpdb $wpdb WordPress database object. 431 474 * 432 475 * @param int $user_id Optional. ID of the user whose blogs are being 433 476 * queried. Defaults to logged-in user. 434 * @return int The number of blogs associated with the user.477 * @return int[] 435 478 */ 436 479 public static function get_blog_ids_for_user( $user_id = 0 ) { … … 439 482 $bp = buddypress(); 440 483 441 if ( ! $user_id )484 if ( ! $user_id ) { 442 485 $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 ); 445 491 } 446 492 447 493 /** 448 494 * Check whether a blog has been recorded by BuddyPress. 495 * 496 * @global wpdb $wpdb WordPress database object. 449 497 * 450 498 * @param int $blog_id ID of the blog being queried. … … 469 517 * cap. 470 518 * 519 * @global wpdb $wpdb WordPress database object. 520 * 471 521 * @param int|null $user_id Optional. ID of the user whose blogs are being 472 522 * queried. Defaults to logged-in user. 473 * @return intBlog count for the user.523 * @return string|null Blog count for the user. 474 524 */ 475 525 public static function total_blog_count_for_user( $user_id = null ) { … … 478 528 $bp = buddypress(); 479 529 480 if ( ! $user_id )530 if ( ! $user_id ) { 481 531 $user_id = bp_displayed_user_id(); 532 } 482 533 483 534 // 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' ) ) { 485 536 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 ) ); 489 540 } 490 541 … … 494 545 * Matches against blog names and descriptions, as stored in the BP 495 546 * blogmeta table. 547 * 548 * @global wpdb $wpdb WordPress database object. 496 549 * 497 550 * @param string $filter The search term. … … 511 564 512 565 $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 } 515 569 516 570 $pag_sql = ''; 517 571 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 ) ); 519 573 } 520 574 … … 529 583 } 530 584 531 return array( 'blogs' => $paged_blogs, 'total' => (int) $total_blogs ); 585 return array( 586 'blogs' => $paged_blogs, 587 'total' => (int) $total_blogs, 588 ); 532 589 } 533 590 … … 537 594 * Query will include hidden blogs if the logged-in user has the 538 595 * 'bp_moderate' cap. 596 * 597 * @global wpdb $wpdb WordPress database object. 539 598 * 540 599 * @param int|null $limit Optional. The maximum number of items to return. … … 551 610 $bp = buddypress(); 552 611 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 ) ) : ''; 555 614 556 615 $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}" ); … … 562 621 } 563 622 564 return array( 'blogs' => $paged_blogs, 'total' => (int) $total_blogs ); 623 return array( 624 'blogs' => $paged_blogs, 625 'total' => (int) $total_blogs, 626 ); 565 627 } 566 628 … … 570 632 * Query will include hidden blogs if the logged-in user has the 571 633 * 'bp_moderate' cap. 634 * 635 * @global wpdb $wpdb WordPress database object. 572 636 * 573 637 * @param string $letter The letter you're looking for. … … 589 653 590 654 $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 } 593 658 594 659 $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 } 597 663 598 664 $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}" ); … … 604 670 } 605 671 606 return array( 'blogs' => $paged_blogs, 'total' => (int) $total_blogs ); 672 return array( 673 'blogs' => $paged_blogs, 674 'total' => (int) $total_blogs, 675 ); 607 676 } 608 677 … … 616 685 * - The blog description 617 686 * 687 * @global wpdb $wpdb WordPress database object. 688 * 618 689 * @param array $paged_blogs Array of results from the original query. 619 690 * @param array $blog_ids Array of IDs returned from the original query. … … 626 697 $bp = buddypress(); 627 698 628 if ( empty( $blog_ids ) ) 699 if ( empty( $blog_ids ) ) { 629 700 return $paged_blogs; 701 } 630 702 631 703 $blog_ids = implode( ',', wp_parse_id_list( $blog_ids ) ); 632 704 633 705 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" ); 636 708 637 709 /** … … 649 721 650 722 // 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 ) ) { 652 724 653 725 // 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 ) ) { 656 728 $images['thumbnail'] = $image[0]; 729 } 657 730 658 731 // 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 ) ) { 661 734 $images['medium'] = $image[0]; 735 } 662 736 663 737 // 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 ) ) { 666 740 $images['large'] = $image[0]; 741 } 667 742 668 743 // 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 ) ) { 671 746 $images['post-thumbnail'] = $image[0]; 747 } 672 748 673 749 // Add the images to the latest_post object. 674 $paged_blogs[ $i]->latest_post->images = $images;750 $paged_blogs[ $i ]->latest_post->images = $images; 675 751 } 676 752 … … 684 760 for ( $i = 0, $count = count( $paged_blogs ); $i < $count; ++$i ) { 685 761 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 } 688 765 } 689 766 } … … 696 773 * 697 774 * Checks the 'public' column in the wp_blogs table. 775 * 776 * @global wpdb $wpdb WordPress database object. 698 777 * 699 778 * @param int $blog_id The ID of the blog being checked. … … 703 782 global $wpdb; 704 783 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 ) ) ) { 706 785 return true; 707 786 } … … 712 791 /** 713 792 * Get ID of user-blog link. 793 * 794 * @global wpdb $wpdb WordPress database object. 714 795 * 715 796 * @param int $user_id ID of user. … … 725 806 726 807 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 ); 733 812 } 734 813 } -
trunk/src/bp-blogs/classes/class-bp-blogs-component.php
r13522 r14010 35 35 array( 36 36 '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' ), 39 39 ) 40 40 ); … … 74 74 // Fetch the default directory title. 75 75 $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 ]; 77 77 78 78 // All globals for blogs component. … … 85 85 'create_single_item' => 'blog_create', 86 86 'directory_action' => 'blogs_action', 87 'directory_action_variables' => 'blogs_action_variables' 87 'directory_action_variables' => 'blogs_action_variables', 88 88 ), 89 89 'directory_title' => isset( $bp->pages->blogs->title ) ? $bp->pages->blogs->title : $default_directory_title, … … 218 218 */ 219 219 if ( ! is_multisite() ) { 220 return false;220 return; 221 221 } 222 222 … … 229 229 'screen_function' => 'bp_blogs_screen_my_blogs', 230 230 'default_subnav_slug' => 'my-sites', 231 'item_css_id' => $this->id 231 'item_css_id' => $this->id, 232 232 ); 233 233 … … 237 237 'parent_slug' => $slug, 238 238 'screen_function' => 'bp_blogs_screen_my_blogs', 239 'position' => 10 239 'position' => 10, 240 240 ); 241 241 … … 334 334 'title' => __( 'Create a Site', 'buddypress' ), 335 335 'href' => $url, 336 'position' => 99 336 'position' => 99, 337 337 ); 338 338 } … … 356 356 } 357 357 358 // If we are not viewing the logged in user, set up the current359 // users avatar and name.358 // If we are not viewing the logged in user, set up the current 359 // users avatar and name. 360 360 } 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( 365 366 /* 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(); 371 373 } 372 374 } … … 383 385 384 386 // 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 ); 388 392 389 393 parent::setup_cache_groups(); … … 430 434 'query' => 'index.php?' . $this->rewrite_ids['directory'] . '=1&' . $this->rewrite_ids['directory_action'] . '=$matches[1]', 431 435 ), 432 'create_single_item' => array(436 'create_single_item' => array( 433 437 'regex' => $this->root_slug . '/' . $create_slug . '/?$', 434 438 'order' => 50, … … 455 459 */ 456 460 if ( ! is_multisite() || 'rewrites' !== bp_core_get_query_parser() ) { 457 return parent::parse_query( $query ); 461 parent::parse_query( $query ); 462 return; 458 463 } 459 464 … … 507 512 public function rest_api_init( $controllers = array() ) { 508 513 if ( is_multisite() ) { 509 $controllers = array( 510 'BP_REST_Blogs_Endpoint', 511 ); 514 $controllers = array( 'BP_REST_Blogs_Endpoint' ); 512 515 513 516 // Support to Blog Avatar. -
trunk/src/bp-blogs/classes/class-bp-blogs-template.php
r13802 r14010 96 96 * @see BP_Blogs_Blog::get() for a description of parameters. 97 97 * 98 * @param array $args {98 * @param array ...$args { 99 99 * Array of arguments. See {@link BP_Blogs_Blog::get()}. 100 100 * } … … 103 103 // Backward compatibility with old method of passing arguments. 104 104 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 ); 118 127 119 128 $args = bp_core_parse_args_array( $old_args_keys, $args ); … … 147 156 $this->blogs = BP_Blogs_Blog::get_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page ); 148 157 149 // Typical blogs query.158 // Typical blogs query. 150 159 } 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 ); 161 172 } 162 173 … … 185 196 // Build pagination links based on total blogs and current page number. 186 197 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( '←', 'Blog pagination previous text', 'buddypress' ), 193 'next_text' => _x( '→', '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( '←', 'Blog pagination previous text', 'buddypress' ), 205 'next_text' => _x( '→', 'Blog pagination next text', 'buddypress' ), 206 'mid_size' => 1, 207 'add_args' => array(), 208 ) 209 ); 197 210 } 198 211 } … … 206 219 */ 207 220 public function has_blogs() { 208 return (bool)! empty( $this->blog_count );221 return ! empty( $this->blog_count ); 209 222 } 210 223 … … 215 228 */ 216 229 public function next_blog() { 217 $this->current_blog++;230 ++$this->current_blog; 218 231 $this->blog = $this->blogs[ $this->current_blog ]; 219 232 … … 271 284 */ 272 285 public function the_blog() { 273 274 286 $this->in_the_loop = true; 275 287 $this->blog = $this->next_blog(); -
trunk/src/bp-blogs/classes/class-bp-blogs-theme-compat.php
r10517 r14010 38 38 39 39 // Bail if not looking at a group. 40 if ( ! bp_is_blogs_component() ) 40 if ( ! bp_is_blogs_component() ) { 41 41 return; 42 } 42 43 43 44 // Bail if looking at a users sites. 44 if ( bp_is_user() ) 45 if ( bp_is_user() ) { 45 46 return; 47 } 46 48 47 49 // Blog Directory. … … 57 59 do_action( 'bp_blogs_screen_index' ); 58 60 59 add_filter( 'bp_get_buddypress_template', 61 add_filter( 'bp_get_buddypress_template', array( $this, 'directory_template_hierarchy' ) ); 60 62 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. 64 66 } elseif ( is_user_logged_in() && bp_blog_signup_enabled() ) { 65 add_filter( 'bp_get_buddypress_template', 67 add_filter( 'bp_get_buddypress_template', array( $this, 'create_template_hierarchy' ) ); 66 68 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' ) ); 68 70 } 69 71 } … … 79 81 * @since 1.8.0 80 82 * 81 * @param string$templates The templates from bp_get_theme_compat_templates().83 * @param array $templates The templates from bp_get_theme_compat_templates(). 82 84 * @return array $templates Array of custom templates to look for. 83 85 */ 84 86 public function directory_template_hierarchy( $templates ) { 87 88 if ( empty( $templates ) || ! is_array( $templates ) ) { 89 $templates = array(); 90 } 85 91 86 92 /** … … 89 95 * @since 1.8.0 90 96 * 91 * @param array $ valueArray 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. 92 98 */ 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 ); 96 105 97 106 // Merge new templates with existing stack 98 107 // @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 ); 102 109 } 103 110 … … 108 115 */ 109 116 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 ); 122 130 } 123 131 … … 126 134 * 127 135 * @since 1.7.0 136 * 137 * @return string|null 128 138 */ 129 139 public function directory_content() { … … 141 151 * @since 1.8.0 142 152 * 143 * @param string$templates The templates from bp_get_theme_compat_templates().153 * @param array $templates The templates from bp_get_theme_compat_templates(). 144 154 * @return array $templates Array of custom templates to look for. 145 155 */ 146 156 public function create_template_hierarchy( $templates ) { 157 158 if ( empty( $templates ) || ! is_array( $templates ) ) { 159 $templates = array(); 160 } 147 161 148 162 /** … … 151 165 * @since 1.8.0 152 166 * 153 * @param array $ valueArray 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. 154 168 */ 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 ); 158 175 159 176 // Merge new templates with existing stack 160 177 // @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 ); 164 179 } 165 180 … … 178 193 } 179 194 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 ); 191 208 } 192 209 … … 195 212 * 196 213 * @since 1.7.0 214 * 215 * @return string|null 197 216 */ 198 217 public function create_content() {
Note: See TracChangeset
for help on using the changeset viewer.