Ticket #7666: 7666.bp_has_activities.patch
File 7666.bp_has_activities.patch, 117.1 KB (added by , 7 years ago) |
---|
-
new file src/bp-activity/bp-activity-functions-loop.php
new file mode 100644
- + 1 <?php 2 3 /** 4 * Determine if there are still activities left in the loop. 5 * 6 * @since 1.0.0 7 * 8 * @global object $activities_template {@link BP_Activity_Template} 9 * 10 * @return bool Returns true when activities are found. 11 */ 12 function bp_activities() { 13 global $activities_template; 14 return $activities_template->user_activities(); 15 } 16 17 /** 18 * Get the current activity object in the loop. 19 * 20 * @since 1.0.0 21 * 22 * @global object $activities_template {@link BP_Activity_Template} 23 * 24 * @return object The current activity within the loop. 25 */ 26 function bp_the_activity() { 27 global $activities_template; 28 return $activities_template->the_activity(); 29 } 30 31 /** 32 * Output the URL for the Load More link. 33 * 34 * @since 2.1.0 35 */ 36 function bp_activity_load_more_link() { 37 echo esc_url( bp_get_activity_load_more_link() ); 38 } 39 /** 40 * Get the URL for the Load More link. 41 * 42 * @since 2.1.0 43 * 44 * @return string $link 45 */ 46 function bp_get_activity_load_more_link() { 47 global $activities_template; 48 49 $url = bp_get_requested_url(); 50 $link = add_query_arg( $activities_template->pag_arg, $activities_template->pag_page + 1, $url ); 51 52 /** 53 * Filters the Load More link URL. 54 * 55 * @since 2.1.0 56 * 57 * @param string $link The "Load More" link URL with appropriate query args. 58 * @param string $url The original URL. 59 * @param object $activities_template The activity template loop global. 60 */ 61 return apply_filters( 'bp_get_activity_load_more_link', $link, $url, $activities_template ); 62 } 63 64 /** 65 * Output the activity pagination count. 66 * 67 * @since 1.0.0 68 * 69 * @global object $activities_template {@link BP_Activity_Template} 70 */ 71 function bp_activity_pagination_count() { 72 echo bp_get_activity_pagination_count(); 73 } 74 75 /** 76 * Return the activity pagination count. 77 * 78 * @since 1.2.0 79 * 80 * @global object $activities_template {@link BP_Activity_Template} 81 * 82 * @return string The pagination text. 83 */ 84 function bp_get_activity_pagination_count() { 85 global $activities_template; 86 87 $start_num = intval( ( $activities_template->pag_page - 1 ) * $activities_template->pag_num ) + 1; 88 $from_num = bp_core_number_format( $start_num ); 89 $to_num = bp_core_number_format( ( $start_num + ( $activities_template->pag_num - 1 ) > $activities_template->total_activity_count ) ? $activities_template->total_activity_count : $start_num + ( $activities_template->pag_num - 1 ) ); 90 $total = bp_core_number_format( $activities_template->total_activity_count ); 91 92 if ( 1 == $activities_template->total_activity_count ) { 93 $message = __( 'Viewing 1 item', 'buddypress' ); 94 } else { 95 $message = sprintf( _n( 'Viewing %1$s - %2$s of %3$s item', 'Viewing %1$s - %2$s of %3$s items', $activities_template->total_activity_count, 'buddypress' ), $from_num, $to_num, $total ); 96 } 97 98 return $message; 99 } 100 101 /** 102 * Output the activity pagination links. 103 * 104 * @since 1.0.0 105 * 106 */ 107 function bp_activity_pagination_links() { 108 echo bp_get_activity_pagination_links(); 109 } 110 111 /** 112 * Return the activity pagination links. 113 * 114 * @since 1.0.0 115 * 116 * @global object $activities_template {@link BP_Activity_Template} 117 * 118 * @return string The pagination links. 119 */ 120 function bp_get_activity_pagination_links() { 121 global $activities_template; 122 123 /** 124 * Filters the activity pagination link output. 125 * 126 * @since 1.0.0 127 * 128 * @param string $pag_links Output for the activity pagination links. 129 */ 130 return apply_filters( 'bp_get_activity_pagination_links', $activities_template->pag_links ); 131 } 132 133 /** 134 * Return true when there are more activity items to be shown than currently appear. 135 * 136 * @since 1.5.0 137 * 138 * @global object $activities_template {@link BP_Activity_Template} 139 * 140 * @return bool $has_more_items True if more items, false if not. 141 */ 142 function bp_activity_has_more_items() { 143 global $activities_template; 144 145 if ( ! empty( $activities_template->has_more_items ) ) { 146 $has_more_items = true; 147 } else { 148 $remaining_pages = 0; 149 150 if ( ! empty( $activities_template->pag_page ) ) { 151 $remaining_pages = floor( ( $activities_template->total_activity_count - 1 ) / ( $activities_template->pag_num * $activities_template->pag_page ) ); 152 } 153 154 $has_more_items = (int) $remaining_pages > 0; 155 } 156 157 /** 158 * Filters whether there are more activity items to display. 159 * 160 * @since 1.5.0 161 * 162 * @param bool $has_more_items Whether or not there are more activity items to display. 163 */ 164 return apply_filters( 'bp_activity_has_more_items', $has_more_items ); 165 } 166 167 /** 168 * Output the activity count. 169 * 170 * @since 1.2.0 171 * 172 */ 173 function bp_activity_count() { 174 echo bp_get_activity_count(); 175 } 176 177 /** 178 * Return the activity count. 179 * 180 * @since 1.2.0 181 * 182 * @global object $activities_template {@link BP_Activity_Template} 183 * 184 * @return int The activity count. 185 */ 186 function bp_get_activity_count() { 187 global $activities_template; 188 189 /** 190 * Filters the activity count for the activity template. 191 * 192 * @since 1.2.0 193 * 194 * @param int $activity_count The count for total activity. 195 */ 196 return apply_filters( 'bp_get_activity_count', (int) $activities_template->activity_count ); 197 } 198 199 /** 200 * Output the number of activities per page. 201 * 202 * @since 1.2.0 203 * 204 */ 205 function bp_activity_per_page() { 206 echo bp_get_activity_per_page(); 207 } 208 209 /** 210 * Return the number of activities per page. 211 * 212 * @since 1.2.0 213 * 214 * @global object $activities_template {@link BP_Activity_Template} 215 * 216 * @return int The activities per page. 217 */ 218 function bp_get_activity_per_page() { 219 global $activities_template; 220 221 /** 222 * Filters the activity posts per page value. 223 * 224 * @since 1.2.0 225 * 226 * @param int $pag_num How many post should be displayed for pagination. 227 */ 228 return apply_filters( 'bp_get_activity_per_page', (int) $activities_template->pag_num ); 229 } 230 231 /** 232 * Output the activities title. 233 * 234 * @since 1.0.0 235 * 236 * @todo Deprecate. 237 */ 238 function bp_activities_title() { 239 echo bp_get_activities_title(); 240 } 241 242 /** 243 * Return the activities title. 244 * 245 * @since 1.0.0 246 * 247 * @global string $bp_activity_title 248 * @todo Deprecate. 249 * 250 * @return string The activities title. 251 */ 252 function bp_get_activities_title() { 253 global $bp_activity_title; 254 255 /** 256 * Filters the activities title for the activity template. 257 * 258 * @since 1.0.0 259 * 260 * @param string $bp_activity_title The title to be displayed. 261 */ 262 return apply_filters( 'bp_get_activities_title', $bp_activity_title ); 263 } 264 265 /** 266 * {@internal Missing Description} 267 * 268 * @since 1.0.0 269 * 270 * @todo Deprecate. 271 */ 272 function bp_activities_no_activity() { 273 echo bp_get_activities_no_activity(); 274 } 275 276 /** 277 * {@internal Missing Description} 278 * 279 * @since 1.0.0 280 * 281 * @global string $bp_activity_no_activity 282 * @todo Deprecate. 283 * 284 * @return string 285 */ 286 function bp_get_activities_no_activity() { 287 global $bp_activity_no_activity; 288 289 /** 290 * Filters the text used when there is no activity to display. 291 * 292 * @since 1.0.0 293 * 294 * @param string $bp_activity_no_activity Text to display for no activity. 295 */ 296 return apply_filters( 'bp_get_activities_no_activity', $bp_activity_no_activity ); 297 } 298 299 /** 300 * Output the activity ID. 301 * 302 * @since 1.2.0 303 * 304 */ 305 function bp_activity_id() { 306 echo bp_get_activity_id(); 307 } 308 309 /** 310 * Return the activity ID. 311 * 312 * @since 1.2.0 313 * 314 * @global object $activities_template {@link BP_Activity_Template} 315 * 316 * @return int The activity ID. 317 */ 318 function bp_get_activity_id() { 319 global $activities_template; 320 321 /** 322 * Filters the activity ID being displayed. 323 * 324 * @since 1.2.0 325 * 326 * @param int $id The activity ID. 327 */ 328 return apply_filters( 'bp_get_activity_id', $activities_template->activity->id ); 329 } 330 331 /** 332 * Output the activity item ID. 333 * 334 * @since 1.2.0 335 * 336 */ 337 function bp_activity_item_id() { 338 echo bp_get_activity_item_id(); 339 } 340 341 /** 342 * Return the activity item ID. 343 * 344 * @since 1.2.0 345 * 346 * @global object $activities_template {@link BP_Activity_Template} 347 * 348 * @return int The activity item ID. 349 */ 350 function bp_get_activity_item_id() { 351 global $activities_template; 352 353 /** 354 * Filters the activity item ID being displayed. 355 * 356 * @since 1.2.0 357 * 358 * @param int $item_id The activity item ID. 359 */ 360 return apply_filters( 'bp_get_activity_item_id', $activities_template->activity->item_id ); 361 } 362 363 /** 364 * Output the activity secondary item ID. 365 * 366 * @since 1.2.0 367 * 368 */ 369 function bp_activity_secondary_item_id() { 370 echo bp_get_activity_secondary_item_id(); 371 } 372 373 /** 374 * Return the activity secondary item ID. 375 * 376 * @since 1.2.0 377 * 378 * @global object $activities_template {@link BP_Activity_Template} 379 * 380 * @return int The activity secondary item ID. 381 */ 382 function bp_get_activity_secondary_item_id() { 383 global $activities_template; 384 385 /** 386 * Filters the activity secondary item ID being displayed. 387 * 388 * @since 1.2.0 389 * 390 * @param int $secondary_item_id The activity secondary item ID. 391 */ 392 return apply_filters( 'bp_get_activity_secondary_item_id', $activities_template->activity->secondary_item_id ); 393 } 394 395 /** 396 * Output the date the activity was recorded. 397 * 398 * @since 1.2.0 399 * 400 */ 401 function bp_activity_date_recorded() { 402 echo bp_get_activity_date_recorded(); 403 } 404 405 /** 406 * Return the date the activity was recorded. 407 * 408 * @since 1.2.0 409 * 410 * @global object $activities_template {@link BP_Activity_Template} 411 * 412 * @return string The date the activity was recorded. 413 */ 414 function bp_get_activity_date_recorded() { 415 global $activities_template; 416 417 /** 418 * Filters the date the activity was recorded. 419 * 420 * @since 1.2.0 421 * 422 * @param int $date_recorded The activity's date. 423 */ 424 return apply_filters( 'bp_get_activity_date_recorded', $activities_template->activity->date_recorded ); 425 } 426 427 /** 428 * Output the activity object name. 429 * 430 * @since 1.2.0 431 * 432 */ 433 function bp_activity_object_name() { 434 echo bp_get_activity_object_name(); 435 } 436 437 /** 438 * Return the activity object name. 439 * 440 * @since 1.2.0 441 * 442 * @global object $activities_template {@link BP_Activity_Template} 443 * 444 * @return string The activity object name. 445 */ 446 function bp_get_activity_object_name() { 447 global $activities_template; 448 449 /** 450 * Filters the activity object name. 451 * 452 * @since 1.2.0 453 * 454 * @param string $activity_component The activity object name. 455 */ 456 return apply_filters( 'bp_get_activity_object_name', $activities_template->activity->component ); 457 } 458 459 /** 460 * Output the activity type. 461 * 462 * @since 1.2.0 463 * 464 */ 465 function bp_activity_type() { 466 echo bp_get_activity_type(); 467 } 468 469 /** 470 * Return the activity type. 471 * 472 * @since 1.2.0 473 * 474 * @global object $activities_template {@link BP_Activity_Template} 475 * 476 * @return string The activity type. 477 */ 478 function bp_get_activity_type() { 479 global $activities_template; 480 481 /** 482 * Filters the activity type. 483 * 484 * @since 1.2.0 485 * 486 * @param string $activity_type The activity type. 487 */ 488 return apply_filters( 'bp_get_activity_type', $activities_template->activity->type ); 489 } 490 491 /** 492 * Output the activity action name. 493 * 494 * Just a wrapper for bp_activity_type(). 495 * 496 * @since 1.2.0 497 * @deprecated 1.5.0 498 * 499 * @todo Properly deprecate in favor of bp_activity_type() and 500 * remove redundant echo 501 * 502 */ 503 function bp_activity_action_name() { echo bp_activity_type(); } 504 505 /** 506 * Return the activity type. 507 * 508 * Just a wrapper for bp_get_activity_type(). 509 * 510 * @since 1.2.0 511 * @deprecated 1.5.0 512 * 513 * @todo Properly deprecate in favor of bp_get_activity_type(). 514 * 515 * 516 * @return string The activity type. 517 */ 518 function bp_get_activity_action_name() { return bp_get_activity_type(); } 519 520 /** 521 * Output the activity user ID. 522 * 523 * @since 1.1.0 524 * 525 */ 526 function bp_activity_user_id() { 527 echo bp_get_activity_user_id(); 528 } 529 530 /** 531 * Return the activity user ID. 532 * 533 * @since 1.1.0 534 * 535 * @global object $activities_template {@link BP_Activity_Template} 536 * 537 * @return int The activity user ID. 538 */ 539 function bp_get_activity_user_id() { 540 global $activities_template; 541 542 /** 543 * Filters the activity user ID. 544 * 545 * @since 1.1.0 546 * 547 * @param int $user_id The activity user ID. 548 */ 549 return apply_filters( 'bp_get_activity_user_id', $activities_template->activity->user_id ); 550 } 551 552 /** 553 * Output the activity user link. 554 * 555 * @since 1.2.0 556 * 557 */ 558 function bp_activity_user_link() { 559 echo bp_get_activity_user_link(); 560 } 561 562 /** 563 * Return the activity user link. 564 * 565 * @since 1.2.0 566 * 567 * @global object $activities_template {@link BP_Activity_Template} 568 * 569 * @return string $link The activity user link. 570 */ 571 function bp_get_activity_user_link() { 572 global $activities_template; 573 574 if ( empty( $activities_template->activity->user_id ) || empty( $activities_template->activity->user_nicename ) || empty( $activities_template->activity->user_login ) ) { 575 $link = $activities_template->activity->primary_link; 576 } else { 577 $link = bp_core_get_user_domain( $activities_template->activity->user_id, $activities_template->activity->user_nicename, $activities_template->activity->user_login ); 578 } 579 580 /** 581 * Filters the activity user link. 582 * 583 * @since 1.2.0 584 * 585 * @param string $link The activity user link. 586 */ 587 return apply_filters( 'bp_get_activity_user_link', $link ); 588 } 589 590 /** 591 * Output the avatar of the user that performed the action. 592 * 593 * @since 1.1.0 594 * 595 * @see bp_get_activity_avatar() for description of arguments. 596 * 597 * @param array|string $args See {@link bp_get_activity_avatar()} for description. 598 */ 599 function bp_activity_avatar( $args = '' ) { 600 echo bp_get_activity_avatar( $args ); 601 } 602 /** 603 * Return the avatar of the user that performed the action. 604 * 605 * @since 1.1.0 606 * 607 * @see bp_core_fetch_avatar() For a description of the arguments. 608 * @global object $activities_template {@link BP_Activity_Template} 609 * 610 * @param array|string $args { 611 * Arguments are listed here with an explanation of their defaults. 612 * For more information about the arguments, see 613 * {@link bp_core_fetch_avatar()}. 614 * @type string $alt Default: 'Profile picture of [user name]' if 615 * activity user name is available, otherwise 'Profile picture'. 616 * @type string $class Default: 'avatar'. 617 * @type string|bool $email Default: Email of the activity's 618 * associated user, if available. Otherwise false. 619 * @type string $type Default: 'full' when viewing a single activity 620 * permalink page, otherwise 'thumb'. 621 * @type int|bool $user_id Default: ID of the activity's user. 622 * } 623 * @return string User avatar string. 624 */ 625 function bp_get_activity_avatar( $args = '' ) { 626 global $activities_template; 627 628 $bp = buddypress(); 629 630 // On activity permalink pages, default to the full-size avatar. 631 $type_default = bp_is_single_activity() ? 'full' : 'thumb'; 632 633 // Within the activity comment loop, the current activity should be set 634 // to current_comment. Otherwise, just use activity. 635 $current_activity_item = isset( $activities_template->activity->current_comment ) ? $activities_template->activity->current_comment : $activities_template->activity; 636 637 // Activity user display name. 638 $dn_default = isset( $current_activity_item->display_name ) ? $current_activity_item->display_name : ''; 639 640 // Prepend some descriptive text to alt. 641 $alt_default = !empty( $dn_default ) ? sprintf( __( 'Profile picture of %s', 'buddypress' ), $dn_default ) : __( 'Profile picture', 'buddypress' ); 642 643 $defaults = array( 644 'alt' => $alt_default, 645 'class' => 'avatar', 646 'email' => false, 647 'type' => $type_default, 648 'user_id' => false 649 ); 650 651 $r = wp_parse_args( $args, $defaults ); 652 extract( $r, EXTR_SKIP ); 653 654 if ( !isset( $height ) && !isset( $width ) ) { 655 656 // Backpat. 657 if ( isset( $bp->avatar->full->height ) || isset( $bp->avatar->thumb->height ) ) { 658 $height = ( 'full' == $type ) ? $bp->avatar->full->height : $bp->avatar->thumb->height; 659 } else { 660 $height = 20; 661 } 662 663 // Backpat. 664 if ( isset( $bp->avatar->full->width ) || isset( $bp->avatar->thumb->width ) ) { 665 $width = ( 'full' == $type ) ? $bp->avatar->full->width : $bp->avatar->thumb->width; 666 } else { 667 $width = 20; 668 } 669 } 670 671 /** 672 * Filters the activity avatar object based on current activity item component. 673 * 674 * This is a variable filter dependent on the component used. 675 * Possible hooks are bp_get_activity_avatar_object_blog, 676 * bp_get_activity_avatar_object_group, and bp_get_activity_avatar_object_user. 677 * 678 * @since 1.1.0 679 * 680 * @param string $component Component being displayed. 681 */ 682 $object = apply_filters( 'bp_get_activity_avatar_object_' . $current_activity_item->component, 'user' ); 683 $item_id = !empty( $user_id ) ? $user_id : $current_activity_item->user_id; 684 685 /** 686 * Filters the activity avatar item ID. 687 * 688 * @since 1.2.10 689 * 690 * @param int $item_id Item ID for the activity avatar. 691 */ 692 $item_id = apply_filters( 'bp_get_activity_avatar_item_id', $item_id ); 693 694 // If this is a user object pass the users' email address for Gravatar so we don't have to prefetch it. 695 if ( 'user' == $object && empty( $user_id ) && empty( $email ) && isset( $current_activity_item->user_email ) ) { 696 $email = $current_activity_item->user_email; 697 } 698 699 /** 700 * Filters the value returned by bp_core_fetch_avatar. 701 * 702 * @since 1.1.3 703 * 704 * @param array $value HTML image element containing the activity avatar. 705 */ 706 return apply_filters( 'bp_get_activity_avatar', bp_core_fetch_avatar( array( 707 'item_id' => $item_id, 708 'object' => $object, 709 'type' => $type, 710 'alt' => $alt, 711 'class' => $class, 712 'width' => $width, 713 'height' => $height, 714 'email' => $email 715 ) ) ); 716 } 717 718 /** 719 * Output the avatar of the object that action was performed on. 720 * 721 * @since 1.2.0 722 * 723 * @see bp_get_activity_secondary_avatar() for description of arguments. 724 * 725 * @param array|string $args See {@link bp_get_activity_secondary_avatar} for description. 726 */ 727 function bp_activity_secondary_avatar( $args = '' ) { 728 echo bp_get_activity_secondary_avatar( $args ); 729 } 730 731 /** 732 * Return the avatar of the object that action was performed on. 733 * 734 * @since 1.2.0 735 * 736 * @see bp_core_fetch_avatar() for description of arguments. 737 * @global object $activities_template {@link BP_Activity_Template} 738 * 739 * @param array|string $args { 740 * For a complete description of arguments, see {@link bp_core_fetch_avatar()}. 741 * @type string $alt Default value varies based on current activity 742 * item component. 743 * @type string $type Default: 'full' when viewing a single activity 744 * permalink page, otherwise 'thumb'. 745 * @type string $class Default: 'avatar'. 746 * @type string|bool $email Default: email of the activity's user. 747 * @type int|bool $user_id Default: ID of the activity's user. 748 * } 749 * @return string The secondary avatar. 750 */ 751 function bp_get_activity_secondary_avatar( $args = '' ) { 752 global $activities_template; 753 754 $r = wp_parse_args( $args, array( 755 'alt' => '', 756 'type' => 'thumb', 757 'width' => 20, 758 'height' => 20, 759 'class' => 'avatar', 760 'link_class' => '', 761 'linked' => true, 762 'email' => false 763 ) ); 764 extract( $r, EXTR_SKIP ); 765 766 // Set item_id and object (default to user). 767 switch ( $activities_template->activity->component ) { 768 case 'groups' : 769 if ( bp_disable_group_avatar_uploads() ) { 770 return false; 771 } 772 773 $object = 'group'; 774 $item_id = $activities_template->activity->item_id; 775 $link = ''; 776 $name = ''; 777 778 // Only if groups is active. 779 if ( bp_is_active( 'groups' ) ) { 780 $group = groups_get_group( $item_id ); 781 $link = bp_get_group_permalink( $group ); 782 $name = $group->name; 783 } 784 785 if ( empty( $alt ) ) { 786 $alt = __( 'Group logo', 'buddypress' ); 787 788 if ( ! empty( $name ) ) { 789 $alt = sprintf( __( 'Group logo of %s', 'buddypress' ), $name ); 790 } 791 } 792 793 break; 794 case 'blogs' : 795 $object = 'blog'; 796 $item_id = $activities_template->activity->item_id; 797 $link = home_url(); 798 799 if ( empty( $alt ) ) { 800 $alt = sprintf( __( 'Profile picture of the author of the site %s', 'buddypress' ), get_blog_option( $item_id, 'blogname' ) ); 801 } 802 803 break; 804 case 'friends' : 805 $object = 'user'; 806 $item_id = $activities_template->activity->secondary_item_id; 807 $link = bp_core_get_userlink( $item_id, false, true ); 808 809 if ( empty( $alt ) ) { 810 $alt = sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname( $activities_template->activity->secondary_item_id ) ); 811 } 812 813 break; 814 default : 815 $object = 'user'; 816 $item_id = $activities_template->activity->user_id; 817 $email = $activities_template->activity->user_email; 818 $link = bp_core_get_userlink( $item_id, false, true ); 819 820 if ( empty( $alt ) ) { 821 $alt = sprintf( __( 'Profile picture of %s', 'buddypress' ), $activities_template->activity->display_name ); 822 } 823 824 break; 825 } 826 827 /** 828 * Filters the activity secondary avatar object based on current activity item component. 829 * 830 * This is a variable filter dependent on the component used. Possible hooks are 831 * bp_get_activity_secondary_avatar_object_blog, bp_get_activity_secondary_avatar_object_group, 832 * and bp_get_activity_secondary_avatar_object_user. 833 * 834 * @since 1.2.10 835 * 836 * @param string $object Component being displayed. 837 */ 838 $object = apply_filters( 'bp_get_activity_secondary_avatar_object_' . $activities_template->activity->component, $object ); 839 840 /** 841 * Filters the activity secondary avatar item ID. 842 * 843 * @since 1.2.10 844 * 845 * @param int $item_id ID for the secondary avatar item. 846 */ 847 $item_id = apply_filters( 'bp_get_activity_secondary_avatar_item_id', $item_id ); 848 849 // If we have no item_id or object, there is no avatar to display. 850 if ( empty( $item_id ) || empty( $object ) ) { 851 return false; 852 } 853 854 // Get the avatar. 855 $avatar = bp_core_fetch_avatar( array( 856 'item_id' => $item_id, 857 'object' => $object, 858 'type' => $type, 859 'alt' => $alt, 860 'class' => $class, 861 'width' => $width, 862 'height' => $height, 863 'email' => $email 864 ) ); 865 866 if ( !empty( $linked ) ) { 867 868 /** 869 * Filters the secondary avatar link for current activity. 870 * 871 * @since 1.7.0 872 * 873 * @param string $link Link to wrap the avatar image in. 874 * @param string $component Activity component being acted on. 875 */ 876 $link = apply_filters( 'bp_get_activity_secondary_avatar_link', $link, $activities_template->activity->component ); 877 878 /** 879 * Filters the determined avatar for the secondary activity item. 880 * 881 * @since 1.2.10 882 * 883 * @param string $avatar Formatted HTML <img> element, or raw avatar URL. 884 */ 885 $avatar = apply_filters( 'bp_get_activity_secondary_avatar', $avatar ); 886 887 return sprintf( '<a href="%s" class="%s">%s</a>', 888 $link, 889 $link_class, 890 $avatar 891 ); 892 } 893 894 /** This filter is documented in bp-activity/bp-activity-template.php */ 895 return apply_filters( 'bp_get_activity_secondary_avatar', $avatar ); 896 } 897 898 /** 899 * Output the activity action. 900 * 901 * @since 1.2.0 902 * 903 * @param array $args See bp_get_activity_action(). 904 */ 905 function bp_activity_action( $args = array() ) { 906 echo bp_get_activity_action( $args ); 907 } 908 909 /** 910 * Return the activity action. 911 * 912 * @since 1.2.0 913 * 914 * @global object $activities_template {@link BP_Activity_Template} 915 * 916 * @param array $args { 917 * @type bool $no_timestamp Whether to exclude the timestamp. 918 * } 919 * 920 * @return string The activity action. 921 */ 922 function bp_get_activity_action( $args = array() ) { 923 global $activities_template; 924 925 $r = wp_parse_args( $args, array( 926 'no_timestamp' => false, 927 ) ); 928 929 /** 930 * Filters the activity action before the action is inserted as meta. 931 * 932 * @since 1.2.10 933 * 934 * @param array $value Array containing the current action, the current activity, and the $args array passed into the function. 935 */ 936 $action = apply_filters_ref_array( 'bp_get_activity_action_pre_meta', array( 937 $activities_template->activity->action, 938 &$activities_template->activity, 939 $r 940 ) ); 941 942 // Prepend the activity action meta (link, time since, etc...). 943 if ( ! empty( $action ) && empty( $r['no_timestamp'] ) ) { 944 $action = bp_insert_activity_meta( $action ); 945 } 946 947 /** 948 * Filters the activity action after the action has been inserted as meta. 949 * 950 * @since 1.2.0 951 * 952 * @param array $value Array containing the current action, the current activity, and the $args array passed into the function. 953 */ 954 return apply_filters_ref_array( 'bp_get_activity_action', array( 955 $action, 956 &$activities_template->activity, 957 $r 958 ) ); 959 } 960 961 /** 962 * Output the activity content body. 963 * 964 * @since 1.2.0 965 * 966 */ 967 function bp_activity_content_body() { 968 echo bp_get_activity_content_body(); 969 } 970 971 /** 972 * Return the activity content body. 973 * 974 * @since 1.2.0 975 * 976 * @global object $activities_template {@link BP_Activity_Template} 977 * 978 * @return string The activity content body. 979 */ 980 function bp_get_activity_content_body() { 981 global $activities_template; 982 983 // Backwards compatibility if action is not being used. 984 if ( empty( $activities_template->activity->action ) && ! empty( $activities_template->activity->content ) ) { 985 $activities_template->activity->content = bp_insert_activity_meta( $activities_template->activity->content ); 986 } 987 988 /** 989 * Filters the activity content body. 990 * 991 * @since 1.2.0 992 * 993 * @param string $content Content body. 994 * @param object $activity Activity object. Passed by reference. 995 */ 996 return apply_filters_ref_array( 'bp_get_activity_content_body', array( $activities_template->activity->content, &$activities_template->activity ) ); 997 } 998 999 /** 1000 * Does the activity have content? 1001 * 1002 * @since 1.2.0 1003 * 1004 * @global object $activities_template {@link BP_Activity_Template} 1005 * 1006 * @return bool True if activity has content, false otherwise. 1007 */ 1008 function bp_activity_has_content() { 1009 global $activities_template; 1010 1011 if ( ! empty( $activities_template->activity->content ) ) { 1012 return true; 1013 } 1014 1015 return false; 1016 } 1017 1018 /** 1019 * Output the activity content. 1020 * 1021 * @since 1.0.0 1022 * @deprecated 1.5.0 1023 * 1024 * @todo properly deprecate this function. 1025 * 1026 */ 1027 function bp_activity_content() { 1028 echo bp_get_activity_content(); 1029 } 1030 1031 /** 1032 * Return the activity content. 1033 * 1034 * @since 1.0.0 1035 * @deprecated 1.5.0 1036 * 1037 * @todo properly deprecate this function. 1038 * 1039 * 1040 * @return string The activity content. 1041 */ 1042 function bp_get_activity_content() { 1043 1044 /** 1045 * If you want to filter activity update content, please use 1046 * the filter 'bp_get_activity_content_body'. 1047 * 1048 * This function is mainly for backwards compatibility. 1049 */ 1050 $content = bp_get_activity_action() . ' ' . bp_get_activity_content_body(); 1051 return apply_filters( 'bp_get_activity_content', $content ); 1052 } 1053 1054 /** 1055 * Attach metadata about an activity item to the activity content. 1056 * 1057 * This metadata includes the time since the item was posted (which will appear 1058 * as a link to the item's permalink). 1059 * 1060 * @since 1.2.0 1061 * 1062 * @global object $activities_template {@link BP_Activity_Template} 1063 * 1064 * @param string $content The activity content. 1065 * @return string The activity content with the metadata string attached. 1066 */ 1067 function bp_insert_activity_meta( $content = '' ) { 1068 global $activities_template; 1069 1070 // Strip any legacy time since placeholders from BP 1.0-1.1. 1071 $new_content = str_replace( '<span class="time-since">%s</span>', '', $content ); 1072 1073 // Get the time since this activity was recorded. 1074 $date_recorded = bp_core_time_since( $activities_template->activity->date_recorded ); 1075 1076 // Set up 'time-since' <span>. 1077 $time_since = sprintf( 1078 '<span class="time-since" data-livestamp="%1$s">%2$s</span>', 1079 bp_core_get_iso8601_date( $activities_template->activity->date_recorded ), 1080 $date_recorded 1081 ); 1082 1083 /** 1084 * Filters the activity item time since markup. 1085 * 1086 * @since 1.2.0 1087 * 1088 * @param array $value Array containing the time since markup and the current activity component. 1089 */ 1090 $time_since = apply_filters_ref_array( 'bp_activity_time_since', array( 1091 $time_since, 1092 &$activities_template->activity 1093 ) ); 1094 1095 // Insert the permalink. 1096 if ( ! bp_is_single_activity() ) { 1097 1098 // Setup variables for activity meta. 1099 $activity_permalink = bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity ); 1100 $activity_meta = sprintf( '%1$s <a href="%2$s" class="view activity-time-since bp-tooltip" data-bp-tooltip="%3$s">%4$s</a>', 1101 $new_content, 1102 $activity_permalink, 1103 esc_attr__( 'View Discussion', 'buddypress' ), 1104 $time_since 1105 ); 1106 1107 /** 1108 * Filters the activity permalink to be added to the activity content. 1109 * 1110 * @since 1.2.0 1111 * 1112 * @param array $value Array containing the html markup for the activity permalink, after being parsed by 1113 * sprintf and current activity component. 1114 */ 1115 $new_content = apply_filters_ref_array( 'bp_activity_permalink', array( 1116 $activity_meta, 1117 &$activities_template->activity 1118 ) ); 1119 } else { 1120 $new_content .= str_pad( $time_since, strlen( $time_since ) + 2, ' ', STR_PAD_BOTH ); 1121 } 1122 1123 /** 1124 * Filters the activity content after activity metadata has been attached. 1125 * 1126 * @since 1.2.0 1127 * 1128 * @param string $content Activity content with the activity metadata added. 1129 */ 1130 return apply_filters( 'bp_insert_activity_meta', $new_content, $content ); 1131 } 1132 1133 /** 1134 * Output the activity parent content. 1135 * 1136 * @since 1.2.0 1137 * 1138 * @see bp_get_activity_parent_content() for a description of arguments. 1139 * 1140 * @param array|string $args See {@link bp_get_activity_parent_content} for description. 1141 */ 1142 function bp_activity_parent_content( $args = '' ) { 1143 echo bp_get_activity_parent_content($args); 1144 } 1145 1146 /** 1147 * Return the activity content. 1148 * 1149 * @since 1.2.0 1150 * 1151 * @global object $activities_template {@link BP_Activity_Template} 1152 * 1153 * @param string $args Unused. Left over from an earlier implementation. 1154 * @return mixed False on failure, otherwise the activity parent content. 1155 */ 1156 function bp_get_activity_parent_content( $args = '' ) { 1157 global $activities_template; 1158 1159 // Bail if no activity on no item ID. 1160 if ( empty( $activities_template->activity ) || empty( $activities_template->activity->item_id ) ) { 1161 return false; 1162 } 1163 1164 // Get the ID of the parent activity content. 1165 $parent_id = $activities_template->activity->item_id; 1166 1167 // Bail if no parent content. 1168 if ( empty( $activities_template->activity_parents[ $parent_id ] ) ) { 1169 return false; 1170 } 1171 1172 // Bail if no action. 1173 if ( empty( $activities_template->activity_parents[ $parent_id ]->action ) ) { 1174 return false; 1175 } 1176 1177 // Content always includes action. 1178 $content = $activities_template->activity_parents[ $parent_id ]->action; 1179 1180 // Maybe append activity content, if it exists. 1181 if ( ! empty( $activities_template->activity_parents[ $parent_id ]->content ) ) { 1182 $content .= ' ' . $activities_template->activity_parents[ $parent_id ]->content; 1183 } 1184 1185 // Remove the time since content for backwards compatibility. 1186 $content = str_replace( '<span class="time-since">%s</span>', '', $content ); 1187 1188 // Remove images. 1189 $content = preg_replace( '/<img[^>]*>/Ui', '', $content ); 1190 1191 /** 1192 * Filters the activity parent content. 1193 * 1194 * @since 1.2.0 1195 * 1196 * @param string $content Content set to be displayed as parent content. 1197 */ 1198 return apply_filters( 'bp_get_activity_parent_content', $content ); 1199 } 1200 1201 /** 1202 * Output the parent activity's user ID. 1203 * 1204 * @since 1.7.0 1205 */ 1206 function bp_activity_parent_user_id() { 1207 echo bp_get_activity_parent_user_id(); 1208 } 1209 1210 /** 1211 * Return the parent activity's user ID. 1212 * 1213 * @since 1.7.0 1214 * 1215 * @global BP_Activity_Template $activities_template 1216 * 1217 * @return bool|int False if parent activity can't be found, otherwise 1218 * the parent activity's user ID. 1219 */ 1220 function bp_get_activity_parent_user_id() { 1221 global $activities_template; 1222 1223 // Bail if no activity on no item ID. 1224 if ( empty( $activities_template->activity ) || empty( $activities_template->activity->item_id ) ) { 1225 return false; 1226 } 1227 1228 // Get the ID of the parent activity content. 1229 $parent_id = $activities_template->activity->item_id; 1230 1231 // Bail if no parent item. 1232 if ( empty( $activities_template->activity_parents[ $parent_id ] ) ) { 1233 return false; 1234 } 1235 1236 // Bail if no parent user ID. 1237 if ( empty( $activities_template->activity_parents[ $parent_id ]->user_id ) ) { 1238 return false; 1239 } 1240 1241 $retval = $activities_template->activity_parents[ $parent_id ]->user_id; 1242 1243 /** 1244 * Filters the activity parent item's user ID. 1245 * 1246 * @since 1.7.0 1247 * 1248 * @param int $retval ID for the activity parent's user. 1249 */ 1250 return (int) apply_filters( 'bp_get_activity_parent_user_id', $retval ); 1251 } 1252 1253 /** 1254 * Output whether or not the current activity is in a current user's favorites. 1255 * 1256 * @since 1.2.0 1257 * 1258 */ 1259 function bp_activity_is_favorite() { 1260 echo bp_get_activity_is_favorite(); 1261 } 1262 1263 /** 1264 * Return whether the current activity is in a current user's favorites. 1265 * 1266 * @since 1.2.0 1267 * 1268 * @global object $activities_template {@link BP_Activity_Template} 1269 * 1270 * @return bool True if user favorite, false otherwise. 1271 */ 1272 function bp_get_activity_is_favorite() { 1273 global $activities_template; 1274 1275 /** 1276 * Filters whether the current activity item is in the current user's favorites. 1277 * 1278 * @since 1.2.0 1279 * 1280 * @param bool $value Whether or not the current activity item is in the current user's favorites. 1281 */ 1282 return (bool) apply_filters( 'bp_get_activity_is_favorite', in_array( $activities_template->activity->id, (array) $activities_template->my_favs ) ); 1283 } 1284 1285 /** 1286 * Output the comment markup for an activity item. 1287 * 1288 * @since 1.2.0 1289 * 1290 * @todo deprecate $args param 1291 * 1292 * @param array|string $args See {@link bp_activity_get_comments} for description. 1293 */ 1294 function bp_activity_comments( $args = '' ) { 1295 echo bp_activity_get_comments( $args ); 1296 } 1297 1298 /** 1299 * Get the comment markup for an activity item. 1300 * 1301 * @since 1.2.0 1302 * 1303 * @todo deprecate $args param 1304 * @todo Given that checks for children already happen in bp_activity_recurse_comments(), 1305 * this function can probably be streamlined or removed. 1306 * 1307 * @global object $activities_template {@link BP_Activity_Template} 1308 * 1309 * @param string $args Unused. Left over from an earlier implementation. 1310 * @return bool 1311 */ 1312 function bp_activity_get_comments( $args = '' ) { 1313 global $activities_template; 1314 1315 if ( empty( $activities_template->activity->children ) ) { 1316 return false; 1317 } 1318 1319 bp_activity_recurse_comments( $activities_template->activity ); 1320 } 1321 1322 /** 1323 * Loops through a level of activity comments and loads the template for each. 1324 * 1325 * Note: The recursion itself used to happen entirely in this function. Now it is 1326 * split between here and the comment.php template. 1327 * 1328 * @since 1.2.0 1329 * 1330 * @global object $activities_template {@link BP_Activity_Template} 1331 * 1332 * @param object $comment The activity object currently being recursed. 1333 * @return bool|string 1334 */ 1335 function bp_activity_recurse_comments( $comment ) { 1336 global $activities_template; 1337 1338 if ( empty( $comment ) ) { 1339 return false; 1340 } 1341 1342 if ( empty( $comment->children ) ) { 1343 return false; 1344 } 1345 1346 /** 1347 * Filters the opening tag for the template that lists activity comments. 1348 * 1349 * @since 1.6.0 1350 * 1351 * @param string $value Opening tag for the HTML markup to use. 1352 */ 1353 echo apply_filters( 'bp_activity_recurse_comments_start_ul', '<ul>' ); 1354 foreach ( (array) $comment->children as $comment_child ) { 1355 1356 // Put the comment into the global so it's available to filters. 1357 $activities_template->activity->current_comment = $comment_child; 1358 1359 $template = bp_locate_template( 'activity/comment.php', false, false ); 1360 1361 // Backward compatibility. In older versions of BP, the markup was 1362 // generated in the PHP instead of a template. This ensures that 1363 // older themes (which are not children of bp-default and won't 1364 // have the new template) will still work. 1365 if ( !$template ) { 1366 $template = buddypress()->plugin_dir . '/bp-themes/bp-default/activity/comment.php'; 1367 } 1368 1369 load_template( $template, false ); 1370 1371 unset( $activities_template->activity->current_comment ); 1372 } 1373 1374 /** 1375 * Filters the closing tag for the template that list activity comments. 1376 * 1377 * @since 1.6.0 1378 * 1379 * @param string $value Closing tag for the HTML markup to use. 1380 */ 1381 echo apply_filters( 'bp_activity_recurse_comments_end_ul', '</ul>' ); 1382 } 1383 1384 /** 1385 * Utility function that returns the comment currently being recursed. 1386 * 1387 * @since 1.5.0 1388 * 1389 * @global object $activities_template {@link BP_Activity_Template} 1390 * 1391 * @return object|bool $current_comment The activity comment currently being 1392 * displayed. False on failure. 1393 */ 1394 function bp_activity_current_comment() { 1395 global $activities_template; 1396 1397 $current_comment = !empty( $activities_template->activity->current_comment ) 1398 ? $activities_template->activity->current_comment 1399 : false; 1400 1401 /** 1402 * Filters the current comment being recursed. 1403 * 1404 * @since 1.5.0 1405 * 1406 * @param object|bool $current_comment The activity comment currently being displayed. False on failure. 1407 */ 1408 return apply_filters( 'bp_activity_current_comment', $current_comment ); 1409 } 1410 1411 1412 /** 1413 * Output the ID of the activity comment currently being displayed. 1414 * 1415 * @since 1.5.0 1416 * 1417 */ 1418 function bp_activity_comment_id() { 1419 echo bp_get_activity_comment_id(); 1420 } 1421 1422 /** 1423 * Return the ID of the activity comment currently being displayed. 1424 * 1425 * @since 1.5.0 1426 * 1427 * @global object $activities_template {@link BP_Activity_Template} 1428 * 1429 * @return int|bool $comment_id The ID of the activity comment currently 1430 * being displayed, false if none is found. 1431 */ 1432 function bp_get_activity_comment_id() { 1433 global $activities_template; 1434 1435 $comment_id = isset( $activities_template->activity->current_comment->id ) ? $activities_template->activity->current_comment->id : false; 1436 1437 /** 1438 * Filters the ID of the activity comment currently being displayed. 1439 * 1440 * @since 1.5.0 1441 * 1442 * @param int|bool $comment_id ID for the comment currently being displayed. 1443 */ 1444 return apply_filters( 'bp_activity_comment_id', $comment_id ); 1445 } 1446 1447 /** 1448 * Output the ID of the author of the activity comment currently being displayed. 1449 * 1450 * @since 1.5.0 1451 * 1452 */ 1453 function bp_activity_comment_user_id() { 1454 echo bp_get_activity_comment_user_id(); 1455 } 1456 1457 /** 1458 * Return the ID of the author of the activity comment currently being displayed. 1459 * 1460 * @since 1.5.0 1461 * 1462 * @global object $activities_template {@link BP_Activity_Template} 1463 * 1464 * @return int|bool $user_id The user_id of the author of the displayed 1465 * activity comment. False on failure. 1466 */ 1467 function bp_get_activity_comment_user_id() { 1468 global $activities_template; 1469 1470 $user_id = isset( $activities_template->activity->current_comment->user_id ) ? $activities_template->activity->current_comment->user_id : false; 1471 1472 /** 1473 * Filters the ID of the author of the activity comment currently being displayed. 1474 * 1475 * @since 1.5.0 1476 * 1477 * @param int|bool $user_id ID for the author of the comment currently being displayed. 1478 */ 1479 return apply_filters( 'bp_activity_comment_user_id', $user_id ); 1480 } 1481 1482 /** 1483 * Output the author link for the activity comment currently being displayed. 1484 * 1485 * @since 1.5.0 1486 * 1487 */ 1488 function bp_activity_comment_user_link() { 1489 echo bp_get_activity_comment_user_link(); 1490 } 1491 1492 /** 1493 * Return the author link for the activity comment currently being displayed. 1494 * 1495 * @since 1.5.0 1496 * 1497 * 1498 * @return string $user_link The URL of the activity comment author's profile. 1499 */ 1500 function bp_get_activity_comment_user_link() { 1501 $user_link = bp_core_get_user_domain( bp_get_activity_comment_user_id() ); 1502 1503 /** 1504 * Filters the author link for the activity comment currently being displayed. 1505 * 1506 * @since 1.5.0 1507 * 1508 * @param string $user_link Link for the author of the activity comment currently being displayed. 1509 */ 1510 return apply_filters( 'bp_activity_comment_user_link', $user_link ); 1511 } 1512 1513 /** 1514 * Output the author name for the activity comment currently being displayed. 1515 * 1516 * @since 1.5.0 1517 * 1518 */ 1519 function bp_activity_comment_name() { 1520 echo bp_get_activity_comment_name(); 1521 } 1522 1523 /** 1524 * Return the author name for the activity comment currently being displayed. 1525 * 1526 * The use of the 'bp_acomment_name' filter is deprecated. Please use 1527 * 'bp_activity_comment_name'. 1528 * 1529 * @since 1.5.0 1530 * 1531 * @global object $activities_template {@link BP_Activity_Template} 1532 * 1533 * @return string $name The full name of the activity comment author. 1534 */ 1535 function bp_get_activity_comment_name() { 1536 global $activities_template; 1537 1538 if ( isset( $activities_template->activity->current_comment->user_fullname ) ) { 1539 1540 $name = apply_filters( 'bp_acomment_name', $activities_template->activity->current_comment->user_fullname, $activities_template->activity->current_comment ); // Backward compatibility. 1541 } else { 1542 $name = $activities_template->activity->current_comment->display_name; 1543 } 1544 1545 /** 1546 * Filters the name of the author for the activity comment. 1547 * 1548 * @since 1.5.0 1549 * 1550 * @param string $name Name to be displayed with the activity comment. 1551 */ 1552 return apply_filters( 'bp_activity_comment_name', $name ); 1553 } 1554 1555 /** 1556 * Output the formatted date_recorded of the activity comment currently being displayed. 1557 * 1558 * @since 1.5.0 1559 * 1560 */ 1561 function bp_activity_comment_date_recorded() { 1562 echo bp_get_activity_comment_date_recorded(); 1563 } 1564 1565 /** 1566 * Return the formatted date_recorded for the activity comment currently being displayed. 1567 * 1568 * @since 1.5.0 1569 * 1570 * 1571 * @return string|bool $date_recorded Time since the activity was recorded, 1572 * in the form "%s ago". False on failure. 1573 */ 1574 function bp_get_activity_comment_date_recorded() { 1575 1576 /** 1577 * Filters the recorded date of the activity comment currently being displayed. 1578 * 1579 * @since 1.5.0 1580 * 1581 * @param string|bool Date for the activity comment currently being displayed. 1582 */ 1583 return apply_filters( 'bp_activity_comment_date_recorded', bp_core_time_since( bp_get_activity_comment_date_recorded_raw() ) ); 1584 } 1585 1586 /** 1587 * Output the date_recorded of the activity comment currently being displayed. 1588 * 1589 * @since 2.3.0 1590 * 1591 */ 1592 function bp_activity_comment_date_recorded_raw() { 1593 echo bp_get_activity_comment_date_recorded_raw(); 1594 } 1595 1596 /** 1597 * Return the date_recorded for the activity comment currently being displayed. 1598 * 1599 * @since 2.3.0 1600 * 1601 * @global object $activities_template {@link BP_Activity_Template} 1602 * 1603 * @return string|bool $date_recorded Time since the activity was recorded, 1604 * in the form "%s ago". False on failure. 1605 */ 1606 function bp_get_activity_comment_date_recorded_raw() { 1607 global $activities_template; 1608 1609 /** 1610 * Filters the raw recorded date of the activity comment currently being displayed. 1611 * 1612 * @since 2.3.0 1613 * 1614 * @param string|bool Raw date for the activity comment currently being displayed. 1615 */ 1616 return apply_filters( 'bp_activity_comment_date_recorded', $activities_template->activity->current_comment->date_recorded ); 1617 } 1618 1619 /** 1620 * Output the 'delete' URL for the activity comment currently being displayed. 1621 * 1622 * @since 1.5.0 1623 * 1624 */ 1625 function bp_activity_comment_delete_link() { 1626 echo bp_get_activity_comment_delete_link(); 1627 } 1628 1629 /** 1630 * Gets the 'delete' URL for the activity comment currently being displayed. 1631 * 1632 * @since 1.5.0 1633 * 1634 * 1635 * @return string $link The nonced URL for deleting the current 1636 * activity comment. 1637 */ 1638 function bp_get_activity_comment_delete_link() { 1639 $link = wp_nonce_url( trailingslashit( bp_get_activity_directory_permalink() . 'delete/' . bp_get_activity_comment_id() ) . '?cid=' . bp_get_activity_comment_id(), 'bp_activity_delete_link' ); 1640 1641 /** 1642 * Filters the link used for deleting the activity comment currently being displayed. 1643 * 1644 * @since 1.5.0 1645 * 1646 * @param string $link Link to use for deleting the currently displayed activity comment. 1647 */ 1648 return apply_filters( 'bp_activity_comment_delete_link', $link ); 1649 } 1650 1651 /** 1652 * Output the content of the activity comment currently being displayed. 1653 * 1654 * @since 1.5.0 1655 * 1656 */ 1657 function bp_activity_comment_content() { 1658 echo bp_get_activity_comment_content(); 1659 } 1660 1661 /** 1662 * Return the content of the activity comment currently being displayed. 1663 * 1664 * The content is run through two filters. 'bp_get_activity_content' 1665 * will apply all filters applied to activity items in general. Use 1666 * 'bp_activity_comment_content' to modify the content of activity 1667 * comments only. 1668 * 1669 * @since 1.5.0 1670 * 1671 * @global object $activities_template {@link BP_Activity_Template} 1672 * 1673 * @return string $content The content of the current activity comment. 1674 */ 1675 function bp_get_activity_comment_content() { 1676 global $activities_template; 1677 1678 /** This filter is documented in bp-activity/bp-activity-template.php */ 1679 $content = apply_filters( 'bp_get_activity_content', $activities_template->activity->current_comment->content ); 1680 1681 /** 1682 * Filters the content of the current activity comment. 1683 * 1684 * @since 1.2.0 1685 * 1686 * @param string $content The content of the current activity comment. 1687 */ 1688 return apply_filters( 'bp_activity_comment_content', $content ); 1689 } 1690 1691 /** 1692 * Output the activity comment count. 1693 * 1694 * @since 1.2.0 1695 * 1696 */ 1697 function bp_activity_comment_count() { 1698 echo bp_activity_get_comment_count(); 1699 } 1700 1701 /** 1702 * Return the comment count of an activity item. 1703 * 1704 * @since 1.2.0 1705 * 1706 * @global object $activities_template {@link BP_Activity_Template} 1707 * 1708 * @param array|null $deprecated Deprecated. 1709 * @return int $count The activity comment count. 1710 */ 1711 function bp_activity_get_comment_count( $deprecated = null ) { 1712 global $activities_template; 1713 1714 // Deprecated notice about $args. 1715 if ( ! empty( $deprecated ) ) { 1716 _deprecated_argument( __FUNCTION__, '1.2', sprintf( __( '%1$s no longer accepts arguments. See the inline documentation at %2$s for more details.', 'buddypress' ), __FUNCTION__, __FILE__ ) ); 1717 } 1718 1719 // Get the count using the purpose-built recursive function. 1720 $count = ! empty( $activities_template->activity->children ) 1721 ? bp_activity_recurse_comment_count( $activities_template->activity ) 1722 : 0; 1723 1724 /** 1725 * Filters the activity comment count. 1726 * 1727 * @since 1.2.0 1728 * 1729 * @param int $count The activity comment count. 1730 */ 1731 return apply_filters( 'bp_activity_get_comment_count', (int) $count ); 1732 } 1733 1734 /** 1735 * Return the total number of comments to the current comment. 1736 * 1737 * This function recursively adds the total number of comments each 1738 * activity child has, and returns them. 1739 * 1740 * @since 1.2.0 1741 * 1742 * 1743 * @param object $comment Activity comment object. 1744 * @param int $count The current iteration count. 1745 * @return int $count The activity comment count. 1746 */ 1747 function bp_activity_recurse_comment_count( $comment, $count = 0 ) { 1748 1749 // Copy the count. 1750 $new_count = $count; 1751 1752 // Loop through children and recursively count comments. 1753 if ( ! empty( $comment->children ) ) { 1754 foreach ( (array) $comment->children as $comment ) { 1755 $new_count++; 1756 $new_count = bp_activity_recurse_comment_count( $comment, $new_count ); 1757 } 1758 } 1759 1760 /** 1761 * Filters the total number of comments for the current comment. 1762 * 1763 * @since 2.1.0 1764 * 1765 * @param int $new_count New total count for the current comment. 1766 * @param object $comment Activity comment object. 1767 * @param int $count Current iteration count for the current comment. 1768 */ 1769 return apply_filters( 'bp_activity_recurse_comment_count', $new_count, $comment, $count ); 1770 } 1771 1772 /** 1773 * Output the activity comment link. 1774 * 1775 * @since 1.2.0 1776 * 1777 */ 1778 function bp_activity_comment_link() { 1779 echo bp_get_activity_comment_link(); 1780 } 1781 1782 /** 1783 * Return the activity comment link. 1784 * 1785 * @since 1.2.0 1786 * 1787 * @global object $activities_template {@link BP_Activity_Template} 1788 * 1789 * @return string The activity comment link. 1790 */ 1791 function bp_get_activity_comment_link() { 1792 global $activities_template; 1793 1794 /** 1795 * Filters the comment link for the current activity comment. 1796 * 1797 * @since 1.2.0 1798 * 1799 * @param string $value Constructed URL parameters with activity IDs. 1800 */ 1801 return apply_filters( 'bp_get_activity_comment_link', '?ac=' . $activities_template->activity->id . '/#ac-form-' . $activities_template->activity->id ); 1802 } 1803 1804 /** 1805 * Output the activity comment form no JavaScript display CSS. 1806 * 1807 * @since 1.2.0 1808 * 1809 */ 1810 function bp_activity_comment_form_nojs_display() { 1811 echo bp_get_activity_comment_form_nojs_display(); 1812 } 1813 1814 /** 1815 * Return the activity comment form no JavaScript display CSS. 1816 * 1817 * @since 1.2.0 1818 * 1819 * @global object $activities_template {@link BP_Activity_Template} 1820 * 1821 * @return string|false The activity comment form no JavaScript 1822 * display CSS. False on failure. 1823 */ 1824 function bp_get_activity_comment_form_nojs_display() { 1825 global $activities_template; 1826 1827 if ( isset( $_GET['ac'] ) && ( $_GET['ac'] === ( $activities_template->activity->id . '/' ) ) ) { 1828 return 'style="display: block"'; 1829 } 1830 1831 return false; 1832 } 1833 1834 /** 1835 * Output the activity comment form action. 1836 * 1837 * @since 1.2.0 1838 * 1839 */ 1840 function bp_activity_comment_form_action() { 1841 echo bp_get_activity_comment_form_action(); 1842 } 1843 1844 /** 1845 * Return the activity comment form action. 1846 * 1847 * @since 1.2.0 1848 * 1849 * 1850 * @return string The activity comment form action. 1851 */ 1852 function bp_get_activity_comment_form_action() { 1853 1854 /** 1855 * Filters the activity comment form action URL. 1856 * 1857 * @since 1.2.0 1858 * 1859 * @param string $value URL to use in the comment form's action attribute. 1860 */ 1861 return apply_filters( 'bp_get_activity_comment_form_action', home_url( bp_get_activity_root_slug() . '/reply/' ) ); 1862 } 1863 1864 /** 1865 * Output the activity thread permalink. 1866 * 1867 * @since 1.2.0 1868 * 1869 */ 1870 function bp_activity_thread_permalink() { 1871 echo esc_url( bp_get_activity_thread_permalink() ); 1872 } 1873 1874 /** 1875 * Return the activity thread permalink. 1876 * 1877 * @since 1.2.0 1878 * 1879 * 1880 * @return string $link The activity thread permalink. 1881 */ 1882 function bp_get_activity_thread_permalink() { 1883 global $activities_template; 1884 1885 $link = bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity ); 1886 1887 /** 1888 * Filters the activity thread permalink. 1889 * 1890 * @since 1.2.0 1891 * 1892 * @param string $link The activity thread permalink. 1893 */ 1894 return apply_filters( 'bp_get_activity_thread_permalink', $link ); 1895 } 1896 1897 /** 1898 * Output the activity comment permalink. 1899 * 1900 * @since 1.8.0 1901 * 1902 */ 1903 function bp_activity_comment_permalink() { 1904 echo esc_url( bp_get_activity_comment_permalink() ); 1905 } 1906 /** 1907 * Return the activity comment permalink. 1908 * 1909 * @since 1.8.0 1910 * 1911 * @return string $link The activity comment permalink. 1912 */ 1913 function bp_get_activity_comment_permalink() { 1914 global $activities_template; 1915 1916 $link = bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity ); 1917 1918 // Used for filter below. 1919 $comment_id = isset( $activities_template->activity->current_comment->id ) 1920 ? $activities_template->activity->current_comment->id 1921 : 0; 1922 1923 /** 1924 * Filters the activity comment permalink. 1925 * 1926 * @since 1.8.0 1927 * 1928 * @param string $link Activity comment permalink. 1929 * @param int $comment_id ID for the current activity comment. 1930 */ 1931 return apply_filters( 'bp_get_activity_comment_permalink', $link, $comment_id ); 1932 } 1933 1934 /** 1935 * Output the activity favorite link. 1936 * 1937 * @since 1.2.0 1938 * 1939 */ 1940 function bp_activity_favorite_link() { 1941 echo bp_get_activity_favorite_link(); 1942 } 1943 1944 /** 1945 * Return the activity favorite link. 1946 * 1947 * @since 1.2.0 1948 * 1949 * @global object $activities_template {@link BP_Activity_Template} 1950 * 1951 * @return string The activity favorite link. 1952 */ 1953 function bp_get_activity_favorite_link() { 1954 global $activities_template; 1955 1956 /** 1957 * Filters the activity favorite link. 1958 * 1959 * @since 1.2.0 1960 * 1961 * @param string $value Constructed link for favoriting the activity comment. 1962 */ 1963 return apply_filters( 'bp_get_activity_favorite_link', wp_nonce_url( home_url( bp_get_activity_root_slug() . '/favorite/' . $activities_template->activity->id . '/' ), 'mark_favorite' ) ); 1964 } 1965 1966 /** 1967 * Output the activity unfavorite link. 1968 * 1969 * @since 1.2.0 1970 * 1971 */ 1972 function bp_activity_unfavorite_link() { 1973 echo bp_get_activity_unfavorite_link(); 1974 } 1975 1976 /** 1977 * Return the activity unfavorite link. 1978 * 1979 * @since 1.2.0 1980 * 1981 * @global object $activities_template {@link BP_Activity_Template} 1982 * 1983 * @return string The activity unfavorite link. 1984 */ 1985 function bp_get_activity_unfavorite_link() { 1986 global $activities_template; 1987 1988 /** 1989 * Filters the activity unfavorite link. 1990 * 1991 * @since 1.2.0 1992 * 1993 * @param string $value Constructed link for unfavoriting the activity comment. 1994 */ 1995 return apply_filters( 'bp_get_activity_unfavorite_link', wp_nonce_url( home_url( bp_get_activity_root_slug() . '/unfavorite/' . $activities_template->activity->id . '/' ), 'unmark_favorite' ) ); 1996 } 1997 1998 /** 1999 * Output the activity CSS class. 2000 * 2001 * @since 1.0.0 2002 * 2003 */ 2004 function bp_activity_css_class() { 2005 echo bp_get_activity_css_class(); 2006 } 2007 2008 /** 2009 * Return the current activity item's CSS class. 2010 * 2011 * @since 1.0.0 2012 * 2013 * @global object $activities_template {@link BP_Activity_Template} 2014 * 2015 * @return string The activity item's CSS class. 2016 */ 2017 function bp_get_activity_css_class() { 2018 global $activities_template; 2019 2020 /** 2021 * Filters the available mini activity actions available as CSS classes. 2022 * 2023 * @since 1.2.0 2024 * 2025 * @param array $value Array of classes used to determine classes applied to HTML element. 2026 */ 2027 $mini_activity_actions = apply_filters( 'bp_activity_mini_activity_types', array( 2028 'friendship_accepted', 2029 'friendship_created', 2030 'new_blog', 2031 'joined_group', 2032 'created_group', 2033 'new_member' 2034 ) ); 2035 2036 $class = ' activity-item'; 2037 2038 if ( in_array( $activities_template->activity->type, (array) $mini_activity_actions ) || empty( $activities_template->activity->content ) ) { 2039 $class .= ' mini'; 2040 } 2041 2042 if ( bp_activity_get_comment_count() && bp_activity_can_comment() ) { 2043 $class .= ' has-comments'; 2044 } 2045 2046 /** 2047 * Filters the determined classes to add to the HTML element. 2048 * 2049 * @since 1.0.0 2050 * 2051 * @param string $value Classes to be added to the HTML element. 2052 */ 2053 return apply_filters( 'bp_get_activity_css_class', $activities_template->activity->component . ' ' . $activities_template->activity->type . $class ); 2054 } 2055 2056 /** 2057 * Output the activity delete link. 2058 * 2059 * @since 1.1.0 2060 * 2061 */ 2062 function bp_activity_delete_link() { 2063 echo bp_get_activity_delete_link(); 2064 } 2065 2066 /** 2067 * Return the activity delete link. 2068 * 2069 * @since 1.1.0 2070 * 2071 * @global object $activities_template {@link BP_Activity_Template} 2072 * 2073 * @return string $link Activity delete link. Contains $redirect_to arg 2074 * if on single activity page. 2075 */ 2076 function bp_get_activity_delete_link() { 2077 2078 $url = bp_get_activity_delete_url(); 2079 $class = 'delete-activity'; 2080 2081 // Determine if we're on a single activity page, and customize accordingly. 2082 if ( bp_is_activity_component() && is_numeric( bp_current_action() ) ) { 2083 $class = 'delete-activity-single'; 2084 } 2085 2086 $link = '<a href="' . esc_url( $url ) . '" class="button item-button bp-secondary-action ' . $class . ' confirm" rel="nofollow">' . __( 'Delete', 'buddypress' ) . '</a>'; 2087 2088 /** 2089 * Filters the activity delete link. 2090 * 2091 * @since 1.1.0 2092 * 2093 * @param string $link Activity delete HTML link. 2094 */ 2095 return apply_filters( 'bp_get_activity_delete_link', $link ); 2096 } 2097 2098 /** 2099 * Output the URL to delete a single activity stream item. 2100 * 2101 * @since 2.1.0 2102 * 2103 */ 2104 function bp_activity_delete_url() { 2105 echo esc_url( bp_get_activity_delete_url() ); 2106 } 2107 /** 2108 * Return the URL to delete a single activity item. 2109 * 2110 * @since 2.1.0 2111 * 2112 * @global object $activities_template {@link BP_Activity_Template} 2113 * 2114 * @return string $link Activity delete link. Contains $redirect_to arg 2115 * if on single activity page. 2116 */ 2117 function bp_get_activity_delete_url() { 2118 global $activities_template; 2119 2120 $url = trailingslashit( bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/delete/' . $activities_template->activity->id ); 2121 2122 // Determine if we're on a single activity page, and customize accordingly. 2123 if ( bp_is_activity_component() && is_numeric( bp_current_action() ) ) { 2124 $url = add_query_arg( array( 'redirect_to' => wp_get_referer() ), $url ); 2125 } 2126 2127 $url = wp_nonce_url( $url, 'bp_activity_delete_link' ); 2128 2129 /** 2130 * Filters the activity delete URL. 2131 * 2132 * @since 2.1.0 2133 * 2134 * @param string $url Activity delete URL. 2135 */ 2136 return apply_filters( 'bp_get_activity_delete_url', $url ); 2137 } -
src/bp-activity/bp-activity-template.php
348 348 349 349 $activities_template = new BP_Activity_Template( $r ); 350 350 351 // Require template loop functions. 352 require_once __DIR__ . '/bp-activity-functions-loop.php'; 353 351 354 /** 352 355 * Filters whether or not there are activity items to display. 353 356 * … … 360 363 return apply_filters( 'bp_has_activities', $activities_template->has_activities(), $activities_template, $r ); 361 364 } 362 365 363 /**364 * Determine if there are still activities left in the loop.365 *366 * @since 1.0.0367 *368 * @global object $activities_template {@link BP_Activity_Template}369 *370 * @return bool Returns true when activities are found.371 */372 function bp_activities() {373 global $activities_template;374 return $activities_template->user_activities();375 }376 377 /**378 * Get the current activity object in the loop.379 *380 * @since 1.0.0381 *382 * @global object $activities_template {@link BP_Activity_Template}383 *384 * @return object The current activity within the loop.385 */386 function bp_the_activity() {387 global $activities_template;388 return $activities_template->the_activity();389 }390 391 /**392 * Output the URL for the Load More link.393 *394 * @since 2.1.0395 */396 function bp_activity_load_more_link() {397 echo esc_url( bp_get_activity_load_more_link() );398 }399 /**400 * Get the URL for the Load More link.401 *402 * @since 2.1.0403 *404 * @return string $link405 */406 function bp_get_activity_load_more_link() {407 global $activities_template;408 409 $url = bp_get_requested_url();410 $link = add_query_arg( $activities_template->pag_arg, $activities_template->pag_page + 1, $url );411 412 /**413 * Filters the Load More link URL.414 *415 * @since 2.1.0416 *417 * @param string $link The "Load More" link URL with appropriate query args.418 * @param string $url The original URL.419 * @param object $activities_template The activity template loop global.420 */421 return apply_filters( 'bp_get_activity_load_more_link', $link, $url, $activities_template );422 }423 424 /**425 * Output the activity pagination count.426 *427 * @since 1.0.0428 *429 * @global object $activities_template {@link BP_Activity_Template}430 */431 function bp_activity_pagination_count() {432 echo bp_get_activity_pagination_count();433 }434 435 /**436 * Return the activity pagination count.437 *438 * @since 1.2.0439 *440 * @global object $activities_template {@link BP_Activity_Template}441 *442 * @return string The pagination text.443 */444 function bp_get_activity_pagination_count() {445 global $activities_template;446 447 $start_num = intval( ( $activities_template->pag_page - 1 ) * $activities_template->pag_num ) + 1;448 $from_num = bp_core_number_format( $start_num );449 $to_num = bp_core_number_format( ( $start_num + ( $activities_template->pag_num - 1 ) > $activities_template->total_activity_count ) ? $activities_template->total_activity_count : $start_num + ( $activities_template->pag_num - 1 ) );450 $total = bp_core_number_format( $activities_template->total_activity_count );451 452 if ( 1 == $activities_template->total_activity_count ) {453 $message = __( 'Viewing 1 item', 'buddypress' );454 } else {455 $message = sprintf( _n( 'Viewing %1$s - %2$s of %3$s item', 'Viewing %1$s - %2$s of %3$s items', $activities_template->total_activity_count, 'buddypress' ), $from_num, $to_num, $total );456 }457 458 return $message;459 }460 461 /**462 * Output the activity pagination links.463 *464 * @since 1.0.0465 *466 */467 function bp_activity_pagination_links() {468 echo bp_get_activity_pagination_links();469 }470 471 /**472 * Return the activity pagination links.473 *474 * @since 1.0.0475 *476 * @global object $activities_template {@link BP_Activity_Template}477 *478 * @return string The pagination links.479 */480 function bp_get_activity_pagination_links() {481 global $activities_template;482 483 /**484 * Filters the activity pagination link output.485 *486 * @since 1.0.0487 *488 * @param string $pag_links Output for the activity pagination links.489 */490 return apply_filters( 'bp_get_activity_pagination_links', $activities_template->pag_links );491 }492 493 /**494 * Return true when there are more activity items to be shown than currently appear.495 *496 * @since 1.5.0497 *498 * @global object $activities_template {@link BP_Activity_Template}499 *500 * @return bool $has_more_items True if more items, false if not.501 */502 function bp_activity_has_more_items() {503 global $activities_template;504 505 if ( ! empty( $activities_template->has_more_items ) ) {506 $has_more_items = true;507 } else {508 $remaining_pages = 0;509 510 if ( ! empty( $activities_template->pag_page ) ) {511 $remaining_pages = floor( ( $activities_template->total_activity_count - 1 ) / ( $activities_template->pag_num * $activities_template->pag_page ) );512 }513 514 $has_more_items = (int) $remaining_pages > 0;515 }516 517 /**518 * Filters whether there are more activity items to display.519 *520 * @since 1.5.0521 *522 * @param bool $has_more_items Whether or not there are more activity items to display.523 */524 return apply_filters( 'bp_activity_has_more_items', $has_more_items );525 }526 527 /**528 * Output the activity count.529 *530 * @since 1.2.0531 *532 */533 function bp_activity_count() {534 echo bp_get_activity_count();535 }536 537 /**538 * Return the activity count.539 *540 * @since 1.2.0541 *542 * @global object $activities_template {@link BP_Activity_Template}543 *544 * @return int The activity count.545 */546 function bp_get_activity_count() {547 global $activities_template;548 549 /**550 * Filters the activity count for the activity template.551 *552 * @since 1.2.0553 *554 * @param int $activity_count The count for total activity.555 */556 return apply_filters( 'bp_get_activity_count', (int) $activities_template->activity_count );557 }558 559 /**560 * Output the number of activities per page.561 *562 * @since 1.2.0563 *564 */565 function bp_activity_per_page() {566 echo bp_get_activity_per_page();567 }568 569 /**570 * Return the number of activities per page.571 *572 * @since 1.2.0573 *574 * @global object $activities_template {@link BP_Activity_Template}575 *576 * @return int The activities per page.577 */578 function bp_get_activity_per_page() {579 global $activities_template;580 581 /**582 * Filters the activity posts per page value.583 *584 * @since 1.2.0585 *586 * @param int $pag_num How many post should be displayed for pagination.587 */588 return apply_filters( 'bp_get_activity_per_page', (int) $activities_template->pag_num );589 }590 591 /**592 * Output the activities title.593 *594 * @since 1.0.0595 *596 * @todo Deprecate.597 */598 function bp_activities_title() {599 echo bp_get_activities_title();600 }601 602 /**603 * Return the activities title.604 *605 * @since 1.0.0606 *607 * @global string $bp_activity_title608 * @todo Deprecate.609 *610 * @return string The activities title.611 */612 function bp_get_activities_title() {613 global $bp_activity_title;614 615 /**616 * Filters the activities title for the activity template.617 *618 * @since 1.0.0619 *620 * @param string $bp_activity_title The title to be displayed.621 */622 return apply_filters( 'bp_get_activities_title', $bp_activity_title );623 }624 625 /**626 * {@internal Missing Description}627 *628 * @since 1.0.0629 *630 * @todo Deprecate.631 */632 function bp_activities_no_activity() {633 echo bp_get_activities_no_activity();634 }635 636 /**637 * {@internal Missing Description}638 *639 * @since 1.0.0640 *641 * @global string $bp_activity_no_activity642 * @todo Deprecate.643 *644 * @return string645 */646 function bp_get_activities_no_activity() {647 global $bp_activity_no_activity;648 649 /**650 * Filters the text used when there is no activity to display.651 *652 * @since 1.0.0653 *654 * @param string $bp_activity_no_activity Text to display for no activity.655 */656 return apply_filters( 'bp_get_activities_no_activity', $bp_activity_no_activity );657 }658 659 /**660 * Output the activity ID.661 *662 * @since 1.2.0663 *664 */665 function bp_activity_id() {666 echo bp_get_activity_id();667 }668 669 /**670 * Return the activity ID.671 *672 * @since 1.2.0673 *674 * @global object $activities_template {@link BP_Activity_Template}675 *676 * @return int The activity ID.677 */678 function bp_get_activity_id() {679 global $activities_template;680 681 /**682 * Filters the activity ID being displayed.683 *684 * @since 1.2.0685 *686 * @param int $id The activity ID.687 */688 return apply_filters( 'bp_get_activity_id', $activities_template->activity->id );689 }690 691 /**692 * Output the activity item ID.693 *694 * @since 1.2.0695 *696 */697 function bp_activity_item_id() {698 echo bp_get_activity_item_id();699 }700 701 /**702 * Return the activity item ID.703 *704 * @since 1.2.0705 *706 * @global object $activities_template {@link BP_Activity_Template}707 *708 * @return int The activity item ID.709 */710 function bp_get_activity_item_id() {711 global $activities_template;712 713 /**714 * Filters the activity item ID being displayed.715 *716 * @since 1.2.0717 *718 * @param int $item_id The activity item ID.719 */720 return apply_filters( 'bp_get_activity_item_id', $activities_template->activity->item_id );721 }722 723 /**724 * Output the activity secondary item ID.725 *726 * @since 1.2.0727 *728 */729 function bp_activity_secondary_item_id() {730 echo bp_get_activity_secondary_item_id();731 }732 733 /**734 * Return the activity secondary item ID.735 *736 * @since 1.2.0737 *738 * @global object $activities_template {@link BP_Activity_Template}739 *740 * @return int The activity secondary item ID.741 */742 function bp_get_activity_secondary_item_id() {743 global $activities_template;744 745 /**746 * Filters the activity secondary item ID being displayed.747 *748 * @since 1.2.0749 *750 * @param int $secondary_item_id The activity secondary item ID.751 */752 return apply_filters( 'bp_get_activity_secondary_item_id', $activities_template->activity->secondary_item_id );753 }754 755 /**756 * Output the date the activity was recorded.757 *758 * @since 1.2.0759 *760 */761 function bp_activity_date_recorded() {762 echo bp_get_activity_date_recorded();763 }764 765 /**766 * Return the date the activity was recorded.767 *768 * @since 1.2.0769 *770 * @global object $activities_template {@link BP_Activity_Template}771 *772 * @return string The date the activity was recorded.773 */774 function bp_get_activity_date_recorded() {775 global $activities_template;776 777 /**778 * Filters the date the activity was recorded.779 *780 * @since 1.2.0781 *782 * @param int $date_recorded The activity's date.783 */784 return apply_filters( 'bp_get_activity_date_recorded', $activities_template->activity->date_recorded );785 }786 787 366 /** 788 367 * Output the display name of the member who posted the activity. 789 368 * … … 820 399 return apply_filters( 'bp_get_activity_member_display_name', $retval ); 821 400 } 822 401 823 /**824 * Output the activity object name.825 *826 * @since 1.2.0827 *828 */829 function bp_activity_object_name() {830 echo bp_get_activity_object_name();831 }832 833 /**834 * Return the activity object name.835 *836 * @since 1.2.0837 *838 * @global object $activities_template {@link BP_Activity_Template}839 *840 * @return string The activity object name.841 */842 function bp_get_activity_object_name() {843 global $activities_template;844 845 /**846 * Filters the activity object name.847 *848 * @since 1.2.0849 *850 * @param string $activity_component The activity object name.851 */852 return apply_filters( 'bp_get_activity_object_name', $activities_template->activity->component );853 }854 855 /**856 * Output the activity type.857 *858 * @since 1.2.0859 *860 */861 function bp_activity_type() {862 echo bp_get_activity_type();863 }864 865 /**866 * Return the activity type.867 *868 * @since 1.2.0869 *870 * @global object $activities_template {@link BP_Activity_Template}871 *872 * @return string The activity type.873 */874 function bp_get_activity_type() {875 global $activities_template;876 877 /**878 * Filters the activity type.879 *880 * @since 1.2.0881 *882 * @param string $activity_type The activity type.883 */884 return apply_filters( 'bp_get_activity_type', $activities_template->activity->type );885 }886 887 /**888 * Output the activity action name.889 *890 * Just a wrapper for bp_activity_type().891 *892 * @since 1.2.0893 * @deprecated 1.5.0894 *895 * @todo Properly deprecate in favor of bp_activity_type() and896 * remove redundant echo897 *898 */899 function bp_activity_action_name() { echo bp_activity_type(); }900 901 /**902 * Return the activity type.903 *904 * Just a wrapper for bp_get_activity_type().905 *906 * @since 1.2.0907 * @deprecated 1.5.0908 *909 * @todo Properly deprecate in favor of bp_get_activity_type().910 *911 *912 * @return string The activity type.913 */914 function bp_get_activity_action_name() { return bp_get_activity_type(); }915 916 /**917 * Output the activity user ID.918 *919 * @since 1.1.0920 *921 */922 function bp_activity_user_id() {923 echo bp_get_activity_user_id();924 }925 926 /**927 * Return the activity user ID.928 *929 * @since 1.1.0930 *931 * @global object $activities_template {@link BP_Activity_Template}932 *933 * @return int The activity user ID.934 */935 function bp_get_activity_user_id() {936 global $activities_template;937 938 /**939 * Filters the activity user ID.940 *941 * @since 1.1.0942 *943 * @param int $user_id The activity user ID.944 */945 return apply_filters( 'bp_get_activity_user_id', $activities_template->activity->user_id );946 }947 948 /**949 * Output the activity user link.950 *951 * @since 1.2.0952 *953 */954 function bp_activity_user_link() {955 echo bp_get_activity_user_link();956 }957 958 /**959 * Return the activity user link.960 *961 * @since 1.2.0962 *963 * @global object $activities_template {@link BP_Activity_Template}964 *965 * @return string $link The activity user link.966 */967 function bp_get_activity_user_link() {968 global $activities_template;969 970 if ( empty( $activities_template->activity->user_id ) || empty( $activities_template->activity->user_nicename ) || empty( $activities_template->activity->user_login ) ) {971 $link = $activities_template->activity->primary_link;972 } else {973 $link = bp_core_get_user_domain( $activities_template->activity->user_id, $activities_template->activity->user_nicename, $activities_template->activity->user_login );974 }975 976 /**977 * Filters the activity user link.978 *979 * @since 1.2.0980 *981 * @param string $link The activity user link.982 */983 return apply_filters( 'bp_get_activity_user_link', $link );984 }985 986 /**987 * Output the avatar of the user that performed the action.988 *989 * @since 1.1.0990 *991 * @see bp_get_activity_avatar() for description of arguments.992 *993 * @param array|string $args See {@link bp_get_activity_avatar()} for description.994 */995 function bp_activity_avatar( $args = '' ) {996 echo bp_get_activity_avatar( $args );997 }998 /**999 * Return the avatar of the user that performed the action.1000 *1001 * @since 1.1.01002 *1003 * @see bp_core_fetch_avatar() For a description of the arguments.1004 * @global object $activities_template {@link BP_Activity_Template}1005 *1006 * @param array|string $args {1007 * Arguments are listed here with an explanation of their defaults.1008 * For more information about the arguments, see1009 * {@link bp_core_fetch_avatar()}.1010 * @type string $alt Default: 'Profile picture of [user name]' if1011 * activity user name is available, otherwise 'Profile picture'.1012 * @type string $class Default: 'avatar'.1013 * @type string|bool $email Default: Email of the activity's1014 * associated user, if available. Otherwise false.1015 * @type string $type Default: 'full' when viewing a single activity1016 * permalink page, otherwise 'thumb'.1017 * @type int|bool $user_id Default: ID of the activity's user.1018 * }1019 * @return string User avatar string.1020 */1021 function bp_get_activity_avatar( $args = '' ) {1022 global $activities_template;1023 1024 $bp = buddypress();1025 1026 // On activity permalink pages, default to the full-size avatar.1027 $type_default = bp_is_single_activity() ? 'full' : 'thumb';1028 1029 // Within the activity comment loop, the current activity should be set1030 // to current_comment. Otherwise, just use activity.1031 $current_activity_item = isset( $activities_template->activity->current_comment ) ? $activities_template->activity->current_comment : $activities_template->activity;1032 1033 // Activity user display name.1034 $dn_default = isset( $current_activity_item->display_name ) ? $current_activity_item->display_name : '';1035 1036 // Prepend some descriptive text to alt.1037 $alt_default = !empty( $dn_default ) ? sprintf( __( 'Profile picture of %s', 'buddypress' ), $dn_default ) : __( 'Profile picture', 'buddypress' );1038 1039 $defaults = array(1040 'alt' => $alt_default,1041 'class' => 'avatar',1042 'email' => false,1043 'type' => $type_default,1044 'user_id' => false1045 );1046 1047 $r = wp_parse_args( $args, $defaults );1048 extract( $r, EXTR_SKIP );1049 1050 if ( !isset( $height ) && !isset( $width ) ) {1051 1052 // Backpat.1053 if ( isset( $bp->avatar->full->height ) || isset( $bp->avatar->thumb->height ) ) {1054 $height = ( 'full' == $type ) ? $bp->avatar->full->height : $bp->avatar->thumb->height;1055 } else {1056 $height = 20;1057 }1058 1059 // Backpat.1060 if ( isset( $bp->avatar->full->width ) || isset( $bp->avatar->thumb->width ) ) {1061 $width = ( 'full' == $type ) ? $bp->avatar->full->width : $bp->avatar->thumb->width;1062 } else {1063 $width = 20;1064 }1065 }1066 1067 /**1068 * Filters the activity avatar object based on current activity item component.1069 *1070 * This is a variable filter dependent on the component used.1071 * Possible hooks are bp_get_activity_avatar_object_blog,1072 * bp_get_activity_avatar_object_group, and bp_get_activity_avatar_object_user.1073 *1074 * @since 1.1.01075 *1076 * @param string $component Component being displayed.1077 */1078 $object = apply_filters( 'bp_get_activity_avatar_object_' . $current_activity_item->component, 'user' );1079 $item_id = !empty( $user_id ) ? $user_id : $current_activity_item->user_id;1080 1081 /**1082 * Filters the activity avatar item ID.1083 *1084 * @since 1.2.101085 *1086 * @param int $item_id Item ID for the activity avatar.1087 */1088 $item_id = apply_filters( 'bp_get_activity_avatar_item_id', $item_id );1089 1090 // If this is a user object pass the users' email address for Gravatar so we don't have to prefetch it.1091 if ( 'user' == $object && empty( $user_id ) && empty( $email ) && isset( $current_activity_item->user_email ) ) {1092 $email = $current_activity_item->user_email;1093 }1094 1095 /**1096 * Filters the value returned by bp_core_fetch_avatar.1097 *1098 * @since 1.1.31099 *1100 * @param array $value HTML image element containing the activity avatar.1101 */1102 return apply_filters( 'bp_get_activity_avatar', bp_core_fetch_avatar( array(1103 'item_id' => $item_id,1104 'object' => $object,1105 'type' => $type,1106 'alt' => $alt,1107 'class' => $class,1108 'width' => $width,1109 'height' => $height,1110 'email' => $email1111 ) ) );1112 }1113 1114 /**1115 * Output the avatar of the object that action was performed on.1116 *1117 * @since 1.2.01118 *1119 * @see bp_get_activity_secondary_avatar() for description of arguments.1120 *1121 * @param array|string $args See {@link bp_get_activity_secondary_avatar} for description.1122 */1123 function bp_activity_secondary_avatar( $args = '' ) {1124 echo bp_get_activity_secondary_avatar( $args );1125 }1126 1127 /**1128 * Return the avatar of the object that action was performed on.1129 *1130 * @since 1.2.01131 *1132 * @see bp_core_fetch_avatar() for description of arguments.1133 * @global object $activities_template {@link BP_Activity_Template}1134 *1135 * @param array|string $args {1136 * For a complete description of arguments, see {@link bp_core_fetch_avatar()}.1137 * @type string $alt Default value varies based on current activity1138 * item component.1139 * @type string $type Default: 'full' when viewing a single activity1140 * permalink page, otherwise 'thumb'.1141 * @type string $class Default: 'avatar'.1142 * @type string|bool $email Default: email of the activity's user.1143 * @type int|bool $user_id Default: ID of the activity's user.1144 * }1145 * @return string The secondary avatar.1146 */1147 function bp_get_activity_secondary_avatar( $args = '' ) {1148 global $activities_template;1149 1150 $r = wp_parse_args( $args, array(1151 'alt' => '',1152 'type' => 'thumb',1153 'width' => 20,1154 'height' => 20,1155 'class' => 'avatar',1156 'link_class' => '',1157 'linked' => true,1158 'email' => false1159 ) );1160 extract( $r, EXTR_SKIP );1161 1162 // Set item_id and object (default to user).1163 switch ( $activities_template->activity->component ) {1164 case 'groups' :1165 if ( bp_disable_group_avatar_uploads() ) {1166 return false;1167 }1168 1169 $object = 'group';1170 $item_id = $activities_template->activity->item_id;1171 $link = '';1172 $name = '';1173 1174 // Only if groups is active.1175 if ( bp_is_active( 'groups' ) ) {1176 $group = groups_get_group( $item_id );1177 $link = bp_get_group_permalink( $group );1178 $name = $group->name;1179 }1180 1181 if ( empty( $alt ) ) {1182 $alt = __( 'Group logo', 'buddypress' );1183 1184 if ( ! empty( $name ) ) {1185 $alt = sprintf( __( 'Group logo of %s', 'buddypress' ), $name );1186 }1187 }1188 1189 break;1190 case 'blogs' :1191 $object = 'blog';1192 $item_id = $activities_template->activity->item_id;1193 $link = home_url();1194 1195 if ( empty( $alt ) ) {1196 $alt = sprintf( __( 'Profile picture of the author of the site %s', 'buddypress' ), get_blog_option( $item_id, 'blogname' ) );1197 }1198 1199 break;1200 case 'friends' :1201 $object = 'user';1202 $item_id = $activities_template->activity->secondary_item_id;1203 $link = bp_core_get_userlink( $item_id, false, true );1204 1205 if ( empty( $alt ) ) {1206 $alt = sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname( $activities_template->activity->secondary_item_id ) );1207 }1208 1209 break;1210 default :1211 $object = 'user';1212 $item_id = $activities_template->activity->user_id;1213 $email = $activities_template->activity->user_email;1214 $link = bp_core_get_userlink( $item_id, false, true );1215 1216 if ( empty( $alt ) ) {1217 $alt = sprintf( __( 'Profile picture of %s', 'buddypress' ), $activities_template->activity->display_name );1218 }1219 1220 break;1221 }1222 1223 /**1224 * Filters the activity secondary avatar object based on current activity item component.1225 *1226 * This is a variable filter dependent on the component used. Possible hooks are1227 * bp_get_activity_secondary_avatar_object_blog, bp_get_activity_secondary_avatar_object_group,1228 * and bp_get_activity_secondary_avatar_object_user.1229 *1230 * @since 1.2.101231 *1232 * @param string $object Component being displayed.1233 */1234 $object = apply_filters( 'bp_get_activity_secondary_avatar_object_' . $activities_template->activity->component, $object );1235 1236 /**1237 * Filters the activity secondary avatar item ID.1238 *1239 * @since 1.2.101240 *1241 * @param int $item_id ID for the secondary avatar item.1242 */1243 $item_id = apply_filters( 'bp_get_activity_secondary_avatar_item_id', $item_id );1244 1245 // If we have no item_id or object, there is no avatar to display.1246 if ( empty( $item_id ) || empty( $object ) ) {1247 return false;1248 }1249 1250 // Get the avatar.1251 $avatar = bp_core_fetch_avatar( array(1252 'item_id' => $item_id,1253 'object' => $object,1254 'type' => $type,1255 'alt' => $alt,1256 'class' => $class,1257 'width' => $width,1258 'height' => $height,1259 'email' => $email1260 ) );1261 1262 if ( !empty( $linked ) ) {1263 1264 /**1265 * Filters the secondary avatar link for current activity.1266 *1267 * @since 1.7.01268 *1269 * @param string $link Link to wrap the avatar image in.1270 * @param string $component Activity component being acted on.1271 */1272 $link = apply_filters( 'bp_get_activity_secondary_avatar_link', $link, $activities_template->activity->component );1273 1274 /**1275 * Filters the determined avatar for the secondary activity item.1276 *1277 * @since 1.2.101278 *1279 * @param string $avatar Formatted HTML <img> element, or raw avatar URL.1280 */1281 $avatar = apply_filters( 'bp_get_activity_secondary_avatar', $avatar );1282 1283 return sprintf( '<a href="%s" class="%s">%s</a>',1284 $link,1285 $link_class,1286 $avatar1287 );1288 }1289 1290 /** This filter is documented in bp-activity/bp-activity-template.php */1291 return apply_filters( 'bp_get_activity_secondary_avatar', $avatar );1292 }1293 1294 /**1295 * Output the activity action.1296 *1297 * @since 1.2.01298 *1299 * @param array $args See bp_get_activity_action().1300 */1301 function bp_activity_action( $args = array() ) {1302 echo bp_get_activity_action( $args );1303 }1304 1305 /**1306 * Return the activity action.1307 *1308 * @since 1.2.01309 *1310 * @global object $activities_template {@link BP_Activity_Template}1311 *1312 * @param array $args {1313 * @type bool $no_timestamp Whether to exclude the timestamp.1314 * }1315 *1316 * @return string The activity action.1317 */1318 function bp_get_activity_action( $args = array() ) {1319 global $activities_template;1320 1321 $r = wp_parse_args( $args, array(1322 'no_timestamp' => false,1323 ) );1324 1325 /**1326 * Filters the activity action before the action is inserted as meta.1327 *1328 * @since 1.2.101329 *1330 * @param array $value Array containing the current action, the current activity, and the $args array passed into the function.1331 */1332 $action = apply_filters_ref_array( 'bp_get_activity_action_pre_meta', array(1333 $activities_template->activity->action,1334 &$activities_template->activity,1335 $r1336 ) );1337 1338 // Prepend the activity action meta (link, time since, etc...).1339 if ( ! empty( $action ) && empty( $r['no_timestamp'] ) ) {1340 $action = bp_insert_activity_meta( $action );1341 }1342 1343 /**1344 * Filters the activity action after the action has been inserted as meta.1345 *1346 * @since 1.2.01347 *1348 * @param array $value Array containing the current action, the current activity, and the $args array passed into the function.1349 */1350 return apply_filters_ref_array( 'bp_get_activity_action', array(1351 $action,1352 &$activities_template->activity,1353 $r1354 ) );1355 }1356 1357 /**1358 * Output the activity content body.1359 *1360 * @since 1.2.01361 *1362 */1363 function bp_activity_content_body() {1364 echo bp_get_activity_content_body();1365 }1366 1367 /**1368 * Return the activity content body.1369 *1370 * @since 1.2.01371 *1372 * @global object $activities_template {@link BP_Activity_Template}1373 *1374 * @return string The activity content body.1375 */1376 function bp_get_activity_content_body() {1377 global $activities_template;1378 1379 // Backwards compatibility if action is not being used.1380 if ( empty( $activities_template->activity->action ) && ! empty( $activities_template->activity->content ) ) {1381 $activities_template->activity->content = bp_insert_activity_meta( $activities_template->activity->content );1382 }1383 1384 /**1385 * Filters the activity content body.1386 *1387 * @since 1.2.01388 *1389 * @param string $content Content body.1390 * @param object $activity Activity object. Passed by reference.1391 */1392 return apply_filters_ref_array( 'bp_get_activity_content_body', array( $activities_template->activity->content, &$activities_template->activity ) );1393 }1394 1395 /**1396 * Does the activity have content?1397 *1398 * @since 1.2.01399 *1400 * @global object $activities_template {@link BP_Activity_Template}1401 *1402 * @return bool True if activity has content, false otherwise.1403 */1404 function bp_activity_has_content() {1405 global $activities_template;1406 1407 if ( ! empty( $activities_template->activity->content ) ) {1408 return true;1409 }1410 1411 return false;1412 }1413 1414 /**1415 * Output the activity content.1416 *1417 * @since 1.0.01418 * @deprecated 1.5.01419 *1420 * @todo properly deprecate this function.1421 *1422 */1423 function bp_activity_content() {1424 echo bp_get_activity_content();1425 }1426 1427 /**1428 * Return the activity content.1429 *1430 * @since 1.0.01431 * @deprecated 1.5.01432 *1433 * @todo properly deprecate this function.1434 *1435 *1436 * @return string The activity content.1437 */1438 function bp_get_activity_content() {1439 1440 /**1441 * If you want to filter activity update content, please use1442 * the filter 'bp_get_activity_content_body'.1443 *1444 * This function is mainly for backwards compatibility.1445 */1446 $content = bp_get_activity_action() . ' ' . bp_get_activity_content_body();1447 return apply_filters( 'bp_get_activity_content', $content );1448 }1449 1450 /**1451 * Attach metadata about an activity item to the activity content.1452 *1453 * This metadata includes the time since the item was posted (which will appear1454 * as a link to the item's permalink).1455 *1456 * @since 1.2.01457 *1458 * @global object $activities_template {@link BP_Activity_Template}1459 *1460 * @param string $content The activity content.1461 * @return string The activity content with the metadata string attached.1462 */1463 function bp_insert_activity_meta( $content = '' ) {1464 global $activities_template;1465 1466 // Strip any legacy time since placeholders from BP 1.0-1.1.1467 $new_content = str_replace( '<span class="time-since">%s</span>', '', $content );1468 1469 // Get the time since this activity was recorded.1470 $date_recorded = bp_core_time_since( $activities_template->activity->date_recorded );1471 1472 // Set up 'time-since' <span>.1473 $time_since = sprintf(1474 '<span class="time-since" data-livestamp="%1$s">%2$s</span>',1475 bp_core_get_iso8601_date( $activities_template->activity->date_recorded ),1476 $date_recorded1477 );1478 1479 /**1480 * Filters the activity item time since markup.1481 *1482 * @since 1.2.01483 *1484 * @param array $value Array containing the time since markup and the current activity component.1485 */1486 $time_since = apply_filters_ref_array( 'bp_activity_time_since', array(1487 $time_since,1488 &$activities_template->activity1489 ) );1490 1491 // Insert the permalink.1492 if ( ! bp_is_single_activity() ) {1493 1494 // Setup variables for activity meta.1495 $activity_permalink = bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity );1496 $activity_meta = sprintf( '%1$s <a href="%2$s" class="view activity-time-since bp-tooltip" data-bp-tooltip="%3$s">%4$s</a>',1497 $new_content,1498 $activity_permalink,1499 esc_attr__( 'View Discussion', 'buddypress' ),1500 $time_since1501 );1502 1503 /**1504 * Filters the activity permalink to be added to the activity content.1505 *1506 * @since 1.2.01507 *1508 * @param array $value Array containing the html markup for the activity permalink, after being parsed by1509 * sprintf and current activity component.1510 */1511 $new_content = apply_filters_ref_array( 'bp_activity_permalink', array(1512 $activity_meta,1513 &$activities_template->activity1514 ) );1515 } else {1516 $new_content .= str_pad( $time_since, strlen( $time_since ) + 2, ' ', STR_PAD_BOTH );1517 }1518 1519 /**1520 * Filters the activity content after activity metadata has been attached.1521 *1522 * @since 1.2.01523 *1524 * @param string $content Activity content with the activity metadata added.1525 */1526 return apply_filters( 'bp_insert_activity_meta', $new_content, $content );1527 }1528 1529 402 /** 1530 403 * Determine if the current user can delete an activity item. 1531 404 * … … 1584 457 return (bool) apply_filters( 'bp_activity_user_can_delete', $can_delete, $activity ); 1585 458 } 1586 459 1587 /**1588 * Output the activity parent content.1589 *1590 * @since 1.2.01591 *1592 * @see bp_get_activity_parent_content() for a description of arguments.1593 *1594 * @param array|string $args See {@link bp_get_activity_parent_content} for description.1595 */1596 function bp_activity_parent_content( $args = '' ) {1597 echo bp_get_activity_parent_content($args);1598 }1599 1600 /**1601 * Return the activity content.1602 *1603 * @since 1.2.01604 *1605 * @global object $activities_template {@link BP_Activity_Template}1606 *1607 * @param string $args Unused. Left over from an earlier implementation.1608 * @return mixed False on failure, otherwise the activity parent content.1609 */1610 function bp_get_activity_parent_content( $args = '' ) {1611 global $activities_template;1612 1613 // Bail if no activity on no item ID.1614 if ( empty( $activities_template->activity ) || empty( $activities_template->activity->item_id ) ) {1615 return false;1616 }1617 1618 // Get the ID of the parent activity content.1619 $parent_id = $activities_template->activity->item_id;1620 1621 // Bail if no parent content.1622 if ( empty( $activities_template->activity_parents[ $parent_id ] ) ) {1623 return false;1624 }1625 1626 // Bail if no action.1627 if ( empty( $activities_template->activity_parents[ $parent_id ]->action ) ) {1628 return false;1629 }1630 1631 // Content always includes action.1632 $content = $activities_template->activity_parents[ $parent_id ]->action;1633 1634 // Maybe append activity content, if it exists.1635 if ( ! empty( $activities_template->activity_parents[ $parent_id ]->content ) ) {1636 $content .= ' ' . $activities_template->activity_parents[ $parent_id ]->content;1637 }1638 1639 // Remove the time since content for backwards compatibility.1640 $content = str_replace( '<span class="time-since">%s</span>', '', $content );1641 1642 // Remove images.1643 $content = preg_replace( '/<img[^>]*>/Ui', '', $content );1644 1645 /**1646 * Filters the activity parent content.1647 *1648 * @since 1.2.01649 *1650 * @param string $content Content set to be displayed as parent content.1651 */1652 return apply_filters( 'bp_get_activity_parent_content', $content );1653 }1654 1655 /**1656 * Output the parent activity's user ID.1657 *1658 * @since 1.7.01659 */1660 function bp_activity_parent_user_id() {1661 echo bp_get_activity_parent_user_id();1662 }1663 1664 /**1665 * Return the parent activity's user ID.1666 *1667 * @since 1.7.01668 *1669 * @global BP_Activity_Template $activities_template1670 *1671 * @return bool|int False if parent activity can't be found, otherwise1672 * the parent activity's user ID.1673 */1674 function bp_get_activity_parent_user_id() {1675 global $activities_template;1676 1677 // Bail if no activity on no item ID.1678 if ( empty( $activities_template->activity ) || empty( $activities_template->activity->item_id ) ) {1679 return false;1680 }1681 1682 // Get the ID of the parent activity content.1683 $parent_id = $activities_template->activity->item_id;1684 1685 // Bail if no parent item.1686 if ( empty( $activities_template->activity_parents[ $parent_id ] ) ) {1687 return false;1688 }1689 1690 // Bail if no parent user ID.1691 if ( empty( $activities_template->activity_parents[ $parent_id ]->user_id ) ) {1692 return false;1693 }1694 1695 $retval = $activities_template->activity_parents[ $parent_id ]->user_id;1696 1697 /**1698 * Filters the activity parent item's user ID.1699 *1700 * @since 1.7.01701 *1702 * @param int $retval ID for the activity parent's user.1703 */1704 return (int) apply_filters( 'bp_get_activity_parent_user_id', $retval );1705 }1706 1707 /**1708 * Output whether or not the current activity is in a current user's favorites.1709 *1710 * @since 1.2.01711 *1712 */1713 function bp_activity_is_favorite() {1714 echo bp_get_activity_is_favorite();1715 }1716 1717 /**1718 * Return whether the current activity is in a current user's favorites.1719 *1720 * @since 1.2.01721 *1722 * @global object $activities_template {@link BP_Activity_Template}1723 *1724 * @return bool True if user favorite, false otherwise.1725 */1726 function bp_get_activity_is_favorite() {1727 global $activities_template;1728 1729 /**1730 * Filters whether the current activity item is in the current user's favorites.1731 *1732 * @since 1.2.01733 *1734 * @param bool $value Whether or not the current activity item is in the current user's favorites.1735 */1736 return (bool) apply_filters( 'bp_get_activity_is_favorite', in_array( $activities_template->activity->id, (array) $activities_template->my_favs ) );1737 }1738 1739 /**1740 * Output the comment markup for an activity item.1741 *1742 * @since 1.2.01743 *1744 * @todo deprecate $args param1745 *1746 * @param array|string $args See {@link bp_activity_get_comments} for description.1747 */1748 function bp_activity_comments( $args = '' ) {1749 echo bp_activity_get_comments( $args );1750 }1751 1752 /**1753 * Get the comment markup for an activity item.1754 *1755 * @since 1.2.01756 *1757 * @todo deprecate $args param1758 * @todo Given that checks for children already happen in bp_activity_recurse_comments(),1759 * this function can probably be streamlined or removed.1760 *1761 * @global object $activities_template {@link BP_Activity_Template}1762 *1763 * @param string $args Unused. Left over from an earlier implementation.1764 * @return bool1765 */1766 function bp_activity_get_comments( $args = '' ) {1767 global $activities_template;1768 1769 if ( empty( $activities_template->activity->children ) ) {1770 return false;1771 }1772 1773 bp_activity_recurse_comments( $activities_template->activity );1774 }1775 1776 /**1777 * Loops through a level of activity comments and loads the template for each.1778 *1779 * Note: The recursion itself used to happen entirely in this function. Now it is1780 * split between here and the comment.php template.1781 *1782 * @since 1.2.01783 *1784 * @global object $activities_template {@link BP_Activity_Template}1785 *1786 * @param object $comment The activity object currently being recursed.1787 * @return bool|string1788 */1789 function bp_activity_recurse_comments( $comment ) {1790 global $activities_template;1791 1792 if ( empty( $comment ) ) {1793 return false;1794 }1795 1796 if ( empty( $comment->children ) ) {1797 return false;1798 }1799 1800 /**1801 * Filters the opening tag for the template that lists activity comments.1802 *1803 * @since 1.6.01804 *1805 * @param string $value Opening tag for the HTML markup to use.1806 */1807 echo apply_filters( 'bp_activity_recurse_comments_start_ul', '<ul>' );1808 foreach ( (array) $comment->children as $comment_child ) {1809 1810 // Put the comment into the global so it's available to filters.1811 $activities_template->activity->current_comment = $comment_child;1812 1813 $template = bp_locate_template( 'activity/comment.php', false, false );1814 1815 // Backward compatibility. In older versions of BP, the markup was1816 // generated in the PHP instead of a template. This ensures that1817 // older themes (which are not children of bp-default and won't1818 // have the new template) will still work.1819 if ( !$template ) {1820 $template = buddypress()->plugin_dir . '/bp-themes/bp-default/activity/comment.php';1821 }1822 1823 load_template( $template, false );1824 1825 unset( $activities_template->activity->current_comment );1826 }1827 1828 /**1829 * Filters the closing tag for the template that list activity comments.1830 *1831 * @since 1.6.01832 *1833 * @param string $value Closing tag for the HTML markup to use.1834 */1835 echo apply_filters( 'bp_activity_recurse_comments_end_ul', '</ul>' );1836 }1837 1838 /**1839 * Utility function that returns the comment currently being recursed.1840 *1841 * @since 1.5.01842 *1843 * @global object $activities_template {@link BP_Activity_Template}1844 *1845 * @return object|bool $current_comment The activity comment currently being1846 * displayed. False on failure.1847 */1848 function bp_activity_current_comment() {1849 global $activities_template;1850 1851 $current_comment = !empty( $activities_template->activity->current_comment )1852 ? $activities_template->activity->current_comment1853 : false;1854 1855 /**1856 * Filters the current comment being recursed.1857 *1858 * @since 1.5.01859 *1860 * @param object|bool $current_comment The activity comment currently being displayed. False on failure.1861 */1862 return apply_filters( 'bp_activity_current_comment', $current_comment );1863 }1864 1865 1866 /**1867 * Output the ID of the activity comment currently being displayed.1868 *1869 * @since 1.5.01870 *1871 */1872 function bp_activity_comment_id() {1873 echo bp_get_activity_comment_id();1874 }1875 1876 /**1877 * Return the ID of the activity comment currently being displayed.1878 *1879 * @since 1.5.01880 *1881 * @global object $activities_template {@link BP_Activity_Template}1882 *1883 * @return int|bool $comment_id The ID of the activity comment currently1884 * being displayed, false if none is found.1885 */1886 function bp_get_activity_comment_id() {1887 global $activities_template;1888 1889 $comment_id = isset( $activities_template->activity->current_comment->id ) ? $activities_template->activity->current_comment->id : false;1890 1891 /**1892 * Filters the ID of the activity comment currently being displayed.1893 *1894 * @since 1.5.01895 *1896 * @param int|bool $comment_id ID for the comment currently being displayed.1897 */1898 return apply_filters( 'bp_activity_comment_id', $comment_id );1899 }1900 1901 /**1902 * Output the ID of the author of the activity comment currently being displayed.1903 *1904 * @since 1.5.01905 *1906 */1907 function bp_activity_comment_user_id() {1908 echo bp_get_activity_comment_user_id();1909 }1910 1911 /**1912 * Return the ID of the author of the activity comment currently being displayed.1913 *1914 * @since 1.5.01915 *1916 * @global object $activities_template {@link BP_Activity_Template}1917 *1918 * @return int|bool $user_id The user_id of the author of the displayed1919 * activity comment. False on failure.1920 */1921 function bp_get_activity_comment_user_id() {1922 global $activities_template;1923 1924 $user_id = isset( $activities_template->activity->current_comment->user_id ) ? $activities_template->activity->current_comment->user_id : false;1925 1926 /**1927 * Filters the ID of the author of the activity comment currently being displayed.1928 *1929 * @since 1.5.01930 *1931 * @param int|bool $user_id ID for the author of the comment currently being displayed.1932 */1933 return apply_filters( 'bp_activity_comment_user_id', $user_id );1934 }1935 1936 /**1937 * Output the author link for the activity comment currently being displayed.1938 *1939 * @since 1.5.01940 *1941 */1942 function bp_activity_comment_user_link() {1943 echo bp_get_activity_comment_user_link();1944 }1945 1946 /**1947 * Return the author link for the activity comment currently being displayed.1948 *1949 * @since 1.5.01950 *1951 *1952 * @return string $user_link The URL of the activity comment author's profile.1953 */1954 function bp_get_activity_comment_user_link() {1955 $user_link = bp_core_get_user_domain( bp_get_activity_comment_user_id() );1956 1957 /**1958 * Filters the author link for the activity comment currently being displayed.1959 *1960 * @since 1.5.01961 *1962 * @param string $user_link Link for the author of the activity comment currently being displayed.1963 */1964 return apply_filters( 'bp_activity_comment_user_link', $user_link );1965 }1966 1967 /**1968 * Output the author name for the activity comment currently being displayed.1969 *1970 * @since 1.5.01971 *1972 */1973 function bp_activity_comment_name() {1974 echo bp_get_activity_comment_name();1975 }1976 1977 /**1978 * Return the author name for the activity comment currently being displayed.1979 *1980 * The use of the 'bp_acomment_name' filter is deprecated. Please use1981 * 'bp_activity_comment_name'.1982 *1983 * @since 1.5.01984 *1985 * @global object $activities_template {@link BP_Activity_Template}1986 *1987 * @return string $name The full name of the activity comment author.1988 */1989 function bp_get_activity_comment_name() {1990 global $activities_template;1991 1992 if ( isset( $activities_template->activity->current_comment->user_fullname ) ) {1993 1994 $name = apply_filters( 'bp_acomment_name', $activities_template->activity->current_comment->user_fullname, $activities_template->activity->current_comment ); // Backward compatibility.1995 } else {1996 $name = $activities_template->activity->current_comment->display_name;1997 }1998 1999 /**2000 * Filters the name of the author for the activity comment.2001 *2002 * @since 1.5.02003 *2004 * @param string $name Name to be displayed with the activity comment.2005 */2006 return apply_filters( 'bp_activity_comment_name', $name );2007 }2008 2009 /**2010 * Output the formatted date_recorded of the activity comment currently being displayed.2011 *2012 * @since 1.5.02013 *2014 */2015 function bp_activity_comment_date_recorded() {2016 echo bp_get_activity_comment_date_recorded();2017 }2018 2019 /**2020 * Return the formatted date_recorded for the activity comment currently being displayed.2021 *2022 * @since 1.5.02023 *2024 *2025 * @return string|bool $date_recorded Time since the activity was recorded,2026 * in the form "%s ago". False on failure.2027 */2028 function bp_get_activity_comment_date_recorded() {2029 2030 /**2031 * Filters the recorded date of the activity comment currently being displayed.2032 *2033 * @since 1.5.02034 *2035 * @param string|bool Date for the activity comment currently being displayed.2036 */2037 return apply_filters( 'bp_activity_comment_date_recorded', bp_core_time_since( bp_get_activity_comment_date_recorded_raw() ) );2038 }2039 2040 /**2041 * Output the date_recorded of the activity comment currently being displayed.2042 *2043 * @since 2.3.02044 *2045 */2046 function bp_activity_comment_date_recorded_raw() {2047 echo bp_get_activity_comment_date_recorded_raw();2048 }2049 2050 /**2051 * Return the date_recorded for the activity comment currently being displayed.2052 *2053 * @since 2.3.02054 *2055 * @global object $activities_template {@link BP_Activity_Template}2056 *2057 * @return string|bool $date_recorded Time since the activity was recorded,2058 * in the form "%s ago". False on failure.2059 */2060 function bp_get_activity_comment_date_recorded_raw() {2061 global $activities_template;2062 2063 /**2064 * Filters the raw recorded date of the activity comment currently being displayed.2065 *2066 * @since 2.3.02067 *2068 * @param string|bool Raw date for the activity comment currently being displayed.2069 */2070 return apply_filters( 'bp_activity_comment_date_recorded', $activities_template->activity->current_comment->date_recorded );2071 }2072 2073 /**2074 * Output the 'delete' URL for the activity comment currently being displayed.2075 *2076 * @since 1.5.02077 *2078 */2079 function bp_activity_comment_delete_link() {2080 echo bp_get_activity_comment_delete_link();2081 }2082 2083 /**2084 * Gets the 'delete' URL for the activity comment currently being displayed.2085 *2086 * @since 1.5.02087 *2088 *2089 * @return string $link The nonced URL for deleting the current2090 * activity comment.2091 */2092 function bp_get_activity_comment_delete_link() {2093 $link = wp_nonce_url( trailingslashit( bp_get_activity_directory_permalink() . 'delete/' . bp_get_activity_comment_id() ) . '?cid=' . bp_get_activity_comment_id(), 'bp_activity_delete_link' );2094 2095 /**2096 * Filters the link used for deleting the activity comment currently being displayed.2097 *2098 * @since 1.5.02099 *2100 * @param string $link Link to use for deleting the currently displayed activity comment.2101 */2102 return apply_filters( 'bp_activity_comment_delete_link', $link );2103 }2104 2105 /**2106 * Output the content of the activity comment currently being displayed.2107 *2108 * @since 1.5.02109 *2110 */2111 function bp_activity_comment_content() {2112 echo bp_get_activity_comment_content();2113 }2114 2115 /**2116 * Return the content of the activity comment currently being displayed.2117 *2118 * The content is run through two filters. 'bp_get_activity_content'2119 * will apply all filters applied to activity items in general. Use2120 * 'bp_activity_comment_content' to modify the content of activity2121 * comments only.2122 *2123 * @since 1.5.02124 *2125 * @global object $activities_template {@link BP_Activity_Template}2126 *2127 * @return string $content The content of the current activity comment.2128 */2129 function bp_get_activity_comment_content() {2130 global $activities_template;2131 2132 /** This filter is documented in bp-activity/bp-activity-template.php */2133 $content = apply_filters( 'bp_get_activity_content', $activities_template->activity->current_comment->content );2134 2135 /**2136 * Filters the content of the current activity comment.2137 *2138 * @since 1.2.02139 *2140 * @param string $content The content of the current activity comment.2141 */2142 return apply_filters( 'bp_activity_comment_content', $content );2143 }2144 2145 /**2146 * Output the activity comment count.2147 *2148 * @since 1.2.02149 *2150 */2151 function bp_activity_comment_count() {2152 echo bp_activity_get_comment_count();2153 }2154 2155 /**2156 * Return the comment count of an activity item.2157 *2158 * @since 1.2.02159 *2160 * @global object $activities_template {@link BP_Activity_Template}2161 *2162 * @param array|null $deprecated Deprecated.2163 * @return int $count The activity comment count.2164 */2165 function bp_activity_get_comment_count( $deprecated = null ) {2166 global $activities_template;2167 2168 // Deprecated notice about $args.2169 if ( ! empty( $deprecated ) ) {2170 _deprecated_argument( __FUNCTION__, '1.2', sprintf( __( '%1$s no longer accepts arguments. See the inline documentation at %2$s for more details.', 'buddypress' ), __FUNCTION__, __FILE__ ) );2171 }2172 2173 // Get the count using the purpose-built recursive function.2174 $count = ! empty( $activities_template->activity->children )2175 ? bp_activity_recurse_comment_count( $activities_template->activity )2176 : 0;2177 2178 /**2179 * Filters the activity comment count.2180 *2181 * @since 1.2.02182 *2183 * @param int $count The activity comment count.2184 */2185 return apply_filters( 'bp_activity_get_comment_count', (int) $count );2186 }2187 2188 /**2189 * Return the total number of comments to the current comment.2190 *2191 * This function recursively adds the total number of comments each2192 * activity child has, and returns them.2193 *2194 * @since 1.2.02195 *2196 *2197 * @param object $comment Activity comment object.2198 * @param int $count The current iteration count.2199 * @return int $count The activity comment count.2200 */2201 function bp_activity_recurse_comment_count( $comment, $count = 0 ) {2202 2203 // Copy the count.2204 $new_count = $count;2205 2206 // Loop through children and recursively count comments.2207 if ( ! empty( $comment->children ) ) {2208 foreach ( (array) $comment->children as $comment ) {2209 $new_count++;2210 $new_count = bp_activity_recurse_comment_count( $comment, $new_count );2211 }2212 }2213 2214 /**2215 * Filters the total number of comments for the current comment.2216 *2217 * @since 2.1.02218 *2219 * @param int $new_count New total count for the current comment.2220 * @param object $comment Activity comment object.2221 * @param int $count Current iteration count for the current comment.2222 */2223 return apply_filters( 'bp_activity_recurse_comment_count', $new_count, $comment, $count );2224 }2225 2226 460 /** 2227 461 * Output the depth of the current activity comment. 2228 462 * … … 2293 527 return apply_filters( 'bp_activity_get_comment_depth', $depth ); 2294 528 } 2295 529 2296 /**2297 * Output the activity comment link.2298 *2299 * @since 1.2.02300 *2301 */2302 function bp_activity_comment_link() {2303 echo bp_get_activity_comment_link();2304 }2305 2306 /**2307 * Return the activity comment link.2308 *2309 * @since 1.2.02310 *2311 * @global object $activities_template {@link BP_Activity_Template}2312 *2313 * @return string The activity comment link.2314 */2315 function bp_get_activity_comment_link() {2316 global $activities_template;2317 2318 /**2319 * Filters the comment link for the current activity comment.2320 *2321 * @since 1.2.02322 *2323 * @param string $value Constructed URL parameters with activity IDs.2324 */2325 return apply_filters( 'bp_get_activity_comment_link', '?ac=' . $activities_template->activity->id . '/#ac-form-' . $activities_template->activity->id );2326 }2327 2328 /**2329 * Output the activity comment form no JavaScript display CSS.2330 *2331 * @since 1.2.02332 *2333 */2334 function bp_activity_comment_form_nojs_display() {2335 echo bp_get_activity_comment_form_nojs_display();2336 }2337 2338 /**2339 * Return the activity comment form no JavaScript display CSS.2340 *2341 * @since 1.2.02342 *2343 * @global object $activities_template {@link BP_Activity_Template}2344 *2345 * @return string|false The activity comment form no JavaScript2346 * display CSS. False on failure.2347 */2348 function bp_get_activity_comment_form_nojs_display() {2349 global $activities_template;2350 2351 if ( isset( $_GET['ac'] ) && ( $_GET['ac'] === ( $activities_template->activity->id . '/' ) ) ) {2352 return 'style="display: block"';2353 }2354 2355 return false;2356 }2357 2358 /**2359 * Output the activity comment form action.2360 *2361 * @since 1.2.02362 *2363 */2364 function bp_activity_comment_form_action() {2365 echo bp_get_activity_comment_form_action();2366 }2367 2368 /**2369 * Return the activity comment form action.2370 *2371 * @since 1.2.02372 *2373 *2374 * @return string The activity comment form action.2375 */2376 function bp_get_activity_comment_form_action() {2377 2378 /**2379 * Filters the activity comment form action URL.2380 *2381 * @since 1.2.02382 *2383 * @param string $value URL to use in the comment form's action attribute.2384 */2385 return apply_filters( 'bp_get_activity_comment_form_action', home_url( bp_get_activity_root_slug() . '/reply/' ) );2386 }2387 2388 530 /** 2389 531 * Output the activity permalink ID. 2390 532 * … … 2415 557 return apply_filters( 'bp_get_activity_permalink_id', bp_current_action() ); 2416 558 } 2417 559 2418 /**2419 * Output the activity thread permalink.2420 *2421 * @since 1.2.02422 *2423 */2424 function bp_activity_thread_permalink() {2425 echo esc_url( bp_get_activity_thread_permalink() );2426 }2427 2428 /**2429 * Return the activity thread permalink.2430 *2431 * @since 1.2.02432 *2433 *2434 * @return string $link The activity thread permalink.2435 */2436 function bp_get_activity_thread_permalink() {2437 global $activities_template;2438 2439 $link = bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity );2440 2441 /**2442 * Filters the activity thread permalink.2443 *2444 * @since 1.2.02445 *2446 * @param string $link The activity thread permalink.2447 */2448 return apply_filters( 'bp_get_activity_thread_permalink', $link );2449 }2450 2451 /**2452 * Output the activity comment permalink.2453 *2454 * @since 1.8.02455 *2456 */2457 function bp_activity_comment_permalink() {2458 echo esc_url( bp_get_activity_comment_permalink() );2459 }2460 /**2461 * Return the activity comment permalink.2462 *2463 * @since 1.8.02464 *2465 * @return string $link The activity comment permalink.2466 */2467 function bp_get_activity_comment_permalink() {2468 global $activities_template;2469 2470 $link = bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity );2471 2472 // Used for filter below.2473 $comment_id = isset( $activities_template->activity->current_comment->id )2474 ? $activities_template->activity->current_comment->id2475 : 0;2476 2477 /**2478 * Filters the activity comment permalink.2479 *2480 * @since 1.8.02481 *2482 * @param string $link Activity comment permalink.2483 * @param int $comment_id ID for the current activity comment.2484 */2485 return apply_filters( 'bp_get_activity_comment_permalink', $link, $comment_id );2486 }2487 2488 /**2489 * Output the activity favorite link.2490 *2491 * @since 1.2.02492 *2493 */2494 function bp_activity_favorite_link() {2495 echo bp_get_activity_favorite_link();2496 }2497 2498 /**2499 * Return the activity favorite link.2500 *2501 * @since 1.2.02502 *2503 * @global object $activities_template {@link BP_Activity_Template}2504 *2505 * @return string The activity favorite link.2506 */2507 function bp_get_activity_favorite_link() {2508 global $activities_template;2509 2510 /**2511 * Filters the activity favorite link.2512 *2513 * @since 1.2.02514 *2515 * @param string $value Constructed link for favoriting the activity comment.2516 */2517 return apply_filters( 'bp_get_activity_favorite_link', wp_nonce_url( home_url( bp_get_activity_root_slug() . '/favorite/' . $activities_template->activity->id . '/' ), 'mark_favorite' ) );2518 }2519 2520 /**2521 * Output the activity unfavorite link.2522 *2523 * @since 1.2.02524 *2525 */2526 function bp_activity_unfavorite_link() {2527 echo bp_get_activity_unfavorite_link();2528 }2529 2530 /**2531 * Return the activity unfavorite link.2532 *2533 * @since 1.2.02534 *2535 * @global object $activities_template {@link BP_Activity_Template}2536 *2537 * @return string The activity unfavorite link.2538 */2539 function bp_get_activity_unfavorite_link() {2540 global $activities_template;2541 2542 /**2543 * Filters the activity unfavorite link.2544 *2545 * @since 1.2.02546 *2547 * @param string $value Constructed link for unfavoriting the activity comment.2548 */2549 return apply_filters( 'bp_get_activity_unfavorite_link', wp_nonce_url( home_url( bp_get_activity_root_slug() . '/unfavorite/' . $activities_template->activity->id . '/' ), 'unmark_favorite' ) );2550 }2551 2552 /**2553 * Output the activity CSS class.2554 *2555 * @since 1.0.02556 *2557 */2558 function bp_activity_css_class() {2559 echo bp_get_activity_css_class();2560 }2561 2562 /**2563 * Return the current activity item's CSS class.2564 *2565 * @since 1.0.02566 *2567 * @global object $activities_template {@link BP_Activity_Template}2568 *2569 * @return string The activity item's CSS class.2570 */2571 function bp_get_activity_css_class() {2572 global $activities_template;2573 2574 /**2575 * Filters the available mini activity actions available as CSS classes.2576 *2577 * @since 1.2.02578 *2579 * @param array $value Array of classes used to determine classes applied to HTML element.2580 */2581 $mini_activity_actions = apply_filters( 'bp_activity_mini_activity_types', array(2582 'friendship_accepted',2583 'friendship_created',2584 'new_blog',2585 'joined_group',2586 'created_group',2587 'new_member'2588 ) );2589 2590 $class = ' activity-item';2591 2592 if ( in_array( $activities_template->activity->type, (array) $mini_activity_actions ) || empty( $activities_template->activity->content ) ) {2593 $class .= ' mini';2594 }2595 2596 if ( bp_activity_get_comment_count() && bp_activity_can_comment() ) {2597 $class .= ' has-comments';2598 }2599 2600 /**2601 * Filters the determined classes to add to the HTML element.2602 *2603 * @since 1.0.02604 *2605 * @param string $value Classes to be added to the HTML element.2606 */2607 return apply_filters( 'bp_get_activity_css_class', $activities_template->activity->component . ' ' . $activities_template->activity->type . $class );2608 }2609 2610 /**2611 * Output the activity delete link.2612 *2613 * @since 1.1.02614 *2615 */2616 function bp_activity_delete_link() {2617 echo bp_get_activity_delete_link();2618 }2619 2620 /**2621 * Return the activity delete link.2622 *2623 * @since 1.1.02624 *2625 * @global object $activities_template {@link BP_Activity_Template}2626 *2627 * @return string $link Activity delete link. Contains $redirect_to arg2628 * if on single activity page.2629 */2630 function bp_get_activity_delete_link() {2631 2632 $url = bp_get_activity_delete_url();2633 $class = 'delete-activity';2634 2635 // Determine if we're on a single activity page, and customize accordingly.2636 if ( bp_is_activity_component() && is_numeric( bp_current_action() ) ) {2637 $class = 'delete-activity-single';2638 }2639 2640 $link = '<a href="' . esc_url( $url ) . '" class="button item-button bp-secondary-action ' . $class . ' confirm" rel="nofollow">' . __( 'Delete', 'buddypress' ) . '</a>';2641 2642 /**2643 * Filters the activity delete link.2644 *2645 * @since 1.1.02646 *2647 * @param string $link Activity delete HTML link.2648 */2649 return apply_filters( 'bp_get_activity_delete_link', $link );2650 }2651 2652 /**2653 * Output the URL to delete a single activity stream item.2654 *2655 * @since 2.1.02656 *2657 */2658 function bp_activity_delete_url() {2659 echo esc_url( bp_get_activity_delete_url() );2660 }2661 /**2662 * Return the URL to delete a single activity item.2663 *2664 * @since 2.1.02665 *2666 * @global object $activities_template {@link BP_Activity_Template}2667 *2668 * @return string $link Activity delete link. Contains $redirect_to arg2669 * if on single activity page.2670 */2671 function bp_get_activity_delete_url() {2672 global $activities_template;2673 2674 $url = trailingslashit( bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/delete/' . $activities_template->activity->id );2675 2676 // Determine if we're on a single activity page, and customize accordingly.2677 if ( bp_is_activity_component() && is_numeric( bp_current_action() ) ) {2678 $url = add_query_arg( array( 'redirect_to' => wp_get_referer() ), $url );2679 }2680 2681 $url = wp_nonce_url( $url, 'bp_activity_delete_link' );2682 2683 /**2684 * Filters the activity delete URL.2685 *2686 * @since 2.1.02687 *2688 * @param string $url Activity delete URL.2689 */2690 return apply_filters( 'bp_get_activity_delete_url', $url );2691 }2692 2693 560 /** 2694 561 * Output the activity latest update link. 2695 562 *