Ticket #9288: 9288.patch
| File 9288.patch, 39.0 KB (added by , 8 months ago) |
|---|
-
bp-blogs-template.php
14 14 * Output the blogs component slug. 15 15 * 16 16 * @since 1.5.0 17 *18 17 */ 19 18 function bp_blogs_slug() { 20 19 echo esc_attr( bp_get_blogs_slug() ); … … 26 25 * 27 26 * @return string The 'blogs' slug. 28 27 */ 29 function bp_get_blogs_slug() {28 function bp_get_blogs_slug() { 30 29 31 /**32 * Filters the blogs component slug.33 *34 * @since 1.5.035 *36 * @param string $slug Slug for the blogs component.37 */38 return apply_filters( 'bp_get_blogs_slug', buddypress()->blogs->slug );39 }30 /** 31 * Filters the blogs component slug. 32 * 33 * @since 1.5.0 34 * 35 * @param string $slug Slug for the blogs component. 36 */ 37 return apply_filters( 'bp_get_blogs_slug', buddypress()->blogs->slug ); 38 } 40 39 41 40 /** 42 41 * Output the blogs component root slug. 43 42 * 44 43 * @since 1.5.0 45 *46 44 */ 47 45 function bp_blogs_root_slug() { 48 46 echo esc_attr( bp_get_blogs_root_slug() ); … … 54 52 * 55 53 * @return string The 'blogs' root slug. 56 54 */ 57 function bp_get_blogs_root_slug() {55 function bp_get_blogs_root_slug() { 58 56 59 /**60 * Filters the blogs component root slug.61 *62 * @since 1.5.063 *64 * @param string $root_slug Root slug for the blogs component.65 */66 return apply_filters( 'bp_get_blogs_root_slug', buddypress()->blogs->root_slug );67 }57 /** 58 * Filters the blogs component root slug. 59 * 60 * @since 1.5.0 61 * 62 * @param string $root_slug Root slug for the blogs component. 63 */ 64 return apply_filters( 'bp_get_blogs_root_slug', buddypress()->blogs->root_slug ); 65 } 68 66 69 67 /** 70 68 * Output Blogs directory's URL. … … 93 91 $path_chunks = bp_parse_args( 94 92 array_intersect_key( $path_chunks, $supported_chunks ), 95 93 array( 96 'component_id' => 'blogs' 94 'component_id' => 'blogs', 97 95 ) 98 96 ); 99 97 … … 173 171 174 172 // Check for and use search terms. 175 173 $search_terms_default = false; 176 $search_query_arg = bp_core_get_component_search_query_arg( 'blogs' );174 $search_query_arg = bp_core_get_component_search_query_arg( 'blogs' ); 177 175 if ( ! empty( $_REQUEST[ $search_query_arg ] ) ) { 178 176 $search_terms_default = stripslashes( $_REQUEST[ $search_query_arg ] ); 179 177 } elseif ( ! empty( $_REQUEST['s'] ) ) { … … 305 303 * 306 304 * @return string HTML pagination links. 307 305 */ 308 function bp_get_blogs_pagination_links() {309 global $blogs_template;306 function bp_get_blogs_pagination_links() { 307 global $blogs_template; 310 308 311 /**312 * Filters the blogs pagination links.313 *314 * @since 1.0.0315 *316 * @param string $pag_links HTML pagination links.317 */318 return apply_filters( 'bp_get_blogs_pagination_links', $blogs_template->pag_links );319 }309 /** 310 * Filters the blogs pagination links. 311 * 312 * @since 1.0.0 313 * 314 * @param string $pag_links HTML pagination links. 315 */ 316 return apply_filters( 'bp_get_blogs_pagination_links', $blogs_template->pag_links ); 317 } 320 318 321 319 /** 322 320 * Output a blog's avatar. … … 361 359 * } 362 360 * @return string|bool User avatar string. False if avatars are turned off. 363 361 */ 364 function bp_get_blog_avatar( $args = '' ) {365 global $blogs_template;362 function bp_get_blog_avatar( $args = '' ) { 363 global $blogs_template; 366 364 367 // Bail if avatars are turned off368 // @todo Should we maybe still filter this?369 if ( ! buddypress()->avatar->show_avatars ) {370 return false;371 }365 // Bail if avatars are turned off 366 // @todo Should we maybe still filter this? 367 if ( ! buddypress()->avatar->show_avatars ) { 368 return false; 369 } 372 370 373 // Set default value for the `alt` attribute.374 $alt_attribute = __( 'Site icon for the blog', 'buddypress' );371 // Set default value for the `alt` attribute. 372 $alt_attribute = __( 'Site icon for the blog', 'buddypress' ); 375 373 376 if ( ! empty( $args['blog_id'] ) ) {377 $blog_id = (int) $args['blog_id'];378 } elseif ( isset( $blogs_template->blog->blog_id ) ) {379 $blog_id = bp_get_blog_id();374 if ( ! empty( $args['blog_id'] ) ) { 375 $blog_id = (int) $args['blog_id']; 376 } elseif ( isset( $blogs_template->blog->blog_id ) ) { 377 $blog_id = bp_get_blog_id(); 380 378 381 /* translators: %s is the blog name */382 $alt_attribute = sprintf( __( 'Site icon for %s', 'buddypress' ), bp_get_blog_name() );383 } else {384 $blog_id = 0;385 }379 /* translators: %s is the blog name */ 380 $alt_attribute = sprintf( __( 'Site icon for %s', 'buddypress' ), bp_get_blog_name() ); 381 } else { 382 $blog_id = 0; 383 } 386 384 387 // Parse the arguments.388 $r = bp_parse_args(389 $args,390 array(391 'item_id' => $blog_id,392 'avatar_dir' => 'blog-avatars',393 'object' => 'blog',394 'type' => 'full',395 'width' => false,396 'height' => false,397 'class' => 'avatar',398 'id' => false,399 'alt' => $alt_attribute,400 'no_grav' => false,401 'html' => true,402 ),403 'blog_avatar'404 );385 // Parse the arguments. 386 $r = bp_parse_args( 387 $args, 388 array( 389 'item_id' => $blog_id, 390 'avatar_dir' => 'blog-avatars', 391 'object' => 'blog', 392 'type' => 'full', 393 'width' => false, 394 'height' => false, 395 'class' => 'avatar', 396 'id' => false, 397 'alt' => $alt_attribute, 398 'no_grav' => false, 399 'html' => true, 400 ), 401 'blog_avatar' 402 ); 405 403 406 /**407 * If the `admin_user_id` was provided, make the Blog avatar408 * defaults to the Blog's Admin user one.409 */410 if ( isset( $r['admin_user_id'] ) && $r['admin_user_id'] ) {411 $r['item_id'] = (int) $r['admin_user_id'];412 $r['avatar_dir'] = 'avatars';413 $r['object'] = 'user';414 } elseif ( ! $r['no_grav'] ) {415 $r['no_grav'] = true;416 }404 /** 405 * If the `admin_user_id` was provided, make the Blog avatar 406 * defaults to the Blog's Admin user one. 407 */ 408 if ( isset( $r['admin_user_id'] ) && $r['admin_user_id'] ) { 409 $r['item_id'] = (int) $r['admin_user_id']; 410 $r['avatar_dir'] = 'avatars'; 411 $r['object'] = 'user'; 412 } elseif ( ! $r['no_grav'] ) { 413 $r['no_grav'] = true; 414 } 417 415 418 // Use site icon if available.419 $avatar = '';420 if ( bp_is_active( 'blogs', 'site-icon' ) ) {421 $site_icon = bp_blogs_get_blogmeta( $blog_id, "site_icon_url_{$r['type']}" );416 // Use site icon if available. 417 $avatar = ''; 418 if ( bp_is_active( 'blogs', 'site-icon' ) ) { 419 $site_icon = bp_blogs_get_blogmeta( $blog_id, "site_icon_url_{$r['type']}" ); 422 420 423 // Never attempted to fetch site icon before; do it now!424 if ( '' === $site_icon ) {425 // Fetch the other size first.426 if ( 'full' === $r['type'] ) {427 $size = bp_core_avatar_thumb_width();428 $save_size = 'thumb';429 } else {430 $size = bp_core_avatar_full_width();431 $save_size = 'full';432 }421 // Never attempted to fetch site icon before; do it now! 422 if ( '' === $site_icon ) { 423 // Fetch the other size first. 424 if ( 'full' === $r['type'] ) { 425 $size = bp_core_avatar_thumb_width(); 426 $save_size = 'thumb'; 427 } else { 428 $size = bp_core_avatar_full_width(); 429 $save_size = 'full'; 430 } 433 431 434 $site_icon = bp_blogs_get_site_icon_url( $blog_id, $size );432 $site_icon = bp_blogs_get_site_icon_url( $blog_id, $size ); 435 433 436 // Empty site icons get saved as integer 0.437 if ( empty( $site_icon ) ) {438 $site_icon = 0;439 }434 // Empty site icons get saved as integer 0. 435 if ( empty( $site_icon ) ) { 436 $site_icon = 0; 437 } 440 438 441 // Sync site icon for other size to blogmeta.442 bp_blogs_update_blogmeta( $blog_id, "site_icon_url_{$save_size}", $site_icon );439 // Sync site icon for other size to blogmeta. 440 bp_blogs_update_blogmeta( $blog_id, "site_icon_url_{$save_size}", $site_icon ); 443 441 444 // Now, fetch the size we want. 445 if ( 0 !== $site_icon ) { 446 $size = 'full' === $r['type'] ? bp_core_avatar_full_width() : bp_core_avatar_thumb_width(); 447 $site_icon = bp_blogs_get_site_icon_url( $blog_id, $size ); 448 } 449 450 // Sync site icon to blogmeta. 451 bp_blogs_update_blogmeta( $blog_id, "site_icon_url_{$r['type']}", $site_icon ); 442 // Now, fetch the size we want. 443 if ( 0 !== $site_icon ) { 444 $size = 'full' === $r['type'] ? bp_core_avatar_full_width() : bp_core_avatar_thumb_width(); 445 $site_icon = bp_blogs_get_site_icon_url( $blog_id, $size ); 452 446 } 453 447 454 // We have a site icon. 455 if ( ! is_numeric( $site_icon ) ) { 456 // Just return the raw url of the Site Icon. 457 if ( ! $r['html'] ) { 458 return esc_url_raw( $site_icon ); 459 } 448 // Sync site icon to blogmeta. 449 bp_blogs_update_blogmeta( $blog_id, "site_icon_url_{$r['type']}", $site_icon ); 450 } 460 451 461 if ( empty( $r['width'] ) && ! isset( $size ) ) { 462 $size = 'full' === $r['type'] ? bp_core_avatar_full_width() : bp_core_avatar_thumb_width(); 463 } else { 464 $size = (int) $r['width']; 465 } 452 // We have a site icon. 453 if ( ! is_numeric( $site_icon ) ) { 454 // Just return the raw url of the Site Icon. 455 if ( ! $r['html'] ) { 456 return esc_url_raw( $site_icon ); 457 } 466 458 467 $avatar = sprintf( '<img src="%1$s" class="%2$s" width="%3$s" height="%3$s" alt="%4$s" />', 468 esc_url( $site_icon ), 469 esc_attr( "{$r['class']} avatar-{$size}" ), 470 esc_attr( $size ), 471 esc_attr( $alt_attribute ) 472 ); 459 if ( empty( $r['width'] ) && ! isset( $size ) ) { 460 $size = 'full' === $r['type'] ? bp_core_avatar_full_width() : bp_core_avatar_thumb_width(); 461 } else { 462 $size = (int) $r['width']; 473 463 } 474 }475 464 476 // Fallback to Default blog avatar. 477 if ( '' === $avatar ) { 478 $avatar = bp_core_fetch_avatar( $r ); 465 $avatar = sprintf( 466 '<img src="%1$s" class="%2$s" width="%3$s" height="%3$s" alt="%4$s" />', 467 esc_url( $site_icon ), 468 esc_attr( "{$r['class']} avatar-{$size}" ), 469 esc_attr( $size ), 470 esc_attr( $alt_attribute ) 471 ); 479 472 } 473 } 480 474 481 /** 482 * Filters a blog's avatar. 483 * 484 * @since 1.5.0 485 * 486 * @param string $avatar Formatted HTML <img> element, or raw avatar 487 * URL based on $html arg. 488 * @param int $blog_id ID of the blog whose avatar is being displayed. 489 * @param array $r Array of arguments used when fetching avatar. 490 */ 491 return apply_filters( 'bp_get_blog_avatar', $avatar, $blog_id, $r ); 475 // Fallback to Default blog avatar. 476 if ( '' === $avatar ) { 477 $avatar = bp_core_fetch_avatar( $r ); 492 478 } 493 479 480 /** 481 * Filters a blog's avatar. 482 * 483 * @since 1.5.0 484 * 485 * @param string $avatar Formatted HTML <img> element, or raw avatar 486 * URL based on $html arg. 487 * @param int $blog_id ID of the blog whose avatar is being displayed. 488 * @param array $r Array of arguments used when fetching avatar. 489 */ 490 return apply_filters( 'bp_get_blog_avatar', $avatar, $blog_id, $r ); 491 } 492 494 493 function bp_blog_permalink() { 495 494 echo esc_url( bp_get_blog_permalink() ); 496 495 } 497 function bp_get_blog_permalink() {498 global $blogs_template;496 function bp_get_blog_permalink() { 497 global $blogs_template; 499 498 500 if ( ! empty( $blogs_template->blog->domain ) ) {501 $permalink = get_site_url( $blogs_template->blog->blog_id );499 if ( ! empty( $blogs_template->blog->domain ) ) { 500 $permalink = get_site_url( $blogs_template->blog->blog_id ); 502 501 503 } else { 504 $protocol = 'http://'; 505 if ( is_ssl() ) { 506 $protocol = 'https://'; 507 } 508 509 $permalink = $protocol . $blogs_template->blog->domain . $blogs_template->blog->path; 502 } else { 503 $protocol = 'http://'; 504 if ( is_ssl() ) { 505 $protocol = 'https://'; 510 506 } 511 507 512 /** 513 * Filters the blog permalink. 514 * 515 * @since 1.0.0 516 * 517 * @param string $permalink Permalink URL for the blog. 518 */ 519 return apply_filters( 'bp_get_blog_permalink', $permalink ); 508 $permalink = $protocol . $blogs_template->blog->domain . $blogs_template->blog->path; 520 509 } 521 510 511 /** 512 * Filters the blog permalink. 513 * 514 * @since 1.0.0 515 * 516 * @param string $permalink Permalink URL for the blog. 517 */ 518 return apply_filters( 'bp_get_blog_permalink', $permalink ); 519 } 520 522 521 /** 523 522 * Output the name of the current blog in the loop. 524 523 */ … … 530 529 * 531 530 * @return string The name of the current blog in the loop. 532 531 */ 533 function bp_get_blog_name() {534 global $blogs_template;532 function bp_get_blog_name() { 533 global $blogs_template; 535 534 536 $name = '';535 $name = ''; 537 536 538 if ( ! empty( $blogs_template->blog->name ) ) { 539 $name = $blogs_template->blog->name; 540 } 541 542 /** 543 * Filters the name of the current blog in the loop. 544 * 545 * @since 1.2.0 546 * 547 * @param string $name Name of the current blog in the loop. 548 */ 549 return apply_filters( 'bp_get_blog_name', $name ); 537 if ( ! empty( $blogs_template->blog->name ) ) { 538 $name = $blogs_template->blog->name; 550 539 } 551 540 541 /** 542 * Filters the name of the current blog in the loop. 543 * 544 * @since 1.2.0 545 * 546 * @param string $name Name of the current blog in the loop. 547 */ 548 return apply_filters( 'bp_get_blog_name', $name ); 549 } 550 552 551 /** 553 552 * Output the ID of the current blog in the loop. 554 553 * … … 564 563 * 565 564 * @return int ID of the current blog in the loop. 566 565 */ 567 function bp_get_blog_id() {568 global $blogs_template;566 function bp_get_blog_id() { 567 global $blogs_template; 569 568 570 /**571 * Filters the ID of the current blog in the loop.572 *573 * @since 1.7.0574 *575 * @param int $blog_id ID of the current blog in the loop.576 */577 return apply_filters( 'bp_get_blog_id', $blogs_template->blog->blog_id );578 }569 /** 570 * Filters the ID of the current blog in the loop. 571 * 572 * @since 1.7.0 573 * 574 * @param int $blog_id ID of the current blog in the loop. 575 */ 576 return apply_filters( 'bp_get_blog_id', $blogs_template->blog->blog_id ); 577 } 579 578 580 579 /** 581 580 * Output the description of the current blog in the loop. … … 596 595 * 597 596 * @return string Description of the current blog in the loop. 598 597 */ 599 function bp_get_blog_description() {600 global $blogs_template;598 function bp_get_blog_description() { 599 global $blogs_template; 601 600 602 /**603 * Filters the description of the current blog in the loop.604 *605 * @since 1.0.0606 *607 * @param string $value Description of the current blog in the loop.608 */609 return apply_filters( 'bp_get_blog_description', $blogs_template->blog->description );610 }601 /** 602 * Filters the description of the current blog in the loop. 603 * 604 * @since 1.0.0 605 * 606 * @param string $value Description of the current blog in the loop. 607 */ 608 return apply_filters( 'bp_get_blog_description', $blogs_template->blog->description ); 609 } 611 610 612 611 /** 613 612 * Output the row class of the current blog in the loop. … … 630 629 * @param array $classes Array of custom classes. 631 630 * @return string Row class of the site. 632 631 */ 633 function bp_get_blog_class( $classes = array() ) {634 global $blogs_template;632 function bp_get_blog_class( $classes = array() ) { 633 global $blogs_template; 635 634 636 // Add even/odd classes, but only if there's more than 1 group.637 if ( $blogs_template->blog_count > 1 ) {638 $pos_in_loop = (int) $blogs_template->current_blog;639 $classes[] = ( $pos_in_loop % 2 ) ? 'even' : 'odd';635 // Add even/odd classes, but only if there's more than 1 group. 636 if ( $blogs_template->blog_count > 1 ) { 637 $pos_in_loop = (int) $blogs_template->current_blog; 638 $classes[] = ( $pos_in_loop % 2 ) ? 'even' : 'odd'; 640 639 641 640 // If we've only one site in the loop, don't bother with odd and even. 642 } else {643 $classes[] = 'bp-single-blog';644 }641 } else { 642 $classes[] = 'bp-single-blog'; 643 } 645 644 646 /**647 * Filters the row class of the current blog in the loop.648 *649 * @since 1.7.0650 *651 * @param array $classes Array of classes to be applied to row.652 */653 $classes = array_map( 'sanitize_html_class', apply_filters( 'bp_get_blog_class', $classes ) );654 $classes = array_merge( $classes, array() );655 $retval = 'class="' . join( ' ', $classes ) . '"';645 /** 646 * Filters the row class of the current blog in the loop. 647 * 648 * @since 1.7.0 649 * 650 * @param array $classes Array of classes to be applied to row. 651 */ 652 $classes = array_map( 'sanitize_html_class', apply_filters( 'bp_get_blog_class', $classes ) ); 653 $classes = array_merge( $classes, array() ); 654 $retval = 'class="' . join( ' ', $classes ) . '"'; 656 655 657 return $retval;658 }656 return $retval; 657 } 659 658 660 659 /** 661 660 * Output the last active date of the current blog in the loop. … … 676 675 * } 677 676 * @return string Last active date. 678 677 */ 679 function bp_get_blog_last_active( $args = array() ) {680 global $blogs_template;678 function bp_get_blog_last_active( $args = array() ) { 679 global $blogs_template; 681 680 682 // Parse the activity format.683 $r = bp_parse_args(684 $args,685 array(686 'active_format' => true,687 )688 );681 // Parse the activity format. 682 $r = bp_parse_args( 683 $args, 684 array( 685 'active_format' => true, 686 ) 687 ); 689 688 690 // Backwards compatibility for anyone forcing a 'true' active_format.691 if ( true === $r['active_format'] ) {692 /* translators: %s: last activity timestamp (e.g. "Active 1 hour ago") */693 $r['active_format'] = _x( 'Active %s', 'last time the site was active', 'buddypress' );694 }689 // Backwards compatibility for anyone forcing a 'true' active_format. 690 if ( true === $r['active_format'] ) { 691 /* translators: %s: last activity timestamp (e.g. "Active 1 hour ago") */ 692 $r['active_format'] = _x( 'Active %s', 'last time the site was active', 'buddypress' ); 693 } 695 694 696 // Blog has been posted to at least once.697 if ( isset( $blogs_template->blog->last_activity ) ) {695 // Blog has been posted to at least once. 696 if ( isset( $blogs_template->blog->last_activity ) ) { 698 697 699 // Backwards compatibility for pre 1.5 'ago' strings.700 $last_activity = ! empty( $r['active_format'] )701 ? bp_core_get_last_activity( $blogs_template->blog->last_activity, $r['active_format'] )702 : bp_core_time_since( $blogs_template->blog->last_activity );698 // Backwards compatibility for pre 1.5 'ago' strings. 699 $last_activity = ! empty( $r['active_format'] ) 700 ? bp_core_get_last_activity( $blogs_template->blog->last_activity, $r['active_format'] ) 701 : bp_core_time_since( $blogs_template->blog->last_activity ); 703 702 704 703 // Blog has never been posted to. 705 } else { 706 $last_activity = __( 'Never active', 'buddypress' ); 707 } 708 709 /** 710 * Filters the last active date of the current blog in the loop. 711 * 712 * @since 1.2.0 713 * 714 * @param string $last_activity Last active date. 715 * @param array $r Array of parsed args used to determine formatting. 716 */ 717 return apply_filters( 'bp_blog_last_active', $last_activity, $r ); 704 } else { 705 $last_activity = __( 'Never active', 'buddypress' ); 718 706 } 719 707 708 /** 709 * Filters the last active date of the current blog in the loop. 710 * 711 * @since 1.2.0 712 * 713 * @param string $last_activity Last active date. 714 * @param array $r Array of parsed args used to determine formatting. 715 */ 716 return apply_filters( 'bp_blog_last_active', $last_activity, $r ); 717 } 718 720 719 /** 721 720 * Output the latest post from the current blog in the loop. 722 721 * … … 743 742 * } 744 743 * @return string $retval String of the form 'Latest Post: [link to post]'. 745 744 */ 746 function bp_get_blog_latest_post( $args = array() ) {747 global $blogs_template;745 function bp_get_blog_latest_post( $args = array() ) { 746 global $blogs_template; 748 747 749 $r = bp_parse_args(750 $args,751 array(752 'latest_format' => true,753 )754 );748 $r = bp_parse_args( 749 $args, 750 array( 751 'latest_format' => true, 752 ) 753 ); 755 754 756 $retval = bp_get_blog_latest_post_title();755 $retval = bp_get_blog_latest_post_title(); 757 756 758 if ( ! empty( $retval ) ) {759 if ( ! empty( $r['latest_format'] ) ) {757 if ( ! empty( $retval ) ) { 758 if ( ! empty( $r['latest_format'] ) ) { 760 759 761 /**762 * Filters the title text of the latest post for the current blog in loop.763 *764 * @since 1.0.0765 *766 * @param string $retval Title of the latest post.767 */768 $retval = sprintf(769 /* translators: %s: the title of the latest post */770 __( 'Latest Post: %s', 'buddypress' ),771 '<a href="' . $blogs_template->blog->latest_post->guid . '">' . apply_filters( 'the_title', $retval ) . '</a>'772 );773 } else {760 /** 761 * Filters the title text of the latest post for the current blog in loop. 762 * 763 * @since 1.0.0 764 * 765 * @param string $retval Title of the latest post. 766 */ 767 $retval = sprintf( 768 /* translators: %s: the title of the latest post */ 769 __( 'Latest Post: %s', 'buddypress' ), 770 '<a href="' . $blogs_template->blog->latest_post->guid . '">' . apply_filters( 'the_title', $retval ) . '</a>' 771 ); 772 } else { 774 773 775 /** This filter is documented in bp-blogs/bp-blogs-template.php */ 776 $retval = '<a href="' . $blogs_template->blog->latest_post->guid . '">' . apply_filters( 'the_title', $retval ) . '</a>'; 777 } 774 /** This filter is documented in bp-blogs/bp-blogs-template.php */ 775 $retval = '<a href="' . $blogs_template->blog->latest_post->guid . '">' . apply_filters( 'the_title', $retval ) . '</a>'; 778 776 } 779 780 /**781 * Filters the HTML markup result for the latest blog post in loop.782 *783 * @since 1.2.0784 * @since 2.6.0 Added the `$r` parameter.785 *786 * @param string $retval HTML markup for the latest post.787 * @param array $r Array of parsed arguments.788 */789 return apply_filters( 'bp_get_blog_latest_post', $retval, $r );790 777 } 791 778 779 /** 780 * Filters the HTML markup result for the latest blog post in loop. 781 * 782 * @since 1.2.0 783 * @since 2.6.0 Added the `$r` parameter. 784 * 785 * @param string $retval HTML markup for the latest post. 786 * @param array $r Array of parsed arguments. 787 */ 788 return apply_filters( 'bp_get_blog_latest_post', $retval, $r ); 789 } 790 792 791 /** 793 792 * Output the title of the latest post on the current blog in the loop. 794 793 * … … 808 807 * 809 808 * @return string Post title. 810 809 */ 811 function bp_get_blog_latest_post_title() {812 global $blogs_template;810 function bp_get_blog_latest_post_title() { 811 global $blogs_template; 813 812 814 $retval = '';813 $retval = ''; 815 814 816 if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->post_title ) ) 817 $retval = $blogs_template->blog->latest_post->post_title; 818 819 /** 820 * Filters the title text of the latest post on the current blog in the loop. 821 * 822 * @since 1.7.0 823 * 824 * @param string $retval Title text for the latest post. 825 */ 826 return apply_filters( 'bp_get_blog_latest_post_title', $retval ); 815 if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->post_title ) ) { 816 $retval = $blogs_template->blog->latest_post->post_title; 827 817 } 828 818 819 /** 820 * Filters the title text of the latest post on the current blog in the loop. 821 * 822 * @since 1.7.0 823 * 824 * @param string $retval Title text for the latest post. 825 */ 826 return apply_filters( 'bp_get_blog_latest_post_title', $retval ); 827 } 828 829 829 /** 830 830 * Output the permalink of the latest post on the current blog in the loop. 831 831 * … … 845 845 * 846 846 * @return string URL of the blog's latest post. 847 847 */ 848 function bp_get_blog_latest_post_permalink() {849 global $blogs_template;848 function bp_get_blog_latest_post_permalink() { 849 global $blogs_template; 850 850 851 $retval = '';851 $retval = ''; 852 852 853 if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->ID ) ) 854 $retval = add_query_arg( 'p', $blogs_template->blog->latest_post->ID, bp_get_blog_permalink() ); 855 856 /** 857 * Filters the permalink of the latest post on the current blog in the loop. 858 * 859 * @since 1.7.0 860 * 861 * @param string $retval Permalink URL of the latest post. 862 */ 863 return apply_filters( 'bp_get_blog_latest_post_permalink', $retval ); 853 if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->ID ) ) { 854 $retval = add_query_arg( 'p', $blogs_template->blog->latest_post->ID, bp_get_blog_permalink() ); 864 855 } 865 856 857 /** 858 * Filters the permalink of the latest post on the current blog in the loop. 859 * 860 * @since 1.7.0 861 * 862 * @param string $retval Permalink URL of the latest post. 863 */ 864 return apply_filters( 'bp_get_blog_latest_post_permalink', $retval ); 865 } 866 866 867 /** 867 868 * Output the content of the latest post on the current blog in the loop. 868 869 * 869 870 * @since 1.7.0 870 *871 871 */ 872 872 function bp_blog_latest_post_content() { 873 873 echo wp_kses_post( bp_get_blog_latest_post_content() ); … … 881 881 * 882 882 * @return string Content of the blog's latest post. 883 883 */ 884 function bp_get_blog_latest_post_content() {885 global $blogs_template;884 function bp_get_blog_latest_post_content() { 885 global $blogs_template; 886 886 887 $retval = '';887 $retval = ''; 888 888 889 if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->post_content ) ) { 890 $retval = $blogs_template->blog->latest_post->post_content; 891 } 892 893 /** 894 * Filters the content of the latest post on the current blog in the loop. 895 * 896 * @since 1.7.0 897 * 898 * @param string $retval Content of the latest post on the current blog in the loop. 899 */ 900 return apply_filters( 'bp_get_blog_latest_post_content', $retval ); 889 if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->post_content ) ) { 890 $retval = $blogs_template->blog->latest_post->post_content; 901 891 } 902 892 893 /** 894 * Filters the content of the latest post on the current blog in the loop. 895 * 896 * @since 1.7.0 897 * 898 * @param string $retval Content of the latest post on the current blog in the loop. 899 */ 900 return apply_filters( 'bp_get_blog_latest_post_content', $retval ); 901 } 902 903 903 /** 904 904 * Output the featured image of the latest post on the current blog in the loop. 905 905 * … … 923 923 * 'large', or 'post-thumbnail'. Default: 'thumbnail'. 924 924 * @return string URL of the image. 925 925 */ 926 function bp_get_blog_latest_post_featured_image( $size = 'thumbnail' ) {927 global $blogs_template;926 function bp_get_blog_latest_post_featured_image( $size = 'thumbnail' ) { 927 global $blogs_template; 928 928 929 $retval = '';929 $retval = ''; 930 930 931 if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->images[$size] ) ) { 932 $retval = $blogs_template->blog->latest_post->images[$size]; 933 } 934 935 /** 936 * Filters the featured image of the latest post on the current blog in the loop. 937 * 938 * @since 1.7.0 939 * 940 * @param string $retval The featured image of the latest post on the current blog in the loop. 941 */ 942 return apply_filters( 'bp_get_blog_latest_post_featured_image', $retval ); 931 if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->images[ $size ] ) ) { 932 $retval = $blogs_template->blog->latest_post->images[ $size ]; 943 933 } 944 934 935 /** 936 * Filters the featured image of the latest post on the current blog in the loop. 937 * 938 * @since 1.7.0 939 * 940 * @param string $retval The featured image of the latest post on the current blog in the loop. 941 */ 942 return apply_filters( 'bp_get_blog_latest_post_featured_image', $retval ); 943 } 944 945 945 /** 946 946 * Does the latest blog post have a featured image? 947 947 * … … 953 953 * featured image of the given size. 954 954 */ 955 955 function bp_blog_latest_post_has_featured_image( $thumbnail = 'thumbnail' ) { 956 $image = bp_get_blog_latest_post_featured_image( $thumbnail );956 $image = bp_get_blog_latest_post_featured_image( $thumbnail ); 957 957 958 958 /** 959 959 * Filters whether or not the latest blog post has a featured image. … … 976 976 */ 977 977 function bp_blog_hidden_fields() { 978 978 if ( isset( $_REQUEST['s'] ) ) { 979 echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['s'] ) . '" name="search_terms" />';979 echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['s'] ) . '" name="search_terms" />'; 980 980 } 981 981 982 982 if ( isset( $_REQUEST['letter'] ) ) { … … 999 999 * 1000 1000 * @return int Total number of blogs. 1001 1001 */ 1002 function bp_get_total_blog_count() {1002 function bp_get_total_blog_count() { 1003 1003 1004 /**1005 * Filters the total number of blogs on the site.1006 *1007 * @since 1.2.01008 *1009 * @param int $value Total number of blogs on the site.1010 */1011 return apply_filters( 'bp_get_total_blog_count', bp_blogs_total_blogs() );1012 }1004 /** 1005 * Filters the total number of blogs on the site. 1006 * 1007 * @since 1.2.0 1008 * 1009 * @param int $value Total number of blogs on the site. 1010 */ 1011 return apply_filters( 'bp_get_total_blog_count', bp_blogs_total_blogs() ); 1012 } 1013 1013 add_filter( 'bp_get_total_blog_count', 'bp_core_number_format' ); 1014 1014 1015 1015 /** … … 1026 1026 * @param int $user_id ID of the user. 1027 1027 * @return int Total number of blogs for the user. 1028 1028 */ 1029 function bp_get_total_blog_count_for_user( $user_id = 0 ) {1029 function bp_get_total_blog_count_for_user( $user_id = 0 ) { 1030 1030 1031 /**1032 * Filters the total number of blogs for a given user.1033 *1034 * @since 1.2.01035 * @since 2.6.0 Added the `$user_id` parameter.1036 *1037 * @param int $value Total number of blogs for a given user.1038 * @param int $user_id ID of the queried user.1039 */1040 return apply_filters( 'bp_get_total_blog_count_for_user', bp_blogs_total_blogs_for_user( $user_id ), $user_id );1041 }1031 /** 1032 * Filters the total number of blogs for a given user. 1033 * 1034 * @since 1.2.0 1035 * @since 2.6.0 Added the `$user_id` parameter. 1036 * 1037 * @param int $value Total number of blogs for a given user. 1038 * @param int $user_id ID of the queried user. 1039 */ 1040 return apply_filters( 'bp_get_total_blog_count_for_user', bp_blogs_total_blogs_for_user( $user_id ), $user_id ); 1041 } 1042 1042 add_filter( 'bp_get_total_blog_count_for_user', 'bp_core_number_format' ); 1043 1043 1044 1044 … … 1076 1076 * WP_Error $errors WP_Error object. 1077 1077 * } 1078 1078 */ 1079 $filtered_results = apply_filters('signup_another_blog_init', array('blogname' => $blogname, 'blog_title' => $blog_title, 'errors' => $errors )); 1079 $filtered_results = apply_filters( 1080 'signup_another_blog_init', 1081 array( 1082 'blogname' => $blogname, 1083 'blog_title' => $blog_title, 1084 'errors' => $errors, 1085 ) 1086 ); 1080 1087 $blogname = $filtered_results['blogname']; 1081 1088 $blog_title = $filtered_results['blog_title']; 1082 1089 $errors = $filtered_results['errors']; … … 1117 1124 * 1118 1125 * @since 1.0.0 1119 1126 */ 1120 do_action( 'signup_hidden_fields' ); ?> 1127 do_action( 'signup_hidden_fields' ); 1128 ?> 1121 1129 1122 1130 <?php bp_blogs_signup_blog( $blogname, $blog_title, $errors ); ?> 1123 1131 <p> … … 1124 1132 <input id="submit" type="submit" name="submit" class="submit" value="<?php esc_attr_e( 'Create Site', 'buddypress' ); ?>" /> 1125 1133 </p> 1126 1134 1127 <?php wp_nonce_field( 'bp_blog_signup_form' ) ?>1135 <?php wp_nonce_field( 'bp_blog_signup_form' ); ?> 1128 1136 </form> 1129 1137 <?php 1130 1138 … … 1206 1214 if ( ! is_user_logged_in() ) { 1207 1215 $url = sprintf( 1208 1216 /* translators: %s is the site domain and path. */ 1209 __( 'domain.%s' , 'buddypress' ),1217 __( 'domain.%s', 'buddypress' ), 1210 1218 $current_site->domain . $current_site->path 1211 1219 ); 1212 1220 … … 1213 1221 if ( ! is_subdomain_install() ) { 1214 1222 $url = sprintf( 1215 1223 /* translators: %s is the site domain and path. */ 1216 __( '%sblogname' , 'buddypress'),1224 __( '%sblogname', 'buddypress' ), 1217 1225 $current_site->domain . $current_site->path 1218 1226 ); 1219 1227 } … … 1222 1230 '<p>(<strong>%1$s.</strong> %2$s)</p>', 1223 1231 sprintf( 1224 1232 /* translators: %s is the site url. */ 1225 esc_html__( 'Your address will be %s' , 'buddypress' ), esc_url( $url ) 1233 esc_html__( 'Your address will be %s', 'buddypress' ), 1234 esc_url( $url ) 1226 1235 ), 1227 esc_html__( 'Must be at least 4 characters, letters and numbers only. It cannot be changed so choose carefully!' , 'buddypress' )1236 esc_html__( 'Must be at least 4 characters, letters and numbers only. It cannot be changed so choose carefully!', 'buddypress' ) 1228 1237 ); 1229 1238 } 1230 1239 … … 1231 1240 // Blog Title. 1232 1241 ?> 1233 1242 <p> 1234 <label for="blog_title"><?php esc_html_e( 'Site Title:', 'buddypress')?></label>1243 <label for="blog_title"><?php esc_html_e( 'Site Title:', 'buddypress' ); ?></label> 1235 1244 <input name="blog_title" type="text" id="blog_title" value="<?php echo esc_html( $blog_title ); ?>" /> 1236 1245 1237 1246 <?php … … 1243 1252 1244 1253 <fieldset class="create-site"> 1245 1254 1246 <legend class="label"><?php esc_html_e( 'Privacy: I would like my site to appear in search engines, and in public listings around this network', 'buddypress' ) ?></legend>1255 <legend class="label"><?php esc_html_e( 'Privacy: I would like my site to appear in search engines, and in public listings around this network', 'buddypress' ); ?></legend> 1247 1256 1248 1257 <p> 1249 1258 <label class="checkbox" for="blog_public_on"> 1250 1259 <input type="radio" id="blog_public_on" name="blog_public" value="1" <?php checked( ! isset( $_POST['blog_public'] ) || 1 === (int) $_POST['blog_public'] ); ?> /> 1251 <strong><?php esc_html_e( 'Yes' , 'buddypress'); ?></strong>1260 <strong><?php esc_html_e( 'Yes', 'buddypress' ); ?></strong> 1252 1261 </label> 1253 1262 </p> 1254 1263 … … 1255 1264 <p> 1256 1265 <label class="checkbox" for="blog_public_off"> 1257 1266 <input type="radio" id="blog_public_off" name="blog_public" value="0" <?php checked( isset( $_POST['blog_public'] ) && 0 === (int) $_POST['blog_public'] ); ?> /> 1258 <strong><?php esc_html_e( 'No' , 'buddypress'); ?></strong>1267 <strong><?php esc_html_e( 'No', 'buddypress' ); ?></strong> 1259 1268 </label> 1260 1269 </p> 1261 1270 … … 1321 1330 * string $public Default public status. 1322 1331 * } 1323 1332 */ 1324 $meta = apply_filters( 'add_signup_meta', array( 'lang_id' => 1, 'public' => $public ) ); 1333 $meta = apply_filters( 1334 'add_signup_meta', 1335 array( 1336 'lang_id' => 1, 1337 'public' => $public, 1338 ) 1339 ); 1325 1340 1326 1341 return wpmu_create_blog( 1327 1342 $blog['domain'], 1328 1343 $blog['path'], 1329 1344 $blog['blog_title'], 1330 $current_user->ID, $meta, 1345 $current_user->ID, 1346 $meta, 1331 1347 $current_site->id 1332 1348 ); 1333 1349 } … … 1427 1443 } 1428 1444 1429 1445 $search_form_html = '<form action="" method="get" id="search-blogs-form"> 1430 <label for="blogs_search"><input type="text" name="' . esc_attr( $query_arg ) . '" id="blogs_search" placeholder="' . esc_attr( $search_value ) .'" /></label>1446 <label for="blogs_search"><input type="text" name="' . esc_attr( $query_arg ) . '" id="blogs_search" placeholder="' . esc_attr( $search_value ) . '" /></label> 1431 1447 <input type="submit" id="blogs_search_submit" name="blogs_search_submit" value="' . esc_attr__( 'Search', 'buddypress' ) . '" /> 1432 1448 </form>'; 1433 1449 … … 1462 1478 * 1463 1479 * @return false|string 1464 1480 */ 1465 function bp_get_blog_create_button() {1466 if ( ! is_user_logged_in() ) {1467 return false;1468 }1481 function bp_get_blog_create_button() { 1482 if ( ! is_user_logged_in() ) { 1483 return false; 1484 } 1469 1485 1470 if ( ! bp_blog_signup_enabled() ) {1471 return false;1472 }1486 if ( ! bp_blog_signup_enabled() ) { 1487 return false; 1488 } 1473 1489 1474 $url = bp_get_blogs_directory_url(1475 array(1476 'create_single_item' => 1,1477 )1478 );1490 $url = bp_get_blogs_directory_url( 1491 array( 1492 'create_single_item' => 1, 1493 ) 1494 ); 1479 1495 1480 $button_args = array(1481 'id' => 'create_blog',1482 'component' => 'blogs',1483 'link_text' => __( 'Create a Site', 'buddypress' ),1484 'link_class' => 'blog-create no-ajax',1485 'link_href' => $url,1486 'wrapper' => false,1487 'block_self' => false,1488 );1496 $button_args = array( 1497 'id' => 'create_blog', 1498 'component' => 'blogs', 1499 'link_text' => __( 'Create a Site', 'buddypress' ), 1500 'link_class' => 'blog-create no-ajax', 1501 'link_href' => $url, 1502 'wrapper' => false, 1503 'block_self' => false, 1504 ); 1489 1505 1490 /**1491 * Filters the Create a Site button.1492 *1493 * @since 2.0.01494 *1495 * @param array $button_args Array of arguments to be used for the Create a Site button.1496 */1497 return bp_get_button( apply_filters( 'bp_get_blog_create_button', $button_args ) );1498 }1506 /** 1507 * Filters the Create a Site button. 1508 * 1509 * @since 2.0.0 1510 * 1511 * @param array $button_args Array of arguments to be used for the Create a Site button. 1512 */ 1513 return bp_get_button( apply_filters( 'bp_get_blog_create_button', $button_args ) ); 1514 } 1499 1515 1500 1516 /** 1501 1517 * Output the Create a Site nav item. … … 1515 1531 * 1516 1532 * @return string 1517 1533 */ 1518 function bp_get_blog_create_nav_item() {1519 // Get the create a site button.1520 $create_blog_button = bp_get_blog_create_button();1534 function bp_get_blog_create_nav_item() { 1535 // Get the create a site button. 1536 $create_blog_button = bp_get_blog_create_button(); 1521 1537 1522 // Make sure the button is available.1523 if ( empty( $create_blog_button ) ) {1524 return;1525 }1538 // Make sure the button is available. 1539 if ( empty( $create_blog_button ) ) { 1540 return; 1541 } 1526 1542 1527 $output = '<li id="blog-create-nav">' . $create_blog_button . '</li>';1543 $output = '<li id="blog-create-nav">' . $create_blog_button . '</li>'; 1528 1544 1529 /**1530 * Filters the Create A Site nav item output.1531 *1532 * @since 2.2.01533 *1534 * @param string $output Nav item output.1535 */1536 return apply_filters( 'bp_get_blog_create_nav_item', $output );1537 }1545 /** 1546 * Filters the Create A Site nav item output. 1547 * 1548 * @since 2.2.0 1549 * 1550 * @param string $output Nav item output. 1551 */ 1552 return apply_filters( 'bp_get_blog_create_nav_item', $output ); 1553 } 1538 1554 1539 1555 /** 1540 1556 * Checks if a specific theme is still filtering the Blogs directory title … … 1593 1609 * } 1594 1610 * @return array Thhe arguments of the button for visiting a blog in a loop. 1595 1611 */ 1596 function bp_get_blogs_visit_blog_button_args( $args = '' ) {1597 $button_args = bp_parse_args(1598 $args,1599 array(1600 'id' => 'visit_blog',1601 'component' => 'blogs',1602 'must_be_logged_in' => false,1603 'block_self' => false,1604 'wrapper_class' => 'blog-button visit',1605 'link_href' => bp_get_blog_permalink(),1606 'link_class' => 'blog-button visit',1607 'link_text' => __( 'Visit Site', 'buddypress' ),1608 'link_title' => __( 'Visit Site', 'buddypress' ),1609 )1610 );1612 function bp_get_blogs_visit_blog_button_args( $args = '' ) { 1613 $button_args = bp_parse_args( 1614 $args, 1615 array( 1616 'id' => 'visit_blog', 1617 'component' => 'blogs', 1618 'must_be_logged_in' => false, 1619 'block_self' => false, 1620 'wrapper_class' => 'blog-button visit', 1621 'link_href' => bp_get_blog_permalink(), 1622 'link_class' => 'blog-button visit', 1623 'link_text' => __( 'Visit Site', 'buddypress' ), 1624 'link_title' => __( 'Visit Site', 'buddypress' ), 1625 ) 1626 ); 1611 1627 1612 /**1613 * Filters the button for visiting a blog in a loop.1614 *1615 * @since 1.2.101616 *1617 * @param array $button_args Array of arguments to be used for the button to visit a blog.1618 */1619 return (array) apply_filters( 'bp_get_blogs_visit_blog_button', $button_args );1620 }1628 /** 1629 * Filters the button for visiting a blog in a loop. 1630 * 1631 * @since 1.2.10 1632 * 1633 * @param array $button_args Array of arguments to be used for the button to visit a blog. 1634 */ 1635 return (array) apply_filters( 'bp_get_blogs_visit_blog_button', $button_args ); 1636 } 1621 1637 1622 1638 /** 1623 1639 * Return button for visiting a blog in a loop. … … 1630 1646 * @param array|string $args See {@link bp_get_blogs_visit_blog_button_args()}. 1631 1647 * @return string The HTML for the Visit button. 1632 1648 */ 1633 function bp_get_blogs_visit_blog_button( $args = '' ) {1634 $button_args = bp_get_blogs_visit_blog_button_args( $args );1649 function bp_get_blogs_visit_blog_button( $args = '' ) { 1650 $button_args = bp_get_blogs_visit_blog_button_args( $args ); 1635 1651 1636 if ( ! array_filter( $button_args ) ) { 1637 return ''; 1638 } 1639 1640 return bp_get_button( $button_args ); 1652 if ( ! array_filter( $button_args ) ) { 1653 return ''; 1641 1654 } 1642 1655 1656 return bp_get_button( $button_args ); 1657 } 1658 1643 1659 /** Stats **********************************************************************/ 1644 1660 1645 1661 /**