[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

/src/includes/forums/ -> template.php (source)

   1  <?php
   2  
   3  /**
   4   * bbPress Forum Template Tags
   5   *
   6   * @package bbPress
   7   * @subpackage TemplateTags
   8   */
   9  
  10  // Exit if accessed directly
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  /** Post Type *****************************************************************/
  14  
  15  /**
  16   * Output the unique id of the custom post type for forums
  17   *
  18   * @since 2.0.0 bbPress (r2857)
  19   */
  20  function bbp_forum_post_type() {
  21      echo bbp_get_forum_post_type();
  22  }
  23      /**
  24       * Return the unique id of the custom post type for forums
  25       *
  26       * @since 2.0.0 bbPress (r2857)
  27       *
  28       * @return string The unique forum post type id
  29       */
  30  	function bbp_get_forum_post_type() {
  31  
  32          // Filter & return
  33          return apply_filters( 'bbp_get_forum_post_type', bbpress()->forum_post_type );
  34      }
  35  
  36  
  37  /**
  38   * Return array of labels used by the forum post type
  39   *
  40   * @since 2.5.0 bbPress (r5129)
  41   *
  42   * @return array
  43   */
  44  function bbp_get_forum_post_type_labels() {
  45  
  46      // Filter & return
  47      return (array) apply_filters( 'bbp_get_forum_post_type_labels', array(
  48          'name'                     => esc_attr__( 'Forums',                     'bbpress' ),
  49          'menu_name'                => esc_attr__( 'Forums',                     'bbpress' ),
  50          'singular_name'            => esc_attr__( 'Forum',                      'bbpress' ),
  51          'all_items'                => esc_attr__( 'All Forums',                 'bbpress' ),
  52          'add_new'                  => esc_attr__( 'Add New',                    'bbpress' ),
  53          'add_new_item'             => esc_attr__( 'Create New Forum',           'bbpress' ),
  54          'edit'                     => esc_attr__( 'Edit',                       'bbpress' ),
  55          'edit_item'                => esc_attr__( 'Edit Forum',                 'bbpress' ),
  56          'new_item'                 => esc_attr__( 'New Forum',                  'bbpress' ),
  57          'view'                     => esc_attr__( 'View Forum',                 'bbpress' ),
  58          'view_item'                => esc_attr__( 'View Forum',                 'bbpress' ),
  59          'view_items'               => esc_attr__( 'View Forums',                'bbpress' ),
  60          'search_items'             => esc_attr__( 'Search Forums',              'bbpress' ),
  61          'not_found'                => esc_attr__( 'No forums found',            'bbpress' ),
  62          'not_found_in_trash'       => esc_attr__( 'No forums found in Trash',   'bbpress' ),
  63          'filter_items_list'        => esc_attr__( 'Filter forums list',         'bbpress' ),
  64          'items_list'               => esc_attr__( 'Forums list',                'bbpress' ),
  65          'items_list_navigation'    => esc_attr__( 'Forums list navigation',     'bbpress' ),
  66          'parent_item_colon'        => esc_attr__( 'Parent Forum:',              'bbpress' ),
  67          'archives'                 => esc_attr__( 'Forums',                     'bbpress' ),
  68          'attributes'               => esc_attr__( 'Forum Attributes',           'bbpress' ),
  69          'insert_into_item'         => esc_attr__( 'Insert into forum',          'bbpress' ),
  70          'uploaded_to_this_item'    => esc_attr__( 'Uploaded to this forum',     'bbpress' ),
  71          'featured_image'           => esc_attr__( 'Forum Image',                'bbpress' ),
  72          'set_featured_image'       => esc_attr__( 'Set forum image',            'bbpress' ),
  73          'remove_featured_image'    => esc_attr__( 'Remove forum image',         'bbpress' ),
  74          'use_featured_image'       => esc_attr__( 'Use as forum image',         'bbpress' ),
  75          'item_published'           => esc_attr__( 'Forum published.',           'bbpress' ),
  76          'item_published_privately' => esc_attr__( 'Forum published privately.', 'bbpress' ),
  77          'item_reverted_to_draft'   => esc_attr__( 'Forum reverted to draft.',   'bbpress' ),
  78          'item_scheduled'           => esc_attr__( 'Forum scheduled.',           'bbpress' ),
  79          'item_updated'             => esc_attr__( 'Forum updated.',             'bbpress' )
  80      ) );
  81  }
  82  
  83  /**
  84   * Return array of forum post type rewrite settings
  85   *
  86   * @since 2.5.0 bbPress (r5129)
  87   *
  88   * @return array
  89   */
  90  function bbp_get_forum_post_type_rewrite() {
  91  
  92      // Filter & return
  93      return (array) apply_filters( 'bbp_get_forum_post_type_rewrite', array(
  94          'slug'       => bbp_get_forum_slug(),
  95          'with_front' => false
  96      ) );
  97  }
  98  
  99  /**
 100   * Return array of features the forum post type supports
 101   *
 102   * @since 2.5.0 bbPress (r5129)
 103   *
 104   * @return array
 105   */
 106  function bbp_get_forum_post_type_supports() {
 107  
 108      // Filter & return
 109      return (array) apply_filters( 'bbp_get_forum_post_type_supports', array(
 110          'title',
 111          'editor',
 112          'revisions'
 113      ) );
 114  }
 115  
 116  /** Forum Loop ****************************************************************/
 117  
 118  /**
 119   * The main forum loop.
 120   *
 121   * WordPress makes this easy for us.
 122   *
 123   * @since 2.0.0 bbPress (r2464)
 124   *
 125   * @param array $args All the arguments supported by {@link WP_Query}
 126   *
 127   * @return object Multidimensional array of forum information
 128   */
 129  function bbp_has_forums( $args = array() ) {
 130  
 131      // Forum archive only shows root
 132      if ( bbp_is_forum_archive() ) {
 133          $default_post_parent = 0;
 134  
 135      // User subscriptions shows any
 136      } elseif ( bbp_is_subscriptions() ) {
 137          $default_post_parent = 'any';
 138  
 139      // Could be anything, so look for possible parent ID
 140      } else {
 141          $default_post_parent = bbp_get_forum_id();
 142      }
 143  
 144      $default_forum_search = bbp_sanitize_search_request( 'fs' );
 145  
 146      // Default argument array
 147      $default = array(
 148          'post_type'           => bbp_get_forum_post_type(),
 149          'post_parent'         => $default_post_parent,
 150          'post_status'         => bbp_get_public_status_id(),
 151          'posts_per_page'      => get_option( '_bbp_forums_per_page', 50 ),
 152          'orderby'             => 'menu_order title',
 153          'order'               => 'ASC',
 154          'no_found_rows'       => true,
 155          'ignore_sticky_posts' => true,
 156  
 157          // Conditionally prime the cache for last active posts
 158          'update_post_family_cache' => true
 159      );
 160  
 161      // Only add 's' arg if searching for forums
 162      // See https://bbpress.trac.wordpress.org/ticket/2607
 163      if ( ! empty( $default_forum_search ) ) {
 164          $default['s'] = $default_forum_search;
 165      }
 166  
 167      // Parse arguments with default forum query for most circumstances
 168      $r = bbp_parse_args( $args, $default, 'has_forums' );
 169  
 170      // Run the query
 171      $bbp              = bbpress();
 172      $bbp->forum_query = new WP_Query( $r );
 173  
 174      // Maybe prime last active posts
 175      if ( ! empty( $r['update_post_family_cache'] ) ) {
 176          bbp_update_post_family_caches( $bbp->forum_query->posts );
 177      }
 178  
 179      // Filter & return
 180      return apply_filters( 'bbp_has_forums', $bbp->forum_query->have_posts(), $bbp->forum_query );
 181  }
 182  
 183  /**
 184   * Whether there are more forums available in the loop
 185   *
 186   * @since 2.0.0 bbPress (r2464)
 187   *
 188   * @return object Forum information
 189   */
 190  function bbp_forums() {
 191  
 192      // Put into variable to check against next
 193      $have_posts = bbpress()->forum_query->have_posts();
 194  
 195      // Reset the post data when finished
 196      if ( empty( $have_posts ) ) {
 197          wp_reset_postdata();
 198      }
 199  
 200      return $have_posts;
 201  }
 202  
 203  /**
 204   * Loads up the current forum in the loop
 205   *
 206   * @since 2.0.0 bbPress (r2464)
 207   *
 208   * @return object Forum information
 209   */
 210  function bbp_the_forum() {
 211      return bbpress()->forum_query->the_post();
 212  }
 213  
 214  /** Forum *********************************************************************/
 215  
 216  /**
 217   * Output forum id
 218   *
 219   * @since 2.0.0 bbPress (r2464)
 220   *
 221   * @param $forum_id Optional. Used to check emptiness
 222   */
 223  function bbp_forum_id( $forum_id = 0 ) {
 224      echo bbp_get_forum_id( $forum_id );
 225  }
 226      /**
 227       * Return the forum id
 228       *
 229       * @since 2.0.0 bbPress (r2464)
 230       *
 231       * @param $forum_id Optional. Used to check emptiness
 232       * @return int The forum id
 233       */
 234  	function bbp_get_forum_id( $forum_id = 0 ) {
 235          $bbp      = bbpress();
 236          $wp_query = bbp_get_wp_query();
 237  
 238          // Easy empty checking
 239          if ( ! empty( $forum_id ) && is_numeric( $forum_id ) ) {
 240              $bbp_forum_id = $forum_id;
 241  
 242          // Currently inside a forum loop
 243          } elseif ( ! empty( $bbp->forum_query->in_the_loop ) && isset( $bbp->forum_query->post->ID ) ) {
 244              $bbp_forum_id = $bbp->forum_query->post->ID;
 245  
 246          // Currently inside a search loop
 247          } elseif ( ! empty( $bbp->search_query->in_the_loop ) && isset( $bbp->search_query->post->ID ) && bbp_is_forum( $bbp->search_query->post->ID ) ) {
 248              $bbp_forum_id = $bbp->search_query->post->ID;
 249  
 250          // Currently viewing a forum
 251          } elseif ( ( bbp_is_single_forum() || bbp_is_forum_edit() ) && ! empty( $bbp->current_forum_id ) ) {
 252              $bbp_forum_id = $bbp->current_forum_id;
 253  
 254          // Currently viewing a forum
 255          } elseif ( ( bbp_is_single_forum() || bbp_is_forum_edit() ) && isset( $wp_query->post->ID ) ) {
 256              $bbp_forum_id = $wp_query->post->ID;
 257  
 258          // Currently viewing a topic
 259          } elseif ( bbp_is_single_topic() ) {
 260              $bbp_forum_id = bbp_get_topic_forum_id();
 261  
 262          // Fallback
 263          } else {
 264              $bbp_forum_id = 0;
 265          }
 266  
 267          // Filter & return
 268          return (int) apply_filters( 'bbp_get_forum_id', (int) $bbp_forum_id, $forum_id );
 269      }
 270  
 271  /**
 272   * Gets a forum
 273   *
 274   * @since 2.0.0 bbPress (r2787)
 275   *
 276   * @param int|object $forum forum id or forum object
 277   * @param string $output Optional. OBJECT, ARRAY_A, or ARRAY_N. Default = OBJECT
 278   * @param string $filter Optional Sanitation filter. See {@link sanitize_post()}
 279   *
 280   * @return mixed Null if error or forum (in specified form) if success
 281   */
 282  function bbp_get_forum( $forum, $output = OBJECT, $filter = 'raw' ) {
 283  
 284      // Maybe get ID from empty or int
 285      if ( empty( $forum ) || is_numeric( $forum ) ) {
 286          $forum = bbp_get_forum_id( $forum );
 287      }
 288  
 289      // Bail if no post object
 290      $forum = get_post( $forum, OBJECT, $filter );
 291      if ( empty( $forum ) ) {
 292          return $forum;
 293      }
 294  
 295      // Bail if not correct post type
 296      if ( $forum->post_type !== bbp_get_forum_post_type() ) {
 297          return null;
 298      }
 299  
 300      // Default return value is OBJECT
 301      $retval = $forum;
 302  
 303      // Array A
 304      if ( $output === ARRAY_A ) {
 305          $retval = get_object_vars( $forum );
 306  
 307      // Array N
 308      } elseif ( $output === ARRAY_N ) {
 309          $retval = array_values( get_object_vars( $forum ) );
 310      }
 311  
 312      // Filter & return
 313      return apply_filters( 'bbp_get_forum', $retval, $forum, $output, $filter );
 314  }
 315  
 316  /**
 317   * Output the link to the forum
 318   *
 319   * @since 2.0.0 bbPress (r2464)
 320   *
 321   * @param int $forum_id Optional. Forum id
 322   * @param string $redirect_to Optional. Pass a redirect value for use with
 323   *                              shortcodes and other fun things.
 324   */
 325  function bbp_forum_permalink( $forum_id = 0, $redirect_to = '' ) {
 326      echo esc_url( bbp_get_forum_permalink( $forum_id, $redirect_to ) );
 327  }
 328      /**
 329       * Return the link to the forum
 330       *
 331       * @since 2.0.0 bbPress (r2464)
 332       *
 333       * @param int $forum_id Optional. Forum id
 334       * @param string $redirect_to Optional. Pass a redirect value for use with
 335       *                              shortcodes and other fun things.
 336       *
 337       * @return string Permanent link to forum
 338       */
 339  	function bbp_get_forum_permalink( $forum_id = 0, $redirect_to = '' ) {
 340          $forum_id = bbp_get_forum_id( $forum_id );
 341  
 342          // Use the redirect address
 343          if ( ! empty( $redirect_to ) ) {
 344              $forum_permalink = esc_url_raw( $redirect_to );
 345  
 346          // Use the topic permalink
 347          } else {
 348              $forum_permalink = get_permalink( $forum_id );
 349          }
 350  
 351          // Filter & return
 352          return apply_filters( 'bbp_get_forum_permalink', $forum_permalink, $forum_id );
 353      }
 354  
 355  /**
 356   * Output the title of the forum
 357   *
 358   * @since 2.0.0 bbPress (r2464)
 359   *
 360   * @param int $forum_id Optional. Forum id
 361   */
 362  function bbp_forum_title( $forum_id = 0 ) {
 363      echo bbp_get_forum_title( $forum_id );
 364  }
 365      /**
 366       * Return the title of the forum
 367       *
 368       * @since 2.0.0 bbPress (r2464)
 369       *
 370       * @param int $forum_id Optional. Forum id
 371       * @return string Title of forum
 372       */
 373  	function bbp_get_forum_title( $forum_id = 0 ) {
 374          $forum_id = bbp_get_forum_id( $forum_id );
 375          $title    = get_the_title( $forum_id );
 376  
 377          // Filter & return
 378          return apply_filters( 'bbp_get_forum_title', $title, $forum_id );
 379      }
 380  
 381  /**
 382   * Output the forum archive title
 383   *
 384   * @since 2.0.0 bbPress (r3249)
 385   *
 386   * @param string $title Default text to use as title
 387   */
 388  function bbp_forum_archive_title( $title = '' ) {
 389      echo bbp_get_forum_archive_title( $title );
 390  }
 391      /**
 392       * Return the forum archive title
 393       *
 394       * @since 2.0.0 bbPress (r3249)
 395       *
 396       * @param string $title Default text to use as title
 397       *
 398       * @return string The forum archive title
 399       */
 400  	function bbp_get_forum_archive_title( $title = '' ) {
 401  
 402          // If no title was passed
 403          if ( empty( $title ) ) {
 404  
 405              // Set root text to page title
 406              $page = bbp_get_page_by_path( bbp_get_root_slug() );
 407              if ( ! empty( $page ) ) {
 408                  $title = get_the_title( $page->ID );
 409  
 410              // Default to forum post type name label
 411              } else {
 412                  $fto    = get_post_type_object( bbp_get_forum_post_type() );
 413                  $title  = $fto->labels->name;
 414              }
 415          }
 416  
 417          // Filter & return
 418          return apply_filters( 'bbp_get_forum_archive_title', $title );
 419      }
 420  
 421  /**
 422   * Output the content of the forum
 423   *
 424   * @since 2.0.0 bbPress (r2780)
 425   *
 426   * @param int $forum_id Optional. Topic id
 427   */
 428  function bbp_forum_content( $forum_id = 0 ) {
 429      echo bbp_get_forum_content( $forum_id );
 430  }
 431      /**
 432       * Return the content of the forum
 433       *
 434       * @since 2.0.0 bbPress (r2780)
 435       *
 436       * @param int $forum_id Optional. Topic id
 437       *
 438       * @return string Content of the forum
 439       */
 440  	function bbp_get_forum_content( $forum_id = 0 ) {
 441          $forum_id = bbp_get_forum_id( $forum_id );
 442  
 443          // Check if password is required
 444          if ( post_password_required( $forum_id ) ) {
 445              return get_the_password_form();
 446          }
 447  
 448          $content = get_post_field( 'post_content', $forum_id );
 449  
 450          // Filter & return
 451          return apply_filters( 'bbp_get_forum_content', $content, $forum_id );
 452      }
 453  
 454  /**
 455   * Allow forum rows to have administrative actions
 456   *
 457   * @since 2.1.0 bbPress (r3653)
 458   *
 459   * @todo Links and filter
 460   */
 461  function bbp_forum_row_actions() {
 462      do_action( 'bbp_forum_row_actions' );
 463  }
 464  
 465  /**
 466   * Output the forums last active ID
 467   *
 468   * @since 2.0.0 bbPress (r2860)
 469   *
 470   * @param int $forum_id Optional. Forum id
 471   */
 472  function bbp_forum_last_active_id( $forum_id = 0 ) {
 473      echo bbp_get_forum_last_active_id( $forum_id );
 474  }
 475      /**
 476       * Return the forums last active ID
 477       *
 478       * @since 2.0.0 bbPress (r2860)
 479       *
 480       * @param int $forum_id Optional. Forum id
 481       *                        the last active id and forum id
 482       * @return int Forum's last active id
 483       */
 484  	function bbp_get_forum_last_active_id( $forum_id = 0 ) {
 485          $forum_id  = bbp_get_forum_id( $forum_id );
 486          $active_id = get_post_meta( $forum_id, '_bbp_last_active_id', true );
 487  
 488          // Filter & return
 489          return (int) apply_filters( 'bbp_get_forum_last_active_id', (int) $active_id, $forum_id );
 490      }
 491  
 492  /**
 493   * Output the forums last update date/time (aka freshness)
 494   *
 495   * @since 2.0.0 bbPress (r2464)
 496   *
 497   * @param int $forum_id Optional. Forum id
 498   */
 499  function bbp_forum_last_active_time( $forum_id = 0 ) {
 500      echo bbp_get_forum_last_active_time( $forum_id );
 501  }
 502      /**
 503       * Return the forums last update date/time (aka freshness)
 504       *
 505       * @since 2.0.0 bbPress (r2464)
 506       *
 507       * @param int $forum_id Optional. Forum id
 508       * @return string Forum last update date/time (freshness)
 509       */
 510  	function bbp_get_forum_last_active_time( $forum_id = 0 ) {
 511  
 512          // Verify forum and get last active meta
 513          $forum_id    = bbp_get_forum_id( $forum_id );
 514          $last_active = get_post_meta( $forum_id, '_bbp_last_active_time', true );
 515  
 516          if ( empty( $last_active ) ) {
 517              $reply_id = bbp_get_forum_last_reply_id( $forum_id );
 518              if ( ! empty( $reply_id ) ) {
 519                  $last_active = get_post_field( 'post_date', $reply_id );
 520              } else {
 521                  $topic_id = bbp_get_forum_last_topic_id( $forum_id );
 522                  if ( ! empty( $topic_id ) ) {
 523                      $last_active = bbp_get_topic_last_active_time( $topic_id );
 524                  }
 525              }
 526          }
 527  
 528          $active_time = ! empty( $last_active ) ? bbp_get_time_since( bbp_convert_date( $last_active ) ) : '';
 529  
 530          // Filter & return
 531          return apply_filters( 'bbp_get_forum_last_active', $active_time, $forum_id );
 532      }
 533  
 534  /**
 535   * Output link to the most recent activity inside a forum.
 536   *
 537   * Outputs a complete link with attributes and content.
 538   *
 539   * @since 2.0.0 bbPress (r2625)
 540   *
 541   * @param int $forum_id Optional. Forum id
 542   */
 543  function bbp_forum_freshness_link( $forum_id = 0) {
 544      echo bbp_get_forum_freshness_link( $forum_id );
 545  }
 546      /**
 547       * Returns link to the most recent activity inside a forum.
 548       *
 549       * Returns a complete link with attributes and content.
 550       *
 551       * @since 2.0.0 bbPress (r2625)
 552       *
 553       * @param int $forum_id Optional. Forum id
 554       */
 555  	function bbp_get_forum_freshness_link( $forum_id = 0 ) {
 556          $forum_id  = bbp_get_forum_id( $forum_id );
 557          $active_id = bbp_get_forum_last_active_id( $forum_id );
 558          $link_url  = $title = '';
 559  
 560          if ( empty( $active_id ) ) {
 561              $active_id = bbp_get_forum_last_reply_id( $forum_id );
 562          }
 563  
 564          if ( empty( $active_id ) ) {
 565              $active_id = bbp_get_forum_last_topic_id( $forum_id );
 566          }
 567  
 568          if ( bbp_is_topic( $active_id ) ) {
 569              $link_url = bbp_get_forum_last_topic_permalink( $forum_id );
 570              $title    = bbp_get_forum_last_topic_title( $forum_id );
 571          } elseif ( bbp_is_reply( $active_id ) ) {
 572              $link_url = bbp_get_forum_last_reply_url( $forum_id );
 573              $title    = bbp_get_forum_last_reply_title( $forum_id );
 574          }
 575  
 576          $time_since = bbp_get_forum_last_active_time( $forum_id );
 577  
 578          if ( ! empty( $time_since ) && ! empty( $link_url ) ) {
 579              $anchor = '<a href="' . esc_url( $link_url ) . '" title="' . esc_attr( $title ) . '">' . esc_html( $time_since ) . '</a>';
 580          } else {
 581              $anchor = esc_html__( 'No Topics', 'bbpress' );
 582          }
 583  
 584          // Filter & return
 585          return apply_filters( 'bbp_get_forum_freshness_link', $anchor, $forum_id, $time_since, $link_url, $title, $active_id );
 586      }
 587  
 588  /**
 589   * Output parent ID of a forum, if exists
 590   *
 591   * @since 2.1.0 bbPress (r3675)
 592   *
 593   * @param int $forum_id Forum ID
 594   */
 595  function bbp_forum_parent_id( $forum_id = 0 ) {
 596      echo bbp_get_forum_parent_id( $forum_id );
 597  }
 598      /**
 599       * Return ID of forum parent, if exists
 600       *
 601       * @since 2.1.0 bbPress (r3675)
 602       *
 603       * @param int $forum_id Optional. Forum id
 604       * @return int Forum parent
 605       */
 606  	function bbp_get_forum_parent_id( $forum_id = 0 ) {
 607          $forum_id  = bbp_get_forum_id( $forum_id );
 608          $parent_id = get_post_field( 'post_parent', $forum_id );
 609  
 610          // Meta-data fallback
 611          if ( empty( $parent_id ) ) {
 612              $parent_id = get_post_meta( $forum_id, '_bbp_forum_id', true );
 613          }
 614  
 615          // Filter
 616          if ( ! empty( $parent_id ) ) {
 617              $parent_id = bbp_get_forum_id( $parent_id );
 618          }
 619  
 620          // Filter & return
 621          return (int) apply_filters( 'bbp_get_forum_parent_id', (int) $parent_id, $forum_id );
 622      }
 623  
 624  /**
 625   * Return array of parent forums
 626   *
 627   * @since 2.0.0 bbPress (r2625)
 628   *
 629   * @param int $forum_id Optional. Forum id
 630   * @return array Forum ancestors
 631   */
 632  function bbp_get_forum_ancestors( $forum_id = 0 ) {
 633      $forum_id  = bbp_get_forum_id( $forum_id );
 634      $ancestors = array();
 635      $forum     = bbp_get_forum( $forum_id );
 636  
 637      if ( ! empty( $forum ) ) {
 638          while ( 0 !== (int) $forum->post_parent ) {
 639              $ancestors[] = $forum->post_parent;
 640              $forum       = bbp_get_forum( $forum->post_parent );
 641          }
 642      }
 643  
 644      // Filter & return
 645      return apply_filters( 'bbp_get_forum_ancestors', $ancestors, $forum_id );
 646  }
 647  
 648  /**
 649   * Return subforums of given forum
 650   *
 651   * @since 2.0.0 bbPress (r2747)
 652   *
 653   * @param array $args All the arguments supported by {@link WP_Query}
 654   * @return mixed false if none, array of subs if yes
 655   */
 656  function bbp_forum_get_subforums( $args = array() ) {
 657  
 658      // Default return value
 659      $retval = array();
 660  
 661      // Use passed integer as post_parent
 662      if ( is_numeric( $args ) && ! empty( $args ) ) {
 663          $args = array( 'post_parent' => bbp_get_forum_id( $args ) );
 664      }
 665  
 666      // Parse arguments against default values
 667      $r = bbp_parse_args( $args, array(
 668          'post_parent'         => 0,
 669          'post_type'           => bbp_get_forum_post_type(),
 670          'posts_per_page'      => get_option( '_bbp_forums_per_page', 50 ),
 671          'orderby'             => 'menu_order title',
 672          'order'               => 'ASC',
 673          'ignore_sticky_posts' => true,
 674          'no_found_rows'       => true
 675      ), 'forum_get_subforums' );
 676  
 677      // Ensure post_parent is properly set
 678      $r['post_parent'] = bbp_get_forum_id( $r['post_parent'] );
 679  
 680      // Query if post_parent has subforums
 681      if ( ! empty( $r['post_parent'] ) && bbp_get_forum_subforum_count( $r['post_parent'], true ) ) {
 682          $get_posts = new WP_Query();
 683          $retval    = $get_posts->query( $r );
 684      }
 685  
 686      // Filter & return
 687      return (array) apply_filters( 'bbp_forum_get_subforums', $retval, $r, $args );
 688  }
 689  
 690  /**
 691   * Output a list of forums (can be used to list subforums)
 692   *
 693   * @since 2.0.0 bbPress (r2708)
 694   *
 695   * @param array $args The function supports these args:
 696   *  - before: To put before the output. Defaults to '<ul class="bbp-forums-list">'
 697   *  - after: To put after the output. Defaults to '</ul>'
 698   *  - link_before: To put before every link. Defaults to '<li class="bbp-forum">'
 699   *  - link_after: To put after every link. Defaults to '</li>'
 700   *  - sep: Separator. Defaults to ''. Make sure your markup is valid!
 701   *  - count_before: String before each count Defaults to ' ('
 702   *  - count_after: String before each count Defaults to ')'
 703   *  - count_sep: Count separator. Defaults to ', '
 704   *  - forum_id: Forum id. Defaults to ''
 705   *  - show_topic_count - To show forum topic count or not. Defaults to true
 706   *  - show_reply_count - To show forum reply count or not. Defaults to true
 707   */
 708  function bbp_list_forums( $args = array() ) {
 709  
 710      // Parse arguments against default values
 711      $r = bbp_parse_args( $args, array(
 712          'before'           => '<ul class="bbp-forums-list">',
 713          'after'            => '</ul>',
 714          'link_before'      => '<li class="bbp-forum css-sep">',
 715          'link_after'       => '</li>',
 716          'sep'              => '',
 717          'count_before'     => ' (',
 718          'count_after'      => ')',
 719          'count_sep'        => ', ',
 720          'forum_id'         => '',
 721          'show_topic_count' => true,
 722          'show_reply_count' => true,
 723          'echo'             => true,
 724  
 725          // Retired, use 'sep' instead
 726          'separator'        => false
 727      ), 'list_forums' );
 728  
 729      /**
 730       * Necessary for backwards compatibility
 731       * @see https://bbpress.trac.wordpress.org/ticket/2900
 732       */
 733      if ( ! empty( $r['separator'] ) ) {
 734          $r['sep'] = $r['separator'];
 735      }
 736  
 737      // Default values
 738      $links  = array();
 739      $output = '';
 740  
 741      // Query for subforums
 742      $sub_forums = ! empty( $r['forum_id'] )
 743          ? bbp_forum_get_subforums( $r['forum_id'] )
 744          : array();
 745  
 746      // Loop through forums and create a list
 747      if ( ! empty( $sub_forums ) ) {
 748          foreach ( $sub_forums as $sub_forum ) {
 749  
 750              // Get forum details
 751              $count     = array();
 752              $permalink = bbp_get_forum_permalink( $sub_forum->ID );
 753              $title     = bbp_get_forum_title( $sub_forum->ID );
 754  
 755              // Show topic count
 756              if ( ! empty( $r['show_topic_count'] ) && ! bbp_is_forum_category( $sub_forum->ID ) ) {
 757                  $count['topic'] = bbp_get_forum_topic_count( $sub_forum->ID );
 758              }
 759  
 760              // Show reply count
 761              if ( ! empty( $r['show_reply_count'] ) && ! bbp_is_forum_category( $sub_forum->ID ) ) {
 762                  $count['reply'] = bbp_get_forum_reply_count( $sub_forum->ID );
 763              }
 764  
 765              // Counts to show
 766              $counts = ! empty( $count )
 767                  ? $r['count_before'] . implode( $r['count_sep'], $count ) . $r['count_after']
 768                  : '';
 769  
 770              // Subforum classes
 771              $subforum_classes      = array( 'bbp-forum-link' );
 772              $subforum_classes      = apply_filters( 'bbp_list_forums_subforum_classes', $subforum_classes, $sub_forum->ID );
 773  
 774              // This could use bbp_get_forum_class() eventually...
 775              $subforum_classes_attr = 'class="' . implode( ' ', array_map( 'sanitize_html_class', $subforum_classes ) ) . '"';
 776  
 777              // Build this sub forums link
 778              $links[] = $r['link_before'] . '<a href="' . esc_url( $permalink ) . '" ' . $subforum_classes_attr . '>' . $title . $counts . '</a>' . $r['link_after'];
 779          }
 780  
 781          // Maybe wrap output
 782          $output = ! empty( $links )
 783              ? $r['before'] . implode( $r['sep'], $links ) . $r['after']
 784              : '';
 785      }
 786  
 787      // Filter output
 788      $the_list = apply_filters( 'bbp_list_forums', $output, $r, $args );
 789  
 790      // Echo or return the forums list
 791      if ( true === $r['echo'] ) {
 792          echo $the_list;
 793      } else {
 794          return $the_list;
 795      }
 796  }
 797  
 798  /** Forum Subscriptions *******************************************************/
 799  
 800  /**
 801   * Output the forum subscription link
 802   *
 803   * @since 2.5.0 bbPress (r5156)
 804   * @since 2.6.0 bbPress (r6308) Add 'redirect_to' support
 805   */
 806  function bbp_forum_subscription_link( $args = array() ) {
 807      echo bbp_get_forum_subscription_link( $args );
 808  }
 809  
 810      /**
 811       * Get the forum subscription link
 812       *
 813       * A custom wrapper for bbp_get_user_subscribe_link()
 814       *
 815       * @since 2.5.0 bbPress (r5156)
 816       * @since 2.6.0 bbPress (r6308) Add 'redirect_to' support
 817       */
 818  	function bbp_get_forum_subscription_link( $args = array() ) {
 819  
 820          // Defaults
 821          $retval      = false;
 822          $redirect_to = bbp_is_subscriptions()
 823              ? bbp_get_subscriptions_permalink()
 824              : '';
 825  
 826          // Parse the arguments
 827          $r = bbp_parse_args( $args, array(
 828              'user_id'     => bbp_get_current_user_id(),
 829              'object_id'   => bbp_get_forum_id(),
 830              'object_type' => 'post',
 831              'before'      => '',
 832              'after'       => '',
 833              'subscribe'   => esc_html__( 'Subscribe',   'bbpress' ),
 834              'unsubscribe' => esc_html__( 'Unsubscribe', 'bbpress' ),
 835              'redirect_to' => $redirect_to
 836          ), 'get_forum_subscribe_link' );
 837  
 838          // No link for categories until we support subscription hierarchy
 839          // @see https://bbpress.trac.wordpress.org/ticket/2475
 840          if ( ! bbp_is_forum_category() ) {
 841              $retval = bbp_get_user_subscribe_link( $r );
 842          }
 843  
 844          // Filter & return
 845          return apply_filters( 'bbp_get_forum_subscribe_link', $retval, $r, $args );
 846      }
 847  
 848  /** Forum Last Topic **********************************************************/
 849  
 850  /**
 851   * Output the forum's last topic id
 852   *
 853   * @since 2.0.0 bbPress (r2464)
 854   *
 855   * @param int $forum_id Optional. Forum id
 856   */
 857  function bbp_forum_last_topic_id( $forum_id = 0 ) {
 858      echo bbp_get_forum_last_topic_id( $forum_id );
 859  }
 860      /**
 861       * Return the forum's last topic id
 862       *
 863       * @since 2.0.0 bbPress (r2464)
 864       *
 865       * @param int $forum_id Optional. Forum id
 866       * @return int Forum's last topic id
 867       */
 868  	function bbp_get_forum_last_topic_id( $forum_id = 0 ) {
 869          $forum_id = bbp_get_forum_id( $forum_id );
 870          $topic_id = get_post_meta( $forum_id, '_bbp_last_topic_id', true );
 871  
 872          // Filter & return
 873          return (int) apply_filters( 'bbp_get_forum_last_topic_id', (int) $topic_id, $forum_id );
 874      }
 875  
 876  /**
 877   * Output the title of the last topic inside a forum
 878   *
 879   * @since 2.0.0 bbPress (r2625)
 880   *
 881   * @param int $forum_id Optional. Forum id
 882   */
 883  function bbp_forum_last_topic_title( $forum_id = 0 ) {
 884      echo bbp_get_forum_last_topic_title( $forum_id );
 885  }
 886      /**
 887       * Return the title of the last topic inside a forum
 888       *
 889       * @since 2.0.0 bbPress (r2625)
 890       *
 891       * @param int $forum_id Optional. Forum id
 892       * @return string Forum's last topic's title
 893       */
 894  	function bbp_get_forum_last_topic_title( $forum_id = 0 ) {
 895          $forum_id = bbp_get_forum_id( $forum_id );
 896          $topic_id = bbp_get_forum_last_topic_id( $forum_id );
 897          $title    = ! empty( $topic_id ) ? bbp_get_topic_title( $topic_id ) : '';
 898  
 899          // Filter & return
 900          return apply_filters( 'bbp_get_forum_last_topic_title', $title, $forum_id );
 901      }
 902  
 903  /**
 904   * Output the link to the last topic in a forum
 905   *
 906   * @since 2.0.0 bbPress (r2464)
 907   *
 908   * @param int $forum_id Optional. Forum id
 909   */
 910  function bbp_forum_last_topic_permalink( $forum_id = 0 ) {
 911      echo esc_url( bbp_get_forum_last_topic_permalink( $forum_id ) );
 912  }
 913      /**
 914       * Return the link to the last topic in a forum
 915       *
 916       * @since 2.0.0 bbPress (r2464)
 917       *
 918       * @param int $forum_id Optional. Forum id
 919       * @return string Permanent link to topic
 920       */
 921  	function bbp_get_forum_last_topic_permalink( $forum_id = 0 ) {
 922          $forum_id = bbp_get_forum_id( $forum_id );
 923          $topic_id = bbp_get_forum_last_topic_id( $forum_id );
 924          $link     = bbp_get_topic_permalink( $topic_id );
 925  
 926          // Filter & return
 927          return apply_filters( 'bbp_get_forum_last_topic_permalink', $link, $forum_id, $topic_id );
 928      }
 929  
 930  /**
 931   * Return the author ID of the last topic of a forum
 932   *
 933   * @since 2.0.0 bbPress (r2625)
 934   *
 935   * @param int $forum_id Optional. Forum id
 936   * @return int Forum's last topic's author id
 937   */
 938  function bbp_get_forum_last_topic_author_id( $forum_id = 0 ) {
 939      $forum_id  = bbp_get_forum_id( $forum_id );
 940      $topic_id  = bbp_get_forum_last_topic_id( $forum_id );
 941      $author_id = bbp_get_topic_author_id( $topic_id );
 942  
 943      // Filter & return
 944      return (int) apply_filters( 'bbp_get_forum_last_topic_author_id', (int) $author_id, $forum_id, $topic_id );
 945  }
 946  
 947  /**
 948   * Output link to author of last topic of forum
 949   *
 950   * @since 2.0.0 bbPress (r2625)
 951   *
 952   * @param int $forum_id Optional. Forum id
 953   */
 954  function bbp_forum_last_topic_author_link( $forum_id = 0 ) {
 955      echo bbp_get_forum_last_topic_author_link( $forum_id );
 956  }
 957      /**
 958       * Return link to author of last topic of forum
 959       *
 960       * @since 2.0.0 bbPress (r2625)
 961       *
 962       * @param int $forum_id Optional. Forum id
 963       * @return string Forum's last topic's author link
 964       */
 965  	function bbp_get_forum_last_topic_author_link( $forum_id = 0 ) {
 966          $forum_id    = bbp_get_forum_id( $forum_id );
 967          $author_id   = bbp_get_forum_last_topic_author_id( $forum_id );
 968          $author_link = bbp_get_user_profile_link( $author_id );
 969  
 970          // Filter & return
 971          return apply_filters( 'bbp_get_forum_last_topic_author_link', $author_link, $forum_id );
 972      }
 973  
 974  /** Forum Last Reply **********************************************************/
 975  
 976  /**
 977   * Output the forums last reply id
 978   *
 979   * @since 2.0.0 bbPress (r2464)
 980   *
 981   * @param int $forum_id Optional. Forum id
 982   */
 983  function bbp_forum_last_reply_id( $forum_id = 0 ) {
 984      echo bbp_get_forum_last_reply_id( $forum_id );
 985  }
 986      /**
 987       * Return the forums last reply id
 988       *
 989       * @since 2.0.0 bbPress (r2464)
 990       *
 991       * @param int $forum_id Optional. Forum id
 992       * @return int Forum's last reply id
 993       */
 994  	function bbp_get_forum_last_reply_id( $forum_id = 0 ) {
 995          $forum_id = bbp_get_forum_id( $forum_id );
 996          $reply_id = get_post_meta( $forum_id, '_bbp_last_reply_id', true );
 997  
 998          // Filter & return
 999          return (int) apply_filters( 'bbp_get_forum_last_reply_id', (int) $reply_id, $forum_id );
1000      }
1001  
1002  /**
1003   * Output the title of the last reply inside a forum
1004   *
1005   * @param int $forum_id Optional. Forum id
1006   */
1007  function bbp_forum_last_reply_title( $forum_id = 0 ) {
1008      echo bbp_get_forum_last_reply_title( $forum_id );
1009  }
1010      /**
1011       * Return the title of the last reply inside a forum
1012       *
1013       * @param int $forum_id Optional. Forum id
1014       * @return string
1015       */
1016  	function bbp_get_forum_last_reply_title( $forum_id = 0 ) {
1017          $forum_id = bbp_get_forum_id( $forum_id );
1018          $reply_id = bbp_get_forum_last_reply_id( $forum_id );
1019          $title    = bbp_get_reply_title( $reply_id );
1020  
1021          // Filter & return
1022          return apply_filters( 'bbp_get_forum_last_reply_title', $title, $forum_id, $reply_id );
1023      }
1024  
1025  /**
1026   * Output the link to the last reply in a forum
1027   *
1028   * @since 2.0.0 bbPress (r2464)
1029   *
1030   * @param int $forum_id Optional. Forum id
1031   */
1032  function bbp_forum_last_reply_permalink( $forum_id = 0 ) {
1033      echo esc_url( bbp_get_forum_last_reply_permalink( $forum_id ) );
1034  }
1035      /**
1036       * Return the link to the last reply in a forum
1037       *
1038       * @since 2.0.0 bbPress (r2464)
1039       *
1040       * @param int $forum_id Optional. Forum id
1041       *
1042       * @return string Permanent link to the forum's last reply
1043       */
1044  	function bbp_get_forum_last_reply_permalink( $forum_id = 0 ) {
1045          $forum_id = bbp_get_forum_id( $forum_id );
1046          $reply_id = bbp_get_forum_last_reply_id( $forum_id );
1047          $link     = bbp_get_reply_permalink( $reply_id );
1048  
1049          // Filter & return
1050          return apply_filters( 'bbp_get_forum_last_reply_permalink', $link, $forum_id, $reply_id );
1051      }
1052  
1053  /**
1054   * Output the url to the last reply in a forum
1055   *
1056   * @since 2.0.0 bbPress (r2683)
1057   *
1058   * @param int $forum_id Optional. Forum id
1059   */
1060  function bbp_forum_last_reply_url( $forum_id = 0 ) {
1061      echo esc_url( bbp_get_forum_last_reply_url( $forum_id ) );
1062  }
1063      /**
1064       * Return the url to the last reply in a forum
1065       *
1066       * @since 2.0.0 bbPress (r2683)
1067       *
1068       * @param int $forum_id Optional. Forum id
1069       * @return string Paginated URL to latest reply
1070       */
1071  	function bbp_get_forum_last_reply_url( $forum_id = 0 ) {
1072          $forum_id = bbp_get_forum_id( $forum_id );
1073  
1074          // If forum has replies, get the last reply and use its url
1075          $reply_id = bbp_get_forum_last_reply_id( $forum_id );
1076          if ( ! empty( $reply_id ) ) {
1077              $reply_url = bbp_get_reply_url( $reply_id );
1078  
1079          // No replies, so look for topics and use last permalink
1080          } else {
1081              $reply_url = bbp_get_forum_last_topic_permalink( $forum_id );
1082  
1083              // No topics either, so set $reply_url as empty string
1084              if ( empty( $reply_url ) ) {
1085                  $reply_url = '';
1086              }
1087          }
1088  
1089          // Filter & return
1090          return apply_filters( 'bbp_get_forum_last_reply_url', $reply_url, $forum_id, $reply_id );
1091      }
1092  
1093  /**
1094   * Output author ID of last reply of forum
1095   *
1096   * @since 2.0.0 bbPress (r2625)
1097   *
1098   * @param int $forum_id Optional. Forum id
1099   */
1100  function bbp_forum_last_reply_author_id( $forum_id = 0 ) {
1101      echo bbp_get_forum_last_reply_author_id( $forum_id );
1102  }
1103      /**
1104       * Return author ID of last reply of forum
1105       *
1106       * @since 2.0.0 bbPress (r2625)
1107       *
1108       * @param int $forum_id Optional. Forum id
1109       * @return int Forum's last reply author id
1110       */
1111  	function bbp_get_forum_last_reply_author_id( $forum_id = 0 ) {
1112          $forum_id  = bbp_get_forum_id( $forum_id );
1113          $reply_id  = bbp_get_forum_last_reply_id( $forum_id );
1114          $author_id = bbp_get_reply_author_id( $reply_id );
1115  
1116          // Filter & return
1117          return apply_filters( 'bbp_get_forum_last_reply_author_id', $author_id, $forum_id, $reply_id );
1118      }
1119  
1120  /**
1121   * Output link to author of last reply of forum
1122   *
1123   * @since 2.0.0 bbPress (r2625)
1124   *
1125   * @param int $forum_id Optional. Forum id
1126   */
1127  function bbp_forum_last_reply_author_link( $forum_id = 0 ) {
1128      echo bbp_get_forum_last_reply_author_link( $forum_id );
1129  }
1130      /**
1131       * Return link to author of last reply of forum
1132       *
1133       * @since 2.0.0 bbPress (r2625)
1134       *
1135       * @param int $forum_id Optional. Forum id
1136       * @return string Link to author of last reply of forum
1137       */
1138  	function bbp_get_forum_last_reply_author_link( $forum_id = 0 ) {
1139          $forum_id    = bbp_get_forum_id( $forum_id );
1140          $author_id   = bbp_get_forum_last_reply_author_id( $forum_id );
1141          $author_link = bbp_get_user_profile_link( $author_id );
1142  
1143          // Filter & return
1144          return apply_filters( 'bbp_get_forum_last_reply_author_link', $author_link, $forum_id, $author_id );
1145      }
1146  
1147  /** Forum Counts **************************************************************/
1148  
1149  /**
1150   * Output the topics link of the forum
1151   *
1152   * @since 2.0.0 bbPress (r2883)
1153   *
1154   * @param int $forum_id Optional. Topic id
1155   */
1156  function bbp_forum_topics_link( $forum_id = 0 ) {
1157      echo bbp_get_forum_topics_link( $forum_id );
1158  }
1159  
1160      /**
1161       * Return the topics link of the forum
1162       *
1163       * @since 2.0.0 bbPress (r2883)
1164       *
1165       * @param int $forum_id Optional. Topic id
1166       */
1167  	function bbp_get_forum_topics_link( $forum_id = 0 ) {
1168          $forum_id = bbp_get_forum_id( $forum_id );
1169          $link     = bbp_get_forum_permalink( $forum_id );
1170          $topics   = sprintf( _n( '%s topic', '%s topics', bbp_get_forum_topic_count( $forum_id, true, true ), 'bbpress' ), bbp_get_forum_topic_count( $forum_id, true, false ) );
1171  
1172          // First link never has view=all
1173          $retval = bbp_get_view_all( 'edit_others_topics' )
1174              ? "<a href='" . esc_url( bbp_remove_view_all( $link ) ) . "'>" . esc_html( $topics ) . "</a>"
1175              : esc_html( $topics );
1176  
1177          // Get deleted topics
1178          $deleted_int = bbp_get_forum_topic_count_hidden( $forum_id, true  );
1179  
1180          // This forum has hidden topics
1181          if ( ! empty( $deleted_int ) && current_user_can( 'edit_others_topics' ) ) {
1182  
1183              // Hidden text
1184              $deleted_num = bbp_get_forum_topic_count_hidden( $forum_id, false );
1185              $extra       = ' ' . sprintf( _n( '(+%s hidden)', '(+%s hidden)', $deleted_int, 'bbpress' ), $deleted_num );
1186  
1187              // Hidden link
1188              $retval .= ! bbp_get_view_all( 'edit_others_topics' )
1189                  ? " <a href='" . esc_url( bbp_add_view_all( $link, true ) ) . "'>" . esc_html( $extra ) . "</a>"
1190                  : " {$extra}";
1191          }
1192  
1193          // Filter & return
1194          return apply_filters( 'bbp_get_forum_topics_link', $retval, $forum_id );
1195      }
1196  
1197  /**
1198   * Output total sub-forum count of a forum
1199   *
1200   * @since 2.0.0 bbPress (r2464)
1201   *
1202   * @param int $forum_id Optional. Forum id to check
1203   * @param boolean $integer Optional. Whether or not to format the result
1204   */
1205  function bbp_forum_subforum_count( $forum_id = 0, $integer = false ) {
1206      echo bbp_get_forum_subforum_count( $forum_id, $integer );
1207  }
1208      /**
1209       * Return total subforum count of a forum
1210       *
1211       * @since 2.0.0 bbPress (r2464)
1212       *
1213       * @param int $forum_id Optional. Forum id
1214       * @param boolean $integer Optional. Whether or not to format the result
1215       * @return int Forum's subforum count
1216       */
1217  	function bbp_get_forum_subforum_count( $forum_id = 0, $integer = false ) {
1218          $forum_id    = bbp_get_forum_id( $forum_id );
1219          $forum_count = get_post_meta( $forum_id, '_bbp_forum_subforum_count', true );
1220          $filter      = ( true === $integer )
1221              ? 'bbp_get_forum_subforum_count_int'
1222              : 'bbp_get_forum_subforum_count';
1223  
1224          return apply_filters( $filter, $forum_count, $forum_id );
1225      }
1226  
1227  /**
1228   * Output total topic count of a forum
1229   *
1230   * @since 2.0.0 bbPress (r2464)
1231   *
1232   * @param int $forum_id Optional. Forum id
1233   * @param bool $total_count Optional. To get the total count or normal count?
1234   * @param boolean $integer Optional. Whether or not to format the result
1235   */
1236  function bbp_forum_topic_count( $forum_id = 0, $total_count = true, $integer = false ) {
1237      echo bbp_get_forum_topic_count( $forum_id, $total_count, $integer );
1238  }
1239      /**
1240       * Return total topic count of a forum
1241       *
1242       * @since 2.0.0 bbPress (r2464)
1243       *
1244       * @param int $forum_id Optional. Forum id
1245       * @param bool $total_count Optional. To get the total count or normal
1246       *                           count? Defaults to total.
1247       * @param boolean $integer Optional. Whether or not to format the result
1248       * @return int Forum topic count
1249       */
1250  	function bbp_get_forum_topic_count( $forum_id = 0, $total_count = true, $integer = false ) {
1251          $forum_id = bbp_get_forum_id( $forum_id );
1252          $meta_key = empty( $total_count ) ? '_bbp_topic_count' : '_bbp_total_topic_count';
1253          $topics   = get_post_meta( $forum_id, $meta_key, true );
1254          $filter   = ( true === $integer )
1255              ? 'bbp_get_forum_topic_count_int'
1256              : 'bbp_get_forum_topic_count';
1257  
1258          return apply_filters( $filter, $topics, $forum_id );
1259      }
1260  
1261  /**
1262   * Output total reply count of a forum
1263   *
1264   * @since 2.0.0 bbPress (r2464)
1265   *
1266   * @param int $forum_id Optional. Forum id
1267   * @param bool $total_count Optional. To get the total count or normal count?
1268   * @param boolean $integer Optional. Whether or not to format the result
1269   */
1270  function bbp_forum_reply_count( $forum_id = 0, $total_count = true, $integer = false ) {
1271      echo bbp_get_forum_reply_count( $forum_id, $total_count, $integer );
1272  }
1273      /**
1274       * Return total post count of a forum
1275       *
1276       * @since 2.0.0 bbPress (r2464)
1277       *
1278       * @param int $forum_id Optional. Forum id
1279       * @param bool $total_count Optional. To get the total count or normal
1280       *                           count?
1281       * @param boolean $integer Optional. Whether or not to format the result
1282       * @return int Forum reply count
1283       */
1284  	function bbp_get_forum_reply_count( $forum_id = 0, $total_count = true, $integer = false ) {
1285          $forum_id = bbp_get_forum_id( $forum_id );
1286          $meta_key = empty( $total_count ) ? '_bbp_reply_count' : '_bbp_total_reply_count';
1287          $replies  = get_post_meta( $forum_id, $meta_key, true );
1288          $filter   = ( true === $integer )
1289              ? 'bbp_get_forum_reply_count_int'
1290              : 'bbp_get_forum_reply_count';
1291  
1292          return apply_filters( $filter, $replies, $forum_id );
1293      }
1294  
1295  /**
1296   * Output total post count of a forum
1297   *
1298   * @since 2.0.0 bbPress (r2954)
1299   *
1300   * @param int $forum_id Optional. Forum id
1301   * @param bool $total_count Optional. To get the total count or normal count?
1302   * @param boolean $integer Optional. Whether or not to format the result
1303   */
1304  function bbp_forum_post_count( $forum_id = 0, $total_count = true, $integer = false ) {
1305      echo bbp_get_forum_post_count( $forum_id, $total_count, $integer );
1306  }
1307      /**
1308       * Return total post count of a forum
1309       *
1310       * @since 2.0.0 bbPress (r2954)
1311       *
1312       * @param int $forum_id Optional. Forum id
1313       * @param bool $total_count Optional. To get the total count or normal
1314       *                           count?
1315       * @param boolean $integer Optional. Whether or not to format the result
1316       * @return int Forum post count
1317       */
1318  	function bbp_get_forum_post_count( $forum_id = 0, $total_count = true, $integer = false ) {
1319          $forum_id = bbp_get_forum_id( $forum_id );
1320          $topics   = bbp_get_forum_topic_count( $forum_id, $total_count, true );
1321          $replies  = bbp_get_forum_reply_count( $forum_id, $total_count, true );
1322          $retval   = $replies + $topics;
1323          $filter   = ( true === $integer )
1324              ? 'bbp_get_forum_post_count_int'
1325              : 'bbp_get_forum_post_count';
1326  
1327          return apply_filters( $filter, $retval, $forum_id );
1328      }
1329  
1330  /**
1331   * Output total hidden topic count of a forum (hidden includes trashed, spammed,
1332   * and pending topics)
1333   *
1334   * @since 2.0.0 bbPress (r2883)
1335   *
1336   * @param int $forum_id Optional. Topic id
1337   * @param boolean $integer Optional. Whether or not to format the result
1338   */
1339  function bbp_forum_topic_count_hidden( $forum_id = 0, $integer = false ) {
1340      echo bbp_get_forum_topic_count_hidden( $forum_id, $integer );
1341  }
1342      /**
1343       * Return total hidden topic count of a forum (hidden includes trashed,
1344       * spammed and pending topics)
1345       *
1346       * @since 2.0.0 bbPress (r2883)
1347       *
1348       * @param int $forum_id Optional. Topic id
1349       * @param boolean $integer Optional. Whether or not to format the result
1350       * @return int Topic hidden topic count
1351       */
1352  	function bbp_get_forum_topic_count_hidden( $forum_id = 0, $integer = false ) {
1353          $forum_id = bbp_get_forum_id( $forum_id );
1354          $topics   = get_post_meta( $forum_id, '_bbp_topic_count_hidden', true );
1355          $filter   = ( true === $integer )
1356              ? 'bbp_get_forum_topic_count_hidden_int'
1357              : 'bbp_get_forum_topic_count_hidden';
1358  
1359          return apply_filters( $filter, $topics, $forum_id );
1360      }
1361  
1362  /**
1363   * Output the status of the forum
1364   *
1365   * @since 2.0.0 bbPress (r2667)
1366   *
1367   * @param int $forum_id Optional. Forum id
1368   */
1369  function bbp_forum_status( $forum_id = 0 ) {
1370      echo bbp_get_forum_status( $forum_id );
1371  }
1372      /**
1373       * Return the status of the forum
1374       *
1375       * @since 2.0.0 bbPress (r2667)
1376       *
1377       * @param int $forum_id Optional. Forum id
1378       * @return string Status of forum
1379       */
1380  	function bbp_get_forum_status( $forum_id = 0 ) {
1381          $forum_id = bbp_get_forum_id( $forum_id );
1382          $status   = get_post_meta( $forum_id, '_bbp_status', true );
1383  
1384          if ( empty( $status ) ) {
1385              $status = 'open';
1386          }
1387  
1388          // Filter & return
1389          return apply_filters( 'bbp_get_forum_status', $status, $forum_id );
1390      }
1391  
1392  /**
1393   * Output the visibility of the forum
1394   *
1395   * @since 2.0.0 bbPress (r2997)
1396   *
1397   * @param int $forum_id Optional. Forum id
1398   */
1399  function bbp_forum_visibility( $forum_id = 0 ) {
1400      echo bbp_get_forum_visibility( $forum_id );
1401  }
1402      /**
1403       * Return the visibility of the forum
1404       *
1405       * @since 2.0.0 bbPress (r2997)
1406       *
1407       * @param int $forum_id Optional. Forum id
1408       * @return string Status of forum
1409       */
1410  	function bbp_get_forum_visibility( $forum_id = 0 ) {
1411          $forum_id   = bbp_get_forum_id( $forum_id );
1412          $visibility = get_post_status( $forum_id );
1413  
1414          // Filter & return
1415          return apply_filters( 'bbp_get_forum_visibility', $visibility, $forum_id );
1416      }
1417  
1418  /**
1419   * Output the type of the forum
1420   *
1421   * @since 2.1.0 bbPress (r3563)
1422   *
1423   * @param int $forum_id Optional. Forum id
1424   */
1425  function bbp_forum_type( $forum_id = 0 ) {
1426      echo bbp_get_forum_type( $forum_id );
1427  }
1428      /**
1429       * Return the type of forum (category/forum/etc...)
1430       *
1431       * @since 2.1.0 bbPress (r3563)
1432       *
1433       * @param int $forum_id Optional. Forum id
1434       * @return bool Whether the forum is a category or not
1435       */
1436  	function bbp_get_forum_type( $forum_id = 0 ) {
1437          $forum_id = bbp_get_forum_id( $forum_id );
1438          $retval   = get_post_meta( $forum_id, '_bbp_forum_type', true );
1439  
1440          if ( empty( $retval ) ) {
1441              $retval = 'forum';
1442          }
1443  
1444          // Filter & return
1445          return apply_filters( 'bbp_get_forum_type', $retval, $forum_id );
1446      }
1447  
1448  /**
1449   * Is the forum a category?
1450   *
1451   * @since 2.0.0 bbPress (r2746)
1452   *
1453   * @param int $forum_id Optional. Forum id
1454   * @return bool Whether the forum is a category or not
1455   */
1456  function bbp_is_forum_category( $forum_id = 0 ) {
1457      $forum_id = bbp_get_forum_id( $forum_id );
1458      $type     = bbp_get_forum_type( $forum_id );
1459      $retval   = ( ! empty( $type ) && 'category' === $type );
1460  
1461      // Filter & return
1462      return (bool) apply_filters( 'bbp_is_forum_category', (bool) $retval, $forum_id );
1463  }
1464  
1465  /**
1466   * Is the forum open?
1467   *
1468   * @since 2.0.0 bbPress (r2746)
1469   *
1470   * @param int $forum_id Optional. Forum id
1471   * @param bool $check_ancestors Check if the ancestors are open (only
1472   *                               if they're a category)
1473   * @return bool Whether the forum is open or not
1474   */
1475  function bbp_is_forum_open( $forum_id = 0, $check_ancestors = true ) {
1476      return ! bbp_is_forum_closed( $forum_id, $check_ancestors );
1477  }
1478  
1479  /**
1480  * Is the forum closed?
1481   *
1482   * @since 2.0.0 bbPress (r2746)
1483   *
1484   * @param int $forum_id Optional. Forum id
1485   * @param bool $check_ancestors Check if the ancestors are closed (only
1486   *                               if they're a category)
1487   * @return bool True if closed, false if not
1488   */
1489  function bbp_is_forum_closed( $forum_id = 0, $check_ancestors = true ) {
1490  
1491      // Get the forum ID
1492      $forum_id = bbp_get_forum_id( $forum_id );
1493  
1494      // Check if the forum or one of it's ancestors is closed
1495      $retval   = bbp_is_forum_status( $forum_id, bbp_get_closed_status_id(), $check_ancestors, 'OR' );
1496  
1497      // Filter & return
1498      return (bool) apply_filters( 'bbp_is_forum_closed', (bool) $retval, $forum_id, $check_ancestors );
1499  }
1500  
1501  /**
1502   * Check if the forum status is a specific one, also maybe checking ancestors
1503   *
1504   * @since 2.6.0 bbPress (r5499)
1505   *
1506   * @param bool $status_name The forum status name to check
1507   * @param bool $check_ancestors Check the forum ancestors
1508   * @param string $operator The logical operation to perform.
1509   *      'OR' means only one forum from the tree needs to match;
1510   *      'AND' means all forums must match. The default is 'AND'.
1511   * @return bool True if match, false if not
1512   */
1513  function bbp_is_forum_status( $forum_id, $status_name, $check_ancestors = true, $operator = 'AND' ) {
1514  
1515      // Setup some default variables
1516      $count        = 0;
1517      $retval       = false;
1518      $operator     = strtoupper( $operator );
1519      $forum_id     = bbp_get_forum_id( $forum_id );
1520      $forum_status = bbp_get_forum_status( $forum_id );
1521  
1522      // Quickly compare statuses of first forum ID
1523      if ( $status_name === $forum_status ) {
1524          $retval = true;
1525          $count++;
1526      }
1527  
1528      // Let's check the forum's ancestors too
1529      if ( ! empty( $check_ancestors ) ) {
1530  
1531          // Adjust the ancestor check based on the count
1532          switch( $operator ) {
1533              default:
1534              case 'AND':
1535                  $check_ancestors = ( $count > 0 );
1536                  break;
1537  
1538              case 'OR':
1539                  $check_ancestors = ( $count < 1 );
1540                  break;
1541          }
1542  
1543          // Ancestor check passed, so continue looping through them
1544          if ( ! empty( $check_ancestors ) ) {
1545  
1546              // Loop through the forum ancestors
1547              foreach ( (array) bbp_get_forum_ancestors( $forum_id ) as $ancestor ) {
1548  
1549                  // Check if the forum is a category
1550                  if ( bbp_is_forum_category( $ancestor ) ) {
1551  
1552                      // Check the ancestor forum status
1553                      $retval = bbp_is_forum_status( $ancestor, $status_name, false );
1554                      if ( true === $retval ) {
1555                          $count++;
1556                      }
1557                  }
1558  
1559                  // Break when it reach the max count
1560                  if ( ( $operator === 'OR' ) && ( $count >= 1 ) ) {
1561                      break;
1562                  }
1563              }
1564          }
1565      }
1566  
1567      // Filter & return
1568      return (bool) apply_filters( 'bbp_is_forum_status', $retval, $count, $forum_id, $status_name, $check_ancestors, $operator );
1569  }
1570  
1571  /**
1572   * Is the forum public?
1573   *
1574   * @since 2.0.0 bbPress (r2997)
1575   *
1576   * @param int $forum_id Optional. Forum id
1577   * @param bool $check_ancestors Check if the ancestors are public
1578   * @return bool True if closed, false if not
1579   */
1580  function bbp_is_forum_public( $forum_id = 0, $check_ancestors = true ) {
1581  
1582      // Get the forum ID
1583      $forum_id = bbp_get_forum_id( $forum_id );
1584  
1585      // Check if the forum and all of it's ancestors are public
1586      $retval   = bbp_is_forum_visibility( $forum_id, bbp_get_public_status_id(), $check_ancestors );
1587  
1588      // Filter & return
1589      return (bool) apply_filters( 'bbp_is_forum_public', $retval, $forum_id, $check_ancestors );
1590  }
1591  
1592  /**
1593   * Is the forum private?
1594   *
1595   * @since 2.0.0 bbPress (r2746)
1596   *
1597   * @param int $forum_id Optional. Forum id
1598   * @param bool $check_ancestors Check if the ancestors are private
1599   * @return bool True if private, false if not
1600   */
1601  function bbp_is_forum_private( $forum_id = 0, $check_ancestors = true ) {
1602  
1603      // Get the forum ID
1604      $forum_id = bbp_get_forum_id( $forum_id );
1605  
1606      // Check if the forum or one of it's ancestors is private
1607      $retval   = bbp_is_forum_visibility( $forum_id, bbp_get_private_status_id(), $check_ancestors, 'OR' );
1608  
1609      // Filter & return
1610      return (bool) apply_filters( 'bbp_is_forum_private', $retval, $forum_id, $check_ancestors );
1611  }
1612  
1613  /**
1614   * Is the forum hidden?
1615   *
1616   * @since 2.0.0 bbPress (r2997)
1617   *
1618   * @param int $forum_id Optional. Forum id
1619   * @param bool $check_ancestors Check if the ancestors are private (only if
1620   *                               they're a category)
1621   * @return bool True if hidden, false if not
1622   */
1623  function bbp_is_forum_hidden( $forum_id = 0, $check_ancestors = true ) {
1624  
1625      // Get the forum ID
1626      $forum_id = bbp_get_forum_id( $forum_id );
1627  
1628      // Check if the forum or one of it's ancestors is hidden
1629      $retval   = bbp_is_forum_visibility( $forum_id, bbp_get_hidden_status_id(), $check_ancestors, 'OR' );
1630  
1631      // Filter & return
1632      return (bool) apply_filters( 'bbp_is_forum_hidden', $retval, $forum_id, $check_ancestors );
1633  }
1634  
1635  /**
1636   * Check the forum visibility ID
1637   *
1638   * @since 2.6.0 bbPress (r5499)
1639   *
1640   * @param int $forum_id Optional. Forum id
1641   * @param bool $status_name The post status name to check
1642   * @param bool $check_ancestors Check the forum ancestors
1643   * @param string $operator The logical operation to perform.
1644   *      'OR' means only one forum from the tree needs to match;
1645   *      'AND' means all forums must match. The default is 'AND'.
1646   * @return bool True if match, false if not
1647   */
1648  function bbp_is_forum_visibility( $forum_id, $status_name, $check_ancestors = true, $operator = 'AND' ) {
1649  
1650      // Setup some default variables
1651      $count      = 0;
1652      $retval     = false;
1653      $operator   = strtoupper( $operator );
1654      $forum_id   = bbp_get_forum_id( $forum_id );
1655      $visibility = bbp_get_forum_visibility( $forum_id );
1656  
1657      // Quickly compare visibility of first forum ID
1658      if ( $status_name === $visibility ) {
1659          $retval = true;
1660          $count++;
1661      }
1662  
1663      // Let's check the forum's ancestors too
1664      if ( ! empty( $check_ancestors ) ) {
1665  
1666          // Adjust the ancestor check based on the count
1667          switch ( $operator ) {
1668  
1669              // Adjust the ancestor check based on the count
1670              default:
1671              case 'AND':
1672                  $check_ancestors = ( $count > 0 );
1673                  break;
1674  
1675              case 'OR':
1676                  $check_ancestors = ( $count < 1 );
1677                  break;
1678          }
1679  
1680          // Ancestor check passed, so continue looping through them
1681          if ( ! empty( $check_ancestors ) ) {
1682  
1683              // Loop through the forum ancestors
1684              foreach ( (array) bbp_get_forum_ancestors( $forum_id ) as $ancestor ) {
1685  
1686                  // Check if the forum is not a category
1687                  if ( bbp_is_forum( $ancestor ) ) {
1688  
1689                      // Check the forum visibility
1690                      $retval = bbp_is_forum_visibility( $ancestor, $status_name, false );
1691                      if ( true === $retval ) {
1692                          $count++;
1693                      }
1694                  }
1695  
1696                  // Break when it reach the max count
1697                  if ( ( $operator === 'OR' ) && ( $count >= 1 ) ) {
1698                      break;
1699                  }
1700              }
1701          }
1702      }
1703  
1704      // Filter & return
1705      return (bool) apply_filters( 'bbp_is_forum_visibility', $retval, $count, $forum_id, $status_name, $check_ancestors, $operator );
1706  }
1707  
1708  /**
1709   * Output the author ID of the forum
1710   *
1711   * @since 2.1.0 bbPress (r3675)
1712   *
1713   * @param int $forum_id Optional. Forum id
1714   */
1715  function bbp_forum_author_id( $forum_id = 0 ) {
1716      echo bbp_get_forum_author_id( $forum_id );
1717  }
1718      /**
1719       * Return the author ID of the forum
1720       *
1721       * @since 2.1.0 bbPress (r3675)
1722       *
1723       * @param int $forum_id Optional. Forum id
1724       *                        id and forum id
1725       * @return string Author of forum
1726       */
1727  	function bbp_get_forum_author_id( $forum_id = 0 ) {
1728          $forum_id  = bbp_get_forum_id( $forum_id );
1729          $author_id = get_post_field( 'post_author', $forum_id );
1730  
1731          // Filter & return
1732          return (int) apply_filters( 'bbp_get_forum_author_id', (int) $author_id, $forum_id );
1733      }
1734  
1735  /**
1736   * Output the author of the forum
1737   *
1738   * @since 2.1.0 bbPress (r3675)
1739   *
1740   * @param int $forum_id Optional. Forum id
1741   */
1742  function bbp_forum_author_display_name( $forum_id = 0 ) {
1743      echo bbp_get_forum_author_display_name( $forum_id );
1744  }
1745      /**
1746       * Return the author of the forum
1747       *
1748       * @since 2.1.0 bbPress (r3675)
1749       *
1750       * @param int $forum_id Optional. Forum id
1751       * @return string Author of forum
1752       */
1753  	function bbp_get_forum_author_display_name( $forum_id = 0 ) {
1754          $forum_id  = bbp_get_forum_id( $forum_id );
1755          $author_id = bbp_get_forum_author_id( $forum_id );
1756          $author    = get_the_author_meta( 'display_name', $author_id );
1757  
1758          // Filter & return
1759          return apply_filters( 'bbp_get_forum_author_display_name', $author, $forum_id, $author_id );
1760      }
1761  
1762  /**
1763   * Replace forum meta details for users that cannot view them.
1764   *
1765   * @since 2.0.0 bbPress (r3162)
1766   *
1767   * @param string $retval
1768   * @param int $forum_id
1769   *
1770   * @return string
1771   */
1772  function bbp_suppress_private_forum_meta( $retval, $forum_id ) {
1773      if ( bbp_is_forum_private( $forum_id, false ) && ! current_user_can( 'read_forum', $forum_id ) ) {
1774          $retval = '-';
1775      }
1776  
1777      // Filter & return
1778      return apply_filters( 'bbp_suppress_private_forum_meta', $retval );
1779  }
1780  
1781  /**
1782   * Replace forum author details for users that cannot view them.
1783   *
1784   * @since 2.0.0 bbPress (r3162)
1785   *
1786   * @param string $author_link
1787   * @param array $args
1788   *
1789   * @return string
1790   */
1791  function bbp_suppress_private_author_link( $author_link = '', $args = array() ) {
1792  
1793      // Assume the author link is the return value
1794      $retval = $author_link;
1795  
1796      // Show the normal author link
1797      if ( ! empty( $args['post_id'] ) && ! current_user_can( 'read_private_forums' ) ) {
1798  
1799          // What post type are we looking at?
1800          switch ( get_post_type( $args['post_id'] ) ) {
1801  
1802              // Topic
1803              case bbp_get_topic_post_type() :
1804                  $forum_id = bbp_get_topic_forum_id( $args['post_id'] );
1805                  break;
1806  
1807              // Reply
1808              case bbp_get_reply_post_type() :
1809                  $forum_id = bbp_get_reply_forum_id( $args['post_id'] );
1810                  break;
1811  
1812              // Post
1813              default :
1814                  $forum_id = bbp_get_forum_id( $args['post_id'] );
1815                  break;
1816          }
1817  
1818          // Hide if forum is private
1819          if ( bbp_is_forum_private( $forum_id ) ) {
1820              $retval = '';
1821          }
1822      }
1823  
1824      // Filter & return
1825      return apply_filters( 'bbp_suppress_private_author_link', $retval, $author_link, $args );
1826  }
1827  
1828  /**
1829   * Output the row class of a forum
1830   *
1831   * @since 2.0.0 bbPress (r2667)
1832   *
1833   * @param int $forum_id Optional. Forum ID.
1834   * @param array Extra classes you can pass when calling this function
1835   */
1836  function bbp_forum_class( $forum_id = 0, $classes = array() ) {
1837      echo bbp_get_forum_class( $forum_id, $classes );
1838  }
1839      /**
1840       * Return the row class of a forum
1841       *
1842       * @since 2.0.0 bbPress (r2667)
1843       *
1844       * @param int $forum_id Optional. Forum ID
1845       * @param array Extra classes you can pass when calling this function
1846       * @return string Row class of the forum
1847       */
1848  	function bbp_get_forum_class( $forum_id = 0, $classes = array() ) {
1849          $bbp        = bbpress();
1850          $forum_id   = bbp_get_forum_id( $forum_id );
1851          $parent_id  = bbp_get_forum_parent_id( $forum_id );
1852          $author_id  = bbp_get_forum_author_id( $forum_id );
1853          $status     = bbp_get_forum_status( $forum_id );
1854          $visibility = bbp_get_forum_visibility( $forum_id );
1855          $classes    = array_filter( (array) $classes );
1856          $count      = isset( $bbp->forum_query->current_post )
1857              ? (int) $bbp->forum_query->current_post
1858              : 1;
1859  
1860          //  Stripes
1861          $even_odd = ( $count % 2 )
1862              ? 'even'
1863              : 'odd';
1864  
1865          // User is moderator of forum
1866          $forum_moderator = ( bbp_is_user_forum_moderator( $author_id, $forum_id ) === $author_id )
1867              ? 'forum-mod'
1868              : '';
1869  
1870          // Is forum a non-postable category?
1871          $category = bbp_is_forum_category( $forum_id )
1872              ? 'status-category'
1873              : '';
1874  
1875          // Forum has children?
1876          $subs = bbp_get_forum_subforum_count( $forum_id )
1877              ? 'bbp-has-subforums'
1878              : '';
1879  
1880          // Forum has parent?
1881          $parent = ! empty( $parent_id )
1882              ? 'bbp-parent-forum-' . $parent_id
1883              : '';
1884  
1885          // Get forum classes
1886          $forum_classes = array(
1887              'loop-item-'            . $count,
1888              'bbp-forum-status-'     . $status,
1889              'bbp-forum-visibility-' . $visibility,
1890              $even_odd,
1891              $forum_moderator,
1892              $category,
1893              $subs,
1894              $parent
1895          );
1896  
1897          // Run the topic classes through the post-class filters, which also
1898          // handles the escaping of each individual class.
1899          $post_classes = get_post_class( array_merge( $classes, $forum_classes ), $forum_id );
1900  
1901          // Filter
1902          $new_classes  = apply_filters( 'bbp_get_forum_class', $post_classes, $forum_id, $classes );
1903  
1904          // Return
1905          return 'class="' . implode( ' ', $new_classes ) . '"';
1906      }
1907  
1908  /** Single Forum **************************************************************/
1909  
1910  /**
1911   * Output a fancy description of the current forum, including total topics,
1912   * total replies, and last activity.
1913   *
1914   * @since 2.0.0 bbPress (r2860)
1915   *
1916   * @param array $args Arguments passed to alter output
1917   */
1918  function bbp_single_forum_description( $args = array() ) {
1919      echo bbp_get_single_forum_description( $args );
1920  }
1921      /**
1922       * Return a fancy description of the current forum, including total
1923       * topics, total replies, and last activity.
1924       *
1925       * @since 2.0.0 bbPress (r2860)
1926       *
1927       * @param array $args This function supports these arguments:
1928       *  - forum_id: Forum id
1929       *  - before: Before the text
1930       *  - after: After the text
1931       *  - size: Size of the avatar
1932       * @return string Filtered forum description
1933       */
1934  	function bbp_get_single_forum_description( $args = array() ) {
1935  
1936          // Parse arguments against default values
1937          $r = bbp_parse_args( $args, array(
1938              'forum_id'  => 0,
1939              'before'    => '<div class="bbp-template-notice info"><ul><li class="bbp-forum-description">',
1940              'after'     => '</li></ul></div>',
1941              'size'      => 14,
1942              'feed'      => true
1943          ), 'get_single_forum_description' );
1944  
1945          // Validate forum_id
1946          $forum_id = bbp_get_forum_id( $r['forum_id'] );
1947  
1948          // Unhook the 'view all' query var adder
1949          remove_filter( 'bbp_get_forum_permalink', 'bbp_add_view_all' );
1950  
1951          // Get some forum data
1952          $tc_int      = bbp_get_forum_topic_count( $forum_id, true, true  );
1953          $rc_int      = bbp_get_forum_reply_count( $forum_id, true, true  );
1954          $topic_count = bbp_get_forum_topic_count( $forum_id, true, false );
1955          $reply_count = bbp_get_forum_reply_count( $forum_id, true, false );
1956          $last_active = bbp_get_forum_last_active_id( $forum_id );
1957  
1958          // Has replies
1959          if ( ! empty( $reply_count ) ) {
1960              $reply_text = sprintf( _n( '%s reply', '%s replies', $rc_int, 'bbpress' ), $reply_count );
1961          }
1962  
1963          // Forum has active data
1964          if ( ! empty( $last_active ) ) {
1965              $topic_text      = bbp_get_forum_topics_link( $forum_id );
1966              $time_since      = bbp_get_forum_freshness_link( $forum_id );
1967              $last_updated_by = bbp_get_author_link( array( 'post_id' => $last_active, 'size' => $r['size'] ) );
1968  
1969          // Forum has no last active data
1970          } else {
1971              $topic_text      = sprintf( _n( '%s topic', '%s topics', $tc_int, 'bbpress' ), $topic_count );
1972          }
1973  
1974          // Forum has active data
1975          if ( ! empty( $last_active ) ) {
1976  
1977              // Has replies
1978              if ( ! empty( $reply_count ) ) {
1979                  $retstr = bbp_is_forum_category( $forum_id )
1980                      ? sprintf( esc_html__( 'This category has %1$s, %2$s, and was last updated %3$s by %4$s.', 'bbpress' ), $topic_text, $reply_text, $time_since, $last_updated_by )
1981                      : sprintf( esc_html__( 'This forum has %1$s, %2$s, and was last updated %3$s by %4$s.',    'bbpress' ), $topic_text, $reply_text, $time_since, $last_updated_by );
1982  
1983              // Only has topics
1984              } else {
1985                  $retstr = bbp_is_forum_category( $forum_id )
1986                      ? sprintf( esc_html__( 'This category has %1$s, and was last updated %2$s by %3$s.', 'bbpress' ), $topic_text, $time_since, $last_updated_by )
1987                      : sprintf( esc_html__( 'This forum has %1$s, and was last updated %2$s by %3$s.',    'bbpress' ), $topic_text, $time_since, $last_updated_by );
1988              }
1989  
1990          // Forum has no last active data (but does have topics & replies)
1991          } elseif ( ! empty( $reply_count ) ) {
1992              $retstr = bbp_is_forum_category( $forum_id )
1993                  ? sprintf( esc_html__( 'This category has %1$s and %2$s.', 'bbpress' ), $topic_text, $reply_text )
1994                  : sprintf( esc_html__( 'This forum has %1$s and %2$s.',    'bbpress' ), $topic_text, $reply_text );
1995  
1996          // Forum has no last active data or replies (but does have topics)
1997          } elseif ( ! empty( $topic_count ) ) {
1998              $retstr = bbp_is_forum_category( $forum_id )
1999                  ? sprintf( esc_html__( 'This category has %1$s.', 'bbpress' ), $topic_text )
2000                  : sprintf( esc_html__( 'This forum has %1$s.',    'bbpress' ), $topic_text );
2001  
2002          // Forum is empty
2003          } else {
2004              $retstr = esc_html__( 'This forum is empty.', 'bbpress' );
2005          }
2006  
2007          // Add the 'view all' filter back
2008          add_filter( 'bbp_get_forum_permalink', 'bbp_add_view_all' );
2009  
2010          // Combine the elements together
2011          $retstr = $r['before'] . $retstr . $r['after'];
2012  
2013          // Filter & return
2014          return apply_filters( 'bbp_get_single_forum_description', $retstr, $r, $args );
2015      }
2016  
2017  /** Forms *********************************************************************/
2018  
2019  /**
2020   * Output the value of forum title field
2021   *
2022   * @since 2.1.0 bbPress (r3551)
2023   */
2024  function bbp_form_forum_title() {
2025      echo bbp_get_form_forum_title();
2026  }
2027      /**
2028       * Return the value of forum title field
2029       *
2030       * @since 2.1.0 bbPress (r3551)
2031       *
2032       * @return string Value of forum title field
2033       */
2034  	function bbp_get_form_forum_title() {
2035  
2036          // Get _POST data
2037          if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_title'] ) ) {
2038              $forum_title = wp_unslash( $_POST['bbp_forum_title'] );
2039  
2040          // Get edit data
2041          } elseif ( bbp_is_forum_edit() ) {
2042              $forum_title = bbp_get_global_post_field( 'post_title', 'raw' );
2043  
2044          // No data
2045          } else {
2046              $forum_title = '';
2047          }
2048  
2049          // Filter & return
2050          return apply_filters( 'bbp_get_form_forum_title', $forum_title );
2051      }
2052  
2053  /**
2054   * Output the value of forum content field
2055   *
2056   * @since 2.1.0 bbPress (r3551)
2057   */
2058  function bbp_form_forum_content() {
2059      echo bbp_get_form_forum_content();
2060  }
2061      /**
2062       * Return the value of forum content field
2063       *
2064       * @since 2.1.0 bbPress (r3551)
2065       *
2066       * @return string Value of forum content field
2067       */
2068  	function bbp_get_form_forum_content() {
2069  
2070          // Get _POST data
2071          if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_content'] ) ) {
2072              $forum_content = wp_unslash( $_POST['bbp_forum_content'] );
2073  
2074          // Get edit data
2075          } elseif ( bbp_is_forum_edit() ) {
2076              $forum_content = bbp_get_global_post_field( 'post_content', 'raw' );
2077  
2078          // No data
2079          } else {
2080              $forum_content = '';
2081          }
2082  
2083          // Filter & return
2084          return apply_filters( 'bbp_get_form_forum_content', $forum_content );
2085      }
2086  
2087  /**
2088   * Output value of forum moderators field
2089   *
2090   * @since 2.6.0 bbPress (r5837)
2091   */
2092  function bbp_form_forum_moderators() {
2093      echo bbp_get_form_forum_moderators();
2094  }
2095      /**
2096       * Return value of forum moderators field
2097       *
2098       * @since 2.6.0 bbPress (r5837)
2099       *
2100       * @return string Value of forum mods field
2101       */
2102  	function bbp_get_form_forum_moderators() {
2103  
2104          // Default return value
2105          $forum_mods = '';
2106  
2107          // Get _POST data
2108          if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_moderators'] ) ) {
2109              $forum_mods = wp_unslash( $_POST['bbp_moderators'] );
2110  
2111          // Get edit data
2112          } elseif ( bbp_is_single_forum() || bbp_is_forum_edit() ) {
2113  
2114              // Get the forum ID
2115              $forum_id = bbp_get_forum_id( get_the_ID() );
2116  
2117              // Forum exists
2118              if ( ! empty( $forum_id ) ) {
2119  
2120                  // Get moderator IDs
2121                  $user_ids = bbp_get_moderator_ids( $forum_id );
2122                  if ( ! empty( $user_ids ) ) {
2123                      $user_nicenames = bbp_get_user_nicenames_from_ids( $user_ids );
2124  
2125                      // Comma separate user nicenames
2126                      if ( ! empty( $user_nicenames ) ) {
2127                          $forum_mods = implode( ', ', wp_list_pluck( $user_nicenames, 'user_nicename' ) );
2128                      }
2129                  }
2130              }
2131          }
2132  
2133          // Filter & return
2134          return apply_filters( 'bbp_get_form_forum_moderators', $forum_mods );
2135      }
2136  
2137  /**
2138   * Output value of forum parent
2139   *
2140   * @since 2.1.0 bbPress (r3551)
2141   */
2142  function bbp_form_forum_parent() {
2143      echo bbp_get_form_forum_parent();
2144  }
2145      /**
2146       * Return value of forum parent
2147       *
2148       * @since 2.1.0 bbPress (r3551)
2149       *
2150       * @return string Value of topic content field
2151       */
2152  	function bbp_get_form_forum_parent() {
2153  
2154          // Get _POST data
2155          if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_id'] ) ) {
2156              $forum_parent = (int) $_POST['bbp_forum_id'];
2157  
2158          // Get edit data
2159          } elseif ( bbp_is_forum_edit() ) {
2160              $forum_parent = bbp_get_forum_parent_id();
2161  
2162          // No data
2163          } else {
2164              $forum_parent = 0;
2165          }
2166  
2167          // Filter & return
2168          return apply_filters( 'bbp_get_form_forum_parent', $forum_parent );
2169      }
2170  
2171  /**
2172   * Output value of forum type
2173   *
2174   * @since 2.1.0 bbPress (r3563)
2175   */
2176  function bbp_form_forum_type() {
2177      echo bbp_get_form_forum_type();
2178  }
2179      /**
2180       * Return value of forum type
2181       *
2182       * @since 2.1.0 bbPress (r3563)
2183       *
2184       * @return string Value of topic content field
2185       */
2186  	function bbp_get_form_forum_type() {
2187  
2188          // Get _POST data
2189          if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_type'] ) ) {
2190              $forum_type = sanitize_key( $_POST['bbp_forum_type'] );
2191  
2192          // Get edit data
2193          } elseif ( bbp_is_forum_edit() ) {
2194              $forum_type = bbp_get_forum_type();
2195  
2196          // No data
2197          } else {
2198              $forum_type = 'forum';
2199          }
2200  
2201          // Filter & return
2202          return apply_filters( 'bbp_get_form_forum_type', $forum_type );
2203      }
2204  
2205  /**
2206   * Output value of forum visibility
2207   *
2208   * @since 2.1.0 bbPress (r3563)
2209   */
2210  function bbp_form_forum_visibility() {
2211      echo bbp_get_form_forum_visibility();
2212  }
2213      /**
2214       * Return value of forum visibility
2215       *
2216       * @since 2.1.0 bbPress (r3563)
2217       *
2218       * @return string Value of topic content field
2219       */
2220  	function bbp_get_form_forum_visibility() {
2221  
2222          // Get _POST data
2223          if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_visibility'] ) ) {
2224              $forum_visibility = sanitize_key( $_POST['bbp_forum_visibility'] );
2225  
2226          // Get edit data
2227          } elseif ( bbp_is_forum_edit() ) {
2228              $forum_visibility = bbp_get_forum_visibility();
2229  
2230          // No data
2231          } else {
2232              $forum_visibility = bbpress()->public_status_id;
2233          }
2234  
2235          // Filter & return
2236          return apply_filters( 'bbp_get_form_forum_visibility', $forum_visibility );
2237      }
2238  
2239  /**
2240   * Output checked value of forum subscription
2241   *
2242   * @since 2.5.0 bbPress (r5156)
2243   */
2244  function bbp_form_forum_subscribed() {
2245      echo bbp_get_form_forum_subscribed();
2246  }
2247      /**
2248       * Return checked value of forum subscription
2249       *
2250       * @since 2.5.0 bbPress (r5156)
2251       *
2252       * @return string Checked value of forum subscription
2253       */
2254  	function bbp_get_form_forum_subscribed() {
2255  
2256          // Default value
2257          $forum_subscribed = false;
2258  
2259          // Get _POST data
2260          if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_subscription'] ) ) {
2261              $forum_subscribed = (bool) $_POST['bbp_forum_subscription'];
2262  
2263          // Get edit data
2264          } elseif ( bbp_is_forum_edit() || bbp_is_reply_edit() ) {
2265              $post_author      = (int) bbp_get_global_post_field( 'post_author', 'raw' );
2266              $forum_subscribed = bbp_is_user_subscribed( $post_author, bbp_get_forum_id() );
2267  
2268          // Get current status
2269          } elseif ( bbp_is_single_forum() ) {
2270              $forum_subscribed = bbp_is_user_subscribed( bbp_get_current_user_id(), bbp_get_forum_id() );
2271          }
2272  
2273          // Get checked output
2274          $checked = checked( $forum_subscribed, true, false );
2275  
2276          // Filter & return
2277          return apply_filters( 'bbp_get_form_forum_subscribed', $checked, $forum_subscribed );
2278      }
2279  
2280  /** Form Dropdowns ************************************************************/
2281  
2282  /**
2283   * Output value forum type dropdown
2284   *
2285   * @since 2.1.0 bbPress (r3563)
2286   *
2287   * @param $args This function supports these arguments:
2288   *  - select_id: Select id. Defaults to bbp_forum_type
2289   *  - tab: Deprecated. Tabindex
2290   *  - forum_id: Forum id
2291   *  - selected: Override the selected option
2292   */
2293  function bbp_form_forum_type_dropdown( $args = array() ) {
2294      echo bbp_get_form_forum_type_dropdown( $args );
2295  }
2296      /**
2297       * Return the forum type dropdown
2298       *
2299       * @since 2.1.0 bbPress (r3563)
2300       *
2301       * @param $args This function supports these arguments:
2302       *  - select_id: Select id. Defaults to bbp_forum_type
2303       *  - tab: Deprecated. Tabindex
2304       *  - forum_id: Forum id
2305       *  - selected: Override the selected option
2306       * @return string HTML select list for selecting forum type
2307       */
2308  	function bbp_get_form_forum_type_dropdown( $args = array() ) {
2309  
2310          // Backpat for handling passing of a forum ID as integer
2311          if ( is_int( $args ) ) {
2312              $forum_id = (int) $args;
2313              $args     = array();
2314          } else {
2315              $forum_id = 0;
2316          }
2317  
2318          // Parse arguments against default values
2319          $r = bbp_parse_args( $args, array(
2320              'select_id'    => 'bbp_forum_type',
2321              'select_class' => 'bbp_dropdown',
2322              'tab'          => false,
2323              'forum_id'     => $forum_id,
2324              'selected'     => false
2325          ), 'forum_type_select' );
2326  
2327          // No specific selected value passed
2328          if ( empty( $r['selected'] ) ) {
2329  
2330              // Post value is passed
2331              if ( bbp_is_forum_form_post_request() && isset( $_POST[ $r['select_id'] ] ) ) {
2332                  $r['selected'] = sanitize_key( $_POST[ $r['select_id'] ] );
2333  
2334              // No Post value was passed
2335              } else {
2336  
2337                  // Edit topic
2338                  if ( bbp_is_forum_edit() ) {
2339                      $r['forum_id'] = bbp_get_forum_id( $r['forum_id'] );
2340                      $r['selected'] = bbp_get_forum_type( $r['forum_id'] );
2341  
2342                  // New topic
2343                  } else {
2344                      $r['selected'] = bbp_get_public_status_id();
2345                  }
2346              }
2347          }
2348  
2349          // Start an output buffer, we'll finish it after the select loop
2350          ob_start(); ?>
2351  
2352          <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ) ?>_select" class="<?php echo esc_attr( $r['select_class'] ); ?>"<?php bbp_tab_index_attribute( $r['tab'] ); ?>>
2353  
2354              <?php foreach ( bbp_get_forum_types( $r['forum_id'] ) as $key => $label ) : ?>
2355  
2356                  <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option>
2357  
2358              <?php endforeach; ?>
2359  
2360          </select>
2361  
2362          <?php
2363  
2364          // Filter & return
2365          return apply_filters( 'bbp_get_form_forum_type_dropdown', ob_get_clean(), $r, $args );
2366      }
2367  
2368  /**
2369   * Output value forum status dropdown
2370   *
2371   * @since 2.1.0 bbPress (r3563)
2372   *
2373   * @param $args This function supports these arguments:
2374   *  - select_id: Select id. Defaults to bbp_forum_status
2375   *  - tab: Deprecated. Tabindex
2376   *  - forum_id: Forum id
2377   *  - selected: Override the selected option
2378   */
2379  function bbp_form_forum_status_dropdown( $args = array() ) {
2380      echo bbp_get_form_forum_status_dropdown( $args );
2381  }
2382      /**
2383       * Return the forum status dropdown
2384       *
2385       * @since 2.1.0 bbPress (r3563)
2386       *
2387       * @param $args This function supports these arguments:
2388       *  - select_id: Select id. Defaults to bbp_forum_status
2389       *  - tab: Deprecated. Tabindex
2390       *  - forum_id: Forum id
2391       *  - selected: Override the selected option
2392       * @return string HTML select list for selecting forum status
2393       */
2394  	function bbp_get_form_forum_status_dropdown( $args = array() ) {
2395  
2396          // Backpat for handling passing of a forum ID
2397          if ( is_int( $args ) ) {
2398              $forum_id = (int) $args;
2399              $args     = array();
2400          } else {
2401              $forum_id = 0;
2402          }
2403  
2404          // Parse arguments against default values
2405          $r = bbp_parse_args( $args, array(
2406              'select_id'    => 'bbp_forum_status',
2407              'select_class' => 'bbp_dropdown',
2408              'tab'          => false,
2409              'forum_id'     => $forum_id,
2410              'selected'     => false
2411          ), 'forum_status_select' );
2412  
2413          // No specific selected value passed
2414          if ( empty( $r['selected'] ) ) {
2415  
2416              // Post value is passed
2417              if ( bbp_is_forum_form_post_request() && isset( $_POST[ $r['select_id'] ] ) ) {
2418                  $r['selected'] = sanitize_key( $_POST[ $r['select_id'] ] );
2419  
2420              // No Post value was passed
2421              } else {
2422  
2423                  // Edit topic
2424                  if ( bbp_is_forum_edit() ) {
2425                      $r['forum_id'] = bbp_get_forum_id( $r['forum_id'] );
2426                      $r['selected'] = bbp_get_forum_status( $r['forum_id'] );
2427  
2428                  // New topic
2429                  } else {
2430                      $r['selected'] = bbp_get_public_status_id();
2431                  }
2432              }
2433          }
2434  
2435          // Start an output buffer, we'll finish it after the select loop
2436          ob_start(); ?>
2437  
2438          <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ) ?>_select" class="<?php echo esc_attr( $r['select_class'] ); ?>"<?php bbp_tab_index_attribute( $r['tab'] ); ?>>
2439  
2440              <?php foreach ( bbp_get_forum_statuses( $r['forum_id'] ) as $key => $label ) : ?>
2441  
2442                  <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option>
2443  
2444              <?php endforeach; ?>
2445  
2446          </select>
2447  
2448          <?php
2449  
2450          // Filter & return
2451          return apply_filters( 'bbp_get_form_forum_status_dropdown', ob_get_clean(), $r, $args );
2452      }
2453  
2454  /**
2455   * Output value forum visibility dropdown
2456   *
2457   * @since 2.1.0 bbPress (r3563)
2458   *
2459   * @param $args This function supports these arguments:
2460   *  - select_id: Select id. Defaults to bbp_forum_visibility
2461   *  - tab: Deprecated. Tabindex
2462   *  - forum_id: Forum id
2463   *  - selected: Override the selected option
2464   */
2465  function bbp_form_forum_visibility_dropdown( $args = array() ) {
2466      echo bbp_get_form_forum_visibility_dropdown( $args );
2467  }
2468      /**
2469       * Return the forum visibility dropdown
2470       *
2471       * @since 2.1.0 bbPress (r3563)
2472       *
2473       * @param $args This function supports these arguments:
2474       *  - select_id: Select id. Defaults to bbp_forum_visibility
2475       *  - tab: Deprecated. Tabindex
2476       *  - forum_id: Forum id
2477       *  - selected: Override the selected option
2478       * @return string HTML select list for selecting forum visibility
2479       */
2480  	function bbp_get_form_forum_visibility_dropdown( $args = array() ) {
2481  
2482          // Backpat for handling passing of a forum ID
2483          if ( is_int( $args ) ) {
2484              $forum_id = (int) $args;
2485              $args     = array();
2486          } else {
2487              $forum_id = 0;
2488          }
2489  
2490          // Parse arguments against default values
2491          $r = bbp_parse_args( $args, array(
2492              'select_id'    => 'bbp_forum_visibility',
2493              'select_class' => 'bbp_dropdown',
2494              'tab'          => false,
2495              'forum_id'     => $forum_id,
2496              'selected'     => false
2497          ), 'forum_type_select' );
2498  
2499          // No specific selected value passed
2500          if ( empty( $r['selected'] ) ) {
2501  
2502              // Post value is passed
2503              if ( bbp_is_forum_form_post_request() && isset( $_POST[ $r['select_id'] ] ) ) {
2504                  $r['selected'] = sanitize_key( $_POST[ $r['select_id'] ] );
2505  
2506              // No Post value was passed
2507              } else {
2508  
2509                  // Edit topic
2510                  if ( bbp_is_forum_edit() ) {
2511                      $r['forum_id'] = bbp_get_forum_id( $r['forum_id'] );
2512                      $r['selected'] = bbp_get_forum_visibility( $r['forum_id'] );
2513  
2514                  // New topic
2515                  } else {
2516                      $r['selected'] = bbp_get_public_status_id();
2517                  }
2518              }
2519          }
2520  
2521          // Start an output buffer, we'll finish it after the select loop
2522          ob_start(); ?>
2523  
2524          <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ) ?>_select" class="<?php echo esc_attr( $r['select_class'] ); ?>"<?php bbp_tab_index_attribute( $r['tab'] ); ?>>
2525  
2526              <?php foreach ( bbp_get_forum_visibilities( $r['forum_id'] ) as $key => $label ) : ?>
2527  
2528                  <option value="<?php echo esc_attr( $key ); ?>"<?php selected( $key, $r['selected'] ); ?>><?php echo esc_html( $label ); ?></option>
2529  
2530              <?php endforeach; ?>
2531  
2532          </select>
2533  
2534          <?php
2535  
2536          // Filter & return
2537          return apply_filters( 'bbp_get_form_forum_type_dropdown', ob_get_clean(), $r, $args );
2538      }
2539  
2540  /**
2541   * Verify if a POST request came from a failed forum attempt.
2542   *
2543   * Used to avoid cross-site request forgeries when checking posted forum form
2544   * content.
2545   *
2546   * @see bbp_forum_form_fields()
2547   *
2548   * @since 2.6.0 bbPress (r5558)
2549   *
2550   * @return boolean True if is a post request with valid nonce
2551   */
2552  function bbp_is_forum_form_post_request() {
2553  
2554      // Bail if not a post request
2555      if ( ! bbp_is_post_request() ) {
2556          return false;
2557      }
2558  
2559      // Creating a new forum
2560      if ( bbp_verify_nonce_request( 'bbp-new-forum' ) ) {
2561          return true;
2562      }
2563  
2564      // Editing an existing forum
2565      if ( bbp_verify_nonce_request( 'bbp-edit-forum_' . bbp_get_forum_id() ) ) {
2566          return true;
2567      }
2568  
2569      return false;
2570  }
2571  
2572  /** Feeds *********************************************************************/
2573  
2574  /**
2575   * Output the link for the forum feed
2576   *
2577   * @since 2.0.0 bbPress (r3172)
2578   *
2579   * @param int $forum_id Optional. Forum ID.
2580   */
2581  function bbp_forum_topics_feed_link( $forum_id = 0 ) {
2582      echo bbp_get_forum_topics_feed_link( $forum_id );
2583  }
2584      /**
2585       * Retrieve the link for the forum feed
2586       *
2587       * @since 2.0.0 bbPress (r3172)
2588       *
2589       * @param int $forum_id Optional. Forum ID.
2590       *
2591       * @return string
2592       */
2593  	function bbp_get_forum_topics_feed_link( $forum_id = 0 ) {
2594  
2595          // Validate forum id
2596          $forum_id = bbp_get_forum_id( $forum_id );
2597  
2598          // Forum is valid
2599          if ( ! empty( $forum_id ) ) {
2600  
2601              // Define local variable(s)
2602              $link = '';
2603  
2604              // Pretty permalinks
2605              if ( get_option( 'permalink_structure' ) ) {
2606  
2607                  // Forum link
2608                  $url = trailingslashit( bbp_get_forum_permalink( $forum_id ) ) . 'feed';
2609                  $url = user_trailingslashit( $url, 'single_feed' );
2610  
2611              // Unpretty permalinks
2612              } else {
2613                  $url = home_url( add_query_arg( array(
2614                      'feed'                    => 'rss2',
2615                      bbp_get_forum_post_type() => get_post_field( 'post_name', $forum_id )
2616                  ) ) );
2617              }
2618  
2619              $link = '<a href="' . esc_url( $url ) . '" class="bbp-forum-rss-link topics"><span>' . esc_attr__( 'Topics', 'bbpress' ) . '</span></a>';
2620          }
2621  
2622          // Filter & return
2623          return apply_filters( 'bbp_get_forum_topics_feed_link', $link, $url, $forum_id );
2624      }
2625  
2626  /**
2627   * Output the link for the forum replies feed
2628   *
2629   * @since 2.0.0 bbPress (r3172)
2630   *
2631   * @param int $forum_id Optional. Forum ID.
2632   */
2633  function bbp_forum_replies_feed_link( $forum_id = 0 ) {
2634      echo bbp_get_forum_replies_feed_link( $forum_id );
2635  }
2636      /**
2637       * Retrieve the link for the forum replies feed
2638       *
2639       * @since 2.0.0 bbPress (r3172)
2640       *
2641       * @param int $forum_id Optional. Forum ID.
2642       *
2643       * @return string
2644       */
2645  	function bbp_get_forum_replies_feed_link( $forum_id = 0 ) {
2646  
2647          // Validate forum id
2648          $forum_id = bbp_get_forum_id( $forum_id );
2649  
2650          // Forum is valid
2651          if ( ! empty( $forum_id ) ) {
2652  
2653              // Define local variable(s)
2654              $link = '';
2655  
2656              // Pretty permalinks
2657              if ( get_option( 'permalink_structure' ) ) {
2658  
2659                  // Forum link
2660                  $url = trailingslashit( bbp_get_forum_permalink( $forum_id ) ) . 'feed';
2661                  $url = user_trailingslashit( $url, 'single_feed' );
2662                  $url = add_query_arg( array( 'type' => 'reply' ), $url );
2663  
2664              // Unpretty permalinks
2665              } else {
2666                  $url = home_url( add_query_arg( array(
2667                      'type'                    => 'reply',
2668                      'feed'                    => 'rss2',
2669                      bbp_get_forum_post_type() => get_post_field( 'post_name', $forum_id )
2670                  ) ) );
2671              }
2672  
2673              $link = '<a href="' . esc_url( $url ) . '" class="bbp-forum-rss-link replies"><span>' . esc_html__( 'Replies', 'bbpress' ) . '</span></a>';
2674          }
2675  
2676          // Filter & return
2677          return apply_filters( 'bbp_get_forum_replies_feed_link', $link, $url, $forum_id );
2678      }


Generated: Tue Jul 16 01:01:32 2019 Cross-referenced by PHPXref 0.7.1