Changeset 7360 for trunk/src/includes/replies/template.php
- Timestamp:
- 11/16/2025 10:43:01 PM (3 months ago)
- File:
-
- 1 edited
-
trunk/src/includes/replies/template.php (modified) (87 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/replies/template.php
r7359 r7360 22 22 echo bbp_get_reply_post_type(); 23 23 } 24 /** 25 * Return the unique id of the custom post type for replies 26 * 27 * @since 2.0.0 bbPress (r2857) 28 * 29 * post type id 30 * @return string The unique reply post type id 31 */ 32 function bbp_get_reply_post_type() { 24 25 /** 26 * Return the unique id of the custom post type for replies 27 * 28 * @since 2.0.0 bbPress (r2857) 29 * 30 * post type id 31 * @return string The unique reply post type id 32 */ 33 function bbp_get_reply_post_type() { 33 34 34 35 // Filter & return 35 36 return apply_filters( 'bbp_get_reply_post_type', bbpress()->reply_post_type ); 36 }37 } 37 38 38 39 /** … … 302 303 echo bbp_get_reply_id( $reply_id ); 303 304 } 304 /** 305 * Return the id of the reply in a replies loop 306 * 307 * @since 2.0.0 bbPress (r2553) 308 * 309 * @param $reply_id Optional. Used to check emptiness 310 * @return int The reply id 311 */ 312 function bbp_get_reply_id( $reply_id = 0 ) { 305 306 /** 307 * Return the id of the reply in a replies loop 308 * 309 * @since 2.0.0 bbPress (r2553) 310 * 311 * @param $reply_id Optional. Used to check emptiness 312 * @return int The reply id 313 */ 314 function bbp_get_reply_id( $reply_id = 0 ) { 313 315 $bbp = bbpress(); 314 316 $wp_query = bbp_get_wp_query(); … … 318 320 $bbp_reply_id = $reply_id; 319 321 320 // Currently inside a replies loop321 } elseif ( ! empty( $bbp->reply_query->in_the_loop ) && isset( $bbp->reply_query->post->ID ) ) {322 // Currently inside a replies loop 323 } elseif ( ! empty( $bbp->reply_query->in_the_loop ) && isset( $bbp->reply_query->post->ID ) ) { 322 324 $bbp_reply_id = $bbp->reply_query->post->ID; 323 325 324 // Currently inside a search loop325 } elseif ( ! empty( $bbp->search_query->in_the_loop ) && isset( $bbp->search_query->post->ID ) && bbp_is_reply( $bbp->search_query->post->ID ) ) {326 // Currently inside a search loop 327 } elseif ( ! empty( $bbp->search_query->in_the_loop ) && isset( $bbp->search_query->post->ID ) && bbp_is_reply( $bbp->search_query->post->ID ) ) { 326 328 $bbp_reply_id = $bbp->search_query->post->ID; 327 329 328 // Currently viewing a forum329 } elseif ( ( bbp_is_single_reply() || bbp_is_reply_edit() ) && ! empty( $bbp->current_reply_id ) ) {330 // Currently viewing a forum 331 } elseif ( ( bbp_is_single_reply() || bbp_is_reply_edit() ) && ! empty( $bbp->current_reply_id ) ) { 330 332 $bbp_reply_id = $bbp->current_reply_id; 331 333 332 // Currently viewing a reply333 } elseif ( ( bbp_is_single_reply() || bbp_is_reply_edit() ) && isset( $wp_query->post->ID ) ) {334 // Currently viewing a reply 335 } elseif ( ( bbp_is_single_reply() || bbp_is_reply_edit() ) && isset( $wp_query->post->ID ) ) { 334 336 $bbp_reply_id = $wp_query->post->ID; 335 337 336 // Fallback337 } else {338 // Fallback 339 } else { 338 340 $bbp_reply_id = 0; 339 }341 } 340 342 341 343 // Filter & return 342 344 return (int) apply_filters( 'bbp_get_reply_id', $bbp_reply_id, $reply_id ); 343 }345 } 344 346 345 347 /** … … 397 399 echo esc_url( bbp_get_reply_permalink( $reply_id ) ); 398 400 } 399 /** 400 * Return the link to the reply 401 * 402 * @since 2.0.0 bbPress (r2553) 403 * 404 * @param int $reply_id Optional. Reply id 405 * 406 * @return string Permanent link to reply 407 */ 408 function bbp_get_reply_permalink( $reply_id = 0 ) { 401 402 /** 403 * Return the link to the reply 404 * 405 * @since 2.0.0 bbPress (r2553) 406 * 407 * @param int $reply_id Optional. Reply id 408 * 409 * @return string Permanent link to reply 410 */ 411 function bbp_get_reply_permalink( $reply_id = 0 ) { 409 412 $reply_id = bbp_get_reply_id( $reply_id ); 410 413 411 414 // Filter & return 412 415 return apply_filters( 'bbp_get_reply_permalink', get_permalink( $reply_id ), $reply_id ); 413 }416 } 414 417 415 418 /** … … 423 426 echo esc_url( bbp_get_reply_url( $reply_id ) ); 424 427 } 425 /** 426 * Return the paginated url to the reply in the reply loop 427 * 428 * @since 2.0.0 bbPress (r2679) 429 * 430 * @param int $reply_id Optional. Reply id 431 * @param string $redirect_to Optional. Pass a redirect value for use with 432 * shortcodes and other fun things. 433 * @return string Link to reply relative to paginated topic 434 */ 435 function bbp_get_reply_url( $reply_id = 0, $redirect_to = '' ) { 428 429 /** 430 * Return the paginated url to the reply in the reply loop 431 * 432 * @since 2.0.0 bbPress (r2679) 433 * 434 * @param int $reply_id Optional. Reply id 435 * @param string $redirect_to Optional. Pass a redirect value for use with 436 * shortcodes and other fun things. 437 * @return string Link to reply relative to paginated topic 438 */ 439 function bbp_get_reply_url( $reply_id = 0, $redirect_to = '' ) { 436 440 437 441 // Set needed variables … … 443 447 $topic_id = bbp_get_reply_topic_id( $reply_id ); 444 448 $topic = bbp_get_topic( $topic_id ); 445 } elseif ( bbp_is_topic( $reply_id ) ) {449 } elseif ( bbp_is_topic( $reply_id ) ) { 446 450 $topic_id = bbp_get_topic_id( $reply_id ); 447 451 $topic = bbp_get_topic( $topic_id ); 448 452 $reply_id = $topic_id; 449 }453 } 450 454 451 455 // Hierarchical reply page … … 453 457 $reply_page = 1; 454 458 455 // Standard reply page456 } else {459 // Standard reply page 460 } else { 457 461 $reply_page = ceil( (int) bbp_get_reply_position( $reply_id, $topic_id ) / (int) bbp_get_replies_per_page() ); 458 }462 } 459 463 460 464 // Get links & URLS … … 475 479 $url = user_trailingslashit( $topic_url ) . $reply_hash; 476 480 477 // Unpretty links478 } else {481 // Unpretty links 482 } else { 479 483 $url = $topic_url . $reply_hash; 480 }481 482 // Include pagination483 } else {484 } 485 486 // Include pagination 487 } else { 484 488 485 489 // Pretty permalinks … … 488 492 $url = user_trailingslashit( $url ) . $reply_hash; 489 493 490 // Unpretty links491 } else {494 // Unpretty links 495 } else { 492 496 $url = add_query_arg( 'paged', $reply_page, $topic_url ) . $reply_hash; 493 }494 497 } 498 } 495 499 496 500 // Add topic view query arg back to end if it is set 497 501 if ( bbp_get_view_all() ) { 498 502 $url = bbp_add_view_all( $url ); 499 }503 } 500 504 501 505 // Filter & return 502 506 return apply_filters( 'bbp_get_reply_url', $url, $reply_id, $redirect_to ); 503 }507 } 504 508 505 509 /** … … 514 518 } 515 519 516 /**517 * Return the title of the reply518 *519 * @since 2.0.0 bbPress (r2553)520 *521 * @param int $reply_id Optional. Reply id522 * @return string Title of reply523 */524 function bbp_get_reply_title( $reply_id = 0 ) {520 /** 521 * Return the title of the reply 522 * 523 * @since 2.0.0 bbPress (r2553) 524 * 525 * @param int $reply_id Optional. Reply id 526 * @return string Title of reply 527 */ 528 function bbp_get_reply_title( $reply_id = 0 ) { 525 529 $reply_id = bbp_get_reply_id( $reply_id ); 526 530 $title = get_post_field( 'post_title', $reply_id ); … … 529 533 // Filter & return 530 534 return apply_filters( 'bbp_get_reply_title', $title, $reply_id ); 531 }532 533 /**534 * Get empty reply title fallback.535 *536 * @since 2.5.0 bbPress (r5177)537 *538 * @param string $post_title Required. Reply Title539 * @param int $post_id Required. Reply ID540 * @return string Title of reply541 */542 function bbp_get_reply_title_fallback( $post_title = '', $post_id = 0 ) {535 } 536 537 /** 538 * Get empty reply title fallback. 539 * 540 * @since 2.5.0 bbPress (r5177) 541 * 542 * @param string $post_title Required. Reply Title 543 * @param int $post_id Required. Reply ID 544 * @return string Title of reply 545 */ 546 function bbp_get_reply_title_fallback( $post_title = '', $post_id = 0 ) { 543 547 544 548 // Bail if title not empty, or post is not a reply 545 549 if ( ! empty( $post_title ) || ! bbp_is_reply( $post_id ) ) { 546 550 return $post_title; 547 }551 } 548 552 549 553 // Get reply topic title. … … 551 555 552 556 // Get empty reply title fallback. 553 $reply_title = sprintf( esc_html__( 'Reply To: %s', 'bbpress' ), $topic_title ); 557 $reply_title = sprintf( 558 /* translators: %s: Topic title */ 559 esc_html__( 'Reply To: %s', 'bbpress' ), 560 $topic_title 561 ); 554 562 555 563 // Filter & return 556 564 return apply_filters( 'bbp_get_reply_title_fallback', $reply_title, $post_id, $topic_title ); 557 }565 } 558 566 559 567 /** … … 567 575 echo bbp_get_reply_content( $reply_id ); 568 576 } 569 /** 570 * Return the content of the reply 571 * 572 * @since 2.0.0 bbPress (r2780) 573 * 574 * @param int $reply_id Optional. reply id 575 * @return string Content of the reply 576 */ 577 function bbp_get_reply_content( $reply_id = 0 ) { 577 578 /** 579 * Return the content of the reply 580 * 581 * @since 2.0.0 bbPress (r2780) 582 * 583 * @param int $reply_id Optional. reply id 584 * @return string Content of the reply 585 */ 586 function bbp_get_reply_content( $reply_id = 0 ) { 578 587 $reply_id = bbp_get_reply_id( $reply_id ); 579 588 … … 581 590 if ( post_password_required( $reply_id ) ) { 582 591 return get_the_password_form(); 583 }592 } 584 593 585 594 $content = get_post_field( 'post_content', $reply_id ); … … 587 596 // Filter & return 588 597 return apply_filters( 'bbp_get_reply_content', $content, $reply_id ); 589 }598 } 590 599 591 600 /** … … 600 609 echo bbp_get_reply_excerpt( $reply_id, $length ); 601 610 } 602 /** 603 * Return the excerpt of the reply 604 * 605 * @since 2.0.0 bbPress (r2751) 606 * 607 * @param int $reply_id Optional. Reply id 608 * @param int $length Optional. Length of the excerpt. Defaults to 100 609 * letters 610 * @return string Reply Excerpt 611 */ 612 function bbp_get_reply_excerpt( $reply_id = 0, $length = 100 ) { 611 612 /** 613 * Return the excerpt of the reply 614 * 615 * @since 2.0.0 bbPress (r2751) 616 * 617 * @param int $reply_id Optional. Reply id 618 * @param int $length Optional. Length of the excerpt. Defaults to 100 619 * letters 620 * @return string Reply Excerpt 621 */ 622 function bbp_get_reply_excerpt( $reply_id = 0, $length = 100 ) { 613 623 $reply_id = bbp_get_reply_id( $reply_id ); 614 624 $length = (int) $length; … … 617 627 if ( empty( $excerpt ) ) { 618 628 $excerpt = bbp_get_reply_content( $reply_id ); 619 }620 621 $excerpt = trim ( strip_tags( $excerpt ) );629 } 630 631 $excerpt = trim( strip_tags( $excerpt ) ); 622 632 623 633 // Multibyte support 624 634 if ( function_exists( 'mb_strlen' ) ) { 625 635 $excerpt_length = mb_strlen( $excerpt ); 626 } else {636 } else { 627 637 $excerpt_length = strlen( $excerpt ); 628 }638 } 629 639 630 640 if ( ! empty( $length ) && ( $excerpt_length > $length ) ) { 631 641 $excerpt = mb_substr( $excerpt, 0, $length - 1 ); 632 642 $excerpt .= '…'; 633 }643 } 634 644 635 645 // Filter & return 636 646 return apply_filters( 'bbp_get_reply_excerpt', $excerpt, $reply_id, $length ); 637 }647 } 638 648 639 649 /** … … 649 659 echo bbp_get_reply_post_date( $reply_id, $humanize, $gmt ); 650 660 } 651 /** 652 * Return the post date and time of a reply 653 * 654 * @since 2.2.0 bbPress (r4155) 655 * 656 * @param int $reply_id Optional. Reply id. 657 * @param bool $humanize Optional. Humanize output using time_since 658 * @param bool $gmt Optional. Use GMT 659 * @return string 660 */ 661 function bbp_get_reply_post_date( $reply_id = 0, $humanize = false, $gmt = false ) { 661 662 /** 663 * Return the post date and time of a reply 664 * 665 * @since 2.2.0 bbPress (r4155) 666 * 667 * @param int $reply_id Optional. Reply id. 668 * @param bool $humanize Optional. Humanize output using time_since 669 * @param bool $gmt Optional. Use GMT 670 * @return string 671 */ 672 function bbp_get_reply_post_date( $reply_id = 0, $humanize = false, $gmt = false ) { 662 673 $reply_id = bbp_get_reply_id( $reply_id ); 663 674 … … 669 680 $result = bbp_get_time_since( $date ); 670 681 671 // August 4, 2012 at 2:37 pm672 } else {682 // August 4, 2012 at 2:37 pm 683 } else { 673 684 $date = get_post_time( get_option( 'date_format' ), $gmt, $reply_id, true ); 674 685 $time = get_post_time( get_option( 'time_format' ), $gmt, $reply_id, true ); 686 /* translators: 1: Date, 2: Time */ 675 687 $result = sprintf( _x( '%1$s at %2$s', 'date at time', 'bbpress' ), $date, $time ); 676 }688 } 677 689 678 690 // Filter & return 679 691 return apply_filters( 'bbp_get_reply_post_date', $result, $reply_id, $humanize, $gmt, $date, $time ); 680 }692 } 681 693 682 694 /** … … 713 725 echo bbp_get_reply_revision_log( $reply_id ); 714 726 } 715 /** 716 * Return the formatted revision log of the reply 717 * 718 * @since 2.0.0 bbPress (r2782) 719 * 720 * @param int $reply_id Optional. Reply id 721 * @return string Revision log of the reply 722 */ 723 function bbp_get_reply_revision_log( $reply_id = 0 ) { 727 728 /** 729 * Return the formatted revision log of the reply 730 * 731 * @since 2.0.0 bbPress (r2782) 732 * 733 * @param int $reply_id Optional. Reply id 734 * @return string Revision log of the reply 735 */ 736 function bbp_get_reply_revision_log( $reply_id = 0 ) { 724 737 725 738 // Create necessary variables … … 729 742 if ( bbp_is_topic( $reply_id ) ) { 730 743 return bbp_get_topic_revision_log( $reply_id ); 731 }744 } 732 745 733 746 // Get the reply revision log (out of post meta … … 737 750 if ( empty( $reply_id ) || empty( $revision_log ) || ! is_array( $revision_log ) ) { 738 751 return false; 739 }752 } 740 753 741 754 // Get the actual revisions … … 743 756 if ( empty( $revisions ) ) { 744 757 return false; 745 }758 } 746 759 747 760 $r = "\n\n" . '<ul id="bbp-reply-revision-log-' . esc_attr( $reply_id ) . '" class="bbp-reply-revision-log">' . "\n\n"; … … 753 766 $author_id = $revision->post_author; 754 767 $reason = ''; 755 } else {768 } else { 756 769 $author_id = $revision_log[ $revision->ID ]['author']; 757 770 $reason = $revision_log[ $revision->ID ]['reason']; 758 }771 } 759 772 760 773 $author = bbp_get_author_link( array( 'size' => 14, 'link_text' => bbp_get_reply_author_display_name( $revision->ID ), 'post_id' => $revision->ID ) ); … … 763 776 $r .= "\t" . '<li id="bbp-reply-revision-log-' . esc_attr( $reply_id ) . '-item-' . esc_attr( $revision->ID ) . '" class="bbp-reply-revision-log-item">' . "\n"; 764 777 if ( ! empty( $reason ) ) { 778 /* translators: 1: Time since modification, 2: Author linked display name, 3: Modification reason */ 765 779 $r .= "\t\t" . sprintf( esc_html__( 'This reply was modified %1$s by %2$s. Reason: %3$s', 'bbpress' ), esc_html( $since ), $author, esc_html( $reason ) ) . "\n"; 766 } else { 780 } else { 781 /* translators: 1: Time since modification, 2: Author linked display name */ 767 782 $r .= "\t\t" . sprintf( esc_html__( 'This reply was modified %1$s by %2$s.', 'bbpress' ), esc_html( $since ), $author ) . "\n"; 768 } 783 } 784 769 785 $r .= "\t" . '</li>' . "\n"; 770 771 } 786 } 772 787 773 788 $r .= "\n" . '</ul>' . "\n\n"; … … 775 790 // Filter & return 776 791 return apply_filters( 'bbp_get_reply_revision_log', $r, $reply_id ); 777 } 778 /** 779 * Return the raw revision log of the reply 780 * 781 * @since 2.0.0 bbPress (r2782) 782 * 783 * @param int $reply_id Optional. Reply id 784 * @return string Raw revision log of the reply 785 */ 786 function bbp_get_reply_raw_revision_log( $reply_id = 0 ) { 792 } 793 794 /** 795 * Return the raw revision log of the reply 796 * 797 * @since 2.0.0 bbPress (r2782) 798 * 799 * @param int $reply_id Optional. Reply id 800 * @return string Raw revision log of the reply 801 */ 802 function bbp_get_reply_raw_revision_log( $reply_id = 0 ) { 787 803 $reply_id = bbp_get_reply_id( $reply_id ); 788 804 $revision_log = get_post_meta( $reply_id, '_bbp_revision_log', true ); 789 805 $revision_log = ! empty( $revision_log ) 790 ? $revision_log791 : array();806 ? $revision_log 807 : array(); 792 808 793 809 // Filter & return 794 810 return apply_filters( 'bbp_get_reply_raw_revision_log', $revision_log, $reply_id ); 795 }811 } 796 812 797 813 /** … … 840 856 echo bbp_get_reply_status( $reply_id ); 841 857 } 842 /** 843 * Return the status of the reply 844 * 845 * @since 2.0.0 bbPress (r2667) 846 * 847 * @param int $reply_id Optional. Reply id 848 * @return string Status of reply 849 */ 850 function bbp_get_reply_status( $reply_id = 0 ) { 858 859 /** 860 * Return the status of the reply 861 * 862 * @since 2.0.0 bbPress (r2667) 863 * 864 * @param int $reply_id Optional. Reply id 865 * @return string Status of reply 866 */ 867 function bbp_get_reply_status( $reply_id = 0 ) { 851 868 $reply_id = bbp_get_reply_id( $reply_id ); 852 869 853 870 // Filter & return 854 871 return apply_filters( 'bbp_get_reply_status', get_post_status( $reply_id ), $reply_id ); 855 }872 } 856 873 857 874 /** … … 1002 1019 */ 1003 1020 function bbp_reply_author( $reply_id = 0 ) { 1004 echo bbp_get_reply_author( $reply_id ); 1005 } 1006 /** 1007 * Deprecated. Use bbp_get_reply_author_display_name() instead. 1008 * 1009 * Return the author of the reply 1010 * 1011 * @since 2.0.0 bbPress (r2667) 1012 * 1013 * @deprecated 2.5.0 bbPress (r5119) 1014 * 1015 * @param int $reply_id Optional. Reply id 1016 * @return string Author of reply 1017 */ 1018 function bbp_get_reply_author( $reply_id = 0 ) { 1021 echo bbp_get_reply_author_display_name( $reply_id ); 1022 } 1023 1024 /** 1025 * Deprecated. Use bbp_get_reply_author_display_name() instead. 1026 * 1027 * Return the author of the reply 1028 * 1029 * @since 2.0.0 bbPress (r2667) 1030 * 1031 * @deprecated 2.5.0 bbPress (r5119) 1032 * 1033 * @param int $reply_id Optional. Reply id 1034 * @return string Author of reply 1035 */ 1036 function bbp_get_reply_author( $reply_id = 0 ) { 1019 1037 $reply_id = bbp_get_reply_id( $reply_id ); 1020 1038 1021 1039 if ( ! bbp_is_reply_anonymous( $reply_id ) ) { 1022 1040 $author = get_the_author_meta( 'display_name', bbp_get_reply_author_id( $reply_id ) ); 1023 } else {1041 } else { 1024 1042 $author = get_post_meta( $reply_id, '_bbp_anonymous_name', true ); 1025 }1043 } 1026 1044 1027 1045 // Filter & return 1028 1046 return apply_filters( 'bbp_get_reply_author', $author, $reply_id ); 1029 }1047 } 1030 1048 1031 1049 /** … … 1039 1057 echo bbp_get_reply_author_id( $reply_id ); 1040 1058 } 1041 /** 1042 * Return the author ID of the reply 1043 * 1044 * @since 2.0.0 bbPress (r2667) 1045 * 1046 * @param int $reply_id Optional. Reply id 1047 * @return string Author id of reply 1048 */ 1049 function bbp_get_reply_author_id( $reply_id = 0 ) { 1059 1060 /** 1061 * Return the author ID of the reply 1062 * 1063 * @since 2.0.0 bbPress (r2667) 1064 * 1065 * @param int $reply_id Optional. Reply id 1066 * @return string Author id of reply 1067 */ 1068 function bbp_get_reply_author_id( $reply_id = 0 ) { 1050 1069 $reply_id = bbp_get_reply_id( $reply_id ); 1051 1070 $author_id = get_post_field( 'post_author', $reply_id ); … … 1053 1072 // Filter & return 1054 1073 return (int) apply_filters( 'bbp_get_reply_author_id', $author_id, $reply_id ); 1055 }1074 } 1056 1075 1057 1076 /** … … 1065 1084 echo bbp_get_reply_author_display_name( $reply_id ); 1066 1085 } 1067 /** 1068 * Return the author display_name of the reply 1069 * 1070 * @since 2.0.0 bbPress (r2667) 1071 * 1072 * @param int $reply_id Optional. Reply id 1073 * @return string The display name of the author of the reply 1074 */ 1075 function bbp_get_reply_author_display_name( $reply_id = 0 ) { 1086 1087 /** 1088 * Return the author display_name of the reply 1089 * 1090 * @since 2.0.0 bbPress (r2667) 1091 * 1092 * @param int $reply_id Optional. Reply id 1093 * @return string The display name of the author of the reply 1094 */ 1095 function bbp_get_reply_author_display_name( $reply_id = 0 ) { 1076 1096 $reply_id = bbp_get_reply_id( $reply_id ); 1077 1097 … … 1088 1108 if ( empty( $author_name ) ) { 1089 1109 $author_name = get_the_author_meta( 'user_login', $author_id ); 1090 }1091 1092 // User does not have an account1093 } else {1110 } 1111 1112 // User does not have an account 1113 } else { 1094 1114 $author_name = get_post_meta( $reply_id, '_bbp_anonymous_name', true ); 1095 }1115 } 1096 1116 1097 1117 // Fallback if nothing could be found 1098 1118 if ( empty( $author_name ) ) { 1099 1119 $author_name = bbp_get_fallback_display_name( $reply_id ); 1100 }1120 } 1101 1121 1102 1122 // Filter & return 1103 1123 return apply_filters( 'bbp_get_reply_author_display_name', $author_name, $reply_id ); 1104 }1124 } 1105 1125 1106 1126 /** … … 1115 1135 echo bbp_get_reply_author_avatar( $reply_id, $size ); 1116 1136 } 1117 /** 1118 * Return the author avatar of the reply 1119 * 1120 * @since 2.0.0 bbPress (r2667) 1121 * 1122 * @param int $reply_id Optional. Reply id 1123 * @param int $size Optional. Size of the avatar. Defaults to 40 1124 * @return string Avatar of author of the reply 1125 */ 1126 function bbp_get_reply_author_avatar( $reply_id = 0, $size = 40 ) { 1137 1138 /** 1139 * Return the author avatar of the reply 1140 * 1141 * @since 2.0.0 bbPress (r2667) 1142 * 1143 * @param int $reply_id Optional. Reply id 1144 * @param int $size Optional. Size of the avatar. Defaults to 40 1145 * @return string Avatar of author of the reply 1146 */ 1147 function bbp_get_reply_author_avatar( $reply_id = 0, $size = 40 ) { 1127 1148 $reply_id = bbp_get_reply_id( $reply_id ); 1149 1128 1150 if ( ! empty( $reply_id ) ) { 1151 1129 1152 // Check for anonymous user 1130 1153 if ( ! bbp_is_reply_anonymous( $reply_id ) ) { 1131 1154 $author_avatar = get_avatar( bbp_get_reply_author_id( $reply_id ), $size ); 1132 } else {1155 } else { 1133 1156 $author_avatar = get_avatar( get_post_meta( $reply_id, '_bbp_anonymous_email', true ), $size ); 1134 }1135 } else {1157 } 1158 } else { 1136 1159 $author_avatar = ''; 1137 }1160 } 1138 1161 1139 1162 // Filter & return 1140 1163 return apply_filters( 'bbp_get_reply_author_avatar', $author_avatar, $reply_id, $size ); 1141 }1164 } 1142 1165 1143 1166 /** … … 1151 1174 echo bbp_get_reply_author_link( $args ); 1152 1175 } 1153 /** 1154 * Return the author link of the reply 1155 * 1156 * @since 2.0.0 bbPress (r2717) 1157 * 1158 * @param array $args Optional. If an integer, it is used as reply id. 1159 * @return string Author link of reply 1160 */ 1161 function bbp_get_reply_author_link( $args = array() ) { 1176 1177 /** 1178 * Return the author link of the reply 1179 * 1180 * @since 2.0.0 bbPress (r2717) 1181 * 1182 * @param array $args Optional. If an integer, it is used as reply id. 1183 * @return string Author link of reply 1184 */ 1185 function bbp_get_reply_author_link( $args = array() ) { 1162 1186 1163 1187 // Parse arguments against default values 1164 1188 $r = bbp_parse_args( $args, array( 1165 'post_id' => 0,1166 'link_title' => '',1167 'type' => 'both',1168 'size' => 80,1169 'sep' => '',1170 'show_role' => false1189 'post_id' => 0, 1190 'link_title' => '', 1191 'type' => 'both', 1192 'size' => 80, 1193 'sep' => '', 1194 'show_role' => false 1171 1195 ), 'get_reply_author_link' ); 1172 1196 1173 // Default return value 1174 $author_link = ''; 1175 1176 // Used as reply_id 1177 $reply_id = is_numeric( $args ) 1178 ? bbp_get_reply_id( $args ) 1179 : bbp_get_reply_id( $r['post_id'] ); 1180 1181 // Reply ID is good 1182 if ( ! empty( $reply_id ) ) { 1183 1184 // Get some useful reply information 1185 $author_url = bbp_get_reply_author_url( $reply_id ); 1186 $anonymous = bbp_is_reply_anonymous( $reply_id ); 1187 1188 // Tweak link title if empty 1189 if ( empty( $r['link_title'] ) ) { 1190 $author = bbp_get_reply_author_display_name( $reply_id ); 1191 $title = empty( $anonymous ) 1192 ? esc_attr__( "View %s's profile", 'bbpress' ) 1193 : esc_attr__( "Visit %s's website", 'bbpress' ); 1194 1195 $link_title = sprintf( $title, $author ); 1197 // Default return value 1198 $author_link = ''; 1199 1200 // Used as reply_id 1201 $reply_id = is_numeric( $args ) 1202 ? bbp_get_reply_id( $args ) 1203 : bbp_get_reply_id( $r['post_id'] ); 1204 1205 // Reply ID is good 1206 if ( ! empty( $reply_id ) ) { 1207 1208 // Get some useful reply information 1209 $author_url = bbp_get_reply_author_url( $reply_id ); 1210 $anonymous = bbp_is_reply_anonymous( $reply_id ); 1211 1212 // Tweak link title if empty 1213 if ( empty( $r['link_title'] ) ) { 1214 $author = bbp_get_reply_author_display_name( $reply_id ); 1215 $title = empty( $anonymous ) 1216 /* translators: %s: Author's display name */ 1217 ? esc_attr__( "View %s's profile", 'bbpress' ) 1218 /* translators: %s: Author's display name */ 1219 : esc_attr__( "Visit %s's website", 'bbpress' ); 1220 1221 $link_title = sprintf( $title, $author ); 1196 1222 1197 1223 // Use what was passed if not 1198 1224 } else { 1199 $link_title = $r['link_title'];1225 $link_title = $r['link_title']; 1200 1226 } 1201 1227 1202 // Setup title and author_links array1203 $author_links = array();1204 $link_title = ! empty( $link_title )1205 ? ' title="' . esc_attr( $link_title ) . '"'1206 : '';1207 1208 // Get avatar (unescaped, because HTML)1209 if ( ( 'avatar' === $r['type'] ) || ( 'both' === $r['type'] ) ) {1210 $author_links['avatar'] = bbp_get_reply_author_avatar( $reply_id, $r['size'] );1228 // Setup title and author_links array 1229 $author_links = array(); 1230 $link_title = ! empty( $link_title ) 1231 ? ' title="' . esc_attr( $link_title ) . '"' 1232 : ''; 1233 1234 // Get avatar (unescaped, because HTML) 1235 if ( ( 'avatar' === $r['type'] ) || ( 'both' === $r['type'] ) ) { 1236 $author_links['avatar'] = bbp_get_reply_author_avatar( $reply_id, $r['size'] ); 1211 1237 } 1212 1238 1213 // Get display name (escaped, because never HTML)1214 if ( ( 'name' === $r['type'] ) || ( 'both' === $r['type'] ) ) {1215 $author_links['name'] = esc_html( bbp_get_reply_author_display_name( $reply_id ) );1239 // Get display name (escaped, because never HTML) 1240 if ( ( 'name' === $r['type'] ) || ( 'both' === $r['type'] ) ) { 1241 $author_links['name'] = esc_html( bbp_get_reply_author_display_name( $reply_id ) ); 1216 1242 } 1217 1243 1218 // Empty array1219 $links = array();1220 $sprint = '<span %1$s>%2$s</span>';1221 1222 // Wrap each link1223 foreach ( $author_links as $link => $link_text ) {1224 $link_class = ' class="bbp-author-' . esc_attr( $link ) . '"';1225 $links[] = sprintf( $sprint, $link_class, $link_text );1244 // Empty array 1245 $links = array(); 1246 $sprint = '<span %1$s>%2$s</span>'; 1247 1248 // Wrap each link 1249 foreach ( $author_links as $link => $link_text ) { 1250 $link_class = ' class="bbp-author-' . esc_attr( $link ) . '"'; 1251 $links[] = sprintf( $sprint, $link_class, $link_text ); 1226 1252 } 1227 1253 1228 // Juggle1229 $author_links = $links;1230 unset( $links );1231 1232 // Filter sections1233 $sections = apply_filters( 'bbp_get_reply_author_links', $author_links, $r, $args );1234 1235 // Assemble sections into author link1236 $author_link = implode( $r['sep'], $sections );1237 1238 // Only wrap in link if profile exists1239 if ( empty( $anonymous ) && bbp_user_has_profile( bbp_get_reply_author_id( $reply_id ) ) ) {1240 $author_link = sprintf( '<a href="%1$s"%2$s%3$s>%4$s</a>', esc_url( $author_url ), $link_title, ' class="bbp-author-link"', $author_link );1254 // Juggle 1255 $author_links = $links; 1256 unset( $links ); 1257 1258 // Filter sections 1259 $sections = apply_filters( 'bbp_get_reply_author_links', $author_links, $r, $args ); 1260 1261 // Assemble sections into author link 1262 $author_link = implode( $r['sep'], $sections ); 1263 1264 // Only wrap in link if profile exists 1265 if ( empty( $anonymous ) && bbp_user_has_profile( bbp_get_reply_author_id( $reply_id ) ) ) { 1266 $author_link = sprintf( '<a href="%1$s"%2$s%3$s>%4$s</a>', esc_url( $author_url ), $link_title, ' class="bbp-author-link"', $author_link ); 1241 1267 } 1242 1268 1243 // Role is not linked1244 if ( true === $r['show_role'] ) {1245 $author_link .= bbp_get_reply_author_role( array( 'reply_id' => $reply_id ) );1269 // Role is not linked 1270 if ( true === $r['show_role'] ) { 1271 $author_link .= bbp_get_reply_author_role( array( 'reply_id' => $reply_id ) ); 1246 1272 } 1247 1273 } 1248 1274 1249 // Filter & return1250 return apply_filters( 'bbp_get_reply_author_link', $author_link, $r, $args );1251 }1275 // Filter & return 1276 return apply_filters( 'bbp_get_reply_author_link', $author_link, $r, $args ); 1277 } 1252 1278 1253 1279 /** … … 1261 1287 echo esc_url( bbp_get_reply_author_url( $reply_id ) ); 1262 1288 } 1263 /** 1264 * Return the author url of the reply 1265 * 1266 * @since 2.0.0 bbPress (r2667) 1267 * 1268 * @param int $reply_id Optional. Reply id 1269 * @return string Author URL of the reply 1270 */ 1271 function bbp_get_reply_author_url( $reply_id = 0 ) { 1289 1290 /** 1291 * Return the author url of the reply 1292 * 1293 * @since 2.0.0 bbPress (r2667) 1294 * 1295 * @param int $reply_id Optional. Reply id 1296 * @return string Author URL of the reply 1297 */ 1298 function bbp_get_reply_author_url( $reply_id = 0 ) { 1272 1299 $reply_id = bbp_get_reply_id( $reply_id ); 1273 1300 … … 1275 1302 if ( ! bbp_is_reply_anonymous( $reply_id ) && bbp_user_has_profile( bbp_get_reply_author_id( $reply_id ) ) ) { 1276 1303 $author_url = bbp_get_user_profile_url( bbp_get_reply_author_id( $reply_id ) ); 1277 } else {1304 } else { 1278 1305 $author_url = get_post_meta( $reply_id, '_bbp_anonymous_website', true ); 1306 1279 1307 if ( empty( $author_url ) ) { 1280 1308 $author_url = ''; 1281 }1282 1309 } 1310 } 1283 1311 1284 1312 // Filter & return 1285 1313 return apply_filters( 'bbp_get_reply_author_url', $author_url, $reply_id ); 1286 }1314 } 1287 1315 1288 1316 /** … … 1296 1324 echo bbp_get_reply_author_email( $reply_id ); 1297 1325 } 1298 /** 1299 * Return the reply author email address 1300 * 1301 * @since 2.0.0 bbPress (r3445) 1302 * 1303 * @param int $reply_id Optional. Reply id 1304 * @return string Reply author email address 1305 */ 1306 function bbp_get_reply_author_email( $reply_id = 0 ) { 1326 1327 /** 1328 * Return the reply author email address 1329 * 1330 * @since 2.0.0 bbPress (r3445) 1331 * 1332 * @param int $reply_id Optional. Reply id 1333 * @return string Reply author email address 1334 */ 1335 function bbp_get_reply_author_email( $reply_id = 0 ) { 1307 1336 $reply_id = bbp_get_reply_id( $reply_id ); 1308 1337 … … 1315 1344 $author_email = ! empty( $user->user_email ) ? $user->user_email : ''; 1316 1345 1317 // Anonymous1318 } else {1346 // Anonymous 1347 } else { 1319 1348 1320 1349 // Get email from post meta … … 1324 1353 if ( empty( $author_email ) ) { 1325 1354 $author_email = ''; 1326 }1327 1355 } 1356 } 1328 1357 1329 1358 // Filter & return 1330 1359 return apply_filters( 'bbp_get_reply_author_email', $author_email, $reply_id ); 1331 }1360 } 1332 1361 1333 1362 /** … … 1341 1370 echo bbp_get_reply_author_role( $args ); 1342 1371 } 1343 /** 1344 * Return the reply author role 1345 * 1346 * @since 2.1.0 bbPress (r3860) 1347 * 1348 * @param array $args Optional. 1349 * @return string Reply author role 1350 */ 1351 function bbp_get_reply_author_role( $args = array() ) { 1372 1373 /** 1374 * Return the reply author role 1375 * 1376 * @since 2.1.0 bbPress (r3860) 1377 * 1378 * @param array $args Optional. 1379 * @return string Reply author role 1380 */ 1381 function bbp_get_reply_author_role( $args = array() ) { 1352 1382 1353 1383 // Parse arguments against default values 1354 1384 $r = bbp_parse_args( $args, array( 1355 'reply_id' => 0,1356 'class' => false,1357 'before' => '<div class="bbp-author-role">',1358 'after' => '</div>'1385 'reply_id' => 0, 1386 'class' => false, 1387 'before' => '<div class="bbp-author-role">', 1388 'after' => '</div>' 1359 1389 ), 'get_reply_author_role' ); 1360 1390 1361 $reply_id = bbp_get_reply_id( $r['reply_id'] );1362 $role = bbp_get_user_display_role( bbp_get_reply_author_id( $reply_id ) );1363 1364 // Backwards compatibilty with old 'class' argument1365 if ( ! empty( $r['class'] ) ) {1366 $author_role = sprintf( '%1$s<div class="%2$s">%3$s</div>%4$s', $r['before'], esc_attr( $r['class'] ), esc_html( $role ), $r['after'] );1391 $reply_id = bbp_get_reply_id( $r['reply_id'] ); 1392 $role = bbp_get_user_display_role( bbp_get_reply_author_id( $reply_id ) ); 1393 1394 // Backwards compatibilty with old 'class' argument 1395 if ( ! empty( $r['class'] ) ) { 1396 $author_role = sprintf( '%1$s<div class="%2$s">%3$s</div>%4$s', $r['before'], esc_attr( $r['class'] ), esc_html( $role ), $r['after'] ); 1367 1397 1368 1398 // Simpler before & after arguments 1369 1399 // https://bbpress.trac.wordpress.org/ticket/2557 1370 1400 } else { 1371 $author_role = $r['before'] . $role . $r['after'];1372 } 1373 1374 // Filter & return1375 return apply_filters( 'bbp_get_reply_author_role', $author_role, $r, $args );1376 }1401 $author_role = $r['before'] . $role . $r['after']; 1402 } 1403 1404 // Filter & return 1405 return apply_filters( 'bbp_get_reply_author_role', $author_role, $r, $args ); 1406 } 1377 1407 1378 1408 /** … … 1386 1416 echo bbp_get_reply_topic_title( $reply_id ); 1387 1417 } 1388 /** 1389 * Return the topic title a reply belongs to 1390 * 1391 * @since 2.0.0 bbPress (r2553) 1392 * 1393 * @param int $reply_id Optional. Reply id 1394 * @return string The topic title of the reply 1395 */ 1396 function bbp_get_reply_topic_title( $reply_id = 0 ) { 1418 1419 /** 1420 * Return the topic title a reply belongs to 1421 * 1422 * @since 2.0.0 bbPress (r2553) 1423 * 1424 * @param int $reply_id Optional. Reply id 1425 * @return string The topic title of the reply 1426 */ 1427 function bbp_get_reply_topic_title( $reply_id = 0 ) { 1397 1428 $reply_id = bbp_get_reply_id( $reply_id ); 1398 1429 $topic_id = bbp_get_reply_topic_id( $reply_id ); … … 1401 1432 // Filter & return 1402 1433 return apply_filters( 'bbp_get_reply_topic_title', $title, $reply_id ); 1403 }1434 } 1404 1435 1405 1436 /** … … 1413 1444 echo bbp_get_reply_topic_id( $reply_id ); 1414 1445 } 1415 /** 1416 * Return the topic id a reply belongs to 1417 * 1418 * @since 2.0.0 bbPress (r2553) 1419 * 1420 * @param int $reply_id Optional. Reply id 1421 * @return int The topic id of the reply 1422 */ 1423 function bbp_get_reply_topic_id( $reply_id = 0 ) { 1446 1447 /** 1448 * Return the topic id a reply belongs to 1449 * 1450 * @since 2.0.0 bbPress (r2553) 1451 * 1452 * @param int $reply_id Optional. Reply id 1453 * @return int The topic id of the reply 1454 */ 1455 function bbp_get_reply_topic_id( $reply_id = 0 ) { 1424 1456 $reply_id = bbp_get_reply_id( $reply_id ); 1425 1457 $topic_id = (int) get_post_field( 'post_parent', $reply_id ); … … 1428 1460 if ( empty( $topic_id ) ) { 1429 1461 $topic_id = (int) get_post_meta( $reply_id, '_bbp_topic_id', true ); 1430 }1462 } 1431 1463 1432 1464 // Filter 1433 1465 if ( ! empty( $topic_id ) ) { 1434 1466 $topic_id = (int) bbp_get_topic_id( $topic_id ); 1435 }1467 } 1436 1468 1437 1469 // Filter & return 1438 1470 return (int) apply_filters( 'bbp_get_reply_topic_id', $topic_id, $reply_id ); 1439 }1471 } 1440 1472 1441 1473 /** … … 1449 1481 echo bbp_get_reply_forum_id( $reply_id ); 1450 1482 } 1451 /** 1452 * Return the forum id a reply belongs to 1453 * 1454 * @since 2.0.0 bbPress (r2679) 1455 * 1456 * @param int $reply_id Optional. Reply id 1457 * 1458 * @return int The forum id of the reply 1459 */ 1460 function bbp_get_reply_forum_id( $reply_id = 0 ) { 1483 1484 /** 1485 * Return the forum id a reply belongs to 1486 * 1487 * @since 2.0.0 bbPress (r2679) 1488 * 1489 * @param int $reply_id Optional. Reply id 1490 * 1491 * @return int The forum id of the reply 1492 */ 1493 function bbp_get_reply_forum_id( $reply_id = 0 ) { 1461 1494 $reply_id = bbp_get_reply_id( $reply_id ); 1462 1495 $topic_id = bbp_get_reply_topic_id( $reply_id ); … … 1466 1499 if ( empty( $forum_id ) ) { 1467 1500 $forum_id = (int) get_post_meta( $reply_id, '_bbp_forum_id', true ); 1468 }1501 } 1469 1502 1470 1503 // Filter 1471 1504 if ( ! empty( $forum_id ) ) { 1472 1505 $forum_id = (int) bbp_get_forum_id( $forum_id ); 1473 }1506 } 1474 1507 1475 1508 // Filter & return 1476 1509 return (int) apply_filters( 'bbp_get_reply_forum_id', $forum_id, $reply_id ); 1477 }1510 } 1478 1511 1479 1512 /** … … 1487 1520 echo bbp_get_reply_ancestor_id( $reply_id ); 1488 1521 } 1489 /** 1490 * Return the ancestor reply id of a reply 1491 * 1492 * @since 2.4.0 bbPress (r4944) 1493 * 1494 * @param in $reply_id Reply id 1495 */ 1496 function bbp_get_reply_ancestor_id( $reply_id = 0 ) { 1522 1523 /** 1524 * Return the ancestor reply id of a reply 1525 * 1526 * @since 2.4.0 bbPress (r4944) 1527 * 1528 * @param in $reply_id Reply id 1529 */ 1530 function bbp_get_reply_ancestor_id( $reply_id = 0 ) { 1497 1531 1498 1532 // Validation … … 1500 1534 if ( empty( $reply_id ) ) { 1501 1535 return false; 1502 }1536 } 1503 1537 1504 1538 // Find highest reply ancestor … … 1507 1541 if ( empty( $parent_id ) || ( $parent_id === $ancestor_id ) || ( bbp_get_reply_topic_id( $reply_id ) === $parent_id ) || ( $parent_id === $reply_id ) ) { 1508 1542 break; 1509 } 1543 } 1544 1510 1545 $ancestor_id = $parent_id; 1511 }1546 } 1512 1547 1513 1548 return (int) $ancestor_id; 1514 }1549 } 1515 1550 1516 1551 /** … … 1524 1559 echo bbp_get_reply_to( $reply_id ); 1525 1560 } 1526 /** 1527 * Return the reply to id of a reply 1528 * 1529 * @since 2.4.0 bbPress (r4944) 1530 * 1531 * @param int $reply_id Optional. Reply id 1532 * @return int The parent reply id of the reply 1533 */ 1534 function bbp_get_reply_to( $reply_id = 0 ) { 1561 1562 /** 1563 * Return the reply to id of a reply 1564 * 1565 * @since 2.4.0 bbPress (r4944) 1566 * 1567 * @param int $reply_id Optional. Reply id 1568 * @return int The parent reply id of the reply 1569 */ 1570 function bbp_get_reply_to( $reply_id = 0 ) { 1535 1571 1536 1572 // Assume there is no reply_to set … … 1543 1579 if ( ! empty( $reply_id ) ) { 1544 1580 $reply_to = (int) get_post_meta( $reply_id, '_bbp_reply_to', true ); 1545 }1581 } 1546 1582 1547 1583 // Filter & return 1548 1584 return (int) apply_filters( 'bbp_get_reply_to', $reply_to, $reply_id ); 1549 }1585 } 1550 1586 1551 1587 /** … … 1560 1596 } 1561 1597 1562 /**1563 * Return the link for a reply to a reply1564 *1565 * @since 2.4.0 bbPress (r4944)1566 *1567 * @param array $args Arguments1568 * @return string Link for a reply to a reply1569 */1570 function bbp_get_reply_to_link( $args = array() ) {1598 /** 1599 * Return the link for a reply to a reply 1600 * 1601 * @since 2.4.0 bbPress (r4944) 1602 * 1603 * @param array $args Arguments 1604 * @return string Link for a reply to a reply 1605 */ 1606 function bbp_get_reply_to_link( $args = array() ) { 1571 1607 1572 1608 // Parse arguments against default values 1573 1609 $r = bbp_parse_args( $args, array( 1574 'id'=> 0,1575 'link_before'=> '',1576 'link_after'=> '',1577 'reply_text'=> esc_html_x( 'Reply', 'verb', 'bbpress' ),1578 'depth'=> 0,1579 'add_below'=> 'post',1580 'respond_id'=> 'new-reply-' . bbp_get_topic_id(),1610 'id' => 0, 1611 'link_before' => '', 1612 'link_after' => '', 1613 'reply_text' => esc_html_x( 'Reply', 'verb', 'bbpress' ), 1614 'depth' => 0, 1615 'add_below' => 'post', 1616 'respond_id' => 'new-reply-' . bbp_get_topic_id(), 1581 1617 ), 'get_reply_to_link' ); 1582 1618 1583 // Get the reply to use it's ID and post_parent1584 $reply = bbp_get_reply( $r['id'] );1585 $topic_id = bbp_get_reply_topic_id( $reply->ID );1586 1587 // Bail if no reply or user cannot reply1588 if ( empty( $reply ) || empty( $topic_id ) || bbp_is_single_reply() || ! bbp_current_user_can_access_create_reply_form() ) {1589 return;1590 } 1591 1592 // Build the URI and return value1593 $uri = bbp_get_reply_url( $reply->ID );1594 $uri = strtok( $uri, '#' );1595 $uri = add_query_arg( array( 'bbp_reply_to' => $reply->ID ), $uri );1596 $uri = wp_nonce_url( $uri, 'respond_id_' . $reply->ID );1597 $uri = $uri . '#new-post';1598 1599 // Only add onclick if replies are threaded1600 if ( bbp_thread_replies() ) {1601 1602 // Array of classes to pass to moveForm1603 $move_form = array(1604 $r['add_below'] . '-' . $reply->ID,1605 $reply->ID,1606 $r['respond_id'],1607 $reply->post_parent1608 );1609 1610 // Build the onclick1611 $onclick= ' onclick="return addReply.moveForm(\'' . implode( "','", $move_form ) . '\');"';1619 // Get the reply to use it's ID and post_parent 1620 $reply = bbp_get_reply( $r['id'] ); 1621 $topic_id = bbp_get_reply_topic_id( $reply->ID ); 1622 1623 // Bail if no reply or user cannot reply 1624 if ( empty( $reply ) || empty( $topic_id ) || bbp_is_single_reply() || ! bbp_current_user_can_access_create_reply_form() ) { 1625 return; 1626 } 1627 1628 // Build the URI and return value 1629 $uri = bbp_get_reply_url( $reply->ID ); 1630 $uri = strtok( $uri, '#' ); 1631 $uri = add_query_arg( array( 'bbp_reply_to' => $reply->ID ), $uri ); 1632 $uri = wp_nonce_url( $uri, 'respond_id_' . $reply->ID ); 1633 $uri = $uri . '#new-post'; 1634 1635 // Only add onclick if replies are threaded 1636 if ( bbp_thread_replies() ) { 1637 1638 // Array of classes to pass to moveForm 1639 $move_form = array( 1640 $r['add_below'] . '-' . $reply->ID, 1641 $reply->ID, 1642 $r['respond_id'], 1643 $reply->post_parent 1644 ); 1645 1646 // Build the onclick 1647 $onclick = ' onclick="return addReply.moveForm(\'' . implode( "','", $move_form ) . '\');"'; 1612 1648 1613 1649 // No onclick if replies are not threaded 1614 1650 } else { 1615 $onclick= '';1616 } 1617 1618 // Add $uri to the array, to be passed through the filter1619 $r['uri'] = $uri;1620 $retval = $r['link_before'] . '<a role="button" href="' . esc_url( $r['uri'] ) . '" class="bbp-reply-to-link"' . $onclick . '>' . $r['reply_text'] . '</a>' . $r['link_after'];1621 1622 // Filter & return1623 return apply_filters( 'bbp_get_reply_to_link', $retval, $r, $args );1624 }1651 $onclick = ''; 1652 } 1653 1654 // Add $uri to the array, to be passed through the filter 1655 $r['uri'] = $uri; 1656 $retval = $r['link_before'] . '<a role="button" href="' . esc_url( $r['uri'] ) . '" class="bbp-reply-to-link"' . $onclick . '>' . $r['reply_text'] . '</a>' . $r['link_after']; 1657 1658 // Filter & return 1659 return apply_filters( 'bbp_get_reply_to_link', $retval, $r, $args ); 1660 } 1625 1661 1626 1662 /** … … 1632 1668 echo bbp_get_cancel_reply_to_link( $text ); 1633 1669 } 1634 /** 1635 * Return the cancellation link for a reply to a reply 1636 * 1637 * @since 2.4.0 bbPress (r4944) 1638 * 1639 * @param string $text The cancel text 1640 * @return string The cancellation link 1641 */ 1642 function bbp_get_cancel_reply_to_link( $text = '' ) { 1670 1671 /** 1672 * Return the cancellation link for a reply to a reply 1673 * 1674 * @since 2.4.0 bbPress (r4944) 1675 * 1676 * @param string $text The cancel text 1677 * @return string The cancellation link 1678 */ 1679 function bbp_get_cancel_reply_to_link( $text = '' ) { 1643 1680 1644 1681 // Bail if not hierarchical or editing a reply 1645 1682 if ( ! bbp_thread_replies() || bbp_is_reply_edit() ) { 1646 1683 return; 1647 }1684 } 1648 1685 1649 1686 // Set default text 1650 1687 if ( empty( $text ) ) { 1651 1688 $text = esc_html__( 'Cancel', 'bbpress' ); 1652 }1689 } 1653 1690 1654 1691 // Replying to... 1655 1692 $reply_to = isset( $_GET['bbp_reply_to'] ) 1656 ? (int) $_GET['bbp_reply_to']1657 : 0;1693 ? (int) $_GET['bbp_reply_to'] 1694 : 0; 1658 1695 1659 1696 // Set visibility … … 1664 1701 // Filter & return 1665 1702 return apply_filters( 'bbp_get_cancel_reply_to_link', $retval, $link, $text ); 1666 }1703 } 1667 1704 1668 1705 /** … … 1677 1714 echo bbp_get_reply_position( $reply_id, $topic_id ); 1678 1715 } 1679 /** 1680 * Return the numeric position of a reply within a topic 1681 * 1682 * @since 2.0.0 bbPress (r2984) 1683 * 1684 * @param int $reply_id Optional. Reply id 1685 * @param int $topic_id Optional. Topic id 1686 * @return int Reply position 1687 */ 1688 function bbp_get_reply_position( $reply_id = 0, $topic_id = 0 ) { 1716 1717 /** 1718 * Return the numeric position of a reply within a topic 1719 * 1720 * @since 2.0.0 bbPress (r2984) 1721 * 1722 * @param int $reply_id Optional. Reply id 1723 * @param int $topic_id Optional. Topic id 1724 * @return int Reply position 1725 */ 1726 function bbp_get_reply_position( $reply_id = 0, $topic_id = 0 ) { 1689 1727 1690 1728 // Get required data … … 1708 1746 if ( ! empty( $reply_position ) ) { 1709 1747 bbp_update_reply_position( $reply_id, $reply_position ); 1710 }1748 } 1711 1749 1712 1750 // Topic's position is always 0 1713 1751 } else { 1714 $reply_position = 0;1752 $reply_position = 0; 1715 1753 } 1716 1754 } … … 1719 1757 if ( ! bbp_show_lead_topic() ) { 1720 1758 $reply_position++; 1721 }1759 } 1722 1760 1723 1761 // Filter & return 1724 1762 return (int) apply_filters( 'bbp_get_reply_position', $reply_position, $reply_id, $topic_id ); 1725 }1763 } 1726 1764 1727 1765 /** Reply Admin Links *********************************************************/ … … 1737 1775 echo bbp_get_reply_admin_links( $args ); 1738 1776 } 1739 /** 1740 * Return admin links for reply 1741 * 1742 * @since 2.0.0 bbPress (r2667) 1743 * 1744 * @param array $args This function supports these arguments: 1745 * - id: Optional. Reply id 1746 * - before: HTML before the links. Defaults to 1747 * '<span class="bbp-admin-links">' 1748 * - after: HTML after the links. Defaults to '</span>' 1749 * - sep: Separator. Defaults to ' | ' 1750 * - links: Array of the links to display. By default, edit, trash, 1751 * spam, reply move, and topic split links are displayed 1752 * @return string Reply admin links 1753 */ 1754 function bbp_get_reply_admin_links( $args = array() ) { 1777 1778 /** 1779 * Return admin links for reply 1780 * 1781 * @since 2.0.0 bbPress (r2667) 1782 * 1783 * @param array $args This function supports these arguments: 1784 * - id: Optional. Reply id 1785 * - before: HTML before the links. Defaults to 1786 * '<span class="bbp-admin-links">' 1787 * - after: HTML after the links. Defaults to '</span>' 1788 * - sep: Separator. Defaults to ' | ' 1789 * - links: Array of the links to display. By default, edit, trash, 1790 * spam, reply move, and topic split links are displayed 1791 * @return string Reply admin links 1792 */ 1793 function bbp_get_reply_admin_links( $args = array() ) { 1755 1794 1756 1795 // Parse arguments against default values 1757 1796 $r = bbp_parse_args( $args, array( 1758 'id' => 0,1759 'before' => '<span class="bbp-admin-links">',1760 'after' => '</span>',1761 'sep' => ' | ',1762 'links' => array()1797 'id' => 0, 1798 'before' => '<span class="bbp-admin-links">', 1799 'after' => '</span>', 1800 'sep' => ' | ', 1801 'links' => array() 1763 1802 ), 'get_reply_admin_links' ); 1764 1803 1765 $r['id'] = bbp_get_reply_id( $r['id'] );1766 1767 // If post is a topic, return the topic admin links instead1768 if ( bbp_is_topic( $r['id'] ) ) {1769 return bbp_get_topic_admin_links( $args );1770 } 1771 1772 // If post is not a reply, return1773 if ( ! bbp_is_reply( $r['id'] ) ) {1774 return;1775 } 1776 1777 // If topic is trashed, do not show admin links1778 if ( bbp_is_topic_trash( bbp_get_reply_topic_id( $r['id'] ) ) ) {1779 return;1780 } 1781 1782 // If no links were passed, default to the standard1783 if ( empty( $r['links'] ) ) {1784 $r['links'] = apply_filters( 'bbp_reply_admin_links', array(1785 'edit' => bbp_get_reply_edit_link ( $r ),1786 'move' => bbp_get_reply_move_link ( $r ),1787 'split' => bbp_get_topic_split_link ( $r ),1788 'trash' => bbp_get_reply_trash_link ( $r ),1789 'spam' => bbp_get_reply_spam_link ( $r ),1790 'approve' => bbp_get_reply_approve_link( $r ),1791 'reply' => bbp_get_reply_to_link ( $r )1792 ), $r['id'] );1793 }1794 1795 // See if links need to be unset1796 $reply_status = bbp_get_reply_status( $r['id'] );1797 if ( in_array( $reply_status, array( bbp_get_spam_status_id(), bbp_get_trash_status_id(), bbp_get_pending_status_id() ), true ) ) {1798 1799 // Spam link shouldn't be visible on trashed topics1800 if ( bbp_get_trash_status_id() === $reply_status ) {1801 unset( $r['links']['spam'] );1804 $r['id'] = bbp_get_reply_id( $r['id'] ); 1805 1806 // If post is a topic, return the topic admin links instead 1807 if ( bbp_is_topic( $r['id'] ) ) { 1808 return bbp_get_topic_admin_links( $args ); 1809 } 1810 1811 // If post is not a reply, return 1812 if ( ! bbp_is_reply( $r['id'] ) ) { 1813 return; 1814 } 1815 1816 // If topic is trashed, do not show admin links 1817 if ( bbp_is_topic_trash( bbp_get_reply_topic_id( $r['id'] ) ) ) { 1818 return; 1819 } 1820 1821 // If no links were passed, default to the standard 1822 if ( empty( $r['links'] ) ) { 1823 $r['links'] = apply_filters( 'bbp_reply_admin_links', array( 1824 'edit' => bbp_get_reply_edit_link ( $r ), 1825 'move' => bbp_get_reply_move_link ( $r ), 1826 'split' => bbp_get_topic_split_link ( $r ), 1827 'trash' => bbp_get_reply_trash_link ( $r ), 1828 'spam' => bbp_get_reply_spam_link ( $r ), 1829 'approve' => bbp_get_reply_approve_link( $r ), 1830 'reply' => bbp_get_reply_to_link ( $r ) 1831 ), $r['id'] ); 1832 } 1833 1834 // See if links need to be unset 1835 $reply_status = bbp_get_reply_status( $r['id'] ); 1836 if ( in_array( $reply_status, array( bbp_get_spam_status_id(), bbp_get_trash_status_id(), bbp_get_pending_status_id() ), true ) ) { 1837 1838 // Spam link shouldn't be visible on trashed topics 1839 if ( bbp_get_trash_status_id() === $reply_status ) { 1840 unset( $r['links']['spam'] ); 1802 1841 1803 1842 // Trash link shouldn't be visible on spam topics 1804 1843 } elseif ( bbp_get_spam_status_id() === $reply_status ) { 1805 unset( $r['links']['trash'] );1844 unset( $r['links']['trash'] ); 1806 1845 } 1807 1846 } 1808 1847 1809 // Process the admin links1810 $links = implode( $r['sep'], array_filter( $r['links'] ) );1811 $retval = $r['before'] . $links . $r['after'];1812 1813 // Filter & return1814 return apply_filters( 'bbp_get_reply_admin_links', $retval, $r, $args );1815 }1848 // Process the admin links 1849 $links = implode( $r['sep'], array_filter( $r['links'] ) ); 1850 $retval = $r['before'] . $links . $r['after']; 1851 1852 // Filter & return 1853 return apply_filters( 'bbp_get_reply_admin_links', $retval, $r, $args ); 1854 } 1816 1855 1817 1856 /** … … 1826 1865 } 1827 1866 1828 /**1829 * Return the edit link of the reply1830 *1831 * @since 2.0.0 bbPress (r2740)1832 *1833 * @param array $args This function supports these arguments:1834 * - id: Reply id1835 * - link_before: HTML before the link1836 * - link_after: HTML after the link1837 * - edit_text: Edit text. Defaults to 'Edit'1838 * @return string Reply edit link1839 */1840 function bbp_get_reply_edit_link( $args = array() ) {1867 /** 1868 * Return the edit link of the reply 1869 * 1870 * @since 2.0.0 bbPress (r2740) 1871 * 1872 * @param array $args This function supports these arguments: 1873 * - id: Reply id 1874 * - link_before: HTML before the link 1875 * - link_after: HTML after the link 1876 * - edit_text: Edit text. Defaults to 'Edit' 1877 * @return string Reply edit link 1878 */ 1879 function bbp_get_reply_edit_link( $args = array() ) { 1841 1880 1842 1881 // Parse arguments against default values 1843 1882 $r = bbp_parse_args( $args, array( 1844 'id' => 0,1845 'link_before' => '',1846 'link_after' => '',1847 'edit_text' => esc_html__( 'Edit', 'bbpress' )1883 'id' => 0, 1884 'link_before' => '', 1885 'link_after' => '', 1886 'edit_text' => esc_html__( 'Edit', 'bbpress' ) 1848 1887 ), 'get_reply_edit_link' ); 1849 1888 1850 // Get reply 1851 $reply = bbp_get_reply( $r['id'] ); 1852 1853 // Bypass check if user has caps 1854 if ( ! current_user_can( 'edit_others_replies' ) ) { 1855 1856 // User cannot edit or it is past the lock time 1857 if ( empty( $reply ) || ! current_user_can( 'edit_reply', $reply->ID ) || bbp_past_edit_lock( $reply->post_date_gmt ) ) { 1889 // Get reply 1890 $reply = bbp_get_reply( $r['id'] ); 1891 1892 // Bypass check if user has caps 1893 if ( ! current_user_can( 'edit_others_replies' ) ) { 1894 1895 // User cannot edit or it is past the lock time 1896 if ( empty( $reply ) || ! current_user_can( 'edit_reply', $reply->ID ) || bbp_past_edit_lock( $reply->post_date_gmt ) ) { 1897 return; 1898 } 1899 } 1900 1901 // Get uri 1902 $uri = bbp_get_reply_edit_url( $r['id'] ); 1903 1904 // Bail if no uri 1905 if ( empty( $uri ) ) { 1858 1906 return; 1859 } 1860 } 1861 1862 // Get uri 1863 $uri = bbp_get_reply_edit_url( $r['id'] ); 1864 1865 // Bail if no uri 1866 if ( empty( $uri ) ) { 1867 return; 1868 } 1869 1870 $retval = $r['link_before'] . '<a href="' . esc_url( $uri ) . '" class="bbp-reply-edit-link">' . $r['edit_text'] . '</a>' . $r['link_after']; 1871 1872 // Filter & return 1873 return apply_filters( 'bbp_get_reply_edit_link', $retval, $r, $args ); 1874 } 1907 } 1908 1909 $retval = $r['link_before'] . '<a href="' . esc_url( $uri ) . '" class="bbp-reply-edit-link">' . $r['edit_text'] . '</a>' . $r['link_after']; 1910 1911 // Filter & return 1912 return apply_filters( 'bbp_get_reply_edit_link', $retval, $r, $args ); 1913 } 1875 1914 1876 1915 /** … … 1884 1923 echo esc_url( bbp_get_reply_edit_url( $reply_id ) ); 1885 1924 } 1886 /** 1887 * Return URL to the reply edit page 1888 * 1889 * @since 2.0.0 bbPress (r2753) 1890 * 1891 * @param int $reply_id Optional. Reply id 1892 * @return string Reply edit url 1893 */ 1894 function bbp_get_reply_edit_url( $reply_id = 0 ) { 1925 1926 /** 1927 * Return URL to the reply edit page 1928 * 1929 * @since 2.0.0 bbPress (r2753) 1930 * 1931 * @param int $reply_id Optional. Reply id 1932 * @return string Reply edit url 1933 */ 1934 function bbp_get_reply_edit_url( $reply_id = 0 ) { 1895 1935 1896 1936 // Bail if no reply … … 1898 1938 if ( empty( $reply ) ) { 1899 1939 return; 1900 }1940 } 1901 1941 1902 1942 $reply_link = bbp_remove_view_all( bbp_get_reply_permalink( $reply_id ) ); … … 1908 1948 $url = user_trailingslashit( $url ); 1909 1949 1910 // Unpretty permalinks1911 } else {1950 // Unpretty permalinks 1951 } else { 1912 1952 $url = add_query_arg( array( 1913 bbp_get_reply_post_type() => $reply->post_name,1914 bbp_get_edit_rewrite_id() => '1'1953 bbp_get_reply_post_type() => $reply->post_name, 1954 bbp_get_edit_rewrite_id() => '1' 1915 1955 ), $reply_link ); 1916 }1956 } 1917 1957 1918 1958 // Maybe add view all … … 1921 1961 // Filter & return 1922 1962 return apply_filters( 'bbp_get_reply_edit_url', $url, $reply_id ); 1923 }1963 } 1924 1964 1925 1965 /** … … 1934 1974 } 1935 1975 1936 /**1937 * Return the trash link of the reply1938 *1939 * @since 2.0.0 bbPress (r2740)1940 *1941 * @param array $args This function supports these arguments:1942 * - id: Reply id1943 * - link_before: HTML before the link1944 * - link_after: HTML after the link1945 * - sep: Separator1946 * - trash_text: Trash text1947 * - restore_text: Restore text1948 * - delete_text: Delete text1949 * @return string Reply trash link1950 */1951 function bbp_get_reply_trash_link( $args = array() ) {1976 /** 1977 * Return the trash link of the reply 1978 * 1979 * @since 2.0.0 bbPress (r2740) 1980 * 1981 * @param array $args This function supports these arguments: 1982 * - id: Reply id 1983 * - link_before: HTML before the link 1984 * - link_after: HTML after the link 1985 * - sep: Separator 1986 * - trash_text: Trash text 1987 * - restore_text: Restore text 1988 * - delete_text: Delete text 1989 * @return string Reply trash link 1990 */ 1991 function bbp_get_reply_trash_link( $args = array() ) { 1952 1992 1953 1993 // Parse arguments against default values 1954 1994 $r = bbp_parse_args( $args, array( 1955 'id' => 0,1956 'link_before' => '',1957 'link_after' => '',1958 'sep' => ' | ',1959 'trash_text' => esc_html__( 'Trash', 'bbpress' ),1960 'restore_text' => esc_html__( 'Restore', 'bbpress' ),1961 'delete_text' => esc_html__( 'Delete', 'bbpress' )1995 'id' => 0, 1996 'link_before' => '', 1997 'link_after' => '', 1998 'sep' => ' | ', 1999 'trash_text' => esc_html__( 'Trash', 'bbpress' ), 2000 'restore_text' => esc_html__( 'Restore', 'bbpress' ), 2001 'delete_text' => esc_html__( 'Delete', 'bbpress' ) 1962 2002 ), 'get_reply_trash_link' ); 1963 2003 1964 // Get reply1965 $reply = bbp_get_reply( $r['id'] );1966 1967 // Bail if no reply or current user cannot delete1968 if ( empty( $reply ) || ! current_user_can( 'delete_reply', $reply->ID ) ) {1969 return;1970 } 1971 1972 $actions = array();1973 $trash_days = bbp_get_trash_days( bbp_get_reply_post_type() );1974 1975 // Trashed1976 if ( bbp_is_reply_trash( $reply->ID ) ) {1977 $actions['untrash'] = '<a title="' . esc_attr__( 'Restore this item from the Trash', 'bbpress' ) . '" href="' . esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'bbp_toggle_reply_trash', 'sub_action' => 'untrash', 'reply_id' => $reply->ID ) ), 'untrash-' . $reply->post_type . '_' . $reply->ID ) ) . '" class="bbp-reply-restore-link">' . $r['restore_text'] . '</a>';2004 // Get reply 2005 $reply = bbp_get_reply( $r['id'] ); 2006 2007 // Bail if no reply or current user cannot delete 2008 if ( empty( $reply ) || ! current_user_can( 'delete_reply', $reply->ID ) ) { 2009 return; 2010 } 2011 2012 $actions = array(); 2013 $trash_days = bbp_get_trash_days( bbp_get_reply_post_type() ); 2014 2015 // Trashed 2016 if ( bbp_is_reply_trash( $reply->ID ) ) { 2017 $actions['untrash'] = '<a title="' . esc_attr__( 'Restore this item from the Trash', 'bbpress' ) . '" href="' . esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'bbp_toggle_reply_trash', 'sub_action' => 'untrash', 'reply_id' => $reply->ID ) ), 'untrash-' . $reply->post_type . '_' . $reply->ID ) ) . '" class="bbp-reply-restore-link">' . $r['restore_text'] . '</a>'; 1978 2018 1979 2019 // Trash 1980 2020 } elseif ( ! empty( $trash_days ) ) { 1981 $actions['trash'] = '<a title="' . esc_attr__( 'Move this item to the Trash', 'bbpress' ) . '" href="' . esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'bbp_toggle_reply_trash', 'sub_action' => 'trash', 'reply_id' => $reply->ID ) ), 'trash-' . $reply->post_type . '_' . $reply->ID ) ) . '" class="bbp-reply-trash-link">' . $r['trash_text'] . '</a>';1982 } 1983 1984 // No trash1985 if ( bbp_is_reply_trash( $reply->ID ) || empty( $trash_days ) ) {1986 $actions['delete'] = '<a title="' . esc_attr__( 'Delete this item permanently', 'bbpress' ) . '" href="' . esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'bbp_toggle_reply_trash', 'sub_action' => 'delete', 'reply_id' => $reply->ID ) ), 'delete-' . $reply->post_type . '_' . $reply->ID ) ) . '" onclick="return confirm(\'' . esc_js( __( 'Are you sure you want to delete that permanently?', 'bbpress' ) ) . '\' );" class="bbp-reply-delete-link">' . $r['delete_text'] . '</a>';1987 } 1988 1989 // Process the admin links1990 $retval = $r['link_before'] . implode( $r['sep'], $actions ) . $r['link_after'];1991 1992 // Filter & return1993 return apply_filters( 'bbp_get_reply_trash_link', $retval, $r, $args );1994 }2021 $actions['trash'] = '<a title="' . esc_attr__( 'Move this item to the Trash', 'bbpress' ) . '" href="' . esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'bbp_toggle_reply_trash', 'sub_action' => 'trash', 'reply_id' => $reply->ID ) ), 'trash-' . $reply->post_type . '_' . $reply->ID ) ) . '" class="bbp-reply-trash-link">' . $r['trash_text'] . '</a>'; 2022 } 2023 2024 // No trash 2025 if ( bbp_is_reply_trash( $reply->ID ) || empty( $trash_days ) ) { 2026 $actions['delete'] = '<a title="' . esc_attr__( 'Delete this item permanently', 'bbpress' ) . '" href="' . esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'bbp_toggle_reply_trash', 'sub_action' => 'delete', 'reply_id' => $reply->ID ) ), 'delete-' . $reply->post_type . '_' . $reply->ID ) ) . '" onclick="return confirm(\'' . esc_js( __( 'Are you sure you want to delete that permanently?', 'bbpress' ) ) . '\' );" class="bbp-reply-delete-link">' . $r['delete_text'] . '</a>'; 2027 } 2028 2029 // Process the admin links 2030 $retval = $r['link_before'] . implode( $r['sep'], $actions ) . $r['link_after']; 2031 2032 // Filter & return 2033 return apply_filters( 'bbp_get_reply_trash_link', $retval, $r, $args ); 2034 } 1995 2035 1996 2036 /** … … 2005 2045 } 2006 2046 2007 /**2008 * Return the spam link of the reply2009 *2010 * @since 2.0.0 bbPress (r2740)2011 *2012 * @param array $args This function supports these arguments:2013 * - id: Reply id2014 * - link_before: HTML before the link2015 * - link_after: HTML after the link2016 * - spam_text: Spam text2017 * - unspam_text: Unspam text2018 * @return string Reply spam link2019 */2020 function bbp_get_reply_spam_link( $args = array() ) {2047 /** 2048 * Return the spam link of the reply 2049 * 2050 * @since 2.0.0 bbPress (r2740) 2051 * 2052 * @param array $args This function supports these arguments: 2053 * - id: Reply id 2054 * - link_before: HTML before the link 2055 * - link_after: HTML after the link 2056 * - spam_text: Spam text 2057 * - unspam_text: Unspam text 2058 * @return string Reply spam link 2059 */ 2060 function bbp_get_reply_spam_link( $args = array() ) { 2021 2061 2022 2062 // Parse arguments against default values 2023 2063 $r = bbp_parse_args( $args, array( 2024 'id' => 0,2025 'link_before' => '',2026 'link_after' => '',2027 'spam_text' => esc_html__( 'Spam', 'bbpress' ),2028 'unspam_text' => esc_html__( 'Unspam', 'bbpress' )2064 'id' => 0, 2065 'link_before' => '', 2066 'link_after' => '', 2067 'spam_text' => esc_html__( 'Spam', 'bbpress' ), 2068 'unspam_text' => esc_html__( 'Unspam', 'bbpress' ) 2029 2069 ), 'get_reply_spam_link' ); 2030 2070 2031 // Get reply2032 $reply = bbp_get_reply( $r['id'] );2033 2034 // Bail if no reply or current user cannot moderate2035 if ( empty( $reply ) || ! current_user_can( 'moderate', $reply->ID ) ) {2036 return;2037 } 2038 2039 $display = bbp_is_reply_spam( $reply->ID ) ? $r['unspam_text'] : $r['spam_text'];2040 $uri = add_query_arg( array( 'action' => 'bbp_toggle_reply_spam', 'reply_id' => $reply->ID ) );2041 $uri = wp_nonce_url( $uri, 'spam-reply_' . $reply->ID );2042 $retval = $r['link_before'] . '<a href="' . esc_url( $uri ) . '" class="bbp-reply-spam-link">' . $display . '</a>' . $r['link_after'];2043 2044 // Filter & return2045 return apply_filters( 'bbp_get_reply_spam_link', $retval, $r, $args );2046 }2071 // Get reply 2072 $reply = bbp_get_reply( $r['id'] ); 2073 2074 // Bail if no reply or current user cannot moderate 2075 if ( empty( $reply ) || ! current_user_can( 'moderate', $reply->ID ) ) { 2076 return; 2077 } 2078 2079 $display = bbp_is_reply_spam( $reply->ID ) ? $r['unspam_text'] : $r['spam_text']; 2080 $uri = add_query_arg( array( 'action' => 'bbp_toggle_reply_spam', 'reply_id' => $reply->ID ) ); 2081 $uri = wp_nonce_url( $uri, 'spam-reply_' . $reply->ID ); 2082 $retval = $r['link_before'] . '<a href="' . esc_url( $uri ) . '" class="bbp-reply-spam-link">' . $display . '</a>' . $r['link_after']; 2083 2084 // Filter & return 2085 return apply_filters( 'bbp_get_reply_spam_link', $retval, $r, $args ); 2086 } 2047 2087 2048 2088 /** … … 2059 2099 } 2060 2100 2061 /**2062 * Get move reply link2063 *2064 * Return the move link of the reply2065 *2066 * @since 2.3.0 bbPress (r4521)2067 *2068 * @param array $args This function supports these arguments:2069 * - id: Reply id2070 * - link_before: HTML before the link2071 * - link_after: HTML after the link2072 * - move_text: Move text2073 * - move_title: Move title attribute2074 * @return string Reply move link2075 */2076 function bbp_get_reply_move_link( $args = array() ) {2101 /** 2102 * Get move reply link 2103 * 2104 * Return the move link of the reply 2105 * 2106 * @since 2.3.0 bbPress (r4521) 2107 * 2108 * @param array $args This function supports these arguments: 2109 * - id: Reply id 2110 * - link_before: HTML before the link 2111 * - link_after: HTML after the link 2112 * - move_text: Move text 2113 * - move_title: Move title attribute 2114 * @return string Reply move link 2115 */ 2116 function bbp_get_reply_move_link( $args = array() ) { 2077 2117 2078 2118 // Parse arguments against default values 2079 2119 $r = bbp_parse_args( $args, array( 2080 'id' => 0,2081 'link_before' => '',2082 'link_after' => '',2083 'split_text' => esc_html__( 'Move', 'bbpress' ),2084 'split_title' => esc_attr__( 'Move this reply', 'bbpress' )2120 'id' => 0, 2121 'link_before' => '', 2122 'link_after' => '', 2123 'split_text' => esc_html__( 'Move', 'bbpress' ), 2124 'split_title' => esc_attr__( 'Move this reply', 'bbpress' ) 2085 2125 ), 'get_reply_move_link' ); 2086 2126 2087 // Get IDs2088 $reply_id = bbp_get_reply_id( $r['id'] );2089 $topic_id = bbp_get_reply_topic_id( $reply_id );2090 2091 // Bail if no reply ID or user cannot moderate2092 if ( empty( $reply_id ) || ! current_user_can( 'moderate', $topic_id ) ) {2093 return;2094 } 2095 2096 $uri = add_query_arg( array(2097 'action' => 'move',2098 'reply_id' => $reply_id2099 ), bbp_get_reply_edit_url( $reply_id ) );2100 2101 $retval = $r['link_before'] . '<a href="' . esc_url( $uri ) . '" title="' . $r['split_title'] . '" class="bbp-reply-move-link">' . $r['split_text'] . '</a>' . $r['link_after'];2102 2103 // Filter & return2104 return apply_filters( 'bbp_get_reply_move_link', $retval, $r, $args );2105 }2127 // Get IDs 2128 $reply_id = bbp_get_reply_id( $r['id'] ); 2129 $topic_id = bbp_get_reply_topic_id( $reply_id ); 2130 2131 // Bail if no reply ID or user cannot moderate 2132 if ( empty( $reply_id ) || ! current_user_can( 'moderate', $topic_id ) ) { 2133 return; 2134 } 2135 2136 $uri = add_query_arg( array( 2137 'action' => 'move', 2138 'reply_id' => $reply_id 2139 ), bbp_get_reply_edit_url( $reply_id ) ); 2140 2141 $retval = $r['link_before'] . '<a href="' . esc_url( $uri ) . '" title="' . $r['split_title'] . '" class="bbp-reply-move-link">' . $r['split_text'] . '</a>' . $r['link_after']; 2142 2143 // Filter & return 2144 return apply_filters( 'bbp_get_reply_move_link', $retval, $r, $args ); 2145 } 2106 2146 2107 2147 /** … … 2118 2158 } 2119 2159 2120 /**2121 * Get split topic link2122 *2123 * Return the split link of the topic (but is bundled with each reply)2124 *2125 * @since 2.0.0 bbPress (r2756)2126 *2127 * @param array $args This function supports these arguments:2128 * - id: Reply id2129 * - link_before: HTML before the link2130 * - link_after: HTML after the link2131 * - split_text: Split text2132 * - split_title: Split title attribute2133 * @return string Topic split link2134 */2135 function bbp_get_topic_split_link( $args = array() ) {2160 /** 2161 * Get split topic link 2162 * 2163 * Return the split link of the topic (but is bundled with each reply) 2164 * 2165 * @since 2.0.0 bbPress (r2756) 2166 * 2167 * @param array $args This function supports these arguments: 2168 * - id: Reply id 2169 * - link_before: HTML before the link 2170 * - link_after: HTML after the link 2171 * - split_text: Split text 2172 * - split_title: Split title attribute 2173 * @return string Topic split link 2174 */ 2175 function bbp_get_topic_split_link( $args = array() ) { 2136 2176 2137 2177 // Parse arguments against default values 2138 2178 $r = bbp_parse_args( $args, array( 2139 'id' => 0,2140 'link_before' => '',2141 'link_after' => '',2142 'split_text' => esc_html__( 'Split', 'bbpress' ),2143 'split_title' => esc_attr__( 'Split the topic from this reply', 'bbpress' )2179 'id' => 0, 2180 'link_before' => '', 2181 'link_after' => '', 2182 'split_text' => esc_html__( 'Split', 'bbpress' ), 2183 'split_title' => esc_attr__( 'Split the topic from this reply', 'bbpress' ) 2144 2184 ), 'get_topic_split_link' ); 2145 2185 2146 // Get IDs2147 $reply_id = bbp_get_reply_id( $r['id'] );2148 $topic_id = bbp_get_reply_topic_id( $reply_id );2149 2150 // Bail if no reply/topic ID, or user cannot moderate2151 if ( empty( $reply_id ) || empty( $topic_id ) || ! current_user_can( 'moderate', $topic_id ) ) {2152 return;2153 } 2154 2155 $uri = add_query_arg( array(2156 'action' => 'split',2157 'reply_id' => $reply_id2158 ), bbp_get_topic_edit_url( $topic_id ) );2159 2160 $retval = $r['link_before'] . '<a href="' . esc_url( $uri ) . '" title="' . $r['split_title'] . '" class="bbp-topic-split-link">' . $r['split_text'] . '</a>' . $r['link_after'];2161 2162 // Filter & return2163 return apply_filters( 'bbp_get_topic_split_link', $retval, $r, $args );2164 }2186 // Get IDs 2187 $reply_id = bbp_get_reply_id( $r['id'] ); 2188 $topic_id = bbp_get_reply_topic_id( $reply_id ); 2189 2190 // Bail if no reply/topic ID, or user cannot moderate 2191 if ( empty( $reply_id ) || empty( $topic_id ) || ! current_user_can( 'moderate', $topic_id ) ) { 2192 return; 2193 } 2194 2195 $uri = add_query_arg( array( 2196 'action' => 'split', 2197 'reply_id' => $reply_id 2198 ), bbp_get_topic_edit_url( $topic_id ) ); 2199 2200 $retval = $r['link_before'] . '<a href="' . esc_url( $uri ) . '" title="' . $r['split_title'] . '" class="bbp-topic-split-link">' . $r['split_text'] . '</a>' . $r['link_after']; 2201 2202 // Filter & return 2203 return apply_filters( 'bbp_get_topic_split_link', $retval, $r, $args ); 2204 } 2165 2205 2166 2206 /** … … 2175 2215 } 2176 2216 2177 /**2178 * Return the approve link of the reply2179 *2180 * @since 2.6.0 bbPress (r5507)2181 *2182 * @param array $args This function supports these args:2183 * - id: Optional. Reply id2184 * - link_before: Before the link2185 * - link_after: After the link2186 * - sep: Separator between links2187 * - approve_text: Approve text2188 * - unapprove_text: Unapprove text2189 * @return string Reply approve link2190 */2191 function bbp_get_reply_approve_link( $args = array() ) {2217 /** 2218 * Return the approve link of the reply 2219 * 2220 * @since 2.6.0 bbPress (r5507) 2221 * 2222 * @param array $args This function supports these args: 2223 * - id: Optional. Reply id 2224 * - link_before: Before the link 2225 * - link_after: After the link 2226 * - sep: Separator between links 2227 * - approve_text: Approve text 2228 * - unapprove_text: Unapprove text 2229 * @return string Reply approve link 2230 */ 2231 function bbp_get_reply_approve_link( $args = array() ) { 2192 2232 2193 2233 // Parse arguments against default values 2194 2234 $r = bbp_parse_args( $args, array( 2195 'id' => 0,2196 'link_before' => '',2197 'link_after' => '',2198 'sep' => ' | ',2199 'approve_text' => _x( 'Approve', 'Pending Status', 'bbpress' ),2200 'unapprove_text' => _x( 'Unapprove', 'Pending Status', 'bbpress' )2235 'id' => 0, 2236 'link_before' => '', 2237 'link_after' => '', 2238 'sep' => ' | ', 2239 'approve_text' => _x( 'Approve', 'Pending Status', 'bbpress' ), 2240 'unapprove_text' => _x( 'Unapprove', 'Pending Status', 'bbpress' ) 2201 2241 ), 'get_reply_approve_link' ); 2202 2242 2203 // Get reply2204 $reply = bbp_get_reply( $r['id'] );2205 2206 // Bail if no reply or current user cannot moderate2207 if ( empty( $reply ) || ! current_user_can( 'moderate', $reply->ID ) ) {2208 return;2209 } 2210 2211 $display = bbp_is_reply_pending( $reply->ID ) ? $r['approve_text'] : $r['unapprove_text'];2212 $uri = add_query_arg( array( 'action' => 'bbp_toggle_reply_approve', 'reply_id' => $reply->ID ) );2213 $uri = wp_nonce_url( $uri, 'approve-reply_' . $reply->ID );2214 $retval = $r['link_before'] . '<a href="' . esc_url( $uri ) . '" class="bbp-reply-approve-link">' . $display . '</a>' . $r['link_after'];2215 2216 // Filter & return2217 return apply_filters( 'bbp_get_reply_approve_link', $retval, $r, $args );2218 }2243 // Get reply 2244 $reply = bbp_get_reply( $r['id'] ); 2245 2246 // Bail if no reply or current user cannot moderate 2247 if ( empty( $reply ) || ! current_user_can( 'moderate', $reply->ID ) ) { 2248 return; 2249 } 2250 2251 $display = bbp_is_reply_pending( $reply->ID ) ? $r['approve_text'] : $r['unapprove_text']; 2252 $uri = add_query_arg( array( 'action' => 'bbp_toggle_reply_approve', 'reply_id' => $reply->ID ) ); 2253 $uri = wp_nonce_url( $uri, 'approve-reply_' . $reply->ID ); 2254 $retval = $r['link_before'] . '<a href="' . esc_url( $uri ) . '" class="bbp-reply-approve-link">' . $display . '</a>' . $r['link_after']; 2255 2256 // Filter & return 2257 return apply_filters( 'bbp_get_reply_approve_link', $retval, $r, $args ); 2258 } 2219 2259 2220 2260 /** … … 2229 2269 echo bbp_get_reply_class( $reply_id, $classes ); 2230 2270 } 2231 /** 2232 * Return the row class of a reply 2233 * 2234 * @since 2.0.0 bbPress (r2678) 2235 * 2236 * @param int $reply_id Optional. Reply ID 2237 * @param array Extra classes you can pass when calling this function 2238 * @return string Row class of the reply 2239 */ 2240 function bbp_get_reply_class( $reply_id = 0, $classes = array() ) { 2271 2272 /** 2273 * Return the row class of a reply 2274 * 2275 * @since 2.0.0 bbPress (r2678) 2276 * 2277 * @param int $reply_id Optional. Reply ID 2278 * @param array Extra classes you can pass when calling this function 2279 * @return string Row class of the reply 2280 */ 2281 function bbp_get_reply_class( $reply_id = 0, $classes = array() ) { 2241 2282 $bbp = bbpress(); 2242 2283 $reply_id = bbp_get_reply_id( $reply_id ); … … 2247 2288 $classes = array_filter( (array) $classes ); 2248 2289 $count = isset( $bbp->reply_query->current_post ) 2249 ? (int) $bbp->reply_query->current_post2250 : 1;2290 ? (int) $bbp->reply_query->current_post 2291 : 1; 2251 2292 2252 2293 // Stripes 2253 2294 $even_odd = ( $count % 2 ) 2254 ? 'even'2255 : 'odd';2295 ? 'even' 2296 : 'odd'; 2256 2297 2257 2298 // Forum moderator replied to topic 2258 2299 $forum_moderator = ( bbp_is_user_forum_moderator( $author_id, $forum_id ) === $author_id ) 2259 ? 'forum-mod'2260 : '';2300 ? 'forum-mod' 2301 : ''; 2261 2302 2262 2303 // Topic author replied to others 2263 2304 $topic_author = ( bbp_get_topic_author_id( $topic_id ) === $author_id ) 2264 ? 'topic-author'2265 : '';2305 ? 'topic-author' 2306 : ''; 2266 2307 2267 2308 // Get reply classes 2268 2309 $reply_classes = array( 2269 'loop-item-' . $count,2270 'user-id-' . $author_id,2271 'bbp-parent-forum-' . $forum_id,2272 'bbp-parent-topic-' . $topic_id,2273 'bbp-reply-position-' . $reply_pos,2274 $even_odd,2275 $topic_author,2276 $forum_moderator2310 'loop-item-' . $count, 2311 'user-id-' . $author_id, 2312 'bbp-parent-forum-' . $forum_id, 2313 'bbp-parent-topic-' . $topic_id, 2314 'bbp-reply-position-' . $reply_pos, 2315 $even_odd, 2316 $topic_author, 2317 $forum_moderator 2277 2318 ); 2278 2319 … … 2286 2327 // Return 2287 2328 return 'class="' . implode( ' ', $new_classes ) . '"'; 2288 }2329 } 2289 2330 2290 2331 /** Pagination ****************************************************************/ … … 2343 2384 echo bbp_get_topic_pagination_count(); 2344 2385 } 2345 /** 2346 * Return the topic pagination count 2347 * 2348 * @since 2.0.0 bbPress (r2519) 2349 * 2350 * @return string Topic pagination count 2351 */ 2352 function bbp_get_topic_pagination_count() { 2386 2387 /** 2388 * Return the topic pagination count 2389 * 2390 * @since 2.0.0 bbPress (r2519) 2391 * 2392 * @return string Topic pagination count 2393 */ 2394 function bbp_get_topic_pagination_count() { 2353 2395 $bbp = bbpress(); 2354 2396 … … 2362 2404 $start_int = intval( ( $bbp->reply_query->paged - 1 ) * $ppp_int ) + 1; 2363 2405 $to_int = intval( ( $start_int + ( $ppp_int - 1 ) > $total_int ) 2364 ? $total_int 2365 : $start_int + ( $ppp_int - 1 ) ); 2366 2367 // Format numbers for display 2368 $count_num = bbp_number_format( $count_int ); 2369 $total_num = bbp_number_format( $total_int ); 2370 $from_num = bbp_number_format( $start_int ); 2371 $to_num = bbp_number_format( $to_int ); 2372 2373 // We are threading replies 2374 if ( bbp_thread_replies() ) { 2375 $walker = new BBP_Walker_Reply(); 2376 $threads = absint( $walker->get_number_of_root_elements( $bbp->reply_query->posts ) - 1 ); 2377 $retstr = sprintf( _n( 'Viewing %1$s reply thread', 'Viewing %1$s reply threads', $threads, 'bbpress' ), bbp_number_format( $threads ) ); 2406 ? $total_int 2407 : $start_int + ( $ppp_int - 1 ) ); 2408 2409 // Format numbers for display 2410 $count_num = bbp_number_format( $count_int ); 2411 $total_num = bbp_number_format( $total_int ); 2412 $from_num = bbp_number_format( $start_int ); 2413 $to_num = bbp_number_format( $to_int ); 2414 2415 // We are threading replies 2416 if ( bbp_thread_replies() ) { 2417 $walker = new BBP_Walker_Reply(); 2418 $threads = absint( $walker->get_number_of_root_elements( $bbp->reply_query->posts ) - 1 ); 2419 /* translators: %s: Number of reply threads */ 2420 $retstr = sprintf( _n( 'Viewing %1$s reply thread', 'Viewing %1$s reply threads', $threads, 'bbpress' ), bbp_number_format( $threads ) ); 2378 2421 2379 2422 // We are not including the lead topic 2380 2423 } elseif ( bbp_show_lead_topic() ) { 2381 2424 2382 // Several replies in a topic with a single page 2383 if ( empty( $to_num ) ) { 2384 $retstr = sprintf( _n( 'Viewing %1$s reply', 'Viewing %1$s replies', $total_int, 'bbpress' ), $total_num ); 2425 // Several replies in a topic with a single page 2426 if ( empty( $to_num ) ) { 2427 /* translators: %1$s: Number of replies */ 2428 $retstr = sprintf( _n( 'Viewing %1$s reply', 'Viewing %1$s replies', $total_int, 'bbpress' ), $total_num ); 2385 2429 2386 2430 // Several replies in a topic with several pages 2387 2431 } else { 2388 $retstr = sprintf( _n( 'Viewing %2$s replies (of %4$s total)', 'Viewing %1$s replies - %2$s through %3$s (of %4$s total)', $count_int, 'bbpress' ), $count_num, $from_num, $to_num, $total_num ); //phpcs:ignore 2432 /* translators: 1: Number of replies being viewed, 2: Starting reply number, 3: Ending reply number, 4: Total replies */ 2433 $retstr = sprintf( _n( 'Viewing %2$s replies (of %4$s total)', 'Viewing %1$s replies - %2$s through %3$s (of %4$s total)', $count_int, 'bbpress' ), $count_num, $from_num, $to_num, $total_num ); //phpcs:ignore 2389 2434 } 2390 2435 … … 2392 2437 } else { 2393 2438 2394 // Several posts in a topic with a single page 2395 if ( empty( $to_num ) ) { 2439 // Several posts in a topic with a single page 2440 if ( empty( $to_num ) ) { 2441 /* translators: %1$s: Number of posts */ 2396 2442 $retstr = sprintf( _n( 'Viewing %1$s post', 'Viewing %1$s posts', $total_int, 'bbpress' ), $total_num ); 2397 2443 2398 // Several posts in a topic with several pages 2399 } else { 2400 $retstr = sprintf( _n( 'Viewing %2$s post (of %4$s total)', 'Viewing %1$s posts - %2$s through %3$s (of %4$s total)', $count_int, 'bbpress' ), $count_num, $from_num, $to_num, $total_num ); //phpcs:ignore 2444 // Several posts in a topic with several pages 2445 } else { 2446 /* translators: 1: Number of posts being viewed, 2: Starting post number, 3: Ending post number, 4: Total posts */ 2447 $retstr = sprintf( _n( 'Viewing %2$s post (of %4$s total)', 'Viewing %1$s posts - %2$s through %3$s (of %4$s total)', $count_int, 'bbpress' ), $count_num, $from_num, $to_num, $total_num ); //phpcs:ignore 2401 2448 } 2402 2449 } 2403 2450 2404 // Escape results of _n()2405 $retstr = esc_html( $retstr );2406 2407 // Filter & return2408 return apply_filters( 'bbp_get_topic_pagination_count', $retstr );2409 }2451 // Escape results of _n() 2452 $retstr = esc_html( $retstr ); 2453 2454 // Filter & return 2455 return apply_filters( 'bbp_get_topic_pagination_count', $retstr ); 2456 } 2410 2457 2411 2458 /** … … 2417 2464 echo bbp_get_topic_pagination_links(); 2418 2465 } 2419 /** 2420 * Return topic pagination links 2421 * 2422 * @since 2.0.0 bbPress (r2519) 2423 * 2424 * @return string Topic pagination links 2425 */ 2426 function bbp_get_topic_pagination_links() { 2466 2467 /** 2468 * Return topic pagination links 2469 * 2470 * @since 2.0.0 bbPress (r2519) 2471 * 2472 * @return string Topic pagination links 2473 */ 2474 function bbp_get_topic_pagination_links() { 2427 2475 $bbp = bbpress(); 2428 2476 2429 2477 if ( ! isset( $bbp->reply_query->pagination_links ) || empty( $bbp->reply_query->pagination_links ) ) { 2430 2478 return false; 2431 }2479 } 2432 2480 2433 2481 // Filter & return 2434 2482 return apply_filters( 'bbp_get_topic_pagination_links', $bbp->reply_query->pagination_links ); 2435 }2483 } 2436 2484 2437 2485 /** Forms *********************************************************************/ … … 2445 2493 echo bbp_get_form_reply_content(); 2446 2494 } 2447 /** 2448 * Return the value of reply content field 2449 * 2450 * @since 2.0.0 bbPress (r3130) 2451 * 2452 * @return string Value of reply content field 2453 */ 2454 function bbp_get_form_reply_content() { 2495 2496 /** 2497 * Return the value of reply content field 2498 * 2499 * @since 2.0.0 bbPress (r3130) 2500 * 2501 * @return string Value of reply content field 2502 */ 2503 function bbp_get_form_reply_content() { 2455 2504 2456 2505 // Get _POST data … … 2458 2507 $reply_content = wp_unslash( $_POST['bbp_reply_content'] ); 2459 2508 2460 // Get edit data2461 } elseif ( bbp_is_reply_edit() ) {2509 // Get edit data 2510 } elseif ( bbp_is_reply_edit() ) { 2462 2511 $reply_content = bbp_get_global_post_field( 'post_content', 'raw' ); 2463 2512 2464 // No data2465 } else {2513 // No data 2514 } else { 2466 2515 $reply_content = ''; 2467 }2516 } 2468 2517 2469 2518 // Filter & return 2470 2519 return apply_filters( 'bbp_get_form_reply_content', $reply_content ); 2471 }2520 } 2472 2521 2473 2522 /** … … 2480 2529 } 2481 2530 2482 /**2483 * Return the value of reply to field2484 *2485 * @since 2.4.0 bbPress (r4944)2486 *2487 * @return string Value of reply to field2488 */2489 function bbp_get_form_reply_to() {2531 /** 2532 * Return the value of reply to field 2533 * 2534 * @since 2.4.0 bbPress (r4944) 2535 * 2536 * @return string Value of reply to field 2537 */ 2538 function bbp_get_form_reply_to() { 2490 2539 2491 2540 // Set initial value … … 2495 2544 if ( isset( $_REQUEST['bbp_reply_to'] ) ) { 2496 2545 $reply_to = bbp_validate_reply_to( $_REQUEST['bbp_reply_to'] ); 2497 }2546 } 2498 2547 2499 2548 // If empty, get from meta 2500 2549 if ( empty( $reply_to ) ) { 2501 2550 $reply_to = bbp_get_reply_to(); 2502 }2551 } 2503 2552 2504 2553 // Filter & return 2505 2554 return apply_filters( 'bbp_get_form_reply_to', $reply_to ); 2506 }2555 } 2507 2556 2508 2557 /** … … 2517 2566 echo bbp_get_reply_to_dropdown( $reply_id ); 2518 2567 } 2519 /** 2520 * Return a select box allowing to pick which topic/reply a reply belongs. 2521 * 2522 * @since 2.6.0 bbPress (r5387) 2523 * 2524 * @param int $reply_id 2525 * 2526 * @return string The dropdown 2527 */ 2528 function bbp_get_reply_to_dropdown( $reply_id = 0 ) { 2568 2569 /** 2570 * Return a select box allowing to pick which topic/reply a reply belongs. 2571 * 2572 * @since 2.6.0 bbPress (r5387) 2573 * 2574 * @param int $reply_id 2575 * 2576 * @return string The dropdown 2577 */ 2578 function bbp_get_reply_to_dropdown( $reply_id = 0 ) { 2529 2579 2530 2580 // Validate the reply data … … 2535 2585 // Get the replies 2536 2586 $posts = get_posts( array( 2537 'post_type' => bbp_get_reply_post_type(),2538 'post_status' => bbp_get_public_status_id(),2539 'post_parent' => $topic_id,2540 'numberposts' => -1,2541 'orderby' => 'menu_order',2542 'order' => 'ASC',2587 'post_type' => bbp_get_reply_post_type(), 2588 'post_status' => bbp_get_public_status_id(), 2589 'post_parent' => $topic_id, 2590 'numberposts' => -1, 2591 'orderby' => 'menu_order', 2592 'order' => 'ASC', 2543 2593 ) ); 2544 2594 2545 // Append `reply_to` for each reply so it can be walked2546 foreach ( $posts as &$post ) {2547 2548 // Check for reply post type2549 $_reply_to = bbp_get_reply_to( $post->ID );2550 2551 // Make sure it's a reply to a reply2552 if ( empty( $_reply_to ) || ( $topic_id === $_reply_to ) ) {2553 $_reply_to = 0;2595 // Append `reply_to` for each reply so it can be walked 2596 foreach ( $posts as &$post ) { 2597 2598 // Check for reply post type 2599 $_reply_to = bbp_get_reply_to( $post->ID ); 2600 2601 // Make sure it's a reply to a reply 2602 if ( empty( $_reply_to ) || ( $topic_id === $_reply_to ) ) { 2603 $_reply_to = 0; 2554 2604 } 2555 2605 2556 // Add reply_to to the post object so we can walk it later 2557 $post->reply_to = $_reply_to; 2558 } 2559 2560 // Default "None" text 2561 $show_none = ( 0 === $reply_id ) 2562 ? esc_attr_x( 'None', 'Default reply to dropdown text', 'bbpress' ) 2563 : sprintf( esc_attr__( '%1$s - %2$s', 'bbpress' ), $topic_id, bbp_get_topic_title( $topic_id ) ); 2564 2565 // Get the dropdown and return it 2566 $retval = bbp_get_dropdown( array( 2567 'show_none' => $show_none, 2568 'select_id' => 'bbp_reply_to', 2569 'select_class' => 'bbp_dropdown', 2570 'exclude' => $reply_id, 2571 'selected' => $reply_to, 2572 'post_parent' => $topic_id, 2573 'post_type' => bbp_get_reply_post_type(), 2574 'max_depth' => bbp_thread_replies_depth(), 2575 'page' => 1, 2576 'per_page' => -1, 2577 'walker' => new BBP_Walker_Reply_Dropdown(), 2578 'posts' => $posts 2579 ) ); 2580 2581 // Filter & return 2582 return apply_filters( 'bbp_get_reply_to_dropdown', $retval, $reply_id, $reply_to, $topic_id ); 2583 } 2606 // Add reply_to to the post object so we can walk it later 2607 $post->reply_to = $_reply_to; 2608 } 2609 2610 // Default "None" text 2611 $show_none = ( 0 === $reply_id ) 2612 ? esc_attr_x( 'None', 'Default reply to dropdown text', 'bbpress' ) 2613 /* translators: 1: Topic ID, 2: Topic title */ 2614 : sprintf( esc_attr__( '%1$s - %2$s', 'bbpress' ), $topic_id, bbp_get_topic_title( $topic_id ) ); 2615 2616 // Get the dropdown and return it 2617 $retval = bbp_get_dropdown( 2618 array( 2619 'show_none' => $show_none, 2620 'select_id' => 'bbp_reply_to', 2621 'select_class' => 'bbp_dropdown', 2622 'exclude' => $reply_id, 2623 'selected' => $reply_to, 2624 'post_parent' => $topic_id, 2625 'post_type' => bbp_get_reply_post_type(), 2626 'max_depth' => bbp_thread_replies_depth(), 2627 'page' => 1, 2628 'per_page' => -1, 2629 'walker' => new BBP_Walker_Reply_Dropdown(), 2630 'posts' => $posts 2631 ) 2632 ); 2633 2634 // Filter & return 2635 return apply_filters( 'bbp_get_reply_to_dropdown', $retval, $reply_id, $reply_to, $topic_id ); 2636 } 2584 2637 2585 2638 /** … … 2591 2644 echo bbp_get_form_reply_log_edit(); 2592 2645 } 2593 /** 2594 * Return checked value of reply log edit field 2595 * 2596 * @since 2.0.0 bbPress (r3130) 2597 * 2598 * @return string Reply log edit checked value 2599 */ 2600 function bbp_get_form_reply_log_edit() { 2646 2647 /** 2648 * Return checked value of reply log edit field 2649 * 2650 * @since 2.0.0 bbPress (r3130) 2651 * 2652 * @return string Reply log edit checked value 2653 */ 2654 function bbp_get_form_reply_log_edit() { 2601 2655 2602 2656 // Get _POST data … … 2604 2658 $reply_revision = (bool) $_POST['bbp_log_reply_edit']; 2605 2659 2606 // No data2607 } else {2660 // No data 2661 } else { 2608 2662 $reply_revision = true; 2609 }2663 } 2610 2664 2611 2665 // Get checked output … … 2614 2668 // Filter & return 2615 2669 return apply_filters( 'bbp_get_form_reply_log_edit', $checked, $reply_revision ); 2616 }2670 } 2617 2671 2618 2672 /** … … 2624 2678 echo bbp_get_form_reply_edit_reason(); 2625 2679 } 2626 /** 2627 * Return the value of the reply edit reason 2628 * 2629 * @since 2.0.0 bbPress (r3130) 2630 * 2631 * @return string Reply edit reason value 2632 */ 2633 function bbp_get_form_reply_edit_reason() { 2680 2681 /** 2682 * Return the value of the reply edit reason 2683 * 2684 * @since 2.0.0 bbPress (r3130) 2685 * 2686 * @return string Reply edit reason value 2687 */ 2688 function bbp_get_form_reply_edit_reason() { 2634 2689 2635 2690 // Get _POST data … … 2637 2692 $reply_edit_reason = wp_unslash( $_POST['bbp_reply_edit_reason'] ); 2638 2693 2639 // No data2640 } else {2694 // No data 2695 } else { 2641 2696 $reply_edit_reason = ''; 2642 }2697 } 2643 2698 2644 2699 // Filter & return 2645 2700 return apply_filters( 'bbp_get_form_reply_edit_reason', $reply_edit_reason ); 2646 }2701 } 2647 2702 2648 2703 /** … … 2660 2715 echo bbp_get_form_reply_status_dropdown( $args ); 2661 2716 } 2662 /** 2663 * Returns reply status dropdown 2664 * 2665 * This dropdown is only intended to be seen by users with the 'moderate' 2666 * capability. Because of this, no additional capability checks are performed 2667 * within this function to check available reply statuses. 2668 * 2669 * @since 2.6.0 bbPress (r5399) 2670 * 2671 * @param $args This function supports these arguments: 2672 * - select_id: Select id. Defaults to bbp_reply_status 2673 * - tab: Deprecated. Tabindex 2674 * - reply_id: Reply id 2675 * - selected: Override the selected option 2676 */ 2677 function bbp_get_form_reply_status_dropdown( $args = array() ) { 2717 2718 /** 2719 * Returns reply status dropdown 2720 * 2721 * This dropdown is only intended to be seen by users with the 'moderate' 2722 * capability. Because of this, no additional capability checks are performed 2723 * within this function to check available reply statuses. 2724 * 2725 * @since 2.6.0 bbPress (r5399) 2726 * 2727 * @param $args This function supports these arguments: 2728 * - select_id: Select id. Defaults to bbp_reply_status 2729 * - tab: Deprecated. Tabindex 2730 * - reply_id: Reply id 2731 * - selected: Override the selected option 2732 */ 2733 function bbp_get_form_reply_status_dropdown( $args = array() ) { 2678 2734 2679 2735 // Parse arguments against default values 2680 2736 $r = bbp_parse_args( $args, array( 2681 'select_id' => 'bbp_reply_status',2682 'select_class' => 'bbp_dropdown',2683 'tab' => false,2684 'reply_id' => 0,2685 'selected' => false2737 'select_id' => 'bbp_reply_status', 2738 'select_class' => 'bbp_dropdown', 2739 'tab' => false, 2740 'reply_id' => 0, 2741 'selected' => false 2686 2742 ), 'reply_status_dropdown' ); 2687 2743 2688 // No specific selected value passed2689 if ( empty( $r['selected'] ) ) {2690 2691 // Post value is passed2692 if ( bbp_is_reply_form_post_request() && isset( $_POST[ $r['select_id'] ] ) ) {2693 $r['selected'] = sanitize_key( $_POST[ $r['select_id'] ] );2744 // No specific selected value passed 2745 if ( empty( $r['selected'] ) ) { 2746 2747 // Post value is passed 2748 if ( bbp_is_reply_form_post_request() && isset( $_POST[ $r['select_id'] ] ) ) { 2749 $r['selected'] = sanitize_key( $_POST[ $r['select_id'] ] ); 2694 2750 2695 2751 // No Post value was passed 2696 2752 } else { 2697 2753 2698 // Edit reply2699 if ( bbp_is_reply_edit() ) {2700 $r['reply_id'] = bbp_get_reply_id( $r['reply_id'] );2701 $r['selected'] = bbp_get_reply_status( $r['reply_id'] );2754 // Edit reply 2755 if ( bbp_is_reply_edit() ) { 2756 $r['reply_id'] = bbp_get_reply_id( $r['reply_id'] ); 2757 $r['selected'] = bbp_get_reply_status( $r['reply_id'] ); 2702 2758 2703 2759 // New reply 2704 2760 } else { 2705 $r['selected'] = bbp_get_public_status_id();2761 $r['selected'] = bbp_get_public_status_id(); 2706 2762 } 2707 }2708 } 2709 2710 // Start an output buffer, we'll finish it after the select loop2711 ob_start(); ?>2712 2713 <select name="<?php echo esc_attr( $r['select_id'] ); ?>" id="<?php echo esc_attr( $r['select_id'] ); ?>_select" class="<?php echo esc_attr( $r['select_class'] ); ?>"<?php bbp_tab_index_attribute( $r['tab'] ); ?>>2714 2715 <?php foreach ( bbp_get_reply_statuses( $r['reply_id'] ) as $key => $label ) : ?>2716 2717 <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option>2718 2719 <?php endforeach; ?>2720 2721 </select>2722 2723 <?php2724 2725 // Filter & return2726 return apply_filters( 'bbp_get_form_reply_status_dropdown', ob_get_clean(), $r, $args );2727 }2763 } 2764 } 2765 2766 // Start an output buffer, we'll finish it after the select loop 2767 ob_start(); ?> 2768 2769 <select name="<?php echo esc_attr( $r['select_id'] ); ?>" id="<?php echo esc_attr( $r['select_id'] ); ?>_select" class="<?php echo esc_attr( $r['select_class'] ); ?>"<?php bbp_tab_index_attribute( $r['tab'] ); ?>> 2770 2771 <?php foreach ( bbp_get_reply_statuses( $r['reply_id'] ) as $key => $label ) : ?> 2772 2773 <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option> 2774 2775 <?php endforeach; ?> 2776 2777 </select> 2778 2779 <?php 2780 2781 // Filter & return 2782 return apply_filters( 'bbp_get_form_reply_status_dropdown', ob_get_clean(), $r, $args ); 2783 } 2728 2784 2729 2785 /**
Note: See TracChangeset
for help on using the changeset viewer.