PluginProbe
bbPress / 2.6.19
bbPress v2.6.19
2.6.19 2.6.18 2.6.17 trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 All 74 releases
← All changes | includes/topics/template.php +1341 -1417 trunk → 2.6.19 View file →
@@ -1,8 +1,8 @@
1 1 <?php
2 2
3 3 /**
4 - * bbPress Topic Template Tags.
4 + * bbPress Topic Template Tags
5 5 *
6 6 * @package bbPress
7 7 * @subpackage TemplateTags
8 8 */
@@ -12,9 +12,9 @@
12 12
13 13 /** Post Type *****************************************************************/
14 14
15 15 /**
16 - * Output the unique id of the custom post type for topics.
16 + * Output the unique id of the custom post type for topics
17 17 *
18 18 * @since 2.0.0 bbPress (r2858)
19 19 */
20 20 function bbp_topic_post_type() {
@@ -19,24 +19,23 @@
19 19 */
20 20 function bbp_topic_post_type() {
21 21 echo bbp_get_topic_post_type();
22 22 }
23 + /**
24 + * Return the unique id of the custom post type for topics
25 + *
26 + * @since 2.0.0 bbPress (r2858)
27 + *
28 + * @return string The unique topic post type id
29 + */
30 + function bbp_get_topic_post_type() {
23 31
24 -/**
25 - * Return the unique id of the custom post type for topics.
26 - *
27 - * @since 2.0.0 bbPress (r2858)
28 - *
29 - * @return string The unique topic post type id.
30 - */
31 -function bbp_get_topic_post_type() {
32 + // Filter & return
33 + return apply_filters( 'bbp_get_topic_post_type', bbpress()->topic_post_type );
34 + }
32 35
33 - // Filter & return
34 - return apply_filters( 'bbp_get_topic_post_type', bbpress()->topic_post_type );
35 -}
36 -
37 36 /**
38 - * Return array of labels used by the topic post type.
37 + * Return array of labels used by the topic post type
39 38 *
40 39 * @since 2.5.0 bbPress (r5130)
41 40 *
42 41 * @return array
@@ -51,9 +50,9 @@
51 50 'menu_name' => esc_attr__( 'Topics', 'bbpress' ),
52 51 'singular_name' => esc_attr__( 'Topic', 'bbpress' ),
53 52 'all_items' => esc_attr__( 'All Topics', 'bbpress' ),
54 53 'add_new' => esc_attr__( 'Add New', 'bbpress' ),
55 - 'add_new_item' => esc_attr__( 'Add Topic', 'bbpress' ),
54 + 'add_new_item' => esc_attr__( 'Create New Topic', 'bbpress' ),
56 55 'edit' => esc_attr__( 'Edit', 'bbpress' ),
57 56 'edit_item' => esc_attr__( 'Edit Topic', 'bbpress' ),
58 57 'new_item' => esc_attr__( 'New Topic', 'bbpress' ),
59 58 'view' => esc_attr__( 'View Topic', 'bbpress' ),
@@ -83,9 +82,9 @@
83 82 );
84 83 }
85 84
86 85 /**
87 - * Return array of topic post type rewrite settings.
86 + * Return array of topic post type rewrite settings
88 87 *
89 88 * @since 2.5.0 bbPress (r5130)
90 89 *
91 90 * @return array
@@ -102,9 +101,9 @@
102 101 );
103 102 }
104 103
105 104 /**
106 - * Return array of features the topic post type supports.
105 + * Return array of features the topic post type supports
107 106 *
108 107 * @since 2.5.0 bbPress (r5130)
109 108 *
110 109 * @return array
@@ -128,10 +127,10 @@
128 127 * - New Style: Topics appear as "lead" posts, ahead of replies
129 128 *
130 129 * @since 2.0.0 bbPress (r2954)
131 130 *
132 - * @param $show_lead Optional. Default false.
133 - * @return bool Yes if the topic appears as a lead, otherwise false.
131 + * @param $show_lead Optional. Default false
132 + * @return bool Yes if the topic appears as a lead, otherwise false
134 133 */
135 134 function bbp_show_lead_topic( $show_lead = false ) {
136 135
137 136 // Never separate the lead topic in feeds
@@ -145,14 +144,14 @@
145 144
146 145 /** Topic Loop ****************************************************************/
147 146
148 147 /**
149 - * The main topic loop. WordPress makes this easy for us.
148 + * The main topic loop. WordPress makes this easy for us
150 149 *
151 150 * @since 2.0.0 bbPress (r2485)
152 151 *
153 - * @param array $args All the arguments supported by {@link WP_Query}.
154 - * @return object Multidimensional array of topic information.
152 + * @param array $args All the arguments supported by {@link WP_Query}
153 + * @return object Multidimensional array of topic information
155 154 */
156 155 function bbp_has_topics( $args = array() ) {
157 156
158 157 /** Defaults **************************************************************/
@@ -167,10 +166,10 @@
167 166 'post_type' => bbp_get_topic_post_type(), // Narrow query down to bbPress topics
168 167 'post_parent' => $default_post_parent, // Forum ID
169 168 'meta_key' => '_bbp_last_active_time', // Make sure topic has some last activity time
170 169 'meta_type' => 'DATETIME',
171 - 'orderby' => 'meta_value', // 'meta_value', 'author', 'date', 'title', 'modified', 'parent', 'rand',
172 - 'order' => 'DESC', // 'ASC' or 'DESC'
170 + 'orderby' => 'meta_value', // 'meta_value', 'author', 'date', 'title', 'modified', 'parent', rand',
171 + 'order' => 'DESC', // 'ASC', 'DESC'
173 172 'posts_per_page' => bbp_get_topics_per_page(), // Topics per page
174 173 'paged' => bbp_get_paged(), // Page Number
175 174 'show_stickies' => $default_show_stickies, // Ignore sticky topics?
176 175 'max_num_pages' => false, // Maximum number of pages to show
@@ -293,13 +292,13 @@
293 292 return apply_filters( 'bbp_has_topics', $bbp->topic_query->have_posts(), $bbp->topic_query );
294 293 }
295 294
296 295 /**
297 - * Whether there are more topics available in the loop.
296 + * Whether there are more topics available in the loop
298 297 *
299 298 * @since 2.0.0 bbPress (r2485)
300 299 *
301 - * @return object Topic information.
300 + * @return object Topic information
302 301 */
303 302 function bbp_topics() {
304 303
305 304 // Put into variable to check against next
@@ -313,13 +312,13 @@
313 312 return $have_posts;
314 313 }
315 314
316 315 /**
317 - * Loads up the current topic in the loop.
316 + * Loads up the current topic in the loop
318 317 *
319 318 * @since 2.0.0 bbPress (r2485)
320 319 *
321 - * @return object Topic information.
320 + * @return object Topic information
322 321 */
323 322 function bbp_the_topic() {
324 323 return bbpress()->topic_query->the_post();
325 324 }
@@ -324,9 +323,9 @@
324 323 return bbpress()->topic_query->the_post();
325 324 }
326 325
327 326 /**
328 - * Add sticky topics to a topics query object.
327 + * Add sticky topics to a topics query object
329 328 *
330 329 * @since 2.6.0 bbPress (r6402)
331 330 *
332 331 * @param WP_Query $query
@@ -466,9 +465,9 @@
466 465 $query->posts = array_merge( $sticky_topics, array_values( $query->posts ) );
467 466 }
468 467
469 468 /**
470 - * Output the topic id.
469 + * Output the topic id
471 470 *
472 471 * @since 2.0.0 bbPress (r2485)
473 472 */
474 473 function bbp_topic_id( $topic_id = 0 ) {
@@ -473,60 +472,59 @@
473 472 */
474 473 function bbp_topic_id( $topic_id = 0 ) {
475 474 echo bbp_get_topic_id( $topic_id );
476 475 }
476 + /**
477 + * Return the topic id
478 + *
479 + * @since 2.0.0 bbPress (r2485)
480 + *
481 + * @param $topic_id Optional. Used to check emptiness
482 + * @return int The topic id
483 + */
484 + function bbp_get_topic_id( $topic_id = 0 ) {
485 + $bbp = bbpress();
486 + $wp_query = bbp_get_wp_query();
477 487
478 -/**
479 - * Return the topic id.
480 - *
481 - * @since 2.0.0 bbPress (r2485)
482 - *
483 - * @param $topic_id Optional. Used to check emptiness.
484 - * @return int The topic id.
485 - */
486 -function bbp_get_topic_id( $topic_id = 0 ) {
487 - $bbp = bbpress();
488 - $wp_query = bbp_get_wp_query();
488 + // Easy empty checking
489 + if ( ! empty( $topic_id ) && is_numeric( $topic_id ) ) {
490 + $bbp_topic_id = $topic_id;
489 491
490 - // Easy empty checking
491 - if ( ! empty( $topic_id ) && is_numeric( $topic_id ) ) {
492 - $bbp_topic_id = $topic_id;
492 + // Currently inside a topic loop
493 + } elseif ( ! empty( $bbp->topic_query->in_the_loop ) && isset( $bbp->topic_query->post->ID ) ) {
494 + $bbp_topic_id = $bbp->topic_query->post->ID;
493 495
494 - // Currently inside a topic loop
495 - } elseif ( ! empty( $bbp->topic_query->in_the_loop ) && isset( $bbp->topic_query->post->ID ) ) {
496 - $bbp_topic_id = $bbp->topic_query->post->ID;
496 + // Currently inside a search loop
497 + } elseif ( ! empty( $bbp->search_query->in_the_loop ) && isset( $bbp->search_query->post->ID ) && bbp_is_topic( $bbp->search_query->post->ID ) ) {
498 + $bbp_topic_id = $bbp->search_query->post->ID;
497 499
498 - // Currently inside a search loop
499 - } elseif ( ! empty( $bbp->search_query->in_the_loop ) && isset( $bbp->search_query->post->ID ) && bbp_is_topic( $bbp->search_query->post->ID ) ) {
500 - $bbp_topic_id = $bbp->search_query->post->ID;
500 + // Currently viewing/editing a topic, likely alone
501 + } elseif ( ( bbp_is_single_topic() || bbp_is_topic_edit() ) && ! empty( $bbp->current_topic_id ) ) {
502 + $bbp_topic_id = $bbp->current_topic_id;
501 503
502 - // Currently viewing/editing a topic, likely alone
503 - } elseif ( ( bbp_is_single_topic() || bbp_is_topic_edit() ) && ! empty( $bbp->current_topic_id ) ) {
504 - $bbp_topic_id = $bbp->current_topic_id;
504 + // Currently viewing/editing a topic, likely in a loop
505 + } elseif ( ( bbp_is_single_topic() || bbp_is_topic_edit() ) && isset( $wp_query->post->ID ) ) {
506 + $bbp_topic_id = $wp_query->post->ID;
505 507
506 - // Currently viewing/editing a topic, likely in a loop
507 - } elseif ( ( bbp_is_single_topic() || bbp_is_topic_edit() ) && isset( $wp_query->post->ID ) ) {
508 - $bbp_topic_id = $wp_query->post->ID;
508 + // Currently viewing/editing a reply
509 + } elseif ( bbp_is_single_reply() || bbp_is_reply_edit() ) {
510 + $bbp_topic_id = bbp_get_reply_topic_id();
509 511
510 - // Currently viewing/editing a reply
511 - } elseif ( bbp_is_single_reply() || bbp_is_reply_edit() ) {
512 - $bbp_topic_id = bbp_get_reply_topic_id();
512 + // Fallback
513 + } else {
514 + $bbp_topic_id = 0;
515 + }
513 516
514 - // Fallback
515 - } else {
516 - $bbp_topic_id = 0;
517 + // Filter & return
518 + return (int) apply_filters( 'bbp_get_topic_id', (int) $bbp_topic_id, $topic_id );
517 519 }
518 520
519 - // Filter & return
520 - return (int) apply_filters( 'bbp_get_topic_id', (int) $bbp_topic_id, $topic_id );
521 -}
522 -
523 521 /**
524 - * Gets a topic.
522 + * Gets a topic
525 523 *
526 524 * @since 2.0.0 bbPress (r2787)
527 525 *
528 - * @return mixed Null if error or topic (in specified form) if success.
526 + * @return mixed Null if error or topic (in specified form) if success
529 527 */
530 528 function bbp_get_topic( $topic, $output = OBJECT, $filter = 'raw' ) {
531 529
532 530 // Maybe get ID from empty or int
@@ -561,13 +559,13 @@
561 559 return apply_filters( 'bbp_get_topic', $retval, $topic, $output, $filter );
562 560 }
563 561
564 562 /**
565 - * Output the link to the topic in the topic loop.
563 + * Output the link to the topic in the topic loop
566 564 *
567 565 * @since 2.0.0 bbPress (r2485)
568 566 *
569 - * @param int $topic_id Optional. Topic id.
567 + * @param int $topic_id Optional. Topic id
570 568 * @param string $redirect_to Optional. Pass a redirect value for use with
571 569 * shortcodes and other fun things.
572 570 */
573 571 function bbp_topic_permalink( $topic_id = 0, $redirect_to = '' ) {
@@ -572,213 +570,206 @@
572 570 */
573 571 function bbp_topic_permalink( $topic_id = 0, $redirect_to = '' ) {
574 572 echo esc_url( bbp_get_topic_permalink( $topic_id, $redirect_to ) );
575 573 }
574 + /**
575 + * Return the link to the topic
576 + *
577 + * @since 2.0.0 bbPress (r2485)
578 + *
579 + * @param int $topic_id Optional. Topic id
580 + * @param string $redirect_to Optional. Pass a redirect value for use with
581 + * shortcodes and other fun things.
582 + * @return string Permanent link to topic
583 + */
584 + function bbp_get_topic_permalink( $topic_id = 0, $redirect_to = '' ) {
585 + $topic_id = bbp_get_topic_id( $topic_id );
576 586
577 -/**
578 - * Return the link to the topic.
579 - *
580 - * @since 2.0.0 bbPress (r2485)
581 - *
582 - * @param int $topic_id Optional. Topic id.
583 - * @param string $redirect_to Optional. Pass a redirect value for use with
584 - * shortcodes and other fun things.
585 - * @return string Permanent link to topic.
586 - */
587 -function bbp_get_topic_permalink( $topic_id = 0, $redirect_to = '' ) {
588 - $topic_id = bbp_get_topic_id( $topic_id );
587 + // Use the redirect address
588 + if ( ! empty( $redirect_to ) ) {
589 + $topic_permalink = esc_url_raw( $redirect_to );
589 590
590 - // Use the redirect address
591 - if ( ! empty( $redirect_to ) ) {
592 - $topic_permalink = esc_url_raw( $redirect_to );
591 + // Use the topic permalink
592 + } else {
593 + $topic_permalink = get_permalink( $topic_id );
594 + }
593 595
594 - // Use the topic permalink
595 - } else {
596 - $topic_permalink = get_permalink( $topic_id );
596 + // Filter & return
597 + return apply_filters( 'bbp_get_topic_permalink', $topic_permalink, $topic_id );
597 598 }
598 599
599 - // Filter & return
600 - return apply_filters( 'bbp_get_topic_permalink', $topic_permalink, $topic_id );
601 -}
602 -
603 600 /**
604 - * Output the title of the topic.
601 + * Output the title of the topic
605 602 *
606 603 * @since 2.0.0 bbPress (r2485)
607 604 *
608 - * @param int $topic_id Optional. Topic id.
605 + * @param int $topic_id Optional. Topic id
609 606 */
610 607 function bbp_topic_title( $topic_id = 0 ) {
611 608 echo bbp_get_topic_title( $topic_id );
612 609 }
610 + /**
611 + * Return the title of the topic
612 + *
613 + * @since 2.0.0 bbPress (r2485)
614 + *
615 + * @param int $topic_id Optional. Topic id
616 + * @return string Title of topic
617 + */
618 + function bbp_get_topic_title( $topic_id = 0 ) {
619 + $topic_id = bbp_get_topic_id( $topic_id );
620 + $title = get_the_title( $topic_id );
613 621
614 -/**
615 - * Return the title of the topic.
616 - *
617 - * @since 2.0.0 bbPress (r2485)
618 - *
619 - * @param int $topic_id Optional. Topic id.
620 - * @return string Title of topic.
621 - */
622 -function bbp_get_topic_title( $topic_id = 0 ) {
623 - $topic_id = bbp_get_topic_id( $topic_id );
624 - $title = get_post_field( 'post_title', $topic_id );
625 - $title = apply_filters( 'the_title', $title, $topic_id );
622 + // Filter & return
623 + return apply_filters( 'bbp_get_topic_title', $title, $topic_id );
624 + }
626 625
627 - // Filter & return
628 - return apply_filters( 'bbp_get_topic_title', $title, $topic_id );
629 -}
630 -
631 626 /**
632 - * Output the topic archive title.
627 + * Output the topic archive title
633 628 *
634 629 * @since 2.0.0 bbPress (r3250)
635 630 *
636 - * @param string $title Default text to use as title.
631 + * @param string $title Default text to use as title
637 632 */
638 633 function bbp_topic_archive_title( $title = '' ) {
639 634 echo bbp_get_topic_archive_title( $title );
640 635 }
636 + /**
637 + * Return the topic archive title
638 + *
639 + * @since 2.0.0 bbPress (r3250)
640 + *
641 + * @param string $title Default text to use as title
642 + *
643 + * @return string The topic archive title
644 + */
645 + function bbp_get_topic_archive_title( $title = '' ) {
641 646
642 -/**
643 - * Return the topic archive title.
644 - *
645 - * @since 2.0.0 bbPress (r3250)
646 - *
647 - * @param string $title Default text to use as title.
648 - *
649 - * @return string The topic archive title.
650 - */
651 -function bbp_get_topic_archive_title( $title = '' ) {
647 + // If no title was passed
648 + if ( empty( $title ) ) {
652 649
653 - // If no title was passed
654 - if ( empty( $title ) ) {
650 + // Set root text to page title
651 + $page = bbp_get_page_by_path( bbp_get_topic_archive_slug() );
652 + if ( ! empty( $page ) ) {
653 + $title = get_the_title( $page->ID );
655 654
656 - // Set root text to page title
657 - $page = bbp_get_page_by_path( bbp_get_topic_archive_slug() );
658 - if ( ! empty( $page ) ) {
659 - $title = get_the_title( $page->ID );
655 + // Default to topic post type name label
656 + } else {
657 + $tto = get_post_type_object( bbp_get_topic_post_type() );
658 + $title = $tto->labels->name;
659 + }
660 + }
660 661
661 - // Default to topic post type name label
662 - } else {
663 - $tto = get_post_type_object( bbp_get_topic_post_type() );
664 - $title = $tto->labels->name;
665 - }
662 + // Filter & return
663 + return apply_filters( 'bbp_get_topic_archive_title', $title );
666 664 }
667 665
668 - // Filter & return
669 - return apply_filters( 'bbp_get_topic_archive_title', $title );
670 -}
671 -
672 666 /**
673 - * Output the content of the topic.
667 + * Output the content of the topic
674 668 *
675 669 * @since 2.0.0 bbPress (r2780)
676 670 *
677 - * @param int $topic_id Optional. Topic id.
671 + * @param int $topic_id Optional. Topic id
678 672 */
679 673 function bbp_topic_content( $topic_id = 0 ) {
680 674 echo bbp_get_topic_content( $topic_id );
681 675 }
676 + /**
677 + * Return the content of the topic
678 + *
679 + * @since 2.0.0 bbPress (r2780)
680 + *
681 + * @param int $topic_id Optional. Topic id
682 + * @return string Content of the topic
683 + */
684 + function bbp_get_topic_content( $topic_id = 0 ) {
685 + $topic_id = bbp_get_topic_id( $topic_id );
682 686
683 -/**
684 - * Return the content of the topic.
685 - *
686 - * @since 2.0.0 bbPress (r2780)
687 - *
688 - * @param int $topic_id Optional. Topic id.
689 - * @return string Content of the topic.
690 - */
691 -function bbp_get_topic_content( $topic_id = 0 ) {
692 - $topic_id = bbp_get_topic_id( $topic_id );
687 + // Check the topic and its forum ancestors.
688 + $password_id = bbp_get_password_required_id( $topic_id );
689 + if ( ! empty( $password_id ) ) {
690 + return get_the_password_form( $password_id );
691 + }
693 692
694 - // Check the topic and its forum ancestors.
695 - $password_id = bbp_get_password_required_id( $topic_id );
696 - if ( ! empty( $password_id ) ) {
697 - return get_the_password_form( $password_id );
693 + $content = get_post_field( 'post_content', $topic_id );
694 +
695 + // Filter & return
696 + return apply_filters( 'bbp_get_topic_content', $content, $topic_id );
698 697 }
699 698
700 - $content = get_post_field( 'post_content', $topic_id );
701 -
702 - // Filter & return
703 - return apply_filters( 'bbp_get_topic_content', $content, $topic_id );
704 -}
705 -
706 699 /**
707 - * Output the excerpt of the topic.
700 + * Output the excerpt of the topic
708 701 *
709 702 * @since 2.0.0 bbPress (r2780)
710 703 *
711 - * @param int $topic_id Optional. Topic id.
712 - * @param int $length Optional. Length of the excerpt. Defaults to 100 letters.
704 + * @param int $topic_id Optional. Topic id
705 + * @param int $length Optional. Length of the excerpt. Defaults to 100 letters
713 706 */
714 707 function bbp_topic_excerpt( $topic_id = 0, $length = 100 ) {
715 708 echo bbp_get_topic_excerpt( $topic_id, $length );
716 709 }
710 + /**
711 + * Return the excerpt of the topic
712 + *
713 + * @since 2.0.0 bbPress (r2780)
714 + *
715 + * @param int $topic_id Optional. topic id
716 + * @param int $length Optional. Length of the excerpt. Defaults to 100
717 + * letters
718 + * @return string topic Excerpt
719 + */
720 + function bbp_get_topic_excerpt( $topic_id = 0, $length = 100 ) {
721 + $topic_id = bbp_get_topic_id( $topic_id );
722 + $length = (int) $length;
723 + $password_id = bbp_get_password_required_id( $topic_id );
724 + $excerpt = ! empty( $password_id )
725 + ? get_the_password_form( $password_id )
726 + : get_post_field( 'post_excerpt', $topic_id );
717 727
718 -/**
719 - * Return the excerpt of the topic.
720 - *
721 - * @since 2.0.0 bbPress (r2780)
722 - *
723 - * @param int $topic_id Optional. topic id.
724 - * @param int $length Optional. Length of the excerpt. Defaults to 100
725 - * letters.
726 - * @return string topic Excerpt.
727 - */
728 -function bbp_get_topic_excerpt( $topic_id = 0, $length = 100 ) {
729 - $topic_id = bbp_get_topic_id( $topic_id );
730 - $length = (int) $length;
731 - $password_id = bbp_get_password_required_id( $topic_id );
732 - $excerpt = ! empty( $password_id )
733 - ? get_the_password_form( $password_id )
734 - : get_post_field( 'post_excerpt', $topic_id );
728 + if ( empty( $excerpt ) ) {
729 + $excerpt = bbp_get_topic_content( $topic_id );
730 + }
735 731
736 - if ( empty( $excerpt ) ) {
737 - $excerpt = bbp_get_topic_content( $topic_id );
738 - }
732 + $excerpt = trim( strip_tags( $excerpt ) );
739 733
740 - $excerpt = wp_strip_all_tags( $excerpt );
734 + // Multibyte support
735 + if ( function_exists( 'mb_strlen' ) ) {
736 + $excerpt_length = mb_strlen( $excerpt );
737 + } else {
738 + $excerpt_length = strlen( $excerpt );
739 + }
741 740
742 - // Multibyte support
743 - if ( function_exists( 'mb_strlen' ) ) {
744 - $excerpt_length = mb_strlen( $excerpt );
745 - } else {
746 - $excerpt_length = strlen( $excerpt );
747 - }
741 + if ( ! empty( $length ) && ( $excerpt_length > $length ) ) {
742 + $excerpt = mb_substr( $excerpt, 0, $length - 1 );
743 + $excerpt .= '&hellip;';
744 + }
748 745
749 - if ( ! empty( $length ) && ( $excerpt_length > $length ) ) {
750 - $excerpt = mb_substr( $excerpt, 0, $length - 1 );
751 - $excerpt .= '&hellip;';
746 + // Filter & return
747 + return apply_filters( 'bbp_get_topic_excerpt', $excerpt, $topic_id, $length );
752 748 }
753 749
754 - // Filter & return
755 - return apply_filters( 'bbp_get_topic_excerpt', $excerpt, $topic_id, $length );
756 -}
757 -
758 750 /**
759 - * Output the post date and time of a topic.
751 + * Output the post date and time of a topic
760 752 *
761 753 * @since 2.2.0 bbPress (r4156)
762 754 *
763 755 * @param int $topic_id Optional. Topic id.
764 - * @param bool $humanize Optional. Humanize output using time_since.
765 - * @param bool $gmt Optional. Use GMT.
756 + * @param bool $humanize Optional. Humanize output using time_since
757 + * @param bool $gmt Optional. Use GMT
766 758 */
767 759 function bbp_topic_post_date( $topic_id = 0, $humanize = false, $gmt = false ) {
768 760 echo bbp_get_topic_post_date( $topic_id, $humanize, $gmt );
769 761 }
770 -
771 -/**
772 - * Return the post date and time of a topic.
773 - *
774 - * @since 2.2.0 bbPress (r4156)
775 - *
776 - * @param int $topic_id Optional. Topic id.
777 - * @param bool $humanize Optional. Humanize output using time_since.
778 - * @param bool $gmt Optional. Use GMT.
779 - * @return string
780 - */
762 + /**
763 + * Return the post date and time of a topic
764 + *
765 + * @since 2.2.0 bbPress (r4156)
766 + *
767 + * @param int $topic_id Optional. Topic id.
768 + * @param bool $humanize Optional. Humanize output using time_since
769 + * @param bool $gmt Optional. Use GMT
770 + * @return string
771 + */
781 772 function bbp_get_topic_post_date( $topic_id = 0, $humanize = false, $gmt = false ) {
782 773 $topic_id = bbp_get_topic_id( $topic_id );
783 774
784 775 // 4 days, 4 hours ago
@@ -800,29 +791,28 @@
800 791 return apply_filters( 'bbp_get_topic_post_date', $result, $topic_id, $humanize, $gmt, $date, $time );
801 792 }
802 793
803 794 /**
804 - * Output pagination links of a topic within the topic loop.
795 + * Output pagination links of a topic within the topic loop
805 796 *
806 797 * @since 2.0.0 bbPress (r2967)
807 798 *
808 - * @param array $args See {@link bbp_get_topic_pagination()}.
799 + * @param array $args See {@link bbp_get_topic_pagination()}
809 800 */
810 801 function bbp_topic_pagination( $args = array() ) {
811 802 echo bbp_get_topic_pagination( $args );
812 803 }
813 -
814 -/**
815 - * Returns pagination links of a topic within the topic loop.
816 - *
817 - * @since 2.0.0 bbPress (r2967)
818 - *
819 - * @param array $args This function supports these arguments:
820 - * - topic_id: Topic id
821 - * - before: Before the links
822 - * - after: After the links
823 - * @return string Pagination links.
824 - */
804 + /**
805 + * Returns pagination links of a topic within the topic loop
806 + *
807 + * @since 2.0.0 bbPress (r2967)
808 + *
809 + * @param array $args This function supports these arguments:
810 + * - topic_id: Topic id
811 + * - before: Before the links
812 + * - after: After the links
813 + * @return string Pagination links
814 + */
825 815 function bbp_get_topic_pagination( $args = array() ) {
826 816
827 817 // Bail if threading replies
828 818 if ( bbp_thread_replies() ) {
@@ -842,15 +832,12 @@
842 832
843 833 // Slug must be checked for topics that have never been approved/published
844 834 $has_slug = bbp_get_topic( $r['topic_id'] )->post_name;
845 835
846 - // Get the topic permalink
847 - $topic_permalink = bbp_get_topic_permalink( $r['topic_id'] );
848 -
849 836 // If pretty permalinks are enabled, make our pagination pretty
850 837 $base = ! empty( $has_slug ) && bbp_use_pretty_urls() && bbp_is_topic_public( $r['topic_id'] )
851 - ? trailingslashit( $topic_permalink ) . user_trailingslashit( bbp_get_paged_slug() . '/%#%/' )
852 - : add_query_arg( 'paged', '%#%', $topic_permalink );
838 + ? trailingslashit( get_permalink( $r['topic_id'] ) ) . user_trailingslashit( bbp_get_paged_slug() . '/%#%/' )
839 + : add_query_arg( 'paged', '%#%', get_permalink( $r['topic_id'] ) );
853 840
854 841 // Get total and add 1 if topic is included in the reply loop
855 842 $total = bbp_get_topic_reply_count( $r['topic_id'], true );
856 843
@@ -855,9 +842,9 @@
855 842 $total = bbp_get_topic_reply_count( $r['topic_id'], true );
856 843
857 844 // Bump if topic is in loop
858 845 if ( ! bbp_show_lead_topic() ) {
859 - ++$total;
846 + ++$total;
860 847 }
861 848
862 849 // Total for pagination boundaries
863 850 $total_pages = ceil( $total / bbp_get_replies_per_page() );
@@ -893,15 +880,15 @@
893 880 return apply_filters( 'bbp_get_topic_pagination', $pagination_links, $args );
894 881 }
895 882
896 883 /**
897 - * Append revisions to the topic content.
884 + * Append revisions to the topic content
898 885 *
899 886 * @since 2.0.0 bbPress (r2782)
900 887 *
901 - * @param string $content Optional. Content to which we need to append the revisions to.
902 - * @param int $topic_id Optional. Topic id.
903 - * @return string Content with the revisions appended.
888 + * @param string $content Optional. Content to which we need to append the revisions to
889 + * @param int $topic_id Optional. Topic id
890 + * @return string Content with the revisions appended
904 891 */
905 892 function bbp_topic_content_append_revisions( $content = '', $topic_id = 0 ) {
906 893
907 894 // Bail if in admin or feed
@@ -916,26 +903,25 @@
916 903 return apply_filters( 'bbp_topic_append_revisions', $content . bbp_get_topic_revision_log( $topic_id ), $content, $topic_id );
917 904 }
918 905
919 906 /**
920 - * Output the revision log of the topic.
907 + * Output the revision log of the topic
921 908 *
922 909 * @since 2.0.0 bbPress (r2782)
923 910 *
924 - * @param int $topic_id Optional. Topic id.
911 + * @param int $topic_id Optional. Topic id
925 912 */
926 913 function bbp_topic_revision_log( $topic_id = 0 ) {
927 914 echo bbp_get_topic_revision_log( $topic_id );
928 915 }
929 -
930 -/**
931 - * Return the formatted revision log of the topic.
932 - *
933 - * @since 2.0.0 bbPress (r2782)
934 - *
935 - * @param int $topic_id Optional. Topic id.
936 - * @return string Revision log of the topic.
937 - */
916 + /**
917 + * Return the formatted revision log of the topic
918 + *
919 + * @since 2.0.0 bbPress (r2782)
920 + *
921 + * @param int $topic_id Optional. Topic id
922 + * @return string Revision log of the topic
923 + */
938 924 function bbp_get_topic_revision_log( $topic_id = 0 ) {
939 925
940 926 // Create necessary variables
941 927 $topic_id = bbp_get_topic_id( $topic_id );
@@ -987,36 +973,35 @@
987 973
988 974 // Filter & return
989 975 return apply_filters( 'bbp_get_topic_revision_log', $retval, $topic_id );
990 976 }
977 + /**
978 + * Return the raw revision log of the topic
979 + *
980 + * @since 2.0.0 bbPress (r2782)
981 + *
982 + * @param int $topic_id Optional. Topic id
983 + * @return string Raw revision log of the topic
984 + */
985 + function bbp_get_topic_raw_revision_log( $topic_id = 0 ) {
986 + $topic_id = bbp_get_topic_id( $topic_id );
991 987
992 -/**
993 - * Return the raw revision log of the topic.
994 - *
995 - * @since 2.0.0 bbPress (r2782)
996 - *
997 - * @param int $topic_id Optional. Topic id.
998 - * @return string Raw revision log of the topic.
999 - */
1000 -function bbp_get_topic_raw_revision_log( $topic_id = 0 ) {
1001 - $topic_id = bbp_get_topic_id( $topic_id );
988 + $revision_log = get_post_meta( $topic_id, '_bbp_revision_log', true );
989 + $revision_log = ! empty( $revision_log )
990 + ? $revision_log
991 + : array();
1002 992
1003 - $revision_log = get_post_meta( $topic_id, '_bbp_revision_log', true );
1004 - $revision_log = ! empty( $revision_log )
1005 - ? $revision_log
1006 - : array();
993 + // Filter & return
994 + return apply_filters( 'bbp_get_topic_raw_revision_log', $revision_log, $topic_id );
995 + }
1007 996
1008 - // Filter & return
1009 - return apply_filters( 'bbp_get_topic_raw_revision_log', $revision_log, $topic_id );
1010 -}
1011 -
1012 997 /**
1013 - * Return the revisions of the topic.
998 + * Return the revisions of the topic
1014 999 *
1015 1000 * @since 2.0.0 bbPress (r2782)
1016 1001 *
1017 - * @param int $topic_id Optional. Topic id.
1018 - * @return WP_Post[]|int[] Topic revisions.
1002 + * @param int $topic_id Optional. Topic id
1003 + * @return WP_Post[]|int[] Topic revisions
1019 1004 */
1020 1005 function bbp_get_topic_revisions( $topic_id = 0 ) {
1021 1006 $topic_id = bbp_get_topic_id( $topic_id );
1022 1007 $revisions = wp_get_post_revisions( $topic_id, array( 'order' => 'ASC' ) );
@@ -1025,14 +1010,14 @@
1025 1010 return apply_filters( 'bbp_get_topic_revisions', $revisions, $topic_id );
1026 1011 }
1027 1012
1028 1013 /**
1029 - * Return the revision count of the topic.
1014 + * Return the revision count of the topic
1030 1015 *
1031 1016 * @since 2.0.0 bbPress (r2782)
1032 1017 *
1033 - * @param int $topic_id Optional. Topic id.
1034 - * @return string Topic revision count.
1018 + * @param int $topic_id Optional. Topic id
1019 + * @return string Topic revision count
1035 1020 */
1036 1021 function bbp_get_topic_revision_count( $topic_id = 0, $integer = false ) {
1037 1022 $topic_id = bbp_get_topic_id( $topic_id );
1038 1023 $count = count( bbp_get_topic_revisions( $topic_id ) );
@@ -1047,9 +1032,9 @@
1047 1032 * Is the topic a sticky or super sticky?
1048 1033 *
1049 1034 * @since 2.0.0 bbPress (r2754)
1050 1035 *
1051 - * @param int $topic_id Optional. Topic id.
1036 + * @param int $topic_id Optional. Topic id
1052 1037 * @param int $check_super Optional. If set to true and if the topic is not a
1053 1038 * normal sticky, it is checked if it is a super
1054 1039 * sticky or not. Defaults to true.
1055 1040 * @return bool True if sticky or super sticky, false if not.
@@ -1073,9 +1058,9 @@
1073 1058 * Is the topic a super sticky?
1074 1059 *
1075 1060 * @since 2.0.0 bbPress (r2754)
1076 1061 *
1077 - * @param int $topic_id Optional. Topic id.
1062 + * @param int $topic_id Optional. Topic id
1078 1063 * @return bool True if super sticky, false if not.
1079 1064 */
1080 1065 function bbp_is_topic_super_sticky( $topic_id = 0 ) {
1081 1066 $topic_id = bbp_get_topic_id( $topic_id );
@@ -1086,39 +1071,38 @@
1086 1071 return (bool) apply_filters( 'bbp_is_topic_super_sticky', $retval, $topic_id );
1087 1072 }
1088 1073
1089 1074 /**
1090 - * Output the status of the topic.
1075 + * Output the status of the topic
1091 1076 *
1092 1077 * @since 2.0.0 bbPress (r2667)
1093 1078 *
1094 - * @param int $topic_id Optional. Topic id.
1079 + * @param int $topic_id Optional. Topic id
1095 1080 */
1096 1081 function bbp_topic_status( $topic_id = 0 ) {
1097 1082 echo bbp_get_topic_status( $topic_id );
1098 1083 }
1084 + /**
1085 + * Return the status of the topic
1086 + *
1087 + * @since 2.0.0 bbPress (r2667)
1088 + *
1089 + * @param int $topic_id Optional. Topic id
1090 + * @return string Status of topic
1091 + */
1092 + function bbp_get_topic_status( $topic_id = 0 ) {
1093 + $topic_id = bbp_get_topic_id( $topic_id );
1099 1094
1100 -/**
1101 - * Return the status of the topic.
1102 - *
1103 - * @since 2.0.0 bbPress (r2667)
1104 - *
1105 - * @param int $topic_id Optional. Topic id.
1106 - * @return string Status of topic.
1107 - */
1108 -function bbp_get_topic_status( $topic_id = 0 ) {
1109 - $topic_id = bbp_get_topic_id( $topic_id );
1095 + // Filter & return
1096 + return apply_filters( 'bbp_get_topic_status', get_post_status( $topic_id ), $topic_id );
1097 + }
1110 1098
1111 - // Filter & return
1112 - return apply_filters( 'bbp_get_topic_status', get_post_status( $topic_id ), $topic_id );
1113 -}
1114 -
1115 1099 /**
1116 1100 * Is the topic closed to new replies?
1117 1101 *
1118 1102 * @since 2.0.0 bbPress (r2746)
1119 1103 *
1120 - * @param int $topic_id Optional. Topic id.
1104 + * @param int $topic_id Optional. Topic id
1121 1105 *
1122 1106 * @return bool True if closed, false if not.
1123 1107 */
1124 1108 function bbp_is_topic_closed( $topic_id = 0 ) {
@@ -1134,9 +1118,9 @@
1134 1118 * Is the topic open to new replies?
1135 1119 *
1136 1120 * @since 2.0.0 bbPress (r2727)
1137 1121 *
1138 - * @param int $topic_id Optional. Topic id.
1122 + * @param int $topic_id Optional. Topic id
1139 1123 *
1140 1124 * @return bool True if open, false if closed.
1141 1125 */
1142 1126 function bbp_is_topic_open( $topic_id = 0 ) {
@@ -1149,9 +1133,9 @@
1149 1133 * See bbp_get_public_topic_statuses() for public statuses.
1150 1134 *
1151 1135 * @since 2.6.0 bbPress (r6384)
1152 1136 *
1153 - * @param int $topic_id Optional. Topic id.
1137 + * @param int $topic_id Optional. Topic id
1154 1138 * @return bool True if public, false if not.
1155 1139 */
1156 1140 function bbp_is_topic_public( $topic_id = 0 ) {
1157 1141 $topic_id = bbp_get_topic_id( $topic_id );
@@ -1167,9 +1151,9 @@
1167 1151 * Does the topic have a published status?
1168 1152 *
1169 1153 * @since 2.0.0 bbPress (r3501)
1170 1154 *
1171 - * @param int $topic_id Optional. Topic id.
1155 + * @param int $topic_id Optional. Topic id
1172 1156 * @return bool True if published, false if not.
1173 1157 */
1174 1158 function bbp_is_topic_published( $topic_id = 0 ) {
1175 1159 $topic_id = bbp_get_topic_id( $topic_id );
@@ -1184,9 +1168,9 @@
1184 1168 * Is the topic marked as spam?
1185 1169 *
1186 1170 * @since 2.0.0 bbPress (r2727)
1187 1171 *
1188 - * @param int $topic_id Optional. Topic id.
1172 + * @param int $topic_id Optional. Topic id
1189 1173 * @return bool True if spam, false if not.
1190 1174 */
1191 1175 function bbp_is_topic_spam( $topic_id = 0 ) {
1192 1176 $topic_id = bbp_get_topic_id( $topic_id );
@@ -1201,9 +1185,9 @@
1201 1185 * Is the topic trashed?
1202 1186 *
1203 1187 * @since 2.0.0 bbPress (r2893)
1204 1188 *
1205 - * @param int $topic_id Optional. Topic id.
1189 + * @param int $topic_id Optional. Topic id
1206 1190 * @return bool True if trashed, false if not.
1207 1191 */
1208 1192 function bbp_is_topic_trash( $topic_id = 0 ) {
1209 1193 $topic_id = bbp_get_topic_id( $topic_id );
@@ -1218,9 +1202,9 @@
1218 1202 * Is the topic pending?
1219 1203 *
1220 1204 * @since 2.6.0 bbPress (r5504)
1221 1205 *
1222 - * @param int $topic_id Optional. Topic id.
1206 + * @param int $topic_id Optional. Topic id
1223 1207 * @return bool True if pending, false if not.
1224 1208 */
1225 1209 function bbp_is_topic_pending( $topic_id = 0 ) {
1226 1210 $topic_id = bbp_get_topic_id( $topic_id );
@@ -1235,9 +1219,9 @@
1235 1219 * Is the topic private?
1236 1220 *
1237 1221 * @since 2.6.0 bbPress (r5504)
1238 1222 *
1239 - * @param int $topic_id Optional. Topic id.
1223 + * @param int $topic_id Optional. Topic id
1240 1224 * @return bool True if private, false if not.
1241 1225 */
1242 1226 function bbp_is_topic_private( $topic_id = 0 ) {
1243 1227 $topic_id = bbp_get_topic_id( $topic_id );
@@ -1252,9 +1236,9 @@
1252 1236 * Is the posted by an anonymous user?
1253 1237 *
1254 1238 * @since 2.0.0 bbPress (r2753)
1255 1239 *
1256 - * @param int $topic_id Optional. Topic id.
1240 + * @param int $topic_id Optional. Topic id
1257 1241 * @return bool True if the post is by an anonymous user, false if not.
1258 1242 */
1259 1243 function bbp_is_topic_anonymous( $topic_id = 0 ) {
1260 1244 $topic_id = bbp_get_topic_id( $topic_id );
@@ -1282,155 +1266,151 @@
1282 1266 * @since 2.0.0 bbPress (r2590)
1283 1267 *
1284 1268 * @deprecated 2.5.0 bbPress (r5119)
1285 1269 *
1286 - * @param int $topic_id Optional. Topic id.
1270 + * @param int $topic_id Optional. Topic id
1287 1271 */
1288 1272 function bbp_topic_author( $topic_id = 0 ) {
1289 - echo bbp_get_topic_author_display_name( $topic_id );
1273 + echo bbp_get_topic_author( $topic_id );
1290 1274 }
1275 + /**
1276 + * Deprecated. Use bbp_get_topic_author_display_name() instead.
1277 + *
1278 + * Return the author of the topic
1279 + *
1280 + * @since 2.0.0 bbPress (r2590)
1281 + *
1282 + * @deprecated 2.5.0 bbPress (r5119)
1283 + *
1284 + * @param int $topic_id Optional. Topic id
1285 + * @return string Author of topic
1286 + */
1287 + function bbp_get_topic_author( $topic_id = 0 ) {
1288 + $topic_id = bbp_get_topic_id( $topic_id );
1291 1289
1292 -/**
1293 - * Deprecated. Use bbp_get_topic_author_display_name() instead.
1294 - *
1295 - * Return the author of the topic.
1296 - *
1297 - * @since 2.0.0 bbPress (r2590)
1298 - *
1299 - * @deprecated 2.5.0 bbPress (r5119)
1300 - *
1301 - * @param int $topic_id Optional. Topic id.
1302 - * @return string Author of topic.
1303 - */
1304 -function bbp_get_topic_author( $topic_id = 0 ) {
1305 - $topic_id = bbp_get_topic_id( $topic_id );
1290 + if ( ! bbp_is_topic_anonymous( $topic_id ) ) {
1291 + $author = get_the_author_meta( 'display_name', bbp_get_topic_author_id( $topic_id ) );
1292 + } else {
1293 + $author = get_post_meta( $topic_id, '_bbp_anonymous_name', true );
1294 + }
1306 1295
1307 - if ( ! bbp_is_topic_anonymous( $topic_id ) ) {
1308 - $author = get_the_author_meta( 'display_name', bbp_get_topic_author_id( $topic_id ) );
1309 - } else {
1310 - $author = get_post_meta( $topic_id, '_bbp_anonymous_name', true );
1296 + // Filter & return
1297 + return apply_filters( 'bbp_get_topic_author', $author, $topic_id );
1311 1298 }
1312 1299
1313 - // Filter & return
1314 - return apply_filters( 'bbp_get_topic_author', $author, $topic_id );
1315 -}
1316 -
1317 1300 /**
1318 - * Output the author ID of the topic.
1301 + * Output the author ID of the topic
1319 1302 *
1320 1303 * @since 2.0.0 bbPress (r2590)
1321 1304 *
1322 - * @param int $topic_id Optional. Topic id.
1305 + * @param int $topic_id Optional. Topic id
1323 1306 */
1324 1307 function bbp_topic_author_id( $topic_id = 0 ) {
1325 1308 echo bbp_get_topic_author_id( $topic_id );
1326 1309 }
1310 + /**
1311 + * Return the author ID of the topic
1312 + *
1313 + * @since 2.0.0 bbPress (r2590)
1314 + *
1315 + * @param int $topic_id Optional. Topic id
1316 + * @return string Author of topic
1317 + */
1318 + function bbp_get_topic_author_id( $topic_id = 0 ) {
1319 + $topic_id = bbp_get_topic_id( $topic_id );
1320 + $author_id = get_post_field( 'post_author', $topic_id );
1327 1321
1328 -/**
1329 - * Return the author ID of the topic.
1330 - *
1331 - * @since 2.0.0 bbPress (r2590)
1332 - *
1333 - * @param int $topic_id Optional. Topic id.
1334 - * @return string Author of topic.
1335 - */
1336 -function bbp_get_topic_author_id( $topic_id = 0 ) {
1337 - $topic_id = bbp_get_topic_id( $topic_id );
1338 - $author_id = get_post_field( 'post_author', $topic_id );
1322 + // Filter & return
1323 + return (int) apply_filters( 'bbp_get_topic_author_id', (int) $author_id, $topic_id );
1324 + }
1339 1325
1340 - // Filter & return
1341 - return (int) apply_filters( 'bbp_get_topic_author_id', (int) $author_id, $topic_id );
1342 -}
1343 -
1344 1326 /**
1345 - * Output the author display_name of the topic.
1327 + * Output the author display_name of the topic
1346 1328 *
1347 1329 * @since 2.0.0 bbPress (r2590)
1348 1330 *
1349 - * @param int $topic_id Optional. Topic id.
1331 + * @param int $topic_id Optional. Topic id
1350 1332 */
1351 1333 function bbp_topic_author_display_name( $topic_id = 0 ) {
1352 1334 echo bbp_get_topic_author_display_name( $topic_id );
1353 1335 }
1336 + /**
1337 + * Return the author display_name of the topic
1338 + *
1339 + * @since 2.0.0 bbPress (r2590)
1340 + *
1341 + * @param int $topic_id Optional. Topic id
1342 + * @return string Topic's author's display name
1343 + */
1344 + function bbp_get_topic_author_display_name( $topic_id = 0 ) {
1345 + $topic_id = bbp_get_topic_id( $topic_id );
1354 1346
1355 -/**
1356 - * Return the author display_name of the topic.
1357 - *
1358 - * @since 2.0.0 bbPress (r2590)
1359 - *
1360 - * @param int $topic_id Optional. Topic id.
1361 - * @return string Topic's author's display name.
1362 - */
1363 -function bbp_get_topic_author_display_name( $topic_id = 0 ) {
1364 - $topic_id = bbp_get_topic_id( $topic_id );
1347 + // Check for anonymous user
1348 + if ( ! bbp_is_topic_anonymous( $topic_id ) ) {
1365 1349
1366 - // Check for anonymous user
1367 - if ( ! bbp_is_topic_anonymous( $topic_id ) ) {
1350 + // Get the author ID
1351 + $author_id = bbp_get_topic_author_id( $topic_id );
1368 1352
1369 - // Get the author ID
1370 - $author_id = bbp_get_topic_author_id( $topic_id );
1353 + // Try to get a display name
1354 + $author_name = get_the_author_meta( 'display_name', $author_id );
1371 1355
1372 - // Try to get a display name
1373 - $author_name = get_the_author_meta( 'display_name', $author_id );
1356 + // Fall back to user login
1357 + if ( empty( $author_name ) ) {
1358 + $author_name = get_the_author_meta( 'user_login', $author_id );
1359 + }
1374 1360
1375 - // Fall back to user login
1361 + // User does not have an account
1362 + } else {
1363 + $author_name = get_post_meta( $topic_id, '_bbp_anonymous_name', true );
1364 + }
1365 +
1366 + // Fallback if nothing could be found
1376 1367 if ( empty( $author_name ) ) {
1377 - $author_name = get_the_author_meta( 'user_login', $author_id );
1368 + $author_name = bbp_get_fallback_display_name( $topic_id );
1378 1369 }
1379 1370
1380 - // User does not have an account
1381 - } else {
1382 - $author_name = get_post_meta( $topic_id, '_bbp_anonymous_name', true );
1371 + // Filter & return
1372 + return apply_filters( 'bbp_get_topic_author_display_name', $author_name, $topic_id );
1383 1373 }
1384 1374
1385 - // Fallback if nothing could be found
1386 - if ( empty( $author_name ) ) {
1387 - $author_name = bbp_get_fallback_display_name( $topic_id );
1388 - }
1389 -
1390 - // Filter & return
1391 - return apply_filters( 'bbp_get_topic_author_display_name', $author_name, $topic_id );
1392 -}
1393 -
1394 1375 /**
1395 - * Output the author avatar of the topic.
1376 + * Output the author avatar of the topic
1396 1377 *
1397 1378 * @since 2.0.0 bbPress (r2590)
1398 1379 *
1399 - * @param int $topic_id Optional. Topic id.
1400 - * @param int $size Optional. Avatar size. Defaults to 40.
1380 + * @param int $topic_id Optional. Topic id
1381 + * @param int $size Optional. Avatar size. Defaults to 40
1401 1382 */
1402 1383 function bbp_topic_author_avatar( $topic_id = 0, $size = 40 ) {
1403 1384 echo bbp_get_topic_author_avatar( $topic_id, $size );
1404 1385 }
1386 + /**
1387 + * Return the author avatar of the topic
1388 + *
1389 + * @since 2.0.0 bbPress (r2590)
1390 + *
1391 + * @param int $topic_id Optional. Topic id
1392 + * @param int $size Optional. Avatar size. Defaults to 40
1393 + * @return string Avatar of the author of the topic
1394 + */
1395 + function bbp_get_topic_author_avatar( $topic_id = 0, $size = 40 ) {
1396 + $author_avatar = '';
1405 1397
1406 -/**
1407 - * Return the author avatar of the topic.
1408 - *
1409 - * @since 2.0.0 bbPress (r2590)
1410 - *
1411 - * @param int $topic_id Optional. Topic id.
1412 - * @param int $size Optional. Avatar size. Defaults to 40.
1413 - * @return string Avatar of the author of the topic.
1414 - */
1415 -function bbp_get_topic_author_avatar( $topic_id = 0, $size = 40 ) {
1416 - $author_avatar = '';
1398 + $topic_id = bbp_get_topic_id( $topic_id );
1399 + if ( ! empty( $topic_id ) ) {
1400 + if ( ! bbp_is_topic_anonymous( $topic_id ) ) {
1401 + $author_avatar = get_avatar( bbp_get_topic_author_id( $topic_id ), $size );
1402 + } else {
1403 + $author_avatar = get_avatar( get_post_meta( $topic_id, '_bbp_anonymous_email', true ), $size );
1404 + }
1405 + }
1417 1406
1418 - $topic_id = bbp_get_topic_id( $topic_id );
1419 - if ( ! empty( $topic_id ) ) {
1420 - if ( ! bbp_is_topic_anonymous( $topic_id ) ) {
1421 - $author_avatar = get_avatar( bbp_get_topic_author_id( $topic_id ), $size );
1422 - } else {
1423 - $author_avatar = get_avatar( get_post_meta( $topic_id, '_bbp_anonymous_email', true ), $size );
1424 - }
1407 + // Filter & return
1408 + return apply_filters( 'bbp_get_topic_author_avatar', $author_avatar, $topic_id, $size );
1425 1409 }
1426 1410
1427 - // Filter & return
1428 - return apply_filters( 'bbp_get_topic_author_avatar', $author_avatar, $topic_id, $size );
1429 -}
1430 -
1431 1411 /**
1432 - * Output the author link of the topic.
1412 + * Output the author link of the topic
1433 1413 *
1434 1414 * @since 2.0.0 bbPress (r2720)
1435 1415 *
1436 1416 * @param mixed|int $args If it is an integer, it is used as topic_id. Optional.
@@ -1437,18 +1417,17 @@
1437 1417 */
1438 1418 function bbp_topic_author_link( $args = array() ) {
1439 1419 echo bbp_get_topic_author_link( $args );
1440 1420 }
1441 -
1442 -/**
1443 - * Return the author link of the topic.
1444 - *
1445 - * @since 2.0.0 bbPress (r2720)
1446 - *
1447 - * @param mixed|int $args If it is an integer, it is used as topic id.
1448 - * Optional.
1449 - * @return string Author link of topic.
1450 - */
1421 + /**
1422 + * Return the author link of the topic
1423 + *
1424 + * @since 2.0.0 bbPress (r2720)
1425 + *
1426 + * @param mixed|int $args If it is an integer, it is used as topic id.
1427 + * Optional.
1428 + * @return string Author link of topic
1429 + */
1451 1430 function bbp_get_topic_author_link( $args = array() ) {
1452 1431
1453 1432 // Parse arguments against default values
1454 1433 $r = bbp_parse_args(
@@ -1512,9 +1491,9 @@
1512 1491 }
1513 1492
1514 1493 // Empty array
1515 1494 $links = array();
1516 - $sprint = '<span%1$s>%2$s</span>';
1495 + $sprint = '<span %1$s>%2$s</span>';
1517 1496
1518 1497 // Wrap each link
1519 1498 foreach ( $author_links as $link => $link_text ) {
1520 1499 $link_class = ' class="bbp-author-' . esc_attr( $link ) . '"';
@@ -1546,93 +1525,92 @@
1546 1525 return apply_filters( 'bbp_get_topic_author_link', $author_link, $r, $args );
1547 1526 }
1548 1527
1549 1528 /**
1550 - * Output the author url of the topic.
1529 + * Output the author url of the topic
1551 1530 *
1552 1531 * @since 2.0.0 bbPress (r2590)
1553 1532 *
1554 - * @param int $topic_id Optional. Topic id.
1533 + * @param int $topic_id Optional. Topic id
1555 1534 */
1556 1535 function bbp_topic_author_url( $topic_id = 0 ) {
1557 1536 echo esc_url( bbp_get_topic_author_url( $topic_id ) );
1558 1537 }
1559 1538
1560 -/**
1561 - * Return the author url of the topic.
1562 - *
1563 - * @since 2.0.0 bbPress (r2590)
1564 - *
1565 - * @param int $topic_id Optional. Topic id.
1566 - * @return string Author URL of topic.
1567 - */
1568 -function bbp_get_topic_author_url( $topic_id = 0 ) {
1569 - $topic_id = bbp_get_topic_id( $topic_id );
1539 + /**
1540 + * Return the author url of the topic
1541 + *
1542 + * @since 2.0.0 bbPress (r2590)
1543 + *
1544 + * @param int $topic_id Optional. Topic id
1545 + * @return string Author URL of topic
1546 + */
1547 + function bbp_get_topic_author_url( $topic_id = 0 ) {
1548 + $topic_id = bbp_get_topic_id( $topic_id );
1570 1549
1571 - // Check for anonymous user or non-existant user
1572 - if ( ! bbp_is_topic_anonymous( $topic_id ) && bbp_user_has_profile( bbp_get_topic_author_id( $topic_id ) ) ) {
1573 - $author_url = bbp_get_user_profile_url( bbp_get_topic_author_id( $topic_id ) );
1574 - } else {
1575 - $author_url = get_post_meta( $topic_id, '_bbp_anonymous_website', true );
1550 + // Check for anonymous user or non-existant user
1551 + if ( ! bbp_is_topic_anonymous( $topic_id ) && bbp_user_has_profile( bbp_get_topic_author_id( $topic_id ) ) ) {
1552 + $author_url = bbp_get_user_profile_url( bbp_get_topic_author_id( $topic_id ) );
1553 + } else {
1554 + $author_url = get_post_meta( $topic_id, '_bbp_anonymous_website', true );
1576 1555
1577 - // Set empty author_url as empty string
1578 - if ( empty( $author_url ) ) {
1579 - $author_url = '';
1556 + // Set empty author_url as empty string
1557 + if ( empty( $author_url ) ) {
1558 + $author_url = '';
1559 + }
1580 1560 }
1561 +
1562 + // Filter & return
1563 + return apply_filters( 'bbp_get_topic_author_url', $author_url, $topic_id );
1581 1564 }
1582 1565
1583 - // Filter & return
1584 - return apply_filters( 'bbp_get_topic_author_url', $author_url, $topic_id );
1585 -}
1586 -
1587 1566 /**
1588 - * Output the topic author email address.
1567 + * Output the topic author email address
1589 1568 *
1590 1569 * @since 2.0.0 bbPress (r3446)
1591 1570 *
1592 - * @param int $topic_id Optional. Reply id.
1571 + * @param int $topic_id Optional. Reply id
1593 1572 */
1594 1573 function bbp_topic_author_email( $topic_id = 0 ) {
1595 1574 echo bbp_get_topic_author_email( $topic_id );
1596 1575 }
1576 + /**
1577 + * Return the topic author email address
1578 + *
1579 + * @since 2.0.0 bbPress (r3446)
1580 + *
1581 + * @param int $topic_id Optional. Reply id
1582 + * @return string Topic author email address
1583 + */
1584 + function bbp_get_topic_author_email( $topic_id = 0 ) {
1585 + $topic_id = bbp_get_topic_id( $topic_id );
1597 1586
1598 -/**
1599 - * Return the topic author email address.
1600 - *
1601 - * @since 2.0.0 bbPress (r3446)
1602 - *
1603 - * @param int $topic_id Optional. Reply id.
1604 - * @return string Topic author email address.
1605 - */
1606 -function bbp_get_topic_author_email( $topic_id = 0 ) {
1607 - $topic_id = bbp_get_topic_id( $topic_id );
1587 + // Not anonymous user
1588 + if ( ! bbp_is_topic_anonymous( $topic_id ) ) {
1608 1589
1609 - // Not anonymous user
1610 - if ( ! bbp_is_topic_anonymous( $topic_id ) ) {
1590 + // Use topic author email address
1591 + $user_id = bbp_get_topic_author_id( $topic_id );
1592 + $user = get_userdata( $user_id );
1593 + $author_email = ! empty( $user->user_email ) ? $user->user_email : '';
1611 1594
1612 - // Use topic author email address
1613 - $user_id = bbp_get_topic_author_id( $topic_id );
1614 - $user = get_userdata( $user_id );
1615 - $author_email = ! empty( $user->user_email ) ? $user->user_email : '';
1595 + // Anonymous
1596 + } else {
1616 1597
1617 - // Anonymous
1618 - } else {
1598 + // Get email from post meta
1599 + $author_email = get_post_meta( $topic_id, '_bbp_anonymous_email', true );
1619 1600
1620 - // Get email from post meta
1621 - $author_email = get_post_meta( $topic_id, '_bbp_anonymous_email', true );
1601 + // Sanity check for missing email address
1602 + if ( empty( $author_email ) ) {
1603 + $author_email = '';
1604 + }
1605 + }
1622 1606
1623 - // Sanity check for missing email address
1624 - if ( empty( $author_email ) ) {
1625 - $author_email = '';
1626 - }
1607 + // Filter & return
1608 + return apply_filters( 'bbp_get_topic_author_email', $author_email, $topic_id );
1627 1609 }
1628 1610
1629 - // Filter & return
1630 - return apply_filters( 'bbp_get_topic_author_email', $author_email, $topic_id );
1631 -}
1632 -
1633 1611 /**
1634 - * Output the topic author role.
1612 + * Output the topic author role
1635 1613 *
1636 1614 * @since 2.1.0 bbPress (r3860)
1637 1615 *
1638 1616 * @param array $args Optional.
@@ -1639,17 +1617,16 @@
1639 1617 */
1640 1618 function bbp_topic_author_role( $args = array() ) {
1641 1619 echo bbp_get_topic_author_role( $args );
1642 1620 }
1643 -
1644 -/**
1645 - * Return the topic author role.
1646 - *
1647 - * @since 2.1.0 bbPress (r3860)
1648 - *
1649 - * @param array $args Optional.
1650 - * @return string topic author role.
1651 - */
1621 + /**
1622 + * Return the topic author role
1623 + *
1624 + * @since 2.1.0 bbPress (r3860)
1625 + *
1626 + * @param array $args Optional.
1627 + * @return string topic author role
1628 + */
1652 1629 function bbp_get_topic_author_role( $args = array() ) {
1653 1630
1654 1631 // Parse arguments against default values
1655 1632 $r = bbp_parse_args(
@@ -1664,15 +1641,9 @@
1664 1641 );
1665 1642
1666 1643 $topic_id = bbp_get_topic_id( $r['topic_id'] );
1667 1644 $role = bbp_get_user_display_role( bbp_get_topic_author_id( $topic_id ) );
1668 - $css_role = sanitize_key( $role );
1669 1645
1670 - // Add role as CSS class to default 'before' value.
1671 - if ( empty( $args['before'] ) ) {
1672 - $r['before'] = '<div class="bbp-author-role bbp-role-' . esc_attr( $css_role ) . '">';
1673 - }
1674 -
1675 1646 // Backwards compatibilty with old 'class' argument
1676 1647 if ( ! empty( $r['class'] ) ) {
1677 1648 $author_role = sprintf( '%1$s<div class="%2$s">%3$s</div>%4$s', $r['before'], $r['class'], $role, $r['after'] );
1678 1649
@@ -1685,142 +1656,139 @@
1685 1656 // Filter & return
1686 1657 return apply_filters( 'bbp_get_topic_author_role', $author_role, $r );
1687 1658 }
1688 1659
1660 +
1689 1661 /**
1690 - * Output the title of the forum a topic belongs to.
1662 + * Output the title of the forum a topic belongs to
1691 1663 *
1692 1664 * @since 2.0.0 bbPress (r2572)
1693 1665 *
1694 - * @param int $topic_id Optional. Topic id.
1666 + * @param int $topic_id Optional. Topic id
1695 1667 */
1696 1668 function bbp_topic_forum_title( $topic_id = 0 ) {
1697 1669 echo bbp_get_topic_forum_title( $topic_id );
1698 1670 }
1671 + /**
1672 + * Return the title of the forum a topic belongs to
1673 + *
1674 + * @since 2.0.0 bbPress (r2572)
1675 + *
1676 + * @param int $topic_id Optional. Topic id
1677 + * @return string Topic forum title
1678 + */
1679 + function bbp_get_topic_forum_title( $topic_id = 0 ) {
1680 + $topic_id = bbp_get_topic_id( $topic_id );
1681 + $forum_id = bbp_get_topic_forum_id( $topic_id );
1699 1682
1700 -/**
1701 - * Return the title of the forum a topic belongs to.
1702 - *
1703 - * @since 2.0.0 bbPress (r2572)
1704 - *
1705 - * @param int $topic_id Optional. Topic id.
1706 - * @return string Topic forum title.
1707 - */
1708 -function bbp_get_topic_forum_title( $topic_id = 0 ) {
1709 - $topic_id = bbp_get_topic_id( $topic_id );
1710 - $forum_id = bbp_get_topic_forum_id( $topic_id );
1683 + // Filter & return
1684 + return apply_filters( 'bbp_get_topic_forum', bbp_get_forum_title( $forum_id ), $topic_id, $forum_id );
1685 + }
1711 1686
1712 - // Filter & return
1713 - return apply_filters( 'bbp_get_topic_forum', bbp_get_forum_title( $forum_id ), $topic_id, $forum_id );
1714 -}
1715 -
1716 1687 /**
1717 - * Output the forum id a topic belongs to.
1688 + * Output the forum id a topic belongs to
1718 1689 *
1719 1690 * @since 2.0.0 bbPress (r2494)
1720 1691 *
1721 - * @param int $topic_id Optional. Topic id.
1692 + * @param int $topic_id Optional. Topic id
1722 1693 */
1723 1694 function bbp_topic_forum_id( $topic_id = 0 ) {
1724 1695 echo bbp_get_topic_forum_id( $topic_id );
1725 1696 }
1697 + /**
1698 + * Return the forum id a topic belongs to
1699 + *
1700 + * @since 2.0.0 bbPress (r2494)
1701 + *
1702 + * @param int $topic_id Optional. Topic id
1703 + * @return int Topic forum id
1704 + */
1705 + function bbp_get_topic_forum_id( $topic_id = 0 ) {
1706 + $topic_id = bbp_get_topic_id( $topic_id );
1707 + $forum_id = (int) get_post_field( 'post_parent', $topic_id );
1726 1708
1727 -/**
1728 - * Return the forum id a topic belongs to.
1729 - *
1730 - * @since 2.0.0 bbPress (r2494)
1731 - *
1732 - * @param int $topic_id Optional. Topic id.
1733 - * @return int Topic forum id.
1734 - */
1735 -function bbp_get_topic_forum_id( $topic_id = 0 ) {
1736 - $topic_id = bbp_get_topic_id( $topic_id );
1737 - $forum_id = (int) get_post_field( 'post_parent', $topic_id );
1709 + // Meta-data fallback
1710 + if ( empty( $forum_id ) ) {
1711 + $forum_id = (int) get_post_meta( $topic_id, '_bbp_forum_id', true );
1712 + }
1738 1713
1739 - // Meta-data fallback
1740 - if ( empty( $forum_id ) ) {
1741 - $forum_id = (int) get_post_meta( $topic_id, '_bbp_forum_id', true );
1742 - }
1714 + // Filter
1715 + if ( ! empty( $forum_id ) ) {
1716 + $forum_id = (int) bbp_get_forum_id( $forum_id );
1717 + }
1743 1718
1744 - // Filter
1745 - if ( ! empty( $forum_id ) ) {
1746 - $forum_id = (int) bbp_get_forum_id( $forum_id );
1719 + // Filter & return
1720 + return (int) apply_filters( 'bbp_get_topic_forum_id', $forum_id, $topic_id );
1747 1721 }
1748 1722
1749 - // Filter & return
1750 - return (int) apply_filters( 'bbp_get_topic_forum_id', $forum_id, $topic_id );
1751 -}
1752 -
1753 1723 /**
1754 - * Output the topics last active ID.
1724 + * Output the topics last active ID
1755 1725 *
1756 1726 * @since 2.0.0 bbPress (r2872)
1757 1727 *
1758 - * @param int $topic_id Optional. Forum id.
1728 + * @param int $topic_id Optional. Forum id
1759 1729 */
1760 1730 function bbp_topic_last_active_id( $topic_id = 0 ) {
1761 1731 echo bbp_get_topic_last_active_id( $topic_id );
1762 1732 }
1733 + /**
1734 + * Return the topics last active ID
1735 + *
1736 + * @since 2.0.0 bbPress (r2872)
1737 + *
1738 + * @param int $topic_id Optional. Forum id
1739 + * @return int Forum's last active id
1740 + */
1741 + function bbp_get_topic_last_active_id( $topic_id = 0 ) {
1742 + $topic_id = bbp_get_topic_id( $topic_id );
1743 + $active_id = (int) get_post_meta( $topic_id, '_bbp_last_active_id', true );
1763 1744
1764 -/**
1765 - * Return the topics last active ID.
1766 - *
1767 - * @since 2.0.0 bbPress (r2872)
1768 - *
1769 - * @param int $topic_id Optional. Forum id.
1770 - * @return int Forum's last active id.
1771 - */
1772 -function bbp_get_topic_last_active_id( $topic_id = 0 ) {
1773 - $topic_id = bbp_get_topic_id( $topic_id );
1774 - $active_id = (int) get_post_meta( $topic_id, '_bbp_last_active_id', true );
1745 + // Filter & return
1746 + return (int) apply_filters( 'bbp_get_topic_last_active_id', $active_id, $topic_id );
1747 + }
1775 1748
1776 - // Filter & return
1777 - return (int) apply_filters( 'bbp_get_topic_last_active_id', $active_id, $topic_id );
1778 -}
1779 -
1780 1749 /**
1781 - * Output the topics last update date/time (aka freshness).
1750 + * Output the topics last update date/time (aka freshness)
1782 1751 *
1783 1752 * @since 2.0.0 bbPress (r2872)
1784 1753 *
1785 - * @param int $topic_id Optional. Topic id.
1754 + * @param int $topic_id Optional. Topic id
1786 1755 */
1787 1756 function bbp_topic_last_active_time( $topic_id = 0 ) {
1788 1757 echo bbp_get_topic_last_active_time( $topic_id );
1789 1758 }
1759 + /**
1760 + * Return the topics last update date/time (aka freshness)
1761 + *
1762 + * @since 2.0.0 bbPress (r2872)
1763 + *
1764 + * @param int $topic_id Optional. Topic id
1765 + * @return string Topic freshness
1766 + */
1767 + function bbp_get_topic_last_active_time( $topic_id = 0 ) {
1768 + $topic_id = bbp_get_topic_id( $topic_id );
1790 1769
1791 -/**
1792 - * Return the topics last update date/time (aka freshness).
1793 - *
1794 - * @since 2.0.0 bbPress (r2872)
1795 - *
1796 - * @param int $topic_id Optional. Topic id.
1797 - * @return string Topic freshness.
1798 - */
1799 -function bbp_get_topic_last_active_time( $topic_id = 0 ) {
1800 - $topic_id = bbp_get_topic_id( $topic_id );
1801 -
1802 - // Try to get the most accurate freshness time possible
1803 - $last_active = get_post_meta( $topic_id, '_bbp_last_active_time', true );
1804 - if ( empty( $last_active ) ) {
1805 - $reply_id = bbp_get_topic_last_reply_id( $topic_id );
1806 - if ( ! empty( $reply_id ) ) {
1807 - $last_active = get_post_field( 'post_date', $reply_id );
1808 - } else {
1809 - $last_active = get_post_field( 'post_date', $topic_id );
1770 + // Try to get the most accurate freshness time possible
1771 + $last_active = get_post_meta( $topic_id, '_bbp_last_active_time', true );
1772 + if ( empty( $last_active ) ) {
1773 + $reply_id = bbp_get_topic_last_reply_id( $topic_id );
1774 + if ( ! empty( $reply_id ) ) {
1775 + $last_active = get_post_field( 'post_date', $reply_id );
1776 + } else {
1777 + $last_active = get_post_field( 'post_date', $topic_id );
1778 + }
1810 1779 }
1811 - }
1812 1780
1813 - $last_active = ! empty( $last_active ) ? bbp_get_time_since( bbp_convert_date( $last_active ) ) : '';
1781 + $last_active = ! empty( $last_active ) ? bbp_get_time_since( bbp_convert_date( $last_active ) ) : '';
1814 1782
1815 - // Filter & return
1816 - return apply_filters( 'bbp_get_topic_last_active', $last_active, $topic_id );
1817 -}
1783 + // Filter & return
1784 + return apply_filters( 'bbp_get_topic_last_active', $last_active, $topic_id );
1785 + }
1818 1786
1819 1787 /** Topic Subscriptions *******************************************************/
1820 1788
1821 1789 /**
1822 - * Output the topic subscription link.
1790 + * Output the topic subscription link
1823 1791 *
1824 1792 * @since 2.5.0 bbPress (r5156)
1825 1793 * @since 2.6.0 bbPress (r6307) Add 'redirect_to' support
1826 1794 */
@@ -1827,16 +1795,16 @@
1827 1795 function bbp_topic_subscription_link( $args = array() ) {
1828 1796 echo bbp_get_topic_subscription_link( $args );
1829 1797 }
1830 1798
1831 -/**
1832 - * Get the topic subscription link.
1833 - *
1834 - * A custom wrapper for bbp_get_user_subscribe_link()
1835 - *
1836 - * @since 2.5.0 bbPress (r5156)
1837 - * @since 2.6.0 bbPress (r6307) Add 'redirect_to' support
1838 - */
1799 + /**
1800 + * Get the topic subscription link
1801 + *
1802 + * A custom wrapper for bbp_get_user_subscribe_link()
1803 + *
1804 + * @since 2.5.0 bbPress (r5156)
1805 + * @since 2.6.0 bbPress (r6307) Add 'redirect_to' support
1806 + */
1839 1807 function bbp_get_topic_subscription_link( $args = array() ) {
1840 1808
1841 1809 // Defaults
1842 1810 $retval = false;
@@ -1870,9 +1838,9 @@
1870 1838
1871 1839 /** Topic Favorites ***********************************************************/
1872 1840
1873 1841 /**
1874 - * Output the topic favorite link.
1842 + * Output the topic favorite link
1875 1843 *
1876 1844 * @since 2.5.0 bbPress (r5156)
1877 1845 * @since 2.6.0 bbPress (r6307) Add 'redirect_to' support
1878 1846 */
@@ -1879,16 +1847,16 @@
1879 1847 function bbp_topic_favorite_link( $args = array() ) {
1880 1848 echo bbp_get_topic_favorite_link( $args );
1881 1849 }
1882 1850
1883 -/**
1884 - * Get the forum favorite link.
1885 - *
1886 - * A custom wrapper for bbp_get_user_favorites_link().
1887 - *
1888 - * @since 2.5.0 bbPress (r5156)
1889 - * @since 2.6.0 bbPress (r6307) Add 'redirect_to' support
1890 - */
1851 + /**
1852 + * Get the forum favorite link
1853 + *
1854 + * A custom wrapper for bbp_get_user_favorites_link()
1855 + *
1856 + * @since 2.5.0 bbPress (r5156)
1857 + * @since 2.6.0 bbPress (r6307) Add 'redirect_to' support
1858 + */
1891 1859 function bbp_get_topic_favorite_link( $args = array() ) {
1892 1860
1893 1861 // No link
1894 1862 $retval = false;
@@ -1922,127 +1890,123 @@
1922 1890
1923 1891 /** Topic Last Reply **********************************************************/
1924 1892
1925 1893 /**
1926 - * Output the id of the topics last reply.
1894 + * Output the id of the topics last reply
1927 1895 *
1928 1896 * @since 2.0.0 bbPress (r2627)
1929 1897 *
1930 - * @param int $topic_id Optional. Topic id.
1898 + * @param int $topic_id Optional. Topic id
1931 1899 */
1932 1900 function bbp_topic_last_reply_id( $topic_id = 0 ) {
1933 1901 echo bbp_get_topic_last_reply_id( $topic_id );
1934 1902 }
1903 + /**
1904 + * Return the id of the topics last reply
1905 + *
1906 + * @since 2.0.0 bbPress (r2627)
1907 + *
1908 + * @param int $topic_id Optional. Topic id
1909 + * @return int Topic last reply id
1910 + */
1911 + function bbp_get_topic_last_reply_id( $topic_id = 0 ) {
1912 + $topic_id = bbp_get_topic_id( $topic_id );
1913 + $reply_id = (int) get_post_meta( $topic_id, '_bbp_last_reply_id', true );
1935 1914
1936 -/**
1937 - * Return the id of the topics last reply.
1938 - *
1939 - * @since 2.0.0 bbPress (r2627)
1940 - *
1941 - * @param int $topic_id Optional. Topic id.
1942 - * @return int Topic last reply id.
1943 - */
1944 -function bbp_get_topic_last_reply_id( $topic_id = 0 ) {
1945 - $topic_id = bbp_get_topic_id( $topic_id );
1946 - $reply_id = (int) get_post_meta( $topic_id, '_bbp_last_reply_id', true );
1915 + // Filter & return
1916 + return (int) apply_filters( 'bbp_get_topic_last_reply_id', $reply_id, $topic_id );
1917 + }
1947 1918
1948 - // Filter & return
1949 - return (int) apply_filters( 'bbp_get_topic_last_reply_id', $reply_id, $topic_id );
1950 -}
1951 -
1952 1919 /**
1953 - * Output the title of the last reply inside a topic.
1920 + * Output the title of the last reply inside a topic
1954 1921 *
1955 1922 * @since 2.0.0 bbPress (r2627)
1956 1923 *
1957 - * @param int $topic_id Optional. Topic id.
1924 + * @param int $topic_id Optional. Topic id
1958 1925 */
1959 1926 function bbp_topic_last_reply_title( $topic_id = 0 ) {
1960 1927 echo bbp_get_topic_last_reply_title( $topic_id );
1961 1928 }
1929 + /**
1930 + * Return the title of the last reply inside a topic
1931 + *
1932 + * @since 2.0.0 bbPress (r2627)
1933 + * @since 2.6.0 bbPress (r6244) https://bbpress.trac.wordpress.org/ticket/3039
1934 + *
1935 + * @param int $topic_id Optional. Topic id
1936 + * @return string Topic last reply title
1937 + */
1938 + function bbp_get_topic_last_reply_title( $topic_id = 0 ) {
1939 + $topic_id = bbp_get_topic_id( $topic_id );
1940 + $reply_id = bbp_get_topic_last_reply_id( $topic_id );
1941 + $retval = bbp_get_reply_title( $reply_id );
1962 1942
1963 -/**
1964 - * Return the title of the last reply inside a topic.
1965 - *
1966 - * @since 2.0.0 bbPress (r2627)
1967 - * @since 2.6.0 bbPress (r6244) https://bbpress.trac.wordpress.org/ticket/3039
1968 - *
1969 - * @param int $topic_id Optional. Topic id.
1970 - * @return string Topic last reply title.
1971 - */
1972 -function bbp_get_topic_last_reply_title( $topic_id = 0 ) {
1973 - $topic_id = bbp_get_topic_id( $topic_id );
1974 - $reply_id = bbp_get_topic_last_reply_id( $topic_id );
1975 - $retval = bbp_get_reply_title( $reply_id );
1943 + // Misspelled. Use 'bbp_get_topic_last_reply_title' hook instead.
1944 + $retval = apply_filters( 'bbp_get_topic_last_topic_title', $retval, $topic_id, $reply_id );
1976 1945
1977 - // Misspelled. Use 'bbp_get_topic_last_reply_title' hook instead.
1978 - $retval = apply_filters( 'bbp_get_topic_last_topic_title', $retval, $topic_id, $reply_id );
1946 + // Filter & return
1947 + return apply_filters( 'bbp_get_topic_last_reply_title', $retval, $topic_id, $reply_id );
1948 + }
1979 1949
1980 - // Filter & return
1981 - return apply_filters( 'bbp_get_topic_last_reply_title', $retval, $topic_id, $reply_id );
1982 -}
1983 -
1984 1950 /**
1985 - * Output the link to the last reply in a topic.
1951 + * Output the link to the last reply in a topic
1986 1952 *
1987 1953 * @since 2.0.0 bbPress (r2627)
1988 1954 *
1989 - * @param int $topic_id Optional. Topic id.
1955 + * @param int $topic_id Optional. Topic id
1990 1956 */
1991 1957 function bbp_topic_last_reply_permalink( $topic_id = 0 ) {
1992 1958 echo esc_url( bbp_get_topic_last_reply_permalink( $topic_id ) );
1993 1959 }
1960 + /**
1961 + * Return the link to the last reply in a topic
1962 + *
1963 + * @since 2.0.0 bbPress (r2627)
1964 + *
1965 + * @param int $topic_id Optional. Topic id
1966 + * @return string Permanent link to the reply
1967 + */
1968 + function bbp_get_topic_last_reply_permalink( $topic_id = 0 ) {
1969 + $topic_id = bbp_get_topic_id( $topic_id );
1970 + $reply_id = bbp_get_topic_last_reply_id( $topic_id );
1971 + $retval = bbp_get_reply_permalink( $reply_id );
1994 1972
1995 -/**
1996 - * Return the link to the last reply in a topic.
1997 - *
1998 - * @since 2.0.0 bbPress (r2627)
1999 - *
2000 - * @param int $topic_id Optional. Topic id.
2001 - * @return string Permanent link to the reply.
2002 - */
2003 -function bbp_get_topic_last_reply_permalink( $topic_id = 0 ) {
2004 - $topic_id = bbp_get_topic_id( $topic_id );
2005 - $reply_id = bbp_get_topic_last_reply_id( $topic_id );
2006 - $retval = bbp_get_reply_permalink( $reply_id );
1973 + // Filter & return
1974 + return apply_filters( 'bbp_get_topic_last_reply_permalink', $retval, $topic_id, $reply_id );
1975 + }
2007 1976
2008 - // Filter & return
2009 - return apply_filters( 'bbp_get_topic_last_reply_permalink', $retval, $topic_id, $reply_id );
2010 -}
2011 -
2012 1977 /**
2013 - * Output the link to the last reply in a topic.
1978 + * Output the link to the last reply in a topic
2014 1979 *
2015 1980 * @since 2.0.0 bbPress (r2684)
2016 1981 *
2017 - * @param int $topic_id Optional. Topic id.
1982 + * @param int $topic_id Optional. Topic id
2018 1983 */
2019 1984 function bbp_topic_last_reply_url( $topic_id = 0 ) {
2020 1985 echo esc_url( bbp_get_topic_last_reply_url( $topic_id ) );
2021 1986 }
1987 + /**
1988 + * Return the link to the last reply in a topic
1989 + *
1990 + * @since 2.0.0 bbPress (r2684)
1991 + *
1992 + * @param int $topic_id Optional. Topic id
1993 + * @return string Topic last reply url
1994 + */
1995 + function bbp_get_topic_last_reply_url( $topic_id = 0 ) {
1996 + $topic_id = bbp_get_topic_id( $topic_id );
1997 + $reply_id = bbp_get_topic_last_reply_id( $topic_id );
2022 1998
2023 -/**
2024 - * Return the link to the last reply in a topic.
2025 - *
2026 - * @since 2.0.0 bbPress (r2684)
2027 - *
2028 - * @param int $topic_id Optional. Topic id.
2029 - * @return string Topic last reply url.
2030 - */
2031 -function bbp_get_topic_last_reply_url( $topic_id = 0 ) {
2032 - $topic_id = bbp_get_topic_id( $topic_id );
2033 - $reply_id = bbp_get_topic_last_reply_id( $topic_id );
1999 + if ( ! empty( $reply_id ) && ( $reply_id !== $topic_id ) ) {
2000 + $reply_url = bbp_get_reply_url( $reply_id );
2001 + } else {
2002 + $reply_url = bbp_get_topic_permalink( $topic_id );
2003 + }
2034 2004
2035 - if ( ! empty( $reply_id ) && ( $reply_id !== $topic_id ) ) {
2036 - $reply_url = bbp_get_reply_url( $reply_id );
2037 - } else {
2038 - $reply_url = bbp_get_topic_permalink( $topic_id );
2005 + // Filter & return
2006 + return apply_filters( 'bbp_get_topic_last_reply_url', $reply_url, $topic_id, $reply_id );
2039 2007 }
2040 2008
2041 - // Filter & return
2042 - return apply_filters( 'bbp_get_topic_last_reply_url', $reply_url, $topic_id, $reply_id );
2043 -}
2044 -
2045 2009 /**
2046 2010 * Output link to the most recent activity inside a topic, complete with link
2047 2011 * attributes and content.
2048 2012 *
@@ -2047,57 +2011,56 @@
2047 2011 * attributes and content.
2048 2012 *
2049 2013 * @since 2.0.0 bbPress (r2627)
2050 2014 *
2051 - * @param int $topic_id Optional. Topic id.
2015 + * @param int $topic_id Optional. Topic id
2052 2016 */
2053 2017 function bbp_topic_freshness_link( $topic_id = 0 ) {
2054 2018 echo bbp_get_topic_freshness_link( $topic_id );
2055 2019 }
2020 + /**
2021 + * Returns link to the most recent activity inside a topic, complete
2022 + * with link attributes and content.
2023 + *
2024 + * @since 2.0.0 bbPress (r2627)
2025 + *
2026 + * @param int $topic_id Optional. Topic id
2027 + * @return string Topic freshness link
2028 + */
2029 + function bbp_get_topic_freshness_link( $topic_id = 0 ) {
2030 + $topic_id = bbp_get_topic_id( $topic_id );
2031 + $link_url = bbp_get_topic_last_reply_url( $topic_id );
2032 + $title = bbp_get_topic_last_reply_title( $topic_id );
2033 + $time_since = bbp_get_topic_last_active_time( $topic_id );
2056 2034
2057 -/**
2058 - * Returns link to the most recent activity inside a topic, complete
2059 - * with link attributes and content.
2060 - *
2061 - * @since 2.0.0 bbPress (r2627)
2062 - *
2063 - * @param int $topic_id Optional. Topic id.
2064 - * @return string Topic freshness link.
2065 - */
2066 -function bbp_get_topic_freshness_link( $topic_id = 0 ) {
2067 - $topic_id = bbp_get_topic_id( $topic_id );
2068 - $link_url = bbp_get_topic_last_reply_url( $topic_id );
2069 - $title = bbp_get_topic_last_reply_title( $topic_id );
2070 - $time_since = bbp_get_topic_last_active_time( $topic_id );
2035 + if ( ! empty( $time_since ) ) {
2036 + $anchor = '<a href="' . esc_url( $link_url ) . '" title="' . esc_attr( $title ) . '">' . esc_html( $time_since ) . '</a>';
2037 + } else {
2038 + $anchor = esc_html__( 'No Replies', 'bbpress' );
2039 + }
2071 2040
2072 - if ( ! empty( $time_since ) ) {
2073 - $anchor = '<a href="' . esc_url( $link_url ) . '" title="' . esc_attr( $title ) . '">' . esc_html( $time_since ) . '</a>';
2074 - } else {
2075 - $anchor = esc_html__( 'No Replies', 'bbpress' );
2041 + // Filter & return
2042 + return apply_filters( 'bbp_get_topic_freshness_link', $anchor, $topic_id, $time_since, $link_url, $title );
2076 2043 }
2077 2044
2078 - // Filter & return
2079 - return apply_filters( 'bbp_get_topic_freshness_link', $anchor, $topic_id, $time_since, $link_url, $title );
2080 -}
2081 -
2082 2045 /**
2083 - * Output the replies link of the topic.
2046 + * Output the replies link of the topic
2084 2047 *
2085 2048 * @since 2.0.0 bbPress (r2740)
2086 2049 *
2087 - * @param int $topic_id Optional. Topic id.
2050 + * @param int $topic_id Optional. Topic id
2088 2051 */
2089 2052 function bbp_topic_replies_link( $topic_id = 0 ) {
2090 2053 echo bbp_get_topic_replies_link( $topic_id );
2091 2054 }
2092 2055
2093 -/**
2094 - * Return the replies link of the topic.
2095 - *
2096 - * @since 2.0.0 bbPress (r2740)
2097 - *
2098 - * @param int $topic_id Optional. Topic id.
2099 - */
2056 + /**
2057 + * Return the replies link of the topic
2058 + *
2059 + * @since 2.0.0 bbPress (r2740)
2060 + *
2061 + * @param int $topic_id Optional. Topic id
2062 + */
2100 2063 function bbp_get_topic_replies_link( $topic_id = 0 ) {
2101 2064 $topic_id = bbp_get_topic_id( $topic_id );
2102 2065 $link = bbp_get_topic_permalink( $topic_id );
2103 2066 /* translators: %s: Number of replies */
@@ -2129,155 +2092,150 @@
2129 2092 return apply_filters( 'bbp_get_topic_replies_link', $retval, $topic_id );
2130 2093 }
2131 2094
2132 2095 /**
2133 - * Output total reply count of a topic.
2096 + * Output total reply count of a topic
2134 2097 *
2135 2098 * @since 2.0.0 bbPress (r2485)
2136 2099 *
2137 - * @param int $topic_id Optional. Topic id.
2138 - * @param boolean $integer Optional. Whether or not to format the result.
2100 + * @param int $topic_id Optional. Topic id
2101 + * @param boolean $integer Optional. Whether or not to format the result
2139 2102 */
2140 2103 function bbp_topic_reply_count( $topic_id = 0, $integer = false ) {
2141 2104 echo bbp_get_topic_reply_count( $topic_id, $integer );
2142 2105 }
2106 + /**
2107 + * Return total reply count of a topic
2108 + *
2109 + * @since 2.0.0 bbPress (r2485)
2110 + *
2111 + * @param int $topic_id Optional. Topic id
2112 + * @param boolean $integer Optional. Whether or not to format the result
2113 + * @return int Reply count
2114 + */
2115 + function bbp_get_topic_reply_count( $topic_id = 0, $integer = false ) {
2116 + $topic_id = bbp_get_topic_id( $topic_id );
2117 + $replies = (int) get_post_meta( $topic_id, '_bbp_reply_count', true );
2118 + $filter = ( true === $integer )
2119 + ? 'bbp_get_topic_reply_count_int'
2120 + : 'bbp_get_topic_reply_count';
2143 2121
2144 -/**
2145 - * Return total reply count of a topic.
2146 - *
2147 - * @since 2.0.0 bbPress (r2485)
2148 - *
2149 - * @param int $topic_id Optional. Topic id.
2150 - * @param boolean $integer Optional. Whether or not to format the result.
2151 - * @return int Reply count.
2152 - */
2153 -function bbp_get_topic_reply_count( $topic_id = 0, $integer = false ) {
2154 - $topic_id = bbp_get_topic_id( $topic_id );
2155 - $replies = (int) get_post_meta( $topic_id, '_bbp_reply_count', true );
2156 - $filter = ( true === $integer )
2157 - ? 'bbp_get_topic_reply_count_int'
2158 - : 'bbp_get_topic_reply_count';
2122 + return apply_filters( $filter, $replies, $topic_id );
2123 + }
2159 2124
2160 - return apply_filters( $filter, $replies, $topic_id );
2161 -}
2162 -
2163 2125 /**
2164 - * Output total post count of a topic.
2126 + * Output total post count of a topic
2165 2127 *
2166 2128 * @since 2.0.0 bbPress (r2955)
2167 2129 *
2168 - * @param int $topic_id Optional. Topic id.
2169 - * @param boolean $integer Optional. Whether or not to format the result.
2130 + * @param int $topic_id Optional. Topic id
2131 + * @param boolean $integer Optional. Whether or not to format the result
2170 2132 */
2171 2133 function bbp_topic_post_count( $topic_id = 0, $integer = false ) {
2172 2134 echo bbp_get_topic_post_count( $topic_id, $integer );
2173 2135 }
2136 + /**
2137 + * Return total post count of a topic
2138 + *
2139 + * @since 2.0.0 bbPress (r2955)
2140 + *
2141 + * @param int $topic_id Optional. Topic id
2142 + * @param boolean $integer Optional. Whether or not to format the result
2143 + * @return int Post count
2144 + */
2145 + function bbp_get_topic_post_count( $topic_id = 0, $integer = false ) {
2146 + $topic_id = bbp_get_topic_id( $topic_id );
2147 + $replies = ( (int) get_post_meta( $topic_id, '_bbp_reply_count', true ) ) + 1;
2148 + $filter = ( true === $integer )
2149 + ? 'bbp_get_topic_post_count_int'
2150 + : 'bbp_get_topic_post_count';
2174 2151
2175 -/**
2176 - * Return total post count of a topic.
2177 - *
2178 - * @since 2.0.0 bbPress (r2955)
2179 - *
2180 - * @param int $topic_id Optional. Topic id.
2181 - * @param boolean $integer Optional. Whether or not to format the result.
2182 - * @return int Post count.
2183 - */
2184 -function bbp_get_topic_post_count( $topic_id = 0, $integer = false ) {
2185 - $topic_id = bbp_get_topic_id( $topic_id );
2186 - $replies = ( (int) get_post_meta( $topic_id, '_bbp_reply_count', true ) ) + 1;
2187 - $filter = ( true === $integer )
2188 - ? 'bbp_get_topic_post_count_int'
2189 - : 'bbp_get_topic_post_count';
2152 + return apply_filters( $filter, $replies, $topic_id );
2153 + }
2190 2154
2191 - return apply_filters( $filter, $replies, $topic_id );
2192 -}
2193 -
2194 2155 /**
2195 2156 * Output total hidden reply count of a topic (hidden includes trashed and
2196 - * spammed replies).
2157 + * spammed replies)
2197 2158 *
2198 2159 * @since 2.0.0 bbPress (r3349)
2199 2160 *
2200 - * @param int $topic_id Optional. Topic id.
2201 - * @param boolean $integer Optional. Whether or not to format the result.
2161 + * @param int $topic_id Optional. Topic id
2162 + * @param boolean $integer Optional. Whether or not to format the result
2202 2163 */
2203 2164 function bbp_topic_reply_count_hidden( $topic_id = 0, $integer = false ) {
2204 2165 echo bbp_get_topic_reply_count_hidden( $topic_id, $integer );
2205 2166 }
2167 + /**
2168 + * Return total hidden reply count of a topic (hidden includes trashed
2169 + * and spammed replies)
2170 + *
2171 + * @since 2.0.0 bbPress (r3349)
2172 + *
2173 + * @param int $topic_id Optional. Topic id
2174 + * @param boolean $integer Optional. Whether or not to format the result
2175 + * @return int Topic hidden reply count
2176 + */
2177 + function bbp_get_topic_reply_count_hidden( $topic_id = 0, $integer = false ) {
2178 + $topic_id = bbp_get_topic_id( $topic_id );
2179 + $replies = (int) get_post_meta( $topic_id, '_bbp_reply_count_hidden', true );
2180 + $filter = ( true === $integer )
2181 + ? 'bbp_get_topic_reply_count_hidden_int'
2182 + : 'bbp_get_topic_reply_count_hidden';
2206 2183
2207 -/**
2208 - * Return total hidden reply count of a topic (hidden includes trashed
2209 - * and spammed replies).
2210 - *
2211 - * @since 2.0.0 bbPress (r3349)
2212 - *
2213 - * @param int $topic_id Optional. Topic id.
2214 - * @param boolean $integer Optional. Whether or not to format the result.
2215 - * @return int Topic hidden reply count.
2216 - */
2217 -function bbp_get_topic_reply_count_hidden( $topic_id = 0, $integer = false ) {
2218 - $topic_id = bbp_get_topic_id( $topic_id );
2219 - $replies = (int) get_post_meta( $topic_id, '_bbp_reply_count_hidden', true );
2220 - $filter = ( true === $integer )
2221 - ? 'bbp_get_topic_reply_count_hidden_int'
2222 - : 'bbp_get_topic_reply_count_hidden';
2184 + return apply_filters( $filter, $replies, $topic_id );
2185 + }
2223 2186
2224 - return apply_filters( $filter, $replies, $topic_id );
2225 -}
2226 -
2227 2187 /**
2228 - * Output total voice count of a topic.
2188 + * Output total voice count of a topic
2229 2189 *
2230 2190 * @since 2.0.0 bbPress (r2567)
2231 2191 *
2232 - * @param int $topic_id Optional. Topic id.
2192 + * @param int $topic_id Optional. Topic id
2233 2193 */
2234 2194 function bbp_topic_voice_count( $topic_id = 0, $integer = false ) {
2235 2195 echo bbp_get_topic_voice_count( $topic_id, $integer );
2236 2196 }
2197 + /**
2198 + * Return total voice count of a topic
2199 + *
2200 + * @since 2.0.0 bbPress (r2567)
2201 + *
2202 + * @param int $topic_id Optional. Topic id
2203 + * @return int Voice count of the topic
2204 + */
2205 + function bbp_get_topic_voice_count( $topic_id = 0, $integer = false ) {
2206 + $topic_id = bbp_get_topic_id( $topic_id );
2207 + $voices = (int) get_post_meta( $topic_id, '_bbp_voice_count', true );
2208 + $filter = ( true === $integer )
2209 + ? 'bbp_get_topic_voice_count_int'
2210 + : 'bbp_get_topic_voice_count';
2237 2211
2238 -/**
2239 - * Return total voice count of a topic.
2240 - *
2241 - * @since 2.0.0 bbPress (r2567)
2242 - *
2243 - * @param int $topic_id Optional. Topic id.
2244 - * @return int Voice count of the topic.
2245 - */
2246 -function bbp_get_topic_voice_count( $topic_id = 0, $integer = false ) {
2247 - $topic_id = bbp_get_topic_id( $topic_id );
2248 - $voices = (int) get_post_meta( $topic_id, '_bbp_voice_count', true );
2249 - $filter = ( true === $integer )
2250 - ? 'bbp_get_topic_voice_count_int'
2251 - : 'bbp_get_topic_voice_count';
2212 + return apply_filters( $filter, $voices, $topic_id );
2213 + }
2252 2214
2253 - return apply_filters( $filter, $voices, $topic_id );
2254 -}
2255 -
2256 2215 /**
2257 - * Output a the tags of a topic.
2216 + * Output a the tags of a topic
2258 2217 *
2259 2218 * @since 2.0.0 bbPress (r2583)
2260 2219 *
2261 - * @param int $topic_id Optional. Topic id.
2262 - * @param array $args See {@link bbp_get_topic_tag_list()}.
2220 + * @param int $topic_id Optional. Topic id
2221 + * @param array $args See {@link bbp_get_topic_tag_list()}
2263 2222 */
2264 2223 function bbp_topic_tag_list( $topic_id = 0, $args = array() ) {
2265 2224 echo bbp_get_topic_tag_list( $topic_id, $args );
2266 2225 }
2267 -
2268 -/**
2269 - * Return the tags of a topic.
2270 - *
2271 - * @since 2.0.0 bbPress (r2583)
2272 - *
2273 - * @param int $topic_id Optional. Topic id.
2274 - * @param array $args This function supports these arguments:
2275 - * - before: Before the tag list
2276 - * - sep: Tag separator
2277 - * - after: After the tag list
2278 - * @return string Tag list of the topic.
2279 - */
2226 + /**
2227 + * Return the tags of a topic
2228 + *
2229 + * @since 2.0.0 bbPress (r2583)
2230 + *
2231 + * @param int $topic_id Optional. Topic id
2232 + * @param array $args This function supports these arguments:
2233 + * - before: Before the tag list
2234 + * - sep: Tag separator
2235 + * - after: After the tag list
2236 + * @return string Tag list of the topic
2237 + */
2280 2238 function bbp_get_topic_tag_list( $topic_id = 0, $args = array() ) {
2281 2239
2282 2240 // Bail if topic-tags are off
2283 2241 if ( ! bbp_allow_topic_tags() ) {
@@ -2324,104 +2282,102 @@
2324 2282 return $retval;
2325 2283 }
2326 2284
2327 2285 /**
2328 - * Output the row class of a topic.
2286 + * Output the row class of a topic
2329 2287 *
2330 2288 * @since 2.0.0 bbPress (r2678)
2331 2289 *
2332 - * @param int $topic_id Optional. Topic id.
2333 - * @param array Extra classes you can pass when calling this function.
2290 + * @param int $topic_id Optional. Topic id
2291 + * @param array Extra classes you can pass when calling this function
2334 2292 */
2335 2293 function bbp_topic_class( $topic_id = 0, $classes = array() ) {
2336 2294 echo bbp_get_topic_class( $topic_id, $classes );
2337 2295 }
2296 + /**
2297 + * Return the row class of a topic
2298 + *
2299 + * @since 2.0.0 bbPress (r2678)
2300 + *
2301 + * @param int $topic_id Optional. Topic id
2302 + * @param array Extra classes you can pass when calling this function
2303 + * @return string Row class of a topic
2304 + */
2305 + function bbp_get_topic_class( $topic_id = 0, $classes = array() ) {
2306 + $bbp = bbpress();
2307 + $topic_id = bbp_get_topic_id( $topic_id );
2308 + $forum_id = bbp_get_topic_forum_id( $topic_id );
2309 + $author_id = bbp_get_topic_author_id( $topic_id );
2310 + $classes = array_filter( (array) $classes );
2311 + $count = isset( $bbp->topic_query->current_post )
2312 + ? (int) $bbp->topic_query->current_post
2313 + : 1;
2338 2314
2339 -/**
2340 - * Return the row class of a topic.
2341 - *
2342 - * @since 2.0.0 bbPress (r2678)
2343 - *
2344 - * @param int $topic_id Optional. Topic id.
2345 - * @param array Extra classes you can pass when calling this function.
2346 - * @return string Row class of a topic.
2347 - */
2348 -function bbp_get_topic_class( $topic_id = 0, $classes = array() ) {
2349 - $bbp = bbpress();
2350 - $topic_id = bbp_get_topic_id( $topic_id );
2351 - $forum_id = bbp_get_topic_forum_id( $topic_id );
2352 - $author_id = bbp_get_topic_author_id( $topic_id );
2353 - $classes = array_filter( (array) $classes );
2354 - $count = isset( $bbp->topic_query->current_post )
2355 - ? (int) $bbp->topic_query->current_post
2356 - : 1;
2315 + // Stripes
2316 + $even_odd = ( $count % 2 )
2317 + ? 'even'
2318 + : 'odd';
2357 2319
2358 - // Stripes
2359 - $even_odd = ( $count % 2 )
2360 - ? 'even'
2361 - : 'odd';
2320 + // Forum moderator replied to topic
2321 + $forum_moderator = ( bbp_is_user_forum_moderator( $author_id, $forum_id ) === $author_id )
2322 + ? 'forum-mod'
2323 + : '';
2362 2324
2363 - // Forum moderator replied to topic
2364 - $forum_moderator = ( bbp_is_user_forum_moderator( $author_id, $forum_id ) === $author_id )
2365 - ? 'forum-mod'
2366 - : '';
2325 + // Is this topic a sticky?
2326 + $sticky = bbp_is_topic_sticky( $topic_id, false )
2327 + ? 'sticky'
2328 + : '';
2367 2329
2368 - // Is this topic a sticky?
2369 - $sticky = bbp_is_topic_sticky( $topic_id, false )
2370 - ? 'sticky'
2371 - : '';
2330 + // Is this topic a super-sticky?
2331 + $super_sticky = bbp_is_topic_super_sticky( $topic_id )
2332 + ? 'super-sticky'
2333 + : '';
2372 2334
2373 - // Is this topic a super-sticky?
2374 - $super_sticky = bbp_is_topic_super_sticky( $topic_id )
2375 - ? 'super-sticky'
2376 - : '';
2335 + // Get topic classes
2336 + $topic_classes = array(
2337 + 'loop-item-' . $count,
2338 + 'user-id-' . $author_id,
2339 + 'bbp-parent-forum-' . $forum_id,
2340 + $even_odd,
2341 + $forum_moderator,
2342 + $sticky,
2343 + $super_sticky
2344 + );
2377 2345
2378 - // Get topic classes
2379 - $topic_classes = array(
2380 - 'loop-item-' . $count,
2381 - 'user-id-' . $author_id,
2382 - 'bbp-parent-forum-' . $forum_id,
2383 - $even_odd,
2384 - $forum_moderator,
2385 - $sticky,
2386 - $super_sticky
2387 - );
2346 + // Run the topic classes through the post-class filters, which also
2347 + // handles the escaping of each individual class.
2348 + $post_classes = get_post_class( array_merge( $classes, $topic_classes ), $topic_id );
2388 2349
2389 - // Run the topic classes through the post-class filters, which also
2390 - // handles the escaping of each individual class.
2391 - $post_classes = get_post_class( array_merge( $classes, $topic_classes ), $topic_id );
2350 + // Filter
2351 + $new_classes = apply_filters( 'bbp_get_topic_class', $post_classes, $topic_id, $classes );
2392 2352
2393 - // Filter
2394 - $new_classes = apply_filters( 'bbp_get_topic_class', $post_classes, $topic_id, $classes );
2353 + // Return
2354 + return 'class="' . implode( ' ', $new_classes ) . '"';
2355 + }
2395 2356
2396 - // Return
2397 - return 'class="' . implode( ' ', $new_classes ) . '"';
2398 -}
2399 -
2400 2357 /** Topic Admin Links *********************************************************/
2401 2358
2402 2359 /**
2403 - * Output admin links for topic.
2360 + * Output admin links for topic
2404 2361 *
2405 - * @param array $args See {@link bbp_get_topic_admin_links()}.
2362 + * @param array $args See {@link bbp_get_topic_admin_links()}
2406 2363 */
2407 2364 function bbp_topic_admin_links( $args = array() ) {
2408 2365 echo bbp_get_topic_admin_links( $args );
2409 2366 }
2410 -
2411 -/**
2412 - * Return admin links for topic.
2413 - *
2414 - * Move topic functionality is handled by the edit topic page.
2415 - *
2416 - * @param array $args This function supports these arguments:
2417 - * - id: Optional. Topic id
2418 - * - before: Before the links
2419 - * - after: After the links
2420 - * - sep: Links separator
2421 - * - links: Topic admin links array
2422 - * @return string Topic admin links.
2423 - */
2367 + /**
2368 + * Return admin links for topic.
2369 + *
2370 + * Move topic functionality is handled by the edit topic page.
2371 + *
2372 + * @param array $args This function supports these arguments:
2373 + * - id: Optional. Topic id
2374 + * - before: Before the links
2375 + * - after: After the links
2376 + * - sep: Links separator
2377 + * - links: Topic admin links array
2378 + * @return string Topic admin links
2379 + */
2424 2380 function bbp_get_topic_admin_links( $args = array() ) {
2425 2381
2426 2382 // Parse arguments against default values
2427 2383 $r = bbp_parse_args(
@@ -2478,30 +2434,30 @@
2478 2434 return apply_filters( 'bbp_get_topic_admin_links', $retval, $r, $args );
2479 2435 }
2480 2436
2481 2437 /**
2482 - * Output the edit link of the topic.
2438 + * Output the edit link of the topic
2483 2439 *
2484 2440 * @since 2.0.0 bbPress (r2727)
2485 2441 *
2486 - * @param array $args See {@link bbp_get_topic_edit_link()}.
2442 + * @param array $args See {@link bbp_get_topic_edit_link()}
2487 2443 */
2488 2444 function bbp_topic_edit_link( $args = array() ) {
2489 2445 echo bbp_get_topic_edit_link( $args );
2490 2446 }
2491 2447
2492 -/**
2493 - * Return the edit link of the topic.
2494 - *
2495 - * @since 2.0.0 bbPress (r2727)
2496 - *
2497 - * @param array $args This function supports these args:
2498 - * - id: Optional. Topic id
2499 - * - link_before: Before the link
2500 - * - link_after: After the link
2501 - * - edit_text: Edit text
2502 - * @return string Topic edit link.
2503 - */
2448 + /**
2449 + * Return the edit link of the topic
2450 + *
2451 + * @since 2.0.0 bbPress (r2727)
2452 + *
2453 + * @param array $args This function supports these args:
2454 + * - id: Optional. Topic id
2455 + * - link_before: Before the link
2456 + * - link_after: After the link
2457 + * - edit_text: Edit text
2458 + * @return string Topic edit link
2459 + */
2504 2460 function bbp_get_topic_edit_link( $args = array() ) {
2505 2461
2506 2462 // Parse arguments against default values
2507 2463 $r = bbp_parse_args(
@@ -2541,26 +2497,25 @@
2541 2497 return apply_filters( 'bbp_get_topic_edit_link', $retval, $r, $args );
2542 2498 }
2543 2499
2544 2500 /**
2545 - * Output URL to the topic edit page.
2501 + * Output URL to the topic edit page
2546 2502 *
2547 2503 * @since 2.0.0 bbPress (r2753)
2548 2504 *
2549 - * @param int $topic_id Optional. Topic id.
2505 + * @param int $topic_id Optional. Topic id
2550 2506 */
2551 2507 function bbp_topic_edit_url( $topic_id = 0 ) {
2552 2508 echo esc_url( bbp_get_topic_edit_url( $topic_id ) );
2553 2509 }
2554 -
2555 -/**
2556 - * Return URL to the topic edit page.
2557 - *
2558 - * @since 2.0.0 bbPress (r2753)
2559 - *
2560 - * @param int $topic_id Optional. Topic id.
2561 - * @return string Topic edit url.
2562 - */
2510 + /**
2511 + * Return URL to the topic edit page
2512 + *
2513 + * @since 2.0.0 bbPress (r2753)
2514 + *
2515 + * @param int $topic_id Optional. Topic id
2516 + * @return string Topic edit url
2517 + */
2563 2518 function bbp_get_topic_edit_url( $topic_id = 0 ) {
2564 2519
2565 2520 $topic = bbp_get_topic( $topic_id );
2566 2521 if ( empty( $topic ) ) {
@@ -2594,33 +2549,33 @@
2594 2549 return apply_filters( 'bbp_get_topic_edit_url', $url, $topic_id );
2595 2550 }
2596 2551
2597 2552 /**
2598 - * Output the trash link of the topic.
2553 + * Output the trash link of the topic
2599 2554 *
2600 2555 * @since 2.0.0 bbPress (r2727)
2601 2556 *
2602 - * @param array $args See {@link bbp_get_topic_trash_link()}.
2557 + * @param array $args See {@link bbp_get_topic_trash_link()}
2603 2558 */
2604 2559 function bbp_topic_trash_link( $args = array() ) {
2605 2560 echo bbp_get_topic_trash_link( $args );
2606 2561 }
2607 2562
2608 -/**
2609 - * Return the trash link of the topic.
2610 - *
2611 - * @since 2.0.0 bbPress (r2727)
2612 - *
2613 - * @param array $args This function supports these args:
2614 - * - id: Optional. Topic id
2615 - * - link_before: Before the link
2616 - * - link_after: After the link
2617 - * - sep: Links separator
2618 - * - trash_text: Trash text
2619 - * - restore_text: Restore text
2620 - * - delete_text: Delete text
2621 - * @return string Topic trash link.
2622 - */
2563 + /**
2564 + * Return the trash link of the topic
2565 + *
2566 + * @since 2.0.0 bbPress (r2727)
2567 + *
2568 + * @param array $args This function supports these args:
2569 + * - id: Optional. Topic id
2570 + * - link_before: Before the link
2571 + * - link_after: After the link
2572 + * - sep: Links separator
2573 + * - trash_text: Trash text
2574 + * - restore_text: Restore text
2575 + * - delete_text: Delete text
2576 + * @return string Topic trash link
2577 + */
2623 2578 function bbp_get_topic_trash_link( $args = array() ) {
2624 2579
2625 2580 // Parse arguments against default values
2626 2581 $r = bbp_parse_args(
@@ -2695,31 +2650,31 @@
2695 2650 return apply_filters( 'bbp_get_topic_trash_link', $retval, $r, $args );
2696 2651 }
2697 2652
2698 2653 /**
2699 - * Output the close link of the topic.
2654 + * Output the close link of the topic
2700 2655 *
2701 2656 * @since 2.0.0 bbPress (r2727)
2702 2657 *
2703 - * @param array $args See {@link bbp_get_topic_close_link()}.
2658 + * @param array $args See {@link bbp_get_topic_close_link()}
2704 2659 */
2705 2660 function bbp_topic_close_link( $args = array() ) {
2706 2661 echo bbp_get_topic_close_link( $args );
2707 2662 }
2708 2663
2709 -/**
2710 - * Return the close link of the topic.
2711 - *
2712 - * @since 2.0.0 bbPress (r2727)
2713 - *
2714 - * @param array $args This function supports these args:
2715 - * - id: Optional. Topic id
2716 - * - link_before: Before the link
2717 - * - link_after: After the link
2718 - * - close_text: Close text
2719 - * - open_text: Open text
2720 - * @return string Topic close link.
2721 - */
2664 + /**
2665 + * Return the close link of the topic
2666 + *
2667 + * @since 2.0.0 bbPress (r2727)
2668 + *
2669 + * @param array $args This function supports these args:
2670 + * - id: Optional. Topic id
2671 + * - link_before: Before the link
2672 + * - link_after: After the link
2673 + * - close_text: Close text
2674 + * - open_text: Open text
2675 + * @return string Topic close link
2676 + */
2722 2677 function bbp_get_topic_close_link( $args = array() ) {
2723 2678
2724 2679 // Parse arguments against default values
2725 2680 $r = bbp_parse_args(
@@ -2757,32 +2712,32 @@
2757 2712 return apply_filters( 'bbp_get_topic_close_link', $retval, $r, $args );
2758 2713 }
2759 2714
2760 2715 /**
2761 - * Output the approve link of the topic.
2716 + * Output the approve link of the topic
2762 2717 *
2763 2718 * @since 2.6.0 bbPress (r5504)
2764 2719 *
2765 - * @param array $args See {@link bbp_get_topic_approve_link()}.
2720 + * @param array $args See {@link bbp_get_topic_approve_link()}
2766 2721 */
2767 2722 function bbp_topic_approve_link( $args = array() ) {
2768 2723 echo bbp_get_topic_approve_link( $args );
2769 2724 }
2770 2725
2771 -/**
2772 - * Return the approve link of the topic.
2773 - *
2774 - * @since 2.6.0 bbPress (r5504)
2775 - *
2776 - * @param array $args This function supports these args:
2777 - * - id: Optional. Topic id
2778 - * - link_before: Before the link
2779 - * - link_after: After the link
2780 - * - sep: Separator between links
2781 - * - approve_text: Approve text
2782 - * - unapprove_text: Unapprove text
2783 - * @return string Topic approve link.
2784 - */
2726 + /**
2727 + * Return the approve link of the topic
2728 + *
2729 + * @since 2.6.0 bbPress (r5504)
2730 + *
2731 + * @param array $args This function supports these args:
2732 + * - id: Optional. Topic id
2733 + * - link_before: Before the link
2734 + * - link_after: After the link
2735 + * - sep: Separator between links
2736 + * - approve_text: Approve text
2737 + * - unapprove_text: Unapprove text
2738 + * @return string Topic approve link
2739 + */
2785 2740 function bbp_get_topic_approve_link( $args = array() ) {
2786 2741
2787 2742 // Parse arguments against default values
2788 2743 $r = bbp_parse_args(
@@ -2820,33 +2775,33 @@
2820 2775 return apply_filters( 'bbp_get_topic_approve_link', $retval, $r, $args );
2821 2776 }
2822 2777
2823 2778 /**
2824 - * Output the stick link of the topic.
2779 + * Output the stick link of the topic
2825 2780 *
2826 2781 * @since 2.0.0 bbPress (r2754)
2827 2782 *
2828 - * @param array $args See {@link bbp_get_topic_stick_link()}.
2783 + * @param array $args See {@link bbp_get_topic_stick_link()}
2829 2784 */
2830 2785 function bbp_topic_stick_link( $args = array() ) {
2831 2786 echo bbp_get_topic_stick_link( $args );
2832 2787 }
2833 2788
2834 -/**
2835 - * Return the stick link of the topic.
2836 - *
2837 - * @since 2.0.0 bbPress (r2754)
2838 - *
2839 - * @param array $args This function supports these args:
2840 - * - id: Optional. Topic id
2841 - * - link_before: Before the link
2842 - * - link_after: After the link
2843 - * - stick_text: Stick text
2844 - * - unstick_text: Unstick text
2845 - * - super_text: Stick to front text
2846 - *
2847 - * @return string Topic stick link.
2848 - */
2789 + /**
2790 + * Return the stick link of the topic
2791 + *
2792 + * @since 2.0.0 bbPress (r2754)
2793 + *
2794 + * @param array $args This function supports these args:
2795 + * - id: Optional. Topic id
2796 + * - link_before: Before the link
2797 + * - link_after: After the link
2798 + * - stick_text: Stick text
2799 + * - unstick_text: Unstick text
2800 + * - super_text: Stick to front text
2801 + *
2802 + * @return string Topic stick link
2803 + */
2849 2804 function bbp_get_topic_stick_link( $args = array() ) {
2850 2805
2851 2806 // Parse arguments against default values
2852 2807 $r = bbp_parse_args(
@@ -2912,9 +2867,9 @@
2912 2867 return apply_filters( 'bbp_get_topic_stick_link', $retval, $r, $args );
2913 2868 }
2914 2869
2915 2870 /**
2916 - * Output the merge link of the topic.
2871 + * Output the merge link of the topic
2917 2872 *
2918 2873 * @since 2.0.0 bbPress (r2756)
2919 2874 *
2920 2875 * @param array $args
@@ -2922,21 +2877,21 @@
2922 2877 function bbp_topic_merge_link( $args = array() ) {
2923 2878 echo bbp_get_topic_merge_link( $args );
2924 2879 }
2925 2880
2926 -/**
2927 - * Return the merge link of the topic.
2928 - *
2929 - * @since 2.0.0 bbPress (r2756)
2930 - *
2931 - * @param array $args This function supports these args:
2932 - * - id: Optional. Topic id
2933 - * - link_before: Before the link
2934 - * - link_after: After the link
2935 - * - merge_text: Merge text
2936 - *
2937 - * @return string Topic merge link.
2938 - */
2881 + /**
2882 + * Return the merge link of the topic
2883 + *
2884 + * @since 2.0.0 bbPress (r2756)
2885 + *
2886 + * @param array $args This function supports these args:
2887 + * - id: Optional. Topic id
2888 + * - link_before: Before the link
2889 + * - link_after: After the link
2890 + * - merge_text: Merge text
2891 + *
2892 + * @return string Topic merge link
2893 + */
2939 2894 function bbp_get_topic_merge_link( $args = array() ) {
2940 2895
2941 2896 // Parse arguments against default values
2942 2897 $r = bbp_parse_args(
@@ -2957,10 +2912,9 @@
2957 2912 if ( empty( $topic ) || ! bbp_current_user_can_access_topic_moderation( $topic->ID ) ) {
2958 2913 return;
2959 2914 }
2960 2915
2961 - $query = array( 'action' => 'merge' );
2962 - $uri = add_query_arg( $query, bbp_get_topic_edit_url( $topic->ID ) );
2916 + $uri = add_query_arg( array( 'action' => 'merge' ), bbp_get_topic_edit_url( $topic->ID ) );
2963 2917 $retval = $r['link_before'] . '<a href="' . esc_url( $uri ) . '" class="bbp-topic-merge-link">' . $r['merge_text'] . '</a>' . $r['link_after'];
2964 2918
2965 2919 // Filter & return
2966 2920 return apply_filters( 'bbp_get_topic_merge_link', $retval, $r, $args );
@@ -2966,32 +2920,32 @@
2966 2920 return apply_filters( 'bbp_get_topic_merge_link', $retval, $r, $args );
2967 2921 }
2968 2922
2969 2923 /**
2970 - * Output the spam link of the topic.
2924 + * Output the spam link of the topic
2971 2925 *
2972 2926 * @since 2.0.0 bbPress (r2727)
2973 2927 *
2974 - * @param array $args See {@link bbp_get_topic_spam_link()}.
2928 + * @param array $args See {@link bbp_get_topic_spam_link()}
2975 2929 */
2976 2930 function bbp_topic_spam_link( $args = array() ) {
2977 2931 echo bbp_get_topic_spam_link( $args );
2978 2932 }
2979 2933
2980 -/**
2981 - * Return the spam link of the topic.
2982 - *
2983 - * @since 2.0.0 bbPress (r2727)
2984 - *
2985 - * @param array $args This function supports these args:
2986 - * - id: Optional. Topic id
2987 - * - link_before: Before the link
2988 - * - link_after: After the link
2989 - * - spam_text: Spam text
2990 - * - unspam_text: Unspam text
2991 - *
2992 - * @return string Topic spam link.
2993 - */
2934 + /**
2935 + * Return the spam link of the topic
2936 + *
2937 + * @since 2.0.0 bbPress (r2727)
2938 + *
2939 + * @param array $args This function supports these args:
2940 + * - id: Optional. Topic id
2941 + * - link_before: Before the link
2942 + * - link_after: After the link
2943 + * - spam_text: Spam text
2944 + * - unspam_text: Unspam text
2945 + *
2946 + * @return string Topic spam link
2947 + */
2994 2948 function bbp_get_topic_spam_link( $args = array() ) {
2995 2949
2996 2950 // Parse arguments against default values
2997 2951 $r = bbp_parse_args(
@@ -3031,9 +2985,9 @@
3031 2985 return apply_filters( 'bbp_get_topic_spam_link', $retval, $r, $args );
3032 2986 }
3033 2987
3034 2988 /**
3035 - * Output the link to go directly to the reply form.
2989 + * Output the link to go directly to the reply form
3036 2990 *
3037 2991 * @since 2.4.0 bbPress (r4966)
3038 2992 *
3039 2993 * @param array $args
@@ -3041,17 +2995,17 @@
3041 2995 function bbp_topic_reply_link( $args = array() ) {
3042 2996 echo bbp_get_topic_reply_link( $args );
3043 2997 }
3044 2998
3045 -/**
3046 - * Return the link to go directly to the reply form.
3047 - *
3048 - * @since 2.4.0 bbPress (r4966)
3049 - *
3050 - * @param array $args Arguments.
3051 - *
3052 - * @return string Link for a reply to a topic.
3053 - */
2999 + /**
3000 + * Return the link to go directly to the reply form
3001 + *
3002 + * @since 2.4.0 bbPress (r4966)
3003 + *
3004 + * @param array $args Arguments
3005 + *
3006 + * @return string Link for a reply to a topic
3007 + */
3054 3008 function bbp_get_topic_reply_link( $args = array() ) {
3055 3009
3056 3010 // Parse arguments against default values
3057 3011 $r = bbp_parse_args(
@@ -3090,13 +3044,13 @@
3090 3044
3091 3045 /** Topic Pagination **********************************************************/
3092 3046
3093 3047 /**
3094 - * Return the base URL used inside of pagination links.
3048 + * Return the base URL used inside of pagination links
3095 3049 *
3096 3050 * @since 2.6.0 bbPress (r6402)
3097 3051 *
3098 - * @param int $forum_id Forum id.
3052 + * @param int $forum_id
3099 3053 * @return string
3100 3054 */
3101 3055 function bbp_get_topics_pagination_base( $forum_id = 0 ) {
3102 3056
@@ -3160,9 +3114,9 @@
3160 3114 return apply_filters( 'bbp_get_topics_pagination_base', $base, $forum_id );
3161 3115 }
3162 3116
3163 3117 /**
3164 - * Output the pagination count.
3118 + * Output the pagination count
3165 3119 *
3166 3120 * The results are unescaped by design, to allow them to be filtered freely via
3167 3121 * the 'bbp_get_forum_pagination_count' filter.
3168 3122 *
@@ -3170,16 +3124,15 @@
3170 3124 */
3171 3125 function bbp_forum_pagination_count() {
3172 3126 echo bbp_get_forum_pagination_count();
3173 3127 }
3174 -
3175 -/**
3176 - * Return the pagination count.
3177 - *
3178 - * @since 2.0.0 bbPress (r2574)
3179 - *
3180 - * @return string Forum Pagination count.
3181 - */
3128 + /**
3129 + * Return the pagination count
3130 + *
3131 + * @since 2.0.0 bbPress (r2574)
3132 + *
3133 + * @return string Forum Pagination count
3134 + */
3182 3135 function bbp_get_forum_pagination_count() {
3183 3136 $bbp = bbpress();
3184 3137
3185 3138 // Define local variable(s)
@@ -3222,9 +3175,9 @@
3222 3175 return apply_filters( 'bbp_get_forum_pagination_count', $retstr );
3223 3176 }
3224 3177
3225 3178 /**
3226 - * Output pagination links.
3179 + * Output pagination links
3227 3180 *
3228 3181 * @since 2.0.0 bbPress (r2574)
3229 3182 */
3230 3183 function bbp_forum_pagination_links() {
@@ -3229,29 +3182,28 @@
3229 3182 */
3230 3183 function bbp_forum_pagination_links() {
3231 3184 echo bbp_get_forum_pagination_links();
3232 3185 }
3186 + /**
3187 + * Return pagination links
3188 + *
3189 + * @since 2.0.0 bbPress (r2574)
3190 + *
3191 + * @return string Pagination links
3192 + */
3193 + function bbp_get_forum_pagination_links() {
3194 + $bbp = bbpress();
3233 3195
3234 -/**
3235 - * Return pagination links.
3236 - *
3237 - * @since 2.0.0 bbPress (r2574)
3238 - *
3239 - * @return string Pagination links.
3240 - */
3241 -function bbp_get_forum_pagination_links() {
3242 - $bbp = bbpress();
3196 + if ( empty( $bbp->topic_query ) ) {
3197 + return false;
3198 + }
3243 3199
3244 - if ( empty( $bbp->topic_query ) ) {
3245 - return false;
3200 + // Filter & return
3201 + return apply_filters( 'bbp_get_forum_pagination_links', $bbp->topic_query->pagination_links );
3246 3202 }
3247 3203
3248 - // Filter & return
3249 - return apply_filters( 'bbp_get_forum_pagination_links', $bbp->topic_query->pagination_links );
3250 -}
3251 -
3252 3204 /**
3253 - * Displays topic notices.
3205 + * Displays topic notices
3254 3206 *
3255 3207 * @since 2.0.0 bbPress (r2744)
3256 3208 */
3257 3209 function bbp_topic_notices() {
@@ -3297,9 +3249,9 @@
3297 3249 bbp_add_error( 'topic_notice', $notice_text, 'message' );
3298 3250 }
3299 3251
3300 3252 /**
3301 - * Displays topic type select box (normal/sticky/super sticky).
3253 + * Displays topic type select box (normal/sticky/super sticky)
3302 3254 *
3303 3255 * @since 2.0.0 bbPress (r2784)
3304 3256 *
3305 3257 * @deprecated 2.4.0 bbPress (r5059)
@@ -3314,9 +3266,9 @@
3314 3266 echo bbp_get_form_topic_type_dropdown( $args );
3315 3267 }
3316 3268
3317 3269 /**
3318 - * Displays topic type select box (normal/sticky/super sticky).
3270 + * Displays topic type select box (normal/sticky/super sticky)
3319 3271 *
3320 3272 * @since 2.4.0 bbPress (r5060)
3321 3273 *
3322 3274 * @param $args This function supports these arguments:
@@ -3327,20 +3279,19 @@
3327 3279 */
3328 3280 function bbp_form_topic_type_dropdown( $args = array() ) {
3329 3281 echo bbp_get_form_topic_type_dropdown( $args );
3330 3282 }
3331 -
3332 -/**
3333 - * Returns topic type select box (normal/sticky/super sticky).
3334 - *
3335 - * @since 2.4.0 bbPress (r5060)
3336 - *
3337 - * @param $args This function supports these arguments:
3338 - * - select_id: Select id. Defaults to bbp_stick_topic
3339 - * - tab: Deprecated. Tabindex
3340 - * - topic_id: Topic id
3341 - * - selected: Override the selected option
3342 - */
3283 + /**
3284 + * Returns topic type select box (normal/sticky/super sticky)
3285 + *
3286 + * @since 2.4.0 bbPress (r5060)
3287 + *
3288 + * @param $args This function supports these arguments:
3289 + * - select_id: Select id. Defaults to bbp_stick_topic
3290 + * - tab: Deprecated. Tabindex
3291 + * - topic_id: Topic id
3292 + * - selected: Override the selected option
3293 + */
3343 3294 function bbp_get_form_topic_type_dropdown( $args = array() ) {
3344 3295
3345 3296 // Parse arguments against default values
3346 3297 $r = bbp_parse_args(
@@ -3409,9 +3360,9 @@
3409 3360 return apply_filters( 'bbp_get_form_topic_type_dropdown', ob_get_clean(), $r, $args );
3410 3361 }
3411 3362
3412 3363 /**
3413 - * Output value topic status dropdown.
3364 + * Output value topic status dropdown
3414 3365 *
3415 3366 * @since 2.4.0 bbPress (r5060)
3416 3367 *
3417 3368 * @param $args This function supports these arguments:
@@ -3422,24 +3373,23 @@
3422 3373 */
3423 3374 function bbp_form_topic_status_dropdown( $args = array() ) {
3424 3375 echo bbp_get_form_topic_status_dropdown( $args );
3425 3376 }
3426 -
3427 -/**
3428 - * Returns topic status dropdown.
3429 - *
3430 - * This dropdown is only intended to be seen by users with the 'moderate'
3431 - * capability. Because of this, no additional capability checks are performed
3432 - * within this function to check available topic statuses.
3433 - *
3434 - * @since 2.4.0 bbPress (r5060)
3435 - *
3436 - * @param $args This function supports these arguments:
3437 - * - select_id: Select id. Defaults to bbp_topic_status
3438 - * - tab: Deprecated. Tabindex
3439 - * - topic_id: Topic id
3440 - * - selected: Override the selected option
3441 - */
3377 + /**
3378 + * Returns topic status dropdown
3379 + *
3380 + * This dropdown is only intended to be seen by users with the 'moderate'
3381 + * capability. Because of this, no additional capability checks are performed
3382 + * within this function to check available topic statuses.
3383 + *
3384 + * @since 2.4.0 bbPress (r5060)
3385 + *
3386 + * @param $args This function supports these arguments:
3387 + * - select_id: Select id. Defaults to bbp_topic_status
3388 + * - tab: Deprecated. Tabindex
3389 + * - topic_id: Topic id
3390 + * - selected: Override the selected option
3391 + */
3442 3392 function bbp_get_form_topic_status_dropdown( $args = array() ) {
3443 3393
3444 3394 // Parse arguments against default values
3445 3395 $r = bbp_parse_args(
@@ -3503,22 +3453,21 @@
3503 3453 */
3504 3454 function bbp_single_topic_description( $args = array() ) {
3505 3455 echo bbp_get_single_topic_description( $args );
3506 3456 }
3507 -
3508 -/**
3509 - * Return a fancy description of the current topic, including total topics,
3510 - * total replies, and last activity.
3511 - *
3512 - * @since 2.0.0 bbPress (r2872)
3513 - *
3514 - * @param array $args This function supports these arguments:
3515 - * - topic_id: Topic id
3516 - * - before: Before the text
3517 - * - after: After the text
3518 - * - size: Size of the avatar
3519 - * @return string Filtered topic description.
3520 - */
3457 + /**
3458 + * Return a fancy description of the current topic, including total topics,
3459 + * total replies, and last activity.
3460 + *
3461 + * @since 2.0.0 bbPress (r2872)
3462 + *
3463 + * @param array $args This function supports these arguments:
3464 + * - topic_id: Topic id
3465 + * - before: Before the text
3466 + * - after: After the text
3467 + * - size: Size of the avatar
3468 + * @return string Filtered topic description
3469 + */
3521 3470 function bbp_get_single_topic_description( $args = array() ) {
3522 3471
3523 3472 // Parse arguments against default values
3524 3473 $r = bbp_parse_args(
@@ -3549,11 +3498,9 @@
3549 3498 $voice_count = sprintf( _n( '%s voice', '%s voices', $vc_int, 'bbpress' ), $voice_count );
3550 3499
3551 3500 // Topic has activity (could be from reply or topic author)
3552 3501 $last_active = bbp_get_topic_last_active_id( $topic_id );
3553 - if ( ! empty( $last_active ) ) {
3554 -
3555 - // Last-updated-by should always exist if last-active does
3502 + if ( ! empty( $vc_int ) && ! empty( $last_active ) ) {
3556 3503 $last_updated_by = bbp_get_author_link(
3557 3504 array(
3558 3505 'post_id' => $last_active,
3559 3506 'size' => $r['size']
@@ -3558,20 +3505,11 @@
3558 3505 'post_id' => $last_active,
3559 3506 'size' => $r['size']
3560 3507 )
3561 3508 );
3562 -
3563 - // Voice count is non-zero (registered users engaged)
3564 - if ( ! empty( $vc_int ) ) {
3565 3509 /* translators: 1: Reply count, 2: Voice count, 3: Last updated time, 4: Last updated by */
3566 3510 $retstr = sprintf( esc_html__( 'This topic has %1$s, %2$s, and was last updated %3$s by %4$s.', 'bbpress' ), $reply_count, $voice_count, $time_since, $last_updated_by );
3567 3511
3568 - // Voice count is zero (anonymous users only)
3569 - } else {
3570 - /* translators: 1: Last updated time, 2: Last updated by */
3571 - $retstr = sprintf( esc_html__( 'This topic was last updated %1$s by %2$s.', 'bbpress' ), $time_since, $last_updated_by );
3572 - }
3573 -
3574 3512 // Topic has no replies
3575 3513 } elseif ( ! empty( $vc_int ) && ! empty( $reply_count ) ) {
3576 3514 /* translators: 1: Voice count, 2: Reply count */
3577 3515 $retstr = sprintf( esc_html__( 'This topic has %1$s and %2$s.', 'bbpress' ), $voice_count, $reply_count );
@@ -3601,9 +3539,9 @@
3601 3539
3602 3540 /** Topic Tags ****************************************************************/
3603 3541
3604 3542 /**
3605 - * Output the unique id of the topic tag taxonomy.
3543 + * Output the unique id of the topic tag taxonomy
3606 3544 *
3607 3545 * @since 2.0.0 bbPress (r3348)
3608 3546 */
3609 3547 function bbp_topic_tag_tax_id() {
@@ -3608,24 +3546,23 @@
3608 3546 */
3609 3547 function bbp_topic_tag_tax_id() {
3610 3548 echo bbp_get_topic_tag_tax_id();
3611 3549 }
3550 + /**
3551 + * Return the unique id of the topic tag taxonomy
3552 + *
3553 + * @since 2.0.0 bbPress (r3348)
3554 + *
3555 + * @return string The unique topic tag taxonomy
3556 + */
3557 + function bbp_get_topic_tag_tax_id() {
3612 3558
3613 -/**
3614 - * Return the unique id of the topic tag taxonomy.
3615 - *
3616 - * @since 2.0.0 bbPress (r3348)
3617 - *
3618 - * @return string The unique topic tag taxonomy.
3619 - */
3620 -function bbp_get_topic_tag_tax_id() {
3559 + // Filter & return
3560 + return apply_filters( 'bbp_get_topic_tag_tax_id', bbpress()->topic_tag_tax_id );
3561 + }
3621 3562
3622 - // Filter & return
3623 - return apply_filters( 'bbp_get_topic_tag_tax_id', bbpress()->topic_tag_tax_id );
3624 -}
3625 -
3626 3563 /**
3627 - * Return array of labels used by the topic-tag taxonomy.
3564 + * Return array of labels used by the topic-tag taxonomy
3628 3565 *
3629 3566 * @since 2.5.0 bbPress (r5130)
3630 3567 *
3631 3568 * @return array
@@ -3662,9 +3599,9 @@
3662 3599 );
3663 3600 }
3664 3601
3665 3602 /**
3666 - * Return an array of topic-tag taxonomy rewrite settings.
3603 + * Return an array of topic-tag taxonomy rewrite settings
3667 3604 *
3668 3605 * @since 2.5.0 bbPress (r5130)
3669 3606 *
3670 3607 * @return array
@@ -3681,44 +3618,44 @@
3681 3618 );
3682 3619 }
3683 3620
3684 3621 /**
3685 - * Output the id of the current tag.
3622 + * Output the id of the current tag
3686 3623 *
3687 3624 * @since 2.0.0 bbPress (r3109)
3625 + *
3688 3626 */
3689 3627 function bbp_topic_tag_id( $tag = '' ) {
3690 3628 echo bbp_get_topic_tag_id( $tag );
3691 3629 }
3630 + /**
3631 + * Return the id of the current tag
3632 + *
3633 + * @since 2.0.0 bbPress (r3109)
3634 + *
3635 + * @return string Term Name
3636 + */
3637 + function bbp_get_topic_tag_id( $tag = '' ) {
3692 3638
3693 -/**
3694 - * Return the id of the current tag.
3695 - *
3696 - * @since 2.0.0 bbPress (r3109)
3697 - *
3698 - * @return string Term Name.
3699 - */
3700 -function bbp_get_topic_tag_id( $tag = '' ) {
3639 + // Get the term
3640 + if ( ! empty( $tag ) ) {
3641 + $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() );
3642 + } else {
3643 + $tag = get_query_var( 'term' );
3644 + $term = get_queried_object();
3645 + }
3701 3646
3702 - // Get the term
3703 - if ( ! empty( $tag ) ) {
3704 - $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() );
3705 - } else {
3706 - $tag = get_query_var( 'term' );
3707 - $term = get_queried_object();
3647 + // Get the term ID
3648 + $retval = ! empty( $term->term_id )
3649 + ? $term->term_id
3650 + : 0;
3651 +
3652 + // Filter & return
3653 + return (int) apply_filters( 'bbp_get_topic_tag_id', (int) $retval, $tag, $term );
3708 3654 }
3709 3655
3710 - // Get the term ID
3711 - $retval = ! empty( $term->term_id )
3712 - ? $term->term_id
3713 - : 0;
3714 -
3715 - // Filter & return
3716 - return (int) apply_filters( 'bbp_get_topic_tag_id', (int) $retval, $tag, $term );
3717 -}
3718 -
3719 3656 /**
3720 - * Output the name of the current tag.
3657 + * Output the name of the current tag
3721 3658 *
3722 3659 * @since 2.0.0 bbPress (r3109)
3723 3660 */
3724 3661 function bbp_topic_tag_name( $tag = '' ) {
@@ -3723,37 +3660,36 @@
3723 3660 */
3724 3661 function bbp_topic_tag_name( $tag = '' ) {
3725 3662 echo bbp_get_topic_tag_name( $tag );
3726 3663 }
3664 + /**
3665 + * Return the name of the current tag
3666 + *
3667 + * @since 2.0.0 bbPress (r3109)
3668 + *
3669 + * @return string Term Name
3670 + */
3671 + function bbp_get_topic_tag_name( $tag = '' ) {
3727 3672
3728 -/**
3729 - * Return the name of the current tag.
3730 - *
3731 - * @since 2.0.0 bbPress (r3109)
3732 - *
3733 - * @return string Term Name.
3734 - */
3735 -function bbp_get_topic_tag_name( $tag = '' ) {
3673 + // Get the term
3674 + if ( ! empty( $tag ) ) {
3675 + $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() );
3676 + } else {
3677 + $tag = get_query_var( 'term' );
3678 + $term = get_queried_object();
3679 + }
3736 3680
3737 - // Get the term
3738 - if ( ! empty( $tag ) ) {
3739 - $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() );
3740 - } else {
3741 - $tag = get_query_var( 'term' );
3742 - $term = get_queried_object();
3681 + // Get the term name
3682 + $retval = ! empty( $term->name )
3683 + ? $term->name
3684 + : '';
3685 +
3686 + // Filter & return
3687 + return apply_filters( 'bbp_get_topic_tag_name', $retval, $tag, $term );
3743 3688 }
3744 3689
3745 - // Get the term name
3746 - $retval = ! empty( $term->name )
3747 - ? $term->name
3748 - : '';
3749 -
3750 - // Filter & return
3751 - return apply_filters( 'bbp_get_topic_tag_name', $retval, $tag, $term );
3752 -}
3753 -
3754 3690 /**
3755 - * Output the slug of the current tag.
3691 + * Output the slug of the current tag
3756 3692 *
3757 3693 * @since 2.0.0 bbPress (r3109)
3758 3694 */
3759 3695 function bbp_topic_tag_slug( $tag = '' ) {
@@ -3758,37 +3694,36 @@
3758 3694 */
3759 3695 function bbp_topic_tag_slug( $tag = '' ) {
3760 3696 echo bbp_get_topic_tag_slug( $tag );
3761 3697 }
3698 + /**
3699 + * Return the slug of the current tag
3700 + *
3701 + * @since 2.0.0 bbPress (r3109)
3702 + *
3703 + * @return string Term Name
3704 + */
3705 + function bbp_get_topic_tag_slug( $tag = '' ) {
3762 3706
3763 -/**
3764 - * Return the slug of the current tag.
3765 - *
3766 - * @since 2.0.0 bbPress (r3109)
3767 - *
3768 - * @return string Term Name.
3769 - */
3770 -function bbp_get_topic_tag_slug( $tag = '' ) {
3707 + // Get the term
3708 + if ( ! empty( $tag ) ) {
3709 + $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() );
3710 + } else {
3711 + $tag = get_query_var( 'term' );
3712 + $term = get_queried_object();
3713 + }
3771 3714
3772 - // Get the term
3773 - if ( ! empty( $tag ) ) {
3774 - $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() );
3775 - } else {
3776 - $tag = get_query_var( 'term' );
3777 - $term = get_queried_object();
3715 + // Get the term slug
3716 + $retval = ! empty( $term->slug )
3717 + ? $term->slug
3718 + : '';
3719 +
3720 + // Filter & return
3721 + return apply_filters( 'bbp_get_topic_tag_slug', $retval, $tag, $term );
3778 3722 }
3779 3723
3780 - // Get the term slug
3781 - $retval = ! empty( $term->slug )
3782 - ? $term->slug
3783 - : '';
3784 -
3785 - // Filter & return
3786 - return apply_filters( 'bbp_get_topic_tag_slug', $retval, $tag, $term );
3787 -}
3788 -
3789 3724 /**
3790 - * Output the link of the current tag.
3725 + * Output the link of the current tag
3791 3726 *
3792 3727 * @since 2.0.0 bbPress (r3348)
3793 3728 */
3794 3729 function bbp_topic_tag_link( $tag = '' ) {
@@ -3793,37 +3728,36 @@
3793 3728 */
3794 3729 function bbp_topic_tag_link( $tag = '' ) {
3795 3730 echo esc_url( bbp_get_topic_tag_link( $tag ) );
3796 3731 }
3732 + /**
3733 + * Return the link of the current tag
3734 + *
3735 + * @since 2.0.0 bbPress (r3348)
3736 + *
3737 + * @return string Term Name
3738 + */
3739 + function bbp_get_topic_tag_link( $tag = '' ) {
3797 3740
3798 -/**
3799 - * Return the link of the current tag.
3800 - *
3801 - * @since 2.0.0 bbPress (r3348)
3802 - *
3803 - * @return string Term Name.
3804 - */
3805 -function bbp_get_topic_tag_link( $tag = '' ) {
3741 + // Get the term
3742 + if ( ! empty( $tag ) ) {
3743 + $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() );
3744 + } else {
3745 + $tag = get_query_var( 'term' );
3746 + $term = get_queried_object();
3747 + }
3806 3748
3807 - // Get the term
3808 - if ( ! empty( $tag ) ) {
3809 - $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() );
3810 - } else {
3811 - $tag = get_query_var( 'term' );
3812 - $term = get_queried_object();
3749 + // Get the term link
3750 + $retval = ! empty( $term->term_id )
3751 + ? get_term_link( $term, bbp_get_topic_tag_tax_id() )
3752 + : '';
3753 +
3754 + // Filter & return
3755 + return apply_filters( 'bbp_get_topic_tag_link', $retval, $tag, $term );
3813 3756 }
3814 3757
3815 - // Get the term link
3816 - $retval = ! empty( $term->term_id )
3817 - ? get_term_link( $term, bbp_get_topic_tag_tax_id() )
3818 - : '';
3819 -
3820 - // Filter & return
3821 - return apply_filters( 'bbp_get_topic_tag_link', $retval, $tag, $term );
3822 -}
3823 -
3824 3758 /**
3825 - * Output the link of the current tag.
3759 + * Output the link of the current tag
3826 3760 *
3827 3761 * @since 2.0.0 bbPress (r3348)
3828 3762 */
3829 3763 function bbp_topic_tag_edit_link( $tag = '' ) {
@@ -3828,45 +3762,44 @@
3828 3762 */
3829 3763 function bbp_topic_tag_edit_link( $tag = '' ) {
3830 3764 echo esc_url( bbp_get_topic_tag_edit_link( $tag ) );
3831 3765 }
3766 + /**
3767 + * Return the link of the current tag
3768 + *
3769 + * @since 2.0.0 bbPress (r3348)
3770 + *
3771 + * @return string Term Name
3772 + */
3773 + function bbp_get_topic_tag_edit_link( $tag = '' ) {
3832 3774
3833 -/**
3834 - * Return the link of the current tag.
3835 - *
3836 - * @since 2.0.0 bbPress (r3348)
3837 - *
3838 - * @return string Term Name.
3839 - */
3840 -function bbp_get_topic_tag_edit_link( $tag = '' ) {
3775 + // Get the term
3776 + if ( ! empty( $tag ) ) {
3777 + $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() );
3778 + } else {
3779 + $tag = get_query_var( 'term' );
3780 + $term = get_queried_object();
3781 + }
3841 3782
3842 - // Get the term
3843 - if ( ! empty( $tag ) ) {
3844 - $term = get_term_by( 'slug', $tag, bbp_get_topic_tag_tax_id() );
3845 - } else {
3846 - $tag = get_query_var( 'term' );
3847 - $term = get_queried_object();
3848 - }
3783 + // Get the term's edit link
3784 + if ( ! empty( $term->term_id ) ) {
3849 3785
3850 - // Get the term's edit link
3851 - if ( ! empty( $term->term_id ) ) {
3786 + // Pretty or ugly URL
3787 + $retval = bbp_use_pretty_urls()
3788 + ? user_trailingslashit( trailingslashit( bbp_get_topic_tag_link() ) . bbp_get_edit_slug() )
3789 + : add_query_arg( array( bbp_get_edit_rewrite_id() => '1' ), bbp_get_topic_tag_link() );
3852 3790
3853 - // Pretty or ugly URL
3854 - $retval = bbp_use_pretty_urls()
3855 - ? user_trailingslashit( trailingslashit( bbp_get_topic_tag_link() ) . bbp_get_edit_slug() )
3856 - : add_query_arg( array( bbp_get_edit_rewrite_id() => '1' ), bbp_get_topic_tag_link() );
3791 + // No link
3792 + } else {
3793 + $retval = '';
3794 + }
3857 3795
3858 - // No link
3859 - } else {
3860 - $retval = '';
3796 + // Filter & return
3797 + return apply_filters( 'bbp_get_topic_tag_edit_link', $retval, $tag, $term );
3861 3798 }
3862 3799
3863 - // Filter & return
3864 - return apply_filters( 'bbp_get_topic_tag_edit_link', $retval, $tag, $term );
3865 -}
3866 -
3867 3800 /**
3868 - * Output the description of the current tag.
3801 + * Output the description of the current tag
3869 3802 *
3870 3803 * @since 2.0.0 bbPress (r3109)
3871 3804 */
3872 3805 function bbp_topic_tag_description( $args = array() ) {
@@ -3871,18 +3804,17 @@
3871 3804 */
3872 3805 function bbp_topic_tag_description( $args = array() ) {
3873 3806 echo bbp_get_topic_tag_description( $args );
3874 3807 }
3875 -
3876 -/**
3877 - * Return the description of the current tag.
3878 - *
3879 - * @since 2.0.0 bbPress (r3109)
3880 - *
3881 - * @param array $args before|after|tag.
3882 - *
3883 - * @return string Term Name.
3884 - */
3808 + /**
3809 + * Return the description of the current tag
3810 + *
3811 + * @since 2.0.0 bbPress (r3109)
3812 + *
3813 + * @param array $args before|after|tag
3814 + *
3815 + * @return string Term Name
3816 + */
3885 3817 function bbp_get_topic_tag_description( $args = array() ) {
3886 3818
3887 3819 // Parse arguments against default values
3888 3820 $r = bbp_parse_args(
@@ -3914,9 +3846,9 @@
3914 3846
3915 3847 /** Forms *********************************************************************/
3916 3848
3917 3849 /**
3918 - * Output the value of topic title field.
3850 + * Output the value of topic title field
3919 3851 *
3920 3852 * @since 2.0.0 bbPress (r2976)
3921 3853 */
3922 3854 function bbp_form_topic_title() {
@@ -3921,37 +3853,36 @@
3921 3853 */
3922 3854 function bbp_form_topic_title() {
3923 3855 echo bbp_get_form_topic_title();
3924 3856 }
3857 + /**
3858 + * Return the value of topic title field
3859 + *
3860 + * @since 2.0.0 bbPress (r2976)
3861 + *
3862 + * @return string Value of topic title field
3863 + */
3864 + function bbp_get_form_topic_title() {
3925 3865
3926 -/**
3927 - * Return the value of topic title field.
3928 - *
3929 - * @since 2.0.0 bbPress (r2976)
3930 - *
3931 - * @return string Value of topic title field.
3932 - */
3933 -function bbp_get_form_topic_title() {
3866 + // Get _POST data
3867 + if ( bbp_is_topic_form_post_request() && isset( $_POST['bbp_topic_title'] ) ) {
3868 + $topic_title = wp_unslash( $_POST['bbp_topic_title'] );
3934 3869
3935 - // Get _POST data
3936 - if ( bbp_is_topic_form_post_request() && isset( $_POST['bbp_topic_title'] ) ) {
3937 - $topic_title = wp_unslash( $_POST['bbp_topic_title'] );
3870 + // Get edit data
3871 + } elseif ( bbp_is_topic_edit() ) {
3872 + $topic_title = bbp_get_global_post_field( 'post_title', 'raw' );
3938 3873
3939 - // Get edit data
3940 - } elseif ( bbp_is_topic_edit() ) {
3941 - $topic_title = bbp_get_global_post_field( 'post_title', 'raw' );
3874 + // No data
3875 + } else {
3876 + $topic_title = '';
3877 + }
3942 3878
3943 - // No data
3944 - } else {
3945 - $topic_title = '';
3879 + // Filter & return
3880 + return apply_filters( 'bbp_get_form_topic_title', $topic_title );
3946 3881 }
3947 3882
3948 - // Filter & return
3949 - return apply_filters( 'bbp_get_form_topic_title', $topic_title );
3950 -}
3951 -
3952 3883 /**
3953 - * Output the value of topic content field.
3884 + * Output the value of topic content field
3954 3885 *
3955 3886 * @since 2.0.0 bbPress (r2976)
3956 3887 */
3957 3888 function bbp_form_topic_content() {
@@ -3956,41 +3887,40 @@
3956 3887 */
3957 3888 function bbp_form_topic_content() {
3958 3889 echo bbp_get_form_topic_content();
3959 3890 }
3891 + /**
3892 + * Return the value of topic content field
3893 + *
3894 + * @since 2.0.0 bbPress (r2976)
3895 + *
3896 + * @return string Value of topic content field
3897 + */
3898 + function bbp_get_form_topic_content() {
3960 3899
3961 -/**
3962 - * Return the value of topic content field.
3963 - *
3964 - * @since 2.0.0 bbPress (r2976)
3965 - *
3966 - * @return string Value of topic content field.
3967 - */
3968 -function bbp_get_form_topic_content() {
3900 + // Get _POST data
3901 + if ( bbp_is_topic_form_post_request() && isset( $_POST['bbp_topic_content'] ) ) {
3902 + $topic_content = wp_unslash( $_POST['bbp_topic_content'] );
3969 3903
3970 - // Get _POST data
3971 - if ( bbp_is_topic_form_post_request() && isset( $_POST['bbp_topic_content'] ) ) {
3972 - $topic_content = wp_unslash( $_POST['bbp_topic_content'] );
3904 + // Get edit data
3905 + } elseif ( bbp_is_topic_edit() ) {
3906 + $topic_content = bbp_get_global_post_field( 'post_content', 'raw' );
3973 3907
3974 - // Get edit data
3975 - } elseif ( bbp_is_topic_edit() ) {
3976 - $topic_content = bbp_get_global_post_field( 'post_content', 'raw' );
3908 + // No data
3909 + } else {
3910 + $topic_content = '';
3911 + }
3977 3912
3978 - // No data
3979 - } else {
3980 - $topic_content = '';
3913 + // Filter & return
3914 + return apply_filters( 'bbp_get_form_topic_content', $topic_content );
3981 3915 }
3982 3916
3983 - // Filter & return
3984 - return apply_filters( 'bbp_get_form_topic_content', $topic_content );
3985 -}
3986 -
3987 3917 /**
3988 - * Allow topic rows to have administrative actions.
3918 + * Allow topic rows to have administrative actions
3989 3919 *
3990 3920 * @since 2.1.0 bbPress (r3654)
3991 3921 *
3992 - * @todo Links and filter.
3922 + * @todo Links and filter
3993 3923 */
3994 3924 function bbp_topic_row_actions() {
3995 3925 do_action( 'bbp_topic_row_actions' );
3996 3926 }
@@ -3995,9 +3925,9 @@
3995 3925 do_action( 'bbp_topic_row_actions' );
3996 3926 }
3997 3927
3998 3928 /**
3999 - * Output value of topic tags field.
3929 + * Output value of topic tags field
4000 3930 *
4001 3931 * @since 2.0.0 bbPress (r2976)
4002 3932 */
4003 3933 function bbp_form_topic_tags() {
@@ -4002,65 +3932,64 @@
4002 3932 */
4003 3933 function bbp_form_topic_tags() {
4004 3934 echo bbp_get_form_topic_tags();
4005 3935 }
3936 + /**
3937 + * Return value of topic tags field
3938 + *
3939 + * @since 2.0.0 bbPress (r2976)
3940 + *
3941 + * @return string Value of topic tags field
3942 + */
3943 + function bbp_get_form_topic_tags() {
4006 3944
4007 -/**
4008 - * Return value of topic tags field.
4009 - *
4010 - * @since 2.0.0 bbPress (r2976)
4011 - *
4012 - * @return string Value of topic tags field.
4013 - */
4014 -function bbp_get_form_topic_tags() {
3945 + // Default return value
3946 + $topic_tags = '';
4015 3947
4016 - // Default return value
4017 - $topic_tags = '';
3948 + // Get _POST data
3949 + if ( ( bbp_is_topic_form_post_request() || bbp_is_reply_form_post_request() ) && isset( $_POST['bbp_topic_tags'] ) ) {
3950 + $topic_tags = wp_unslash( $_POST['bbp_topic_tags'] );
4018 3951
4019 - // Get _POST data
4020 - if ( ( bbp_is_topic_form_post_request() || bbp_is_reply_form_post_request() ) && isset( $_POST['bbp_topic_tags'] ) ) {
4021 - $topic_tags = wp_unslash( $_POST['bbp_topic_tags'] );
3952 + // Get edit data
3953 + } elseif ( bbp_is_single_topic() || bbp_is_single_reply() || bbp_is_topic_edit() || bbp_is_reply_edit() ) {
4022 3954
4023 - // Get edit data
4024 - } elseif ( bbp_is_single_topic() || bbp_is_single_reply() || bbp_is_topic_edit() || bbp_is_reply_edit() ) {
3955 + // Determine the topic id based on the post type
3956 + switch ( get_post_type() ) {
4025 3957
4026 - // Determine the topic id based on the post type
4027 - switch ( get_post_type() ) {
3958 + // Post is a topic
3959 + case bbp_get_topic_post_type() :
3960 + $topic_id = bbp_get_topic_id( get_the_ID() );
3961 + break;
4028 3962
4029 - // Post is a topic
4030 - case bbp_get_topic_post_type() :
4031 - $topic_id = bbp_get_topic_id( get_the_ID() );
4032 - break;
3963 + // Post is a reply
3964 + case bbp_get_reply_post_type() :
3965 + $topic_id = bbp_get_reply_topic_id( get_the_ID() );
3966 + break;
3967 + }
4033 3968
4034 - // Post is a reply
4035 - case bbp_get_reply_post_type() :
4036 - $topic_id = bbp_get_reply_topic_id( get_the_ID() );
4037 - break;
4038 - }
3969 + // Topic exists
3970 + if ( ! empty( $topic_id ) ) {
4039 3971
4040 - // Topic exists
4041 - if ( ! empty( $topic_id ) ) {
3972 + // Topic is spammed so display pre-spam terms
3973 + if ( bbp_is_topic_spam( $topic_id ) ) {
4042 3974
4043 - // Topic is spammed so display pre-spam terms
4044 - if ( bbp_is_topic_spam( $topic_id ) ) {
3975 + // Get pre-spam terms
3976 + $spam_terms = get_post_meta( $topic_id, '_bbp_spam_topic_tags', true );
3977 + $topic_tags = ( ! empty( $spam_terms ) ) ? implode( ', ', $spam_terms ) : '';
4045 3978
4046 - // Get pre-spam terms
4047 - $spam_terms = get_post_meta( $topic_id, '_bbp_spam_topic_tags', true );
4048 - $topic_tags = ( ! empty( $spam_terms ) ) ? implode( ', ', $spam_terms ) : '';
4049 -
4050 - // Topic is not spam so get real terms
4051 - } else {
4052 - $topic_tags = bbp_get_topic_tag_names( $topic_id );
3979 + // Topic is not spam so get real terms
3980 + } else {
3981 + $topic_tags = bbp_get_topic_tag_names( $topic_id );
3982 + }
4053 3983 }
4054 3984 }
3985 +
3986 + // Filter & return
3987 + return apply_filters( 'bbp_get_form_topic_tags', $topic_tags );
4055 3988 }
4056 3989
4057 - // Filter & return
4058 - return apply_filters( 'bbp_get_form_topic_tags', $topic_tags );
4059 -}
4060 -
4061 3990 /**
4062 - * Output value of topic forum.
3991 + * Output value of topic forum
4063 3992 *
4064 3993 * @since 2.0.0 bbPress (r2976)
4065 3994 */
4066 3995 function bbp_form_topic_forum() {
@@ -4065,37 +3994,36 @@
4065 3994 */
4066 3995 function bbp_form_topic_forum() {
4067 3996 echo bbp_get_form_topic_forum();
4068 3997 }
3998 + /**
3999 + * Return value of topic forum
4000 + *
4001 + * @since 2.0.0 bbPress (r2976)
4002 + *
4003 + * @return string Value of topic content field
4004 + */
4005 + function bbp_get_form_topic_forum() {
4069 4006
4070 -/**
4071 - * Return value of topic forum.
4072 - *
4073 - * @since 2.0.0 bbPress (r2976)
4074 - *
4075 - * @return string Value of topic content field.
4076 - */
4077 -function bbp_get_form_topic_forum() {
4007 + // Get _POST data
4008 + if ( bbp_is_topic_form_post_request() && isset( $_POST['bbp_forum_id'] ) ) {
4009 + $topic_forum = (int) $_POST['bbp_forum_id'];
4078 4010
4079 - // Get _POST data
4080 - if ( bbp_is_topic_form_post_request() && isset( $_POST['bbp_forum_id'] ) ) {
4081 - $topic_forum = (int) $_POST['bbp_forum_id'];
4011 + // Get edit data
4012 + } elseif ( bbp_is_topic_edit() ) {
4013 + $topic_forum = bbp_get_topic_forum_id();
4082 4014
4083 - // Get edit data
4084 - } elseif ( bbp_is_topic_edit() ) {
4085 - $topic_forum = bbp_get_topic_forum_id();
4015 + // No data
4016 + } else {
4017 + $topic_forum = 0;
4018 + }
4086 4019
4087 - // No data
4088 - } else {
4089 - $topic_forum = 0;
4020 + // Filter & return
4021 + return apply_filters( 'bbp_get_form_topic_forum', $topic_forum );
4090 4022 }
4091 4023
4092 - // Filter & return
4093 - return apply_filters( 'bbp_get_form_topic_forum', $topic_forum );
4094 -}
4095 -
4096 4024 /**
4097 - * Output checked value of topic subscription.
4025 + * Output checked value of topic subscription
4098 4026 *
4099 4027 * @since 2.0.0 bbPress (r2976)
4100 4028 */
4101 4029 function bbp_form_topic_subscribed() {
@@ -4100,44 +4028,43 @@
4100 4028 */
4101 4029 function bbp_form_topic_subscribed() {
4102 4030 echo bbp_get_form_topic_subscribed();
4103 4031 }
4032 + /**
4033 + * Return checked value of topic subscription
4034 + *
4035 + * @since 2.0.0 bbPress (r2976)
4036 + *
4037 + * @return string Checked value of topic subscription
4038 + */
4039 + function bbp_get_form_topic_subscribed() {
4104 4040
4105 -/**
4106 - * Return checked value of topic subscription.
4107 - *
4108 - * @since 2.0.0 bbPress (r2976)
4109 - *
4110 - * @return string Checked value of topic subscription.
4111 - */
4112 -function bbp_get_form_topic_subscribed() {
4041 + // Default value
4042 + $topic_subscribed = false;
4113 4043
4114 - // Default value
4115 - $topic_subscribed = false;
4044 + // Get _POST data
4045 + if ( bbp_is_topic_form_post_request() && isset( $_POST['bbp_topic_subscription'] ) ) {
4046 + $topic_subscribed = (bool) $_POST['bbp_topic_subscription'];
4116 4047
4117 - // Get _POST data
4118 - if ( bbp_is_topic_form_post_request() && isset( $_POST['bbp_topic_subscription'] ) ) {
4119 - $topic_subscribed = (bool) $_POST['bbp_topic_subscription'];
4048 + // Get edit data
4049 + } elseif ( bbp_is_topic_edit() || bbp_is_reply_edit() ) {
4050 + $post_author = (int) bbp_get_global_post_field( 'post_author', 'raw' );
4051 + $topic_subscribed = bbp_is_user_subscribed( $post_author, bbp_get_topic_id() );
4120 4052
4121 - // Get edit data
4122 - } elseif ( bbp_is_topic_edit() || bbp_is_reply_edit() ) {
4123 - $post_author = (int) bbp_get_global_post_field( 'post_author', 'raw' );
4124 - $topic_subscribed = bbp_is_user_subscribed( $post_author, bbp_get_topic_id() );
4053 + // Get current status
4054 + } elseif ( bbp_is_single_topic() ) {
4055 + $topic_subscribed = bbp_is_user_subscribed( bbp_get_current_user_id(), bbp_get_topic_id() );
4056 + }
4125 4057
4126 - // Get current status
4127 - } elseif ( bbp_is_single_topic() ) {
4128 - $topic_subscribed = bbp_is_user_subscribed( bbp_get_current_user_id(), bbp_get_topic_id() );
4058 + // Get checked output
4059 + $checked = checked( $topic_subscribed, true, false );
4060 +
4061 + // Filter & return
4062 + return apply_filters( 'bbp_get_form_topic_subscribed', $checked, $topic_subscribed );
4129 4063 }
4130 4064
4131 - // Get checked output
4132 - $checked = checked( $topic_subscribed, true, false );
4133 -
4134 - // Filter & return
4135 - return apply_filters( 'bbp_get_form_topic_subscribed', $checked, $topic_subscribed );
4136 -}
4137 -
4138 4065 /**
4139 - * Output checked value of topic log edit field.
4066 + * Output checked value of topic log edit field
4140 4067 *
4141 4068 * @since 2.0.0 bbPress (r2976)
4142 4069 */
4143 4070 function bbp_form_topic_log_edit() {
@@ -4142,36 +4069,35 @@
4142 4069 */
4143 4070 function bbp_form_topic_log_edit() {
4144 4071 echo bbp_get_form_topic_log_edit();
4145 4072 }
4073 + /**
4074 + * Return checked value of topic log edit field
4075 + *
4076 + * @since 2.0.0 bbPress (r2976)
4077 + *
4078 + * @return string Topic log edit checked value
4079 + */
4080 + function bbp_get_form_topic_log_edit() {
4146 4081
4147 -/**
4148 - * Return checked value of topic log edit field.
4149 - *
4150 - * @since 2.0.0 bbPress (r2976)
4151 - *
4152 - * @return string Topic log edit checked value.
4153 - */
4154 -function bbp_get_form_topic_log_edit() {
4082 + // Get _POST data
4083 + if ( bbp_is_topic_form_post_request() && isset( $_POST['bbp_log_topic_edit'] ) ) {
4084 + $topic_revision = (bool) $_POST['bbp_log_topic_edit'];
4155 4085
4156 - // Get _POST data
4157 - if ( bbp_is_topic_form_post_request() && isset( $_POST['bbp_log_topic_edit'] ) ) {
4158 - $topic_revision = (bool) $_POST['bbp_log_topic_edit'];
4086 + // No data
4087 + } else {
4088 + $topic_revision = true;
4089 + }
4159 4090
4160 - // No data
4161 - } else {
4162 - $topic_revision = true;
4091 + // Get checked output
4092 + $checked = checked( $topic_revision, true, false );
4093 +
4094 + // Filter & return
4095 + return apply_filters( 'bbp_get_form_topic_log_edit', $checked, $topic_revision );
4163 4096 }
4164 4097
4165 - // Get checked output
4166 - $checked = checked( $topic_revision, true, false );
4167 -
4168 - // Filter & return
4169 - return apply_filters( 'bbp_get_form_topic_log_edit', $checked, $topic_revision );
4170 -}
4171 -
4172 4098 /**
4173 - * Output the value of the topic edit reason.
4099 + * Output the value of the topic edit reason
4174 4100 *
4175 4101 * @since 2.0.0 bbPress (r2976)
4176 4102 */
4177 4103 function bbp_form_topic_edit_reason() {
@@ -4176,31 +4102,30 @@
4176 4102 */
4177 4103 function bbp_form_topic_edit_reason() {
4178 4104 echo bbp_get_form_topic_edit_reason();
4179 4105 }
4106 + /**
4107 + * Return the value of the topic edit reason
4108 + *
4109 + * @since 2.0.0 bbPress (r2976)
4110 + *
4111 + * @return string Topic edit reason value
4112 + */
4113 + function bbp_get_form_topic_edit_reason() {
4180 4114
4181 -/**
4182 - * Return the value of the topic edit reason.
4183 - *
4184 - * @since 2.0.0 bbPress (r2976)
4185 - *
4186 - * @return string Topic edit reason value.
4187 - */
4188 -function bbp_get_form_topic_edit_reason() {
4115 + // Get _POST data
4116 + if ( bbp_is_topic_form_post_request() && isset( $_POST['bbp_topic_edit_reason'] ) ) {
4117 + $topic_edit_reason = wp_unslash( $_POST['bbp_topic_edit_reason'] );
4189 4118
4190 - // Get _POST data
4191 - if ( bbp_is_topic_form_post_request() && isset( $_POST['bbp_topic_edit_reason'] ) ) {
4192 - $topic_edit_reason = wp_unslash( $_POST['bbp_topic_edit_reason'] );
4119 + // No data
4120 + } else {
4121 + $topic_edit_reason = '';
4122 + }
4193 4123
4194 - // No data
4195 - } else {
4196 - $topic_edit_reason = '';
4124 + // Filter & return
4125 + return apply_filters( 'bbp_get_form_topic_edit_reason', $topic_edit_reason );
4197 4126 }
4198 4127
4199 - // Filter & return
4200 - return apply_filters( 'bbp_get_form_topic_edit_reason', $topic_edit_reason );
4201 -}
4202 -
4203 4128 /**
4204 4129 * Verify if a POST request came from a failed topic attempt.
4205 4130 *
4206 4131 * Used to avoid cross-site request forgeries when checking posted topic form
@@ -4209,9 +4134,9 @@
4209 4134 * @see bbp_topic_form_fields()
4210 4135 *
4211 4136 * @since 2.6.0 bbPress (r5558)
4212 4137 *
4213 - * @return boolean True if is a post request with valid nonce.
4138 + * @return boolean True if is a post request with valid nonce
4214 4139 */
4215 4140 function bbp_is_topic_form_post_request() {
4216 4141
4217 4142 // Bail if not a post request
@@ -4269,25 +4194,24 @@
4269 4194 return (bool) apply_filters( 'bbp_show_topic_lock_alert', $retval, $topic_id );
4270 4195 }
4271 4196
4272 4197 /**
4273 - * Output the topic lock description.
4198 + * Output the topic lock description
4274 4199 *
4275 4200 * @since 2.6.0 bbPress (r6344)
4276 4201 *
4277 - * @param int $topic_id Optional. Topic id.
4202 + * @param int $topic_id Optional. Topic id
4278 4203 */
4279 4204 function bbp_topic_lock_description( $topic_id = 0 ) {
4280 4205 echo bbp_get_topic_lock_description( $topic_id );
4281 4206 }
4282 -
4283 -/**
4284 - * Return the topic lock description.
4285 - *
4286 - * @since 2.6.0 bbPress (r6344)
4287 - *
4288 - * @param int $topic_id Optional. Topic id.
4289 - */
4207 + /**
4208 + * Return the topic lock description
4209 + *
4210 + * @since 2.6.0 bbPress (r6344)
4211 + *
4212 + * @param int $topic_id Optional. Topic id
4213 + */
4290 4214 function bbp_get_topic_lock_description( $topic_id = 0 ) {
4291 4215
4292 4216 // Check if topic is edit locked
4293 4217 $topic_id = bbp_get_topic_id( $topic_id );