[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * BuddyPress Blogs Template Tags. 4 * 5 * @package BuddyPress 6 * @subpackage BlogsTemplate 7 * @since 1.5.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * Output the blogs component slug. 15 * 16 * @since 1.5.0 17 * 18 */ 19 function bp_blogs_slug() { 20 echo bp_get_blogs_slug(); 21 } 22 /** 23 * Return the blogs component slug. 24 * 25 * @since 1.5.0 26 * 27 * @return string The 'blogs' slug. 28 */ 29 function bp_get_blogs_slug() { 30 31 /** 32 * Filters the blogs component slug. 33 * 34 * @since 1.5.0 35 * 36 * @param string $slug Slug for the blogs component. 37 */ 38 return apply_filters( 'bp_get_blogs_slug', buddypress()->blogs->slug ); 39 } 40 41 /** 42 * Output the blogs component root slug. 43 * 44 * @since 1.5.0 45 * 46 */ 47 function bp_blogs_root_slug() { 48 echo bp_get_blogs_root_slug(); 49 } 50 /** 51 * Return the blogs component root slug. 52 * 53 * @since 1.5.0 54 * 55 * @return string The 'blogs' root slug. 56 */ 57 function bp_get_blogs_root_slug() { 58 59 /** 60 * Filters the blogs component root slug. 61 * 62 * @since 1.5.0 63 * 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 } 68 69 /** 70 * Output blog directory permalink. 71 * 72 * @since 1.5.0 73 * 74 */ 75 function bp_blogs_directory_permalink() { 76 echo esc_url( bp_get_blogs_directory_permalink() ); 77 } 78 /** 79 * Return blog directory permalink. 80 * 81 * @since 1.5.0 82 * 83 * 84 * @return string The URL of the Blogs directory. 85 */ 86 function bp_get_blogs_directory_permalink() { 87 88 /** 89 * Filters the blog directory permalink. 90 * 91 * @since 1.5.0 92 * 93 * @param string $value Permalink URL for the blog directory. 94 */ 95 return apply_filters( 'bp_get_blogs_directory_permalink', trailingslashit( bp_get_root_domain() . '/' . bp_get_blogs_root_slug() ) ); 96 } 97 98 /** 99 * Rewind the blogs and reset blog index. 100 */ 101 function bp_rewind_blogs() { 102 global $blogs_template; 103 104 $blogs_template->rewind_blogs(); 105 } 106 107 /** 108 * Initialize the blogs loop. 109 * 110 * Based on the $args passed, bp_has_blogs() populates the $blogs_template 111 * global, enabling the use of BuddyPress templates and template functions to 112 * display a list of activity items. 113 * 114 * @global object $blogs_template {@link BP_Blogs_Template} 115 * 116 * @param array|string $args { 117 * Arguments for limiting the contents of the blogs loop. Most arguments 118 * are in the same format as {@link BP_Blogs_Blog::get()}. However, because 119 * the format of the arguments accepted here differs in a number of ways, 120 * and because bp_has_blogs() determines some default arguments in a 121 * dynamic fashion, we list all accepted arguments here as well. 122 * 123 * Arguments can be passed as an associative array, or as a URL query 124 * string (eg, 'user_id=4&per_page=3'). 125 * 126 * @type int $page Which page of results to fetch. Using page=1 without 127 * per_page will result in no pagination. Default: 1. 128 * @type int|bool $per_page Number of results per page. Default: 20. 129 * @type string $page_arg The string used as a query parameter in 130 * pagination links. Default: 'bpage'. 131 * @type int|bool $max Maximum number of results to return. 132 * Default: false (unlimited). 133 * @type string $type The order in which results should be fetched. 134 * 'active', 'alphabetical', 'newest', or 'random'. 135 * @type array $include_blog_ids Array of blog IDs to limit results to. 136 * @type string $sort 'ASC' or 'DESC'. Default: 'DESC'. 137 * @type string $search_terms Limit results by a search term. Default: the value of `$_REQUEST['s']` or 138 * `$_REQUEST['sites_search']`, if present. 139 * @type int $user_id The ID of the user whose blogs should be retrieved. 140 * When viewing a user profile page, 'user_id' defaults to the 141 * ID of the displayed user. Otherwise the default is false. 142 * } 143 * @return bool Returns true when blogs are found, otherwise false. 144 */ 145 function bp_has_blogs( $args = '' ) { 146 global $blogs_template; 147 148 // Check for and use search terms. 149 $search_terms_default = false; 150 $search_query_arg = bp_core_get_component_search_query_arg( 'blogs' ); 151 if ( ! empty( $_REQUEST[ $search_query_arg ] ) ) { 152 $search_terms_default = stripslashes( $_REQUEST[ $search_query_arg ] ); 153 } elseif ( ! empty( $_REQUEST['s'] ) ) { 154 $search_terms_default = stripslashes( $_REQUEST['s'] ); 155 } 156 157 // Parse arguments. 158 $r = bp_parse_args( $args, array( 159 'type' => 'active', 160 'page_arg' => 'bpage', // See https://buddypress.trac.wordpress.org/ticket/3679. 161 'page' => 1, 162 'per_page' => 20, 163 'max' => false, 164 'user_id' => bp_displayed_user_id(), // Pass a user_id to limit to only blogs this user is a member of. 165 'include_blog_ids' => false, 166 'search_terms' => $search_terms_default, 167 'update_meta_cache' => true 168 ), 'has_blogs' ); 169 170 // Set per_page to maximum if max is enforced. 171 if ( ! empty( $r['max'] ) && ( (int) $r['per_page'] > (int) $r['max'] ) ) { 172 $r['per_page'] = (int) $r['max']; 173 } 174 175 // Get the blogs. 176 $blogs_template = new BP_Blogs_Template( $r['type'], $r['page'], $r['per_page'], $r['max'], $r['user_id'], $r['search_terms'], $r['page_arg'], $r['update_meta_cache'], $r['include_blog_ids'] ); 177 178 /** 179 * Filters whether or not there are blogs to list. 180 * 181 * @since 1.1.0 182 * 183 * @param bool $value Whether or not there are blogs to list. 184 * @param BP_Blogs_Template $blogs_template Current blogs template object. 185 * @param array $r Parsed arguments used in blogs template query. 186 */ 187 return apply_filters( 'bp_has_blogs', $blogs_template->has_blogs(), $blogs_template, $r ); 188 } 189 190 /** 191 * Determine if there are still blogs left in the loop. 192 * 193 * @global object $blogs_template {@link BP_Blogs_Template} 194 * 195 * @return bool Returns true when blogs are found. 196 */ 197 function bp_blogs() { 198 global $blogs_template; 199 200 return $blogs_template->blogs(); 201 } 202 203 /** 204 * Get the current blog object in the loop. 205 * 206 * @global object $blogs_template {@link BP_Blogs_Template} 207 * 208 * @return object The current blog within the loop. 209 */ 210 function bp_the_blog() { 211 global $blogs_template; 212 213 return $blogs_template->the_blog(); 214 } 215 216 /** 217 * Output the blogs pagination count. 218 * 219 * @since 1.0.0 220 */ 221 function bp_blogs_pagination_count() { 222 echo bp_get_blogs_pagination_count(); 223 } 224 225 /** 226 * Get the blogs pagination count. 227 * 228 * @since 2.7.0 229 * 230 * @global object $blogs_template {@link BP_Blogs_Template} 231 * 232 * @return string 233 */ 234 function bp_get_blogs_pagination_count() { 235 global $blogs_template; 236 237 $start_num = intval( ( $blogs_template->pag_page - 1 ) * $blogs_template->pag_num ) + 1; 238 $from_num = bp_core_number_format( $start_num ); 239 $to_num = bp_core_number_format( ( $start_num + ( $blogs_template->pag_num - 1 ) > $blogs_template->total_blog_count ) ? $blogs_template->total_blog_count : $start_num + ( $blogs_template->pag_num - 1 ) ); 240 $total = bp_core_number_format( $blogs_template->total_blog_count ); 241 242 if ( 1 == $blogs_template->total_blog_count ) { 243 $message = __( 'Viewing 1 site', 'buddypress' ); 244 } else { 245 /* translators: 1: the site from number. 2: the site to number. 3: the total number of sites. */ 246 $message = sprintf( _n( 'Viewing %1$s - %2$s of %3$s site', 'Viewing %1$s - %2$s of %3$s sites', $blogs_template->total_blog_count, 'buddypress' ), $from_num, $to_num, $total ); 247 } 248 249 /** 250 * Filters the "Viewing x-y of z blogs" pagination message. 251 * 252 * @since 2.7.0 253 * 254 * @param string $message "Viewing x-y of z blogs" text. 255 * @param string $from_num Total amount for the low value in the range. 256 * @param string $to_num Total amount for the high value in the range. 257 * @param string $total Total amount of blogs found. 258 */ 259 return apply_filters( 'bp_get_blogs_pagination_count', $message, $from_num, $to_num, $total ); 260 } 261 262 /** 263 * Output the blogs pagination links. 264 */ 265 function bp_blogs_pagination_links() { 266 echo bp_get_blogs_pagination_links(); 267 } 268 /** 269 * Return the blogs pagination links. 270 * 271 * @global object $blogs_template {@link BP_Blogs_Template} 272 * 273 * @return string HTML pagination links. 274 */ 275 function bp_get_blogs_pagination_links() { 276 global $blogs_template; 277 278 /** 279 * Filters the blogs pagination links. 280 * 281 * @since 1.0.0 282 * 283 * @param string $pag_links HTML pagination links. 284 */ 285 return apply_filters( 'bp_get_blogs_pagination_links', $blogs_template->pag_links ); 286 } 287 288 /** 289 * Output a blog's avatar. 290 * 291 * @see bp_get_blog_avatar() for description of arguments. 292 * 293 * @param array|string $args See {@link bp_get_blog_avatar()}. 294 */ 295 function bp_blog_avatar( $args = '' ) { 296 echo bp_get_blog_avatar( $args ); 297 } 298 /** 299 * Get a blog's avatar. 300 * 301 * At the moment, unless the blog has a site icon, the blog's avatar defaults 302 * to the /bp-core/images/mystery-blog.png image or the Blog's Admin user avatar 303 * if the `admin_user_id` argument contains the Blog's Admin user ID. 304 * 305 * @since 2.4.0 Introduced `$title` argument. 306 * @since 6.0.0 Introduced the `$blog_id`, `$admin_user_id` and `html` arguments. 307 * @since 7.0.0 Introduced the Blog's default avatar {@see bp_blogs_default_avatar()}. 308 * Removed the `'bp_get_blog_avatar_' . $blog_id` filter (it was deprecated since 1.5). 309 * 310 * @see bp_core_fetch_avatar() For a description of arguments and 311 * return values. 312 * 313 * @param array|string $args { 314 * Arguments are listed here with an explanation of their defaults. 315 * For more information about the arguments, see 316 * {@link bp_core_fetch_avatar()}. 317 * @type string $alt Default: 'Profile picture of site author [user name]'. 318 * @type string $class Default: 'avatar'. 319 * @type string $type Default: 'full'. 320 * @type int|bool $width Default: false. 321 * @type int|bool $height Default: false. 322 * @type bool $id Currently unused. 323 * @type bool $no_grav Default: false. 324 * @type int $blog_id The blog ID. Default: O. 325 * @type int $admin_user_id The Blog Admin user ID. Default: 0. 326 * @type bool $html Default: true. 327 * } 328 * @return string User avatar string. 329 */ 330 function bp_get_blog_avatar( $args = '' ) { 331 global $blogs_template; 332 333 // Bail if avatars are turned off 334 // @todo Should we maybe still filter this? 335 if ( ! buddypress()->avatar->show_avatars ) { 336 return false; 337 } 338 339 // Set default value for the `alt` attribute. 340 $alt_attribute = __( 'Site icon for the blog', 'buddypress' ); 341 342 if ( ! $blogs_template && isset( $args['blog_id'] ) && $args['blog_id'] ) { 343 $blog_id = (int) $args['blog_id']; 344 } else { 345 $blog_id = bp_get_blog_id(); 346 347 /* translators: %s is the blog name */ 348 $alt_attribute = sprintf( __( 'Site icon for %s', 'buddypress' ), bp_get_blog_name() ); 349 } 350 351 // Parse the arguments. 352 $r = bp_parse_args( $args, array( 353 'item_id' => $blog_id, 354 'avatar_dir' => 'blog-avatars', 355 'object' => 'blog', 356 'type' => 'full', 357 'width' => false, 358 'height' => false, 359 'class' => 'avatar', 360 'id' => false, 361 'alt' => $alt_attribute, 362 'no_grav' => false, 363 'html' => true, 364 ), 'blog_avatar' ); 365 366 /** 367 * If the `admin_user_id` was provided, make the Blog avatar 368 * defaults to the Blog's Admin user one. 369 */ 370 if ( isset( $r['admin_user_id'] ) && $r['admin_user_id'] ) { 371 $r['item_id'] = (int) $r['admin_user_id']; 372 $r['avatar_dir'] = 'avatars'; 373 $r['object'] = 'user'; 374 } elseif ( ! $r['no_grav'] ) { 375 $r['no_grav'] = true; 376 } 377 378 // Use site icon if available. 379 $avatar = ''; 380 if ( bp_is_active( 'blogs', 'site-icon' ) ) { 381 $site_icon = bp_blogs_get_blogmeta( $blog_id, "site_icon_url_{$r['type']}" ); 382 383 // Never attempted to fetch site icon before; do it now! 384 if ( '' === $site_icon ) { 385 // Fetch the other size first. 386 if ( 'full' === $r['type'] ) { 387 $size = bp_core_avatar_thumb_width(); 388 $save_size = 'thumb'; 389 } else { 390 $size = bp_core_avatar_full_width(); 391 $save_size = 'full'; 392 } 393 394 $site_icon = bp_blogs_get_site_icon_url( $blog_id, $size ); 395 396 // Empty site icons get saved as integer 0. 397 if ( empty( $site_icon ) ) { 398 $site_icon = 0; 399 } 400 401 // Sync site icon for other size to blogmeta. 402 bp_blogs_update_blogmeta( $blog_id, "site_icon_url_{$save_size}", $site_icon ); 403 404 // Now, fetch the size we want. 405 if ( 0 !== $site_icon ) { 406 $size = 'full' === $r['type'] ? bp_core_avatar_full_width() : bp_core_avatar_thumb_width(); 407 $site_icon = bp_blogs_get_site_icon_url( $blog_id, $size ); 408 } 409 410 // Sync site icon to blogmeta. 411 bp_blogs_update_blogmeta( $blog_id, "site_icon_url_{$r['type']}", $site_icon ); 412 } 413 414 // We have a site icon. 415 if ( ! is_numeric( $site_icon ) ) { 416 // Just return the raw url of the Site Icon. 417 if ( ! $r['html'] ) { 418 return esc_url_raw( $site_icon ); 419 } 420 421 if ( empty( $r['width'] ) && ! isset( $size ) ) { 422 $size = 'full' === $r['type'] ? bp_core_avatar_full_width() : bp_core_avatar_thumb_width(); 423 } else { 424 $size = (int) $r['width']; 425 } 426 427 $avatar = sprintf( '<img src="%1$s" class="%2$s" width="%3$s" height="%3$s" alt="%4$s" />', 428 esc_url( $site_icon ), 429 esc_attr( "{$r['class']} avatar-{$size}" ), 430 esc_attr( $size ), 431 esc_attr( $alt_attribute ) 432 ); 433 } 434 } 435 436 // Fallback to Default blog avatar. 437 if ( '' === $avatar ) { 438 $avatar = bp_core_fetch_avatar( $r ); 439 } 440 441 /** 442 * Filters a blog's avatar. 443 * 444 * @since 1.5.0 445 * 446 * @param string $avatar Formatted HTML <img> element, or raw avatar 447 * URL based on $html arg. 448 * @param int $blog_id ID of the blog whose avatar is being displayed. 449 * @param array $r Array of arguments used when fetching avatar. 450 */ 451 return apply_filters( 'bp_get_blog_avatar', $avatar, $blog_id, $r ); 452 } 453 454 function bp_blog_permalink() { 455 echo bp_get_blog_permalink(); 456 } 457 function bp_get_blog_permalink() { 458 global $blogs_template; 459 460 if ( empty( $blogs_template->blog->domain ) ) 461 $permalink = bp_get_root_domain() . $blogs_template->blog->path; 462 else { 463 $protocol = 'http://'; 464 if ( is_ssl() ) 465 $protocol = 'https://'; 466 467 $permalink = $protocol . $blogs_template->blog->domain . $blogs_template->blog->path; 468 } 469 470 /** 471 * Filters the blog permalink. 472 * 473 * @since 1.0.0 474 * 475 * @param string $permalink Permalink URL for the blog. 476 */ 477 return apply_filters( 'bp_get_blog_permalink', $permalink ); 478 } 479 480 /** 481 * Output the name of the current blog in the loop. 482 */ 483 function bp_blog_name() { 484 echo bp_get_blog_name(); 485 } 486 /** 487 * Return the name of the current blog in the loop. 488 * 489 * @return string The name of the current blog in the loop. 490 */ 491 function bp_get_blog_name() { 492 global $blogs_template; 493 494 /** 495 * Filters the name of the current blog in the loop. 496 * 497 * @since 1.2.0 498 * 499 * @param string $name Name of the current blog in the loop. 500 */ 501 return apply_filters( 'bp_get_blog_name', $blogs_template->blog->name ); 502 } 503 504 /** 505 * Output the ID of the current blog in the loop. 506 * 507 * @since 1.7.0 508 */ 509 function bp_blog_id() { 510 echo bp_get_blog_id(); 511 } 512 /** 513 * Return the ID of the current blog in the loop. 514 * 515 * @since 1.7.0 516 * 517 * @return int ID of the current blog in the loop. 518 */ 519 function bp_get_blog_id() { 520 global $blogs_template; 521 522 /** 523 * Filters the ID of the current blog in the loop. 524 * 525 * @since 1.7.0 526 * 527 * @param int $blog_id ID of the current blog in the loop. 528 */ 529 return apply_filters( 'bp_get_blog_id', $blogs_template->blog->blog_id ); 530 } 531 532 /** 533 * Output the description of the current blog in the loop. 534 */ 535 function bp_blog_description() { 536 537 /** 538 * Filters the description of the current blog in the loop. 539 * 540 * @since 1.2.0 541 * 542 * @param string $value Description of the current blog in the loop. 543 */ 544 echo apply_filters( 'bp_blog_description', bp_get_blog_description() ); 545 } 546 /** 547 * Return the description of the current blog in the loop. 548 * 549 * @return string Description of the current blog in the loop. 550 */ 551 function bp_get_blog_description() { 552 global $blogs_template; 553 554 /** 555 * Filters the description of the current blog in the loop. 556 * 557 * @since 1.0.0 558 * 559 * @param string $value Description of the current blog in the loop. 560 */ 561 return apply_filters( 'bp_get_blog_description', $blogs_template->blog->description ); 562 } 563 564 /** 565 * Output the row class of the current blog in the loop. 566 * 567 * @since 1.7.0 568 * 569 * @param array $classes Array of custom classes. 570 */ 571 function bp_blog_class( $classes = array() ) { 572 echo bp_get_blog_class( $classes ); 573 } 574 /** 575 * Return the row class of the current blog in the loop. 576 * 577 * @since 1.7.0 578 * 579 * @global BP_Blogs_Template $blogs_template 580 * 581 * @param array $classes Array of custom classes. 582 * @return string Row class of the site. 583 */ 584 function bp_get_blog_class( $classes = array() ) { 585 global $blogs_template; 586 587 // Add even/odd classes, but only if there's more than 1 group. 588 if ( $blogs_template->blog_count > 1 ) { 589 $pos_in_loop = (int) $blogs_template->current_blog; 590 $classes[] = ( $pos_in_loop % 2 ) ? 'even' : 'odd'; 591 592 // If we've only one site in the loop, don't bother with odd and even. 593 } else { 594 $classes[] = 'bp-single-blog'; 595 } 596 597 /** 598 * Filters the row class of the current blog in the loop. 599 * 600 * @since 1.7.0 601 * 602 * @param array $classes Array of classes to be applied to row. 603 */ 604 $classes = apply_filters( 'bp_get_blog_class', $classes ); 605 $classes = array_merge( $classes, array() ); 606 $retval = 'class="' . join( ' ', $classes ) . '"'; 607 608 return $retval; 609 } 610 611 /** 612 * Output the last active date of the current blog in the loop. 613 * 614 * @param array $args See {@link bp_get_blog_last_active()}. 615 */ 616 function bp_blog_last_active( $args = array() ) { 617 echo bp_get_blog_last_active( $args ); 618 } 619 /** 620 * Return the last active date of the current blog in the loop. 621 * 622 * @param array $args { 623 * Array of optional arguments. 624 * @type bool $active_format If true, formatted "Active 5 minutes ago". 625 * If false, formatted "5 minutes ago". 626 * Default: true. 627 * } 628 * @return string Last active date. 629 */ 630 function bp_get_blog_last_active( $args = array() ) { 631 global $blogs_template; 632 633 // Parse the activity format. 634 $r = bp_parse_args( $args, array( 635 'active_format' => true 636 ) ); 637 638 // Backwards compatibility for anyone forcing a 'true' active_format. 639 if ( true === $r['active_format'] ) { 640 /* translators: %s: human time diff of the last time the site was active. */ 641 $r['active_format'] = _x( 'Active %s', 'last time the site was active', 'buddypress' ); 642 } 643 644 // Blog has been posted to at least once. 645 if ( isset( $blogs_template->blog->last_activity ) ) { 646 647 // Backwards compatibility for pre 1.5 'ago' strings. 648 $last_activity = ! empty( $r['active_format'] ) 649 ? bp_core_get_last_activity( $blogs_template->blog->last_activity, $r['active_format'] ) 650 : bp_core_time_since( $blogs_template->blog->last_activity ); 651 652 // Blog has never been posted to. 653 } else { 654 $last_activity = __( 'Never active', 'buddypress' ); 655 } 656 657 /** 658 * Filters the last active date of the current blog in the loop. 659 * 660 * @since 1.2.0 661 * 662 * @param string $last_activity Last active date. 663 * @param array $r Array of parsed args used to determine formatting. 664 */ 665 return apply_filters( 'bp_blog_last_active', $last_activity, $r ); 666 } 667 668 /** 669 * Output the latest post from the current blog in the loop. 670 * 671 * @param array $args See {@link bp_get_blog_latest_post()}. 672 */ 673 function bp_blog_latest_post( $args = array() ) { 674 echo bp_get_blog_latest_post( $args ); 675 } 676 /** 677 * Return the latest post from the current blog in the loop. 678 * 679 * @param array $args { 680 * Array of optional arguments. 681 * @type bool $latest_format If true, formatted "Latest post: [link to post]". 682 * If false, formatted "[link to post]". 683 * Default: true. 684 * } 685 * @return string $retval String of the form 'Latest Post: [link to post]'. 686 */ 687 function bp_get_blog_latest_post( $args = array() ) { 688 global $blogs_template; 689 690 $r = wp_parse_args( $args, array( 691 'latest_format' => true, 692 ) ); 693 694 $retval = bp_get_blog_latest_post_title(); 695 696 if ( ! empty( $retval ) ) { 697 if ( ! empty( $r['latest_format'] ) ) { 698 699 /** 700 * Filters the title text of the latest post for the current blog in loop. 701 * 702 * @since 1.0.0 703 * 704 * @param string $retval Title of the latest post. 705 */ 706 $retval = sprintf( 707 /* translators: %s: the title of the latest post */ 708 __( 'Latest Post: %s', 'buddypress' ), 709 '<a href="' . $blogs_template->blog->latest_post->guid . '">' . apply_filters( 'the_title', $retval ) . '</a>' 710 ); 711 } else { 712 713 /** This filter is documented in bp-blogs/bp-blogs-template.php */ 714 $retval = '<a href="' . $blogs_template->blog->latest_post->guid . '">' . apply_filters( 'the_title', $retval ) . '</a>'; 715 } 716 } 717 718 /** 719 * Filters the HTML markup result for the latest blog post in loop. 720 * 721 * @since 1.2.0 722 * @since 2.6.0 Added the `$r` parameter. 723 * 724 * @param string $retval HTML markup for the latest post. 725 * @param array $r Array of parsed arguments. 726 */ 727 return apply_filters( 'bp_get_blog_latest_post', $retval, $r ); 728 } 729 730 /** 731 * Output the title of the latest post on the current blog in the loop. 732 * 733 * @since 1.7.0 734 * 735 * @see bp_get_blog_latest_post_title() 736 */ 737 function bp_blog_latest_post_title() { 738 echo bp_get_blog_latest_post_title(); 739 } 740 /** 741 * Return the title of the latest post on the current blog in the loop. 742 * 743 * @since 1.7.0 744 * 745 * @global BP_Blogs_Template 746 * 747 * @return string Post title. 748 */ 749 function bp_get_blog_latest_post_title() { 750 global $blogs_template; 751 752 $retval = ''; 753 754 if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->post_title ) ) 755 $retval = $blogs_template->blog->latest_post->post_title; 756 757 /** 758 * Filters the title text of the latest post on the current blog in the loop. 759 * 760 * @since 1.7.0 761 * 762 * @param string $retval Title text for the latest post. 763 */ 764 return apply_filters( 'bp_get_blog_latest_post_title', $retval ); 765 } 766 767 /** 768 * Output the permalink of the latest post on the current blog in the loop. 769 * 770 * @since 1.7.0 771 * 772 * @see bp_get_blog_latest_post_title() 773 */ 774 function bp_blog_latest_post_permalink() { 775 echo esc_url( bp_get_blog_latest_post_permalink() ); 776 } 777 /** 778 * Return the permalink of the latest post on the current blog in the loop. 779 * 780 * @since 1.7.0 781 * 782 * @global BP_Blogs_Template 783 * 784 * @return string URL of the blog's latest post. 785 */ 786 function bp_get_blog_latest_post_permalink() { 787 global $blogs_template; 788 789 $retval = ''; 790 791 if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->ID ) ) 792 $retval = add_query_arg( 'p', $blogs_template->blog->latest_post->ID, bp_get_blog_permalink() ); 793 794 /** 795 * Filters the permalink of the latest post on the current blog in the loop. 796 * 797 * @since 1.7.0 798 * 799 * @param string $retval Permalink URL of the latest post. 800 */ 801 return apply_filters( 'bp_get_blog_latest_post_permalink', $retval ); 802 } 803 804 /** 805 * Output the content of the latest post on the current blog in the loop. 806 * 807 * @since 1.7.0 808 * 809 */ 810 function bp_blog_latest_post_content() { 811 echo bp_get_blog_latest_post_content(); 812 } 813 /** 814 * Return the content of the latest post on the current blog in the loop. 815 * 816 * @since 1.7.0 817 * 818 * @global BP_Blogs_Template 819 * 820 * @return string Content of the blog's latest post. 821 */ 822 function bp_get_blog_latest_post_content() { 823 global $blogs_template; 824 825 $retval = ''; 826 827 if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->post_content ) ) 828 $retval = $blogs_template->blog->latest_post->post_content; 829 830 /** 831 * Filters the content of the latest post on the current blog in the loop. 832 * 833 * @since 1.7.0 834 * 835 * @param string $retval Content of the latest post on the current blog in the loop. 836 */ 837 return apply_filters( 'bp_get_blog_latest_post_content', $retval ); 838 } 839 840 /** 841 * Output the featured image of the latest post on the current blog in the loop. 842 * 843 * @since 1.7.0 844 * 845 * @see bp_get_blog_latest_post_content() For description of parameters. 846 * 847 * @param string $size See {@link bp_get_blog_latest_post_featured_image()}. 848 */ 849 function bp_blog_latest_post_featured_image( $size = 'thumbnail' ) { 850 echo bp_get_blog_latest_post_featured_image( $size ); 851 } 852 /** 853 * Return the featured image of the latest post on the current blog in the loop. 854 * 855 * @since 1.7.0 856 * 857 * @global BP_Blogs_Template 858 * 859 * @param string $size Image version to return. 'thumbnail', 'medium', 860 * 'large', or 'post-thumbnail'. Default: 'thumbnail'. 861 * @return string URL of the image. 862 */ 863 function bp_get_blog_latest_post_featured_image( $size = 'thumbnail' ) { 864 global $blogs_template; 865 866 $retval = ''; 867 868 if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->images[$size] ) ) 869 $retval = $blogs_template->blog->latest_post->images[$size]; 870 871 /** 872 * Filters the featured image of the latest post on the current blog in the loop. 873 * 874 * @since 1.7.0 875 * 876 * @param string $retval The featured image of the latest post on the current blog in the loop. 877 */ 878 return apply_filters( 'bp_get_blog_latest_post_featured_image', $retval ); 879 } 880 881 /** 882 * Does the latest blog post have a featured image? 883 * 884 * @since 1.7.0 885 * 886 * @param string $thumbnail Image version to return. 'thumbnail', 'medium', 'large', 887 * or 'post-thumbnail'. Default: 'thumbnail'. 888 * @return bool True if the latest blog post from the current blog has a 889 * featured image of the given size. 890 */ 891 function bp_blog_latest_post_has_featured_image( $thumbnail = 'thumbnail' ) { 892 $image = bp_get_blog_latest_post_featured_image( $thumbnail ); 893 894 /** 895 * Filters whether or not the latest blog post has a featured image. 896 * 897 * @since 1.7.0 898 * 899 * @param bool $value Whether or not the latest blog post has a featured image. 900 * @param string $thumbnail Image version to return. 901 * @param string $image Returned value from bp_get_blog_latest_post_featured_image. 902 */ 903 return apply_filters( 'bp_blog_latest_post_has_featured_image', ! empty( $image ), $thumbnail, $image ); 904 } 905 906 /** 907 * Output hidden fields to help with form submissions in Sites directory. 908 * 909 * This function detects whether 's', 'letter', or 'blogs_search' requests are 910 * currently being made (as in a URL parameter), and creates corresponding 911 * hidden fields. 912 */ 913 function bp_blog_hidden_fields() { 914 if ( isset( $_REQUEST['s'] ) ) 915 echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['s'] ). '" name="search_terms" />'; 916 917 if ( isset( $_REQUEST['letter'] ) ) 918 echo '<input type="hidden" id="selected_letter" value="' . esc_attr( $_REQUEST['letter'] ) . '" name="selected_letter" />'; 919 920 if ( isset( $_REQUEST['blogs_search'] ) ) 921 echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['blogs_search'] ) . '" name="search_terms" />'; 922 } 923 924 /** 925 * Output the total number of blogs on the site. 926 */ 927 function bp_total_blog_count() { 928 echo bp_get_total_blog_count(); 929 } 930 /** 931 * Return the total number of blogs on the site. 932 * 933 * @return int Total number of blogs. 934 */ 935 function bp_get_total_blog_count() { 936 937 /** 938 * Filters the total number of blogs on the site. 939 * 940 * @since 1.2.0 941 * 942 * @param int $value Total number of blogs on the site. 943 */ 944 return apply_filters( 'bp_get_total_blog_count', bp_blogs_total_blogs() ); 945 } 946 add_filter( 'bp_get_total_blog_count', 'bp_core_number_format' ); 947 948 /** 949 * Output the total number of blogs for a given user. 950 * 951 * @param int $user_id ID of the user. 952 */ 953 function bp_total_blog_count_for_user( $user_id = 0 ) { 954 echo bp_get_total_blog_count_for_user( $user_id ); 955 } 956 /** 957 * Return the total number of blogs for a given user. 958 * 959 * @param int $user_id ID of the user. 960 * @return int Total number of blogs for the user. 961 */ 962 function bp_get_total_blog_count_for_user( $user_id = 0 ) { 963 964 /** 965 * Filters the total number of blogs for a given user. 966 * 967 * @since 1.2.0 968 * @since 2.6.0 Added the `$user_id` parameter. 969 * 970 * @param int $value Total number of blogs for a given user. 971 * @param int $user_id ID of the queried user. 972 */ 973 return apply_filters( 'bp_get_total_blog_count_for_user', bp_blogs_total_blogs_for_user( $user_id ), $user_id ); 974 } 975 add_filter( 'bp_get_total_blog_count_for_user', 'bp_core_number_format' ); 976 977 978 /** Blog Registration ********************************************************/ 979 980 /** 981 * Output the wrapper markup for the blog signup form. 982 * 983 * @since 1.0.0 984 * 985 * @param string $blogname Optional. The default blog name (path or domain). 986 * @param string $blog_title Optional. The default blog title. 987 * @param string|WP_Error $errors Optional. The WP_Error object returned by a previous 988 * submission attempt. 989 */ 990 function bp_show_blog_signup_form( $blogname = '', $blog_title = '', $errors = '' ) { 991 $blog_id = bp_blogs_validate_blog_signup(); 992 993 // Display the signup form. 994 if ( false === $blog_id || is_wp_error( $blog_id ) ) { 995 if ( is_wp_error( $blog_id ) ) { 996 $errors = $blog_id; 997 } else { 998 $errors = new WP_Error(); 999 } 1000 1001 /** 1002 * Filters the default values for Blog name, title, and any current errors. 1003 * 1004 * @since 1.0.0 1005 * 1006 * @param array $value { 1007 * string $blogname Default blog name provided. 1008 * string $blog_title Default blog title provided. 1009 * WP_Error $errors WP_Error object. 1010 * } 1011 */ 1012 $filtered_results = apply_filters('signup_another_blog_init', array('blogname' => $blogname, 'blog_title' => $blog_title, 'errors' => $errors )); 1013 $blogname = $filtered_results['blogname']; 1014 $blog_title = $filtered_results['blog_title']; 1015 $errors = $filtered_results['errors']; 1016 1017 if ( $errors->get_error_code() ) { 1018 if ( in_array( $errors->get_error_code(), array( 'blogname', 'blog_title' ), true ) ) { 1019 printf( 1020 '<p class="error">%s</p>', 1021 esc_html__( 'There was a problem; please correct the form below and try again.', 'buddypress' ) 1022 ); 1023 } else { 1024 printf( 1025 '<p class="error">%s</p>', 1026 $errors->get_error_message() 1027 ); 1028 } 1029 } 1030 1031 printf( 1032 '<p>%1$s <strong>%2$s</strong>. %3$s</p>', 1033 esc_html__( 'By filling out the form below, you can', 'buddypress' ), 1034 esc_html__( 'add a site to your account', 'buddypress' ), 1035 esc_html__( 'There is no limit to the number of sites that you can have, so create to your heart’s content, but blog responsibly!', 'buddypress' ) 1036 ); 1037 ?> 1038 1039 <p> 1040 <?php esc_html_e( 'If you’re not going to use a great domain, leave it for a new user. Now have at it!', 'buddypress' ); ?> 1041 </p> 1042 1043 <form class="standard-form" id="setupform" method="post" action=""> 1044 1045 <input type="hidden" name="stage" value="gimmeanotherblog" /> 1046 <?php 1047 1048 /** 1049 * Fires after the default hidden fields in blog signup form markup. 1050 * 1051 * @since 1.0.0 1052 */ 1053 do_action( 'signup_hidden_fields' ); ?> 1054 1055 <?php bp_blogs_signup_blog( $blogname, $blog_title, $errors ); ?> 1056 <p> 1057 <input id="submit" type="submit" name="submit" class="submit" value="<?php esc_attr_e( 'Create Site', 'buddypress' ); ?>" /> 1058 </p> 1059 1060 <?php wp_nonce_field( 'bp_blog_signup_form' ) ?> 1061 </form> 1062 <?php 1063 1064 // Display the confirmation form. 1065 } elseif ( is_numeric( $blog_id ) ) { 1066 // Validate the site. 1067 $site = get_site( $blog_id ); 1068 1069 if ( isset( $site->id ) && $site->id ) { 1070 $current_user = wp_get_current_user(); 1071 1072 bp_blogs_confirm_blog_signup( 1073 $site->domain, 1074 $site->path, 1075 $site->blogname, 1076 $current_user->user_login, 1077 $current_user->user_email, 1078 '', 1079 $site->id 1080 ); 1081 } 1082 } 1083 } 1084 1085 /** 1086 * Output the input fields for the blog creation form. 1087 * 1088 * @since 1.0.0 1089 * 1090 * @param string $blogname Optional. The default blog name (path or domain). 1091 * @param string $blog_title Optional. The default blog title. 1092 * @param string|WP_Error $errors Optional. The WP_Error object returned by a previous 1093 * submission attempt. 1094 */ 1095 function bp_blogs_signup_blog( $blogname = '', $blog_title = '', $errors = '' ) { 1096 $current_site = get_current_site(); 1097 1098 if ( ! $blogname && ! $blog_title ) { 1099 $submitted_vars = bp_blogs_get_signup_form_submitted_vars(); 1100 1101 if ( array_filter( $submitted_vars ) ) { 1102 $blogname = $submitted_vars['blogname']; 1103 $blog_title = $submitted_vars['blog_title']; 1104 } 1105 } 1106 ?> 1107 1108 <p> 1109 <?php 1110 // Blog name. 1111 if ( ! is_subdomain_install() ) { 1112 printf( '<label for="blogname">%s</label>', esc_html__( 'Site Name:', 'buddypress' ) ); 1113 } else { 1114 printf( '<label for="blogname">%s</label>', esc_html__( 'Site Domain:', 'buddypress' ) ); 1115 } 1116 1117 if ( ! is_subdomain_install() ) { 1118 printf( 1119 '<span class="prefix_address">%1$s</span> <input name="blogname" type="text" id="blogname" value="%2$s" maxlength="63" style="width: auto!important" /><br />', 1120 esc_html( $current_site->domain . $current_site->path ), 1121 esc_attr( $blogname ) 1122 ); 1123 } else { 1124 printf( 1125 '<input name="blogname" type="text" id="blogname" value="%1$s" maxlength="63" style="width: auto!important" %2$s/> <span class="suffix_address">.%3$s</span><br />', 1126 esc_attr( $blogname ), 1127 bp_get_form_field_attributes( 'blogname' ), 1128 bp_signup_get_subdomain_base() 1129 ); 1130 } 1131 if ( is_wp_error( $errors ) && $errors->get_error_message( 'blogname' ) ) { 1132 printf( '<div class="error">%s</div>', $errors->get_error_message( 'blogname' ) ); 1133 } 1134 ?> 1135 </p> 1136 1137 <?php 1138 if ( ! is_user_logged_in() ) { 1139 $url = sprintf( 1140 /* translators: %s is the site domain and path. */ 1141 __( 'domain.%s' , 'buddypress' ), 1142 $current_site->domain . $current_site->path 1143 ); 1144 1145 if ( ! is_subdomain_install() ) { 1146 $url = sprintf( 1147 /* translators: %s is the site domain and path. */ 1148 __( '%sblogname' , 'buddypress'), 1149 $current_site->domain . $current_site->path 1150 ); 1151 } 1152 1153 printf( 1154 '<p>(<strong>%1$s.</strong> %2$s)</p>', 1155 sprintf( 1156 /* translators: %s is the site url. */ 1157 esc_html__( 'Your address will be %s' , 'buddypress' ), $url 1158 ), 1159 esc_html__( 'Must be at least 4 characters, letters and numbers only. It cannot be changed so choose carefully!' , 'buddypress' ) 1160 ); 1161 } 1162 1163 // Blog Title. 1164 ?> 1165 <p> 1166 <label for="blog_title"><?php esc_html_e('Site Title:', 'buddypress') ?></label> 1167 <input name="blog_title" type="text" id="blog_title" value="<?php echo esc_html( $blog_title ); ?>" /> 1168 1169 <?php 1170 if ( is_wp_error( $errors ) && $errors->get_error_message( 'blog_title' ) ) { 1171 printf( '<div class="error">%s</div>', $errors->get_error_message( 'blog_title' ) ); 1172 } 1173 ?> 1174 </p> 1175 1176 <fieldset class="create-site"> 1177 1178 <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> 1179 1180 <p> 1181 <label class="checkbox" for="blog_public_on"> 1182 <input type="radio" id="blog_public_on" name="blog_public" value="1" <?php checked( ! isset( $_POST['blog_public'] ) || 1 === (int) $_POST['blog_public'] ); ?> /> 1183 <strong><?php esc_html_e( 'Yes' , 'buddypress'); ?></strong> 1184 </label> 1185 </p> 1186 1187 <p> 1188 <label class="checkbox" for="blog_public_off"> 1189 <input type="radio" id="blog_public_off" name="blog_public" value="0" <?php checked( isset( $_POST['blog_public'] ) && 0 === (int) $_POST['blog_public'] ); ?> /> 1190 <strong><?php esc_html_e( 'No' , 'buddypress'); ?></strong> 1191 </label> 1192 </p> 1193 1194 </fieldset> 1195 1196 <?php 1197 1198 /** 1199 * Fires at the end of all of the default input fields for blog creation form. 1200 * 1201 * @since 1.0.0 1202 * 1203 * @param WP_Error $errors WP_Error object if any present. 1204 */ 1205 do_action( 'signup_blogform', $errors ); 1206 } 1207 1208 /** 1209 * Process a blog registration submission. 1210 * 1211 * Passes submitted values to {@link wpmu_create_blog()}. 1212 * 1213 * @since 1.0.0 1214 * 1215 * @return bool|int|WP_Error False if not a form submission, the Blog ID on success, a WP_Error object on failure. 1216 */ 1217 function bp_blogs_validate_blog_signup() { 1218 if ( ! isset( $_POST['submit'] ) ) { 1219 return false; 1220 } 1221 1222 $current_site = get_current_site(); 1223 $current_user = wp_get_current_user(); 1224 $blog_name = ''; 1225 $blog_title = ''; 1226 $public = 1; 1227 1228 if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( wp_unslash( $_POST['_wpnonce'] ), 'bp_blog_signup_form' ) || ! $current_user->ID ) { 1229 return new WP_Error( 'bp_blogs_doing_it_wrong', __( 'Sorry, we cannot create the site. Please try again later.', 'buddypress' ) ); 1230 } 1231 1232 $submitted_vars = bp_blogs_get_signup_form_submitted_vars(); 1233 1234 if ( array_filter( $submitted_vars ) ) { 1235 $blog_name = $submitted_vars['blogname']; 1236 $blog_title = $submitted_vars['blog_title']; 1237 $public = (int) $submitted_vars['blog_public']; 1238 } 1239 1240 $blog = bp_blogs_validate_blog_form( $blog_name, $blog_title ); 1241 1242 if ( is_wp_error( $blog['errors'] ) && $blog['errors']->get_error_code() ) { 1243 return $blog['errors']; 1244 } 1245 1246 /** 1247 * Filters the default values for Blog meta. 1248 * 1249 * @since 1.0.0 1250 * 1251 * @param array $meta { 1252 * string $value Default blog language ID. 1253 * string $public Default public status. 1254 * } 1255 */ 1256 $meta = apply_filters( 'add_signup_meta', array( 'lang_id' => 1, 'public' => $public ) ); 1257 1258 return wpmu_create_blog( 1259 $blog['domain'], 1260 $blog['path'], 1261 $blog['blog_title'], 1262 $current_user->ID, $meta, 1263 $current_site->id 1264 ); 1265 } 1266 1267 /** 1268 * Display a message after successful blog registration. 1269 * 1270 * @since 1.0.0 1271 * @since 2.6.0 Introduced `$blog_id` parameter. 1272 * 1273 * @param string $domain The new blog's domain. 1274 * @param string $path The new blog's path. 1275 * @param string $blog_title The new blog's title. 1276 * @param string $user_name The user name of the user who created the blog. Unused. 1277 * @param string $user_email The email of the user who created the blog. Unused. 1278 * @param string|array $meta Meta values associated with the new blog. Unused. 1279 * @param int|null $blog_id ID of the newly created blog. 1280 */ 1281 function bp_blogs_confirm_blog_signup( $domain, $path, $blog_title, $user_name, $user_email = '', $meta = '', $blog_id = null ) { 1282 switch_to_blog( $blog_id ); 1283 $blog_url = set_url_scheme( home_url() ); 1284 $login_url = set_url_scheme( wp_login_url() ); 1285 restore_current_blog(); 1286 1287 ?> 1288 <p class="success"><?php esc_html_e( 'Congratulations! You have successfully registered a new site.', 'buddypress' ) ?></p> 1289 <p> 1290 <?php printf( 1291 '%s %s', 1292 sprintf( 1293 /* translators: %s: the link of the new site */ 1294 __( '%s is your new site.', 'buddypress' ), 1295 sprintf( '<a href="%s">%s</a>', esc_url( $blog_url ), esc_url( $blog_url ) ) 1296 ), 1297 sprintf( 1298 /* translators: 1: Login URL, 2: User name */ 1299 __( '<a href="%1$s">Log in</a> as "%2$s" using your existing password.', 'buddypress' ), 1300 esc_url( $login_url ), 1301 esc_html( $user_name ) 1302 ) 1303 ); ?> 1304 </p> 1305 1306 <?php 1307 1308 /** 1309 * Fires after the default successful blog registration message markup. 1310 * 1311 * @since 1.0.0 1312 */ 1313 do_action( 'signup_finished' ); 1314 } 1315 1316 /** 1317 * Output a "Create a Site" link for users viewing their own profiles. 1318 * 1319 * This function is not used by BuddyPress as of 1.2, but is kept here for older 1320 * themes that may still be using it. 1321 */ 1322 function bp_create_blog_link() { 1323 1324 // Don't show this link when not on your own profile. 1325 if ( ! bp_is_my_profile() ) { 1326 return; 1327 } 1328 1329 /** 1330 * Filters "Create a Site" links for users viewing their own profiles. 1331 * 1332 * @since 1.0.0 1333 * 1334 * @param string $value HTML link for creating a site. 1335 */ 1336 echo apply_filters( 'bp_create_blog_link', '<a href="' . trailingslashit( bp_get_blogs_directory_permalink() . 'create' ) . '">' . __( 'Create a Site', 'buddypress' ) . '</a>' ); 1337 } 1338 1339 /** 1340 * Output navigation tabs for a user Blogs page. 1341 * 1342 * Currently unused by BuddyPress. 1343 */ 1344 function bp_blogs_blog_tabs() { 1345 1346 // Don't show these tabs on a user's own profile. 1347 if ( bp_is_my_profile() ) { 1348 return false; 1349 } ?> 1350 1351 <ul class="content-header-nav"> 1352 <li<?php if ( bp_is_current_action( 'my-blogs' ) || !bp_current_action() ) : ?> class="current"<?php endif; ?>> 1353 <a href="<?php echo trailingslashit( bp_displayed_user_domain() . bp_get_blogs_slug() . '/my-blogs' ); ?>"> 1354 <?php 1355 /* translators: %s: the User Display Name */ 1356 printf( __( "%s's Sites", 'buddypress' ), bp_get_displayed_user_fullname() ); 1357 ?> 1358 </a> 1359 </li> 1360 <li<?php if ( bp_is_current_action( 'recent-posts' ) ) : ?> class="current"<?php endif; ?>> 1361 <a href="<?php echo trailingslashit( bp_displayed_user_domain() . bp_get_blogs_slug() . '/recent-posts' ); ?>"> 1362 <?php 1363 /* translators: %s: the User Display Name */ 1364 printf( __( "%s's Recent Posts", 'buddypress' ), bp_get_displayed_user_fullname() ); 1365 ?> 1366 </a> 1367 </li> 1368 <li<?php if ( bp_is_current_action( 'recent-comments' ) ) : ?> class="current"<?php endif; ?>> 1369 <a href="<?php echo trailingslashit( bp_displayed_user_domain() . bp_get_blogs_slug() . '/recent-comments' ); ?>"> 1370 <?php 1371 /* translators: %s: the User Display Name */ 1372 printf( __( "%s's Recent Comments", 'buddypress' ), bp_get_displayed_user_fullname() ); 1373 ?> 1374 </a> 1375 </li> 1376 </ul> 1377 1378 <?php 1379 1380 /** 1381 * Fires after the markup for the navigation tabs for a user Blogs page. 1382 * 1383 * @since 1.0.0 1384 */ 1385 do_action( 'bp_blogs_blog_tabs' ); 1386 } 1387 1388 /** 1389 * Output the blog directory search form. 1390 */ 1391 function bp_directory_blogs_search_form() { 1392 1393 $query_arg = bp_core_get_component_search_query_arg( 'blogs' ); 1394 1395 if ( ! empty( $_REQUEST[ $query_arg ] ) ) { 1396 $search_value = stripslashes( $_REQUEST[ $query_arg ] ); 1397 } else { 1398 $search_value = bp_get_search_default_text( 'blogs' ); 1399 } 1400 1401 $search_form_html = '<form action="" method="get" id="search-blogs-form"> 1402 <label for="blogs_search"><input type="text" name="' . esc_attr( $query_arg ) . '" id="blogs_search" placeholder="'. esc_attr( $search_value ) .'" /></label> 1403 <input type="submit" id="blogs_search_submit" name="blogs_search_submit" value="' . __( 'Search', 'buddypress' ) . '" /> 1404 </form>'; 1405 1406 /** 1407 * Filters the output for the blog directory search form. 1408 * 1409 * @since 1.9.0 1410 * 1411 * @param string $search_form_html HTML markup for blog directory search form. 1412 */ 1413 echo apply_filters( 'bp_directory_blogs_search_form', $search_form_html ); 1414 } 1415 1416 /** 1417 * Output the Create a Site button. 1418 * 1419 * @since 2.0.0 1420 */ 1421 function bp_blog_create_button() { 1422 echo bp_get_blog_create_button(); 1423 } 1424 /** 1425 * Get the Create a Site button. 1426 * 1427 * @since 2.0.0 1428 * 1429 * @return false|string 1430 */ 1431 function bp_get_blog_create_button() { 1432 if ( ! is_user_logged_in() ) { 1433 return false; 1434 } 1435 1436 if ( ! bp_blog_signup_enabled() ) { 1437 return false; 1438 } 1439 1440 $button_args = array( 1441 'id' => 'create_blog', 1442 'component' => 'blogs', 1443 'link_text' => __( 'Create a Site', 'buddypress' ), 1444 'link_class' => 'blog-create no-ajax', 1445 'link_href' => trailingslashit( bp_get_blogs_directory_permalink() . 'create' ), 1446 'wrapper' => false, 1447 'block_self' => false, 1448 ); 1449 1450 /** 1451 * Filters the Create a Site button. 1452 * 1453 * @since 2.0.0 1454 * 1455 * @param array $button_args Array of arguments to be used for the Create a Site button. 1456 */ 1457 return bp_get_button( apply_filters( 'bp_get_blog_create_button', $button_args ) ); 1458 } 1459 1460 /** 1461 * Output the Create a Site nav item. 1462 * 1463 * @since 2.2.0 1464 */ 1465 function bp_blog_create_nav_item() { 1466 echo bp_get_blog_create_nav_item(); 1467 } 1468 1469 /** 1470 * Get the Create a Site nav item. 1471 * 1472 * @since 2.2.0 1473 * 1474 * @return string 1475 */ 1476 function bp_get_blog_create_nav_item() { 1477 // Get the create a site button. 1478 $create_blog_button = bp_get_blog_create_button(); 1479 1480 // Make sure the button is available. 1481 if ( empty( $create_blog_button ) ) { 1482 return; 1483 } 1484 1485 $output = '<li id="blog-create-nav">' . $create_blog_button . '</li>'; 1486 1487 /** 1488 * Filters the Create A Site nav item output. 1489 * 1490 * @since 2.2.0 1491 * 1492 * @param string $output Nav item output. 1493 */ 1494 return apply_filters( 'bp_get_blog_create_nav_item', $output ); 1495 } 1496 1497 /** 1498 * Checks if a specific theme is still filtering the Blogs directory title 1499 * if so, transform the title button into a Blogs directory nav item. 1500 * 1501 * @since 2.2.0 1502 * 1503 * @return string|null HTML Output 1504 */ 1505 function bp_blog_backcompat_create_nav_item() { 1506 // Bail if Blogs nav item is already used by bp-legacy. 1507 if ( has_action( 'bp_blogs_directory_blog_types', 'bp_legacy_theme_blog_create_nav', 999 ) ) { 1508 return; 1509 } 1510 1511 // Bail if the theme is not filtering the Blogs directory title. 1512 if ( ! has_filter( 'bp_blogs_directory_header' ) ) { 1513 return; 1514 } 1515 1516 bp_blog_create_nav_item(); 1517 } 1518 add_action( 'bp_blogs_directory_blog_types', 'bp_blog_backcompat_create_nav_item', 1000 ); 1519 1520 /** 1521 * Output button for visiting a blog in a loop. 1522 * 1523 * @see bp_get_blogs_visit_blog_button() for description of arguments. 1524 * 1525 * @param array|string $args See {@link bp_get_blogs_visit_blog_button()}. 1526 */ 1527 function bp_blogs_visit_blog_button( $args = '' ) { 1528 echo bp_get_blogs_visit_blog_button( $args ); 1529 } 1530 /** 1531 * Return button for visiting a blog in a loop. 1532 * 1533 * @see BP_Button for a complete description of arguments and return 1534 * value. 1535 * 1536 * @param array|string $args { 1537 * Arguments are listed below, with their default values. For a 1538 * complete description of arguments, see {@link BP_Button}. 1539 * @type string $id Default: 'visit_blog'. 1540 * @type string $component Default: 'blogs'. 1541 * @type bool $must_be_logged_in Default: false. 1542 * @type bool $block_self Default: false. 1543 * @type string $wrapper_class Default: 'blog-button visit'. 1544 * @type string $link_href Permalink of the current blog in the loop. 1545 * @type string $link_class Default: 'blog-button visit'. 1546 * @type string $link_text Default: 'Visit Site'. 1547 * } 1548 * @return string The HTML for the Visit button. 1549 */ 1550 function bp_get_blogs_visit_blog_button( $args = '' ) { 1551 $defaults = array( 1552 'id' => 'visit_blog', 1553 'component' => 'blogs', 1554 'must_be_logged_in' => false, 1555 'block_self' => false, 1556 'wrapper_class' => 'blog-button visit', 1557 'link_href' => bp_get_blog_permalink(), 1558 'link_class' => 'blog-button visit', 1559 'link_text' => __( 'Visit Site', 'buddypress' ), 1560 ); 1561 1562 $button = wp_parse_args( $args, $defaults ); 1563 1564 /** 1565 * Filters the button for visiting a blog in a loop. 1566 * 1567 * @since 1.2.10 1568 * 1569 * @param array $button Array of arguments to be used for the button to visit a blog. 1570 */ 1571 return bp_get_button( apply_filters( 'bp_get_blogs_visit_blog_button', $button ) ); 1572 } 1573 1574 /** Stats **********************************************************************/ 1575 1576 /** 1577 * Display the number of blogs in user's profile. 1578 * 1579 * @since 2.0.0 1580 * 1581 * @param array|string $args Before|after|user_id. 1582 */ 1583 function bp_blogs_profile_stats( $args = '' ) { 1584 echo bp_blogs_get_profile_stats( $args ); 1585 } 1586 add_action( 'bp_members_admin_user_stats', 'bp_blogs_profile_stats', 9, 1 ); 1587 1588 /** 1589 * Return the number of blogs in user's profile. 1590 * 1591 * @since 2.0.0 1592 * 1593 * @param array|string $args Before|after|user_id. 1594 * @return string HTML for stats output. 1595 */ 1596 function bp_blogs_get_profile_stats( $args = '' ) { 1597 1598 // Parse the args. 1599 $r = bp_parse_args( $args, array( 1600 'before' => '<li class="bp-blogs-profile-stats">', 1601 'after' => '</li>', 1602 'user_id' => bp_displayed_user_id(), 1603 'blogs' => 0, 1604 'output' => '' 1605 ), 'blogs_get_profile_stats' ); 1606 1607 // Allow completely overloaded output. 1608 if ( is_multisite() && empty( $r['output'] ) ) { 1609 1610 // Only proceed if a user ID was passed. 1611 if ( ! empty( $r['user_id'] ) ) { 1612 1613 // Get the user's blogs. 1614 if ( empty( $r['blogs'] ) ) { 1615 $r['blogs'] = absint( bp_blogs_total_blogs_for_user( $r['user_id'] ) ); 1616 } 1617 1618 // If blogs exist, show some formatted output. 1619 $r['output'] = $r['before']; 1620 1621 /* translators: %s: the number of blogs */ 1622 $r['output'] .= sprintf( _n( '%s site', '%s sites', $r['blogs'], 'buddypress' ), '<strong>' . $r['blogs'] . '</strong>' ); 1623 $r['output'] .= $r['after']; 1624 } 1625 } 1626 1627 /** 1628 * Filters the number of blogs in user's profile. 1629 * 1630 * @since 2.0.0 1631 * 1632 * @param string $value Output determined for the profile stats. 1633 * @param array $r Array of arguments used for default output if none provided. 1634 */ 1635 return apply_filters( 'bp_blogs_get_profile_stats', $r['output'], $r ); 1636 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sat Jan 16 01:01:34 2021 | Cross-referenced by PHPXref 0.7.1 |