[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

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

   1  <?php
   2  
   3  /**
   4   * bbPress Common Template Tags
   5   *
   6   * Common template tags are ones that are used by more than one component, like
   7   * forums, topics, replies, users, topic tags, etc...
   8   *
   9   * @package bbPress
  10   * @subpackage TemplateTags
  11   */
  12  
  13  // Exit if accessed directly
  14  defined( 'ABSPATH' ) || exit;
  15  
  16  /** URLs **********************************************************************/
  17  
  18  /**
  19   * Output the forum URL
  20   *
  21   * @since 2.1.0 bbPress (r3979)
  22   *
  23   * @param string $path Additional path with leading slash
  24   */
  25  function bbp_forums_url( $path = '/' ) {
  26      echo esc_url( bbp_get_forums_url( $path ) );
  27  }
  28      /**
  29       * Return the forum URL
  30       *
  31       * @since 2.1.0 bbPress (r3979)
  32       *
  33       * @param string $path Additional path with leading slash
  34       */
  35  	function bbp_get_forums_url( $path = '/' ) {
  36          return home_url( bbp_get_root_slug() . $path );
  37      }
  38  
  39  /**
  40   * Output the forum URL
  41   *
  42   * @since 2.1.0 bbPress (r3979)
  43   *
  44   * @param string $path Additional path with leading slash
  45   */
  46  function bbp_topics_url( $path = '/' ) {
  47      echo esc_url( bbp_get_topics_url( $path ) );
  48  }
  49      /**
  50       * Return the forum URL
  51       *
  52       * @since 2.1.0 bbPress (r3979)
  53       *
  54       * @param string $path Additional path with leading slash
  55       * @return The URL to the topics archive
  56       */
  57  	function bbp_get_topics_url( $path = '/' ) {
  58          return home_url( bbp_get_topic_archive_slug() . $path );
  59      }
  60  
  61  /** Add-on Actions ************************************************************/
  62  
  63  /**
  64   * Add our custom head action to wp_head
  65   *
  66   * @since 2.0.0 bbPress (r2464)
  67   */
  68  function bbp_head() {
  69      do_action( 'bbp_head' );
  70  }
  71  
  72  /**
  73   * Add our custom head action to wp_head
  74   *
  75   * @since 2.0.0 bbPress (r2464)
  76   */
  77  function bbp_footer() {
  78      do_action( 'bbp_footer' );
  79  }
  80  
  81  /** is_ ***********************************************************************/
  82  
  83  /**
  84   * Check if current site is public
  85   *
  86   * @since 2.0.0 bbPress (r3398)
  87   *
  88   * @param int $site_id
  89   * @return bool True if site is public, false if private
  90   */
  91  function bbp_is_site_public( $site_id = 0 ) {
  92  
  93      // Get the current site ID
  94      if ( empty( $site_id ) ) {
  95          $site_id = get_current_blog_id();
  96      }
  97  
  98      // Get the site visibility setting
  99      $public = is_multisite()
 100          ? get_blog_option( $site_id, 'blog_public', 1 )
 101          : get_option( 'blog_public', 1 );
 102  
 103      // Filter & return
 104      return (bool) apply_filters( 'bbp_is_site_public', $public, $site_id );
 105  }
 106  
 107  /**
 108   * Check if current page is a bbPress forum
 109   *
 110   * @since 2.0.0 bbPress (r2549)
 111   *
 112   * @param int $post_id Possible post_id to check
 113   * @return bool True if it's a forum page, false if not
 114   */
 115  function bbp_is_forum( $post_id = 0 ) {
 116  
 117      // Assume false
 118      $retval = false;
 119  
 120      // Supplied ID is a forum
 121      if ( ! empty( $post_id ) && ( bbp_get_forum_post_type() === get_post_type( $post_id ) ) ) {
 122          $retval = true;
 123      }
 124  
 125      // Filter & return
 126      return (bool) apply_filters( 'bbp_is_forum', $retval, $post_id );
 127  }
 128  
 129  /**
 130   * Check if we are viewing a forum archive.
 131   *
 132   * @since 2.0.0 bbPress (r3251)
 133   *
 134   * @return bool
 135   */
 136  function bbp_is_forum_archive() {
 137  
 138      // Default to false
 139      $retval = false;
 140  
 141      // Get the main query global
 142      $wp_query = bbp_get_wp_query();
 143  
 144      // In forum archive
 145      if ( is_post_type_archive( bbp_get_forum_post_type() ) || bbp_is_query_name( 'bbp_forum_archive' ) || ! empty( $wp_query->bbp_show_topics_on_root ) ) {
 146          $retval = true;
 147      }
 148  
 149      // Filter & return
 150      return (bool) apply_filters( 'bbp_is_forum_archive', $retval );
 151  }
 152  
 153  /**
 154   * Viewing a single forum
 155   *
 156   * @since 2.0.0 bbPress (r3338)
 157   *
 158   * @return bool
 159   */
 160  function bbp_is_single_forum() {
 161  
 162      // Assume false
 163      $retval = false;
 164  
 165      // Edit is not a single forum
 166      if ( bbp_is_forum_edit() ) {
 167          return false;
 168      }
 169  
 170      // Single and a match
 171      if ( is_singular( bbp_get_forum_post_type() ) || bbp_is_query_name( 'bbp_single_forum' ) ) {
 172          $retval = true;
 173      }
 174  
 175      // Filter & return
 176      return (bool) apply_filters( 'bbp_is_single_forum', $retval );
 177  }
 178  
 179  /**
 180   * Check if current page is a forum edit page
 181   *
 182   * @since 2.1.0 bbPress (r3553)
 183   *
 184   * @return bool True if it's the forum edit page, false if not
 185   */
 186  function bbp_is_forum_edit() {
 187      global $pagenow;
 188  
 189      // Assume false
 190      $retval = false;
 191  
 192      // Get the main query global
 193      $wp_query = bbp_get_wp_query();
 194  
 195      // Check query
 196      if ( ! empty( $wp_query->bbp_is_forum_edit ) && ( $wp_query->bbp_is_forum_edit === true ) ) {
 197          $retval = true;
 198  
 199      // Editing in admin
 200      } elseif ( is_admin() && ( 'post.php' === $pagenow ) && ( get_post_type() === bbp_get_forum_post_type() ) && ( ! empty( $_GET['action'] ) && ( 'edit' === $_GET['action'] ) ) ) {
 201          $retval = true;
 202      }
 203  
 204      // Filter & return
 205      return (bool) apply_filters( 'bbp_is_forum_edit', $retval );
 206  }
 207  
 208  /**
 209   * Check if current page is a bbPress topic
 210   *
 211   * @since 2.0.0 bbPress (r2549)
 212   *
 213   * @param int $post_id Possible post_id to check
 214   * @return bool True if it's a topic page, false if not
 215   */
 216  function bbp_is_topic( $post_id = 0 ) {
 217  
 218      // Assume false
 219      $retval = false;
 220  
 221      // Supplied ID is a topic
 222      if ( ! empty( $post_id ) && ( bbp_get_topic_post_type() === get_post_type( $post_id ) ) ) {
 223          $retval = true;
 224      }
 225  
 226      // Filter & return
 227      return (bool) apply_filters( 'bbp_is_topic', $retval, $post_id );
 228  }
 229  
 230  /**
 231   * Viewing a single topic
 232   *
 233   * @since 2.0.0 bbPress (r3338)
 234   *
 235   * @return bool
 236   */
 237  function bbp_is_single_topic() {
 238  
 239      // Assume false
 240      $retval = false;
 241  
 242      // Edit is not a single topic
 243      if ( bbp_is_topic_edit() ) {
 244          return false;
 245      }
 246  
 247      // Single and a match
 248      if ( is_singular( bbp_get_topic_post_type() ) || bbp_is_query_name( 'bbp_single_topic' ) ) {
 249          $retval = true;
 250      }
 251  
 252      // Filter & return
 253      return (bool) apply_filters( 'bbp_is_single_topic', $retval );
 254  }
 255  
 256  /**
 257   * Check if we are viewing a topic archive.
 258   *
 259   * @since 2.0.0 bbPress (r3251)
 260   *
 261   * @return bool
 262   */
 263  function bbp_is_topic_archive() {
 264  
 265      // Default to false
 266      $retval = false;
 267  
 268      // In topic archive
 269      if ( is_post_type_archive( bbp_get_topic_post_type() ) || bbp_is_query_name( 'bbp_topic_archive' ) ) {
 270          $retval = true;
 271      }
 272  
 273      // Filter & return
 274      return (bool) apply_filters( 'bbp_is_topic_archive', $retval );
 275  }
 276  
 277  /**
 278   * Check if current page is a topic edit page
 279   *
 280   * @since 2.0.0 bbPress (r2753)
 281   *
 282   * @return bool True if it's the topic edit page, false if not
 283   */
 284  function bbp_is_topic_edit() {
 285      global $pagenow;
 286  
 287      // Assume false
 288      $retval = false;
 289  
 290      // Get the main query global
 291      $wp_query = bbp_get_wp_query();
 292  
 293      // Check query
 294      if ( ! empty( $wp_query->bbp_is_topic_edit ) && ( $wp_query->bbp_is_topic_edit === true ) ) {
 295          $retval = true;
 296  
 297      // Editing in admin
 298      } elseif ( is_admin() && ( 'post.php' === $pagenow ) && ( get_post_type() === bbp_get_topic_post_type() ) && ( ! empty( $_GET['action'] ) && ( 'edit' === $_GET['action'] ) ) ) {
 299          $retval = true;
 300      }
 301  
 302      // Filter & return
 303      return (bool) apply_filters( 'bbp_is_topic_edit', $retval );
 304  }
 305  
 306  /**
 307   * Check if current page is a topic merge page
 308   *
 309   * @since 2.0.0 bbPress (r2756)
 310   *
 311   * @return bool True if it's the topic merge page, false if not
 312   */
 313  function bbp_is_topic_merge() {
 314  
 315      // Assume false
 316      $retval = false;
 317  
 318      // Check topic edit and GET params
 319      if ( bbp_is_topic_edit() && ! empty( $_GET['action'] ) && ( 'merge' === $_GET['action'] ) ) {
 320          return true;
 321      }
 322  
 323      // Filter & return
 324      return (bool) apply_filters( 'bbp_is_topic_merge', $retval );
 325  }
 326  
 327  /**
 328   * Check if current page is a topic split page
 329   *
 330   * @since 2.0.0 bbPress (r2756)
 331   *
 332   * @return bool True if it's the topic split page, false if not
 333   */
 334  function bbp_is_topic_split() {
 335  
 336      // Assume false
 337      $retval = false;
 338  
 339      // Check topic edit and GET params
 340      if ( bbp_is_topic_edit() && ! empty( $_GET['action'] ) && ( 'split' === $_GET['action'] ) ) {
 341          $retval = true;
 342      }
 343  
 344      // Filter & return
 345      return (bool) apply_filters( 'bbp_is_topic_split', $retval );
 346  }
 347  
 348  /**
 349   * Check if the current page is a topic tag
 350   *
 351   * @since 2.0.0 bbPress (r3311)
 352   *
 353   * @return bool True if it's a topic tag, false if not
 354   */
 355  function bbp_is_topic_tag() {
 356  
 357      // Bail if topic-tags are off
 358      if ( ! bbp_allow_topic_tags() ) {
 359          return false;
 360      }
 361  
 362      // Return false if editing a topic tag
 363      if ( bbp_is_topic_tag_edit() ) {
 364          return false;
 365      }
 366  
 367      // Assume false
 368      $retval = false;
 369  
 370      // Check tax and query vars
 371      if ( is_tax( bbp_get_topic_tag_tax_id() ) || ! empty( bbpress()->topic_query->is_tax ) || get_query_var( 'bbp_topic_tag' ) ) {
 372          $retval = true;
 373      }
 374  
 375      // Filter & return
 376      return (bool) apply_filters( 'bbp_is_topic_tag', $retval );
 377  }
 378  
 379  /**
 380   * Check if the current page is editing a topic tag
 381   *
 382   * @since 2.0.0 bbPress (r3346)
 383   *
 384   * @return bool True if editing a topic tag, false if not
 385   */
 386  function bbp_is_topic_tag_edit() {
 387      global $pagenow, $taxnow;
 388  
 389      // Bail if topic-tags are off
 390      if ( ! bbp_allow_topic_tags() ) {
 391          return false;
 392      }
 393  
 394      // Assume false
 395      $retval = false;
 396  
 397      // Get the main query global
 398      $wp_query = bbp_get_wp_query();
 399  
 400      // Check query
 401      if ( ! empty( $wp_query->bbp_is_topic_tag_edit ) && ( true === $wp_query->bbp_is_topic_tag_edit ) ) {
 402          $retval = true;
 403  
 404      // Editing in admin
 405      } elseif ( is_admin() && ( 'edit-tags.php' === $pagenow ) && ( bbp_get_topic_tag_tax_id() === $taxnow ) && ( ! empty( $_GET['action'] ) && ( 'edit' === $_GET['action'] ) ) ) {
 406          $retval = true;
 407      }
 408  
 409      // Filter & return
 410      return (bool) apply_filters( 'bbp_is_topic_tag_edit', $retval );
 411  }
 412  
 413  /**
 414   * Check if the current post type is one that comes with bbPress
 415   *
 416   * @since 2.0.0 bbPress (r3311)
 417   *
 418   * @param mixed $the_post Optional. Post object or post ID.
 419   *
 420   * @return bool
 421   */
 422  function bbp_is_custom_post_type( $the_post = false ) {
 423  
 424      // Assume false
 425      $retval = false;
 426  
 427      // Viewing one of the bbPress post types
 428      if ( in_array( get_post_type( $the_post ), array(
 429          bbp_get_forum_post_type(),
 430          bbp_get_topic_post_type(),
 431          bbp_get_reply_post_type()
 432      ), true ) ) {
 433          $retval = true;
 434      }
 435  
 436      // Filter & return
 437      return (bool) apply_filters( 'bbp_is_custom_post_type', $retval, $the_post );
 438  }
 439  
 440  /**
 441   * Check if current page is a bbPress reply
 442   *
 443   * @since 2.0.0 bbPress (r2549)
 444   *
 445   * @param int $post_id Possible post_id to check
 446   * @return bool True if it's a reply page, false if not
 447   */
 448  function bbp_is_reply( $post_id = 0 ) {
 449  
 450      // Assume false
 451      $retval = false;
 452  
 453      // Supplied ID is a reply
 454      if ( ! empty( $post_id ) && ( bbp_get_reply_post_type() === get_post_type( $post_id ) ) ) {
 455          $retval = true;
 456      }
 457  
 458      // Filter & return
 459      return (bool) apply_filters( 'bbp_is_reply', $retval, $post_id );
 460  }
 461  
 462  /**
 463   * Check if current page is a reply edit page
 464   *
 465   * @since 2.0.0 bbPress (r2753)
 466   *
 467   * @return bool True if it's the reply edit page, false if not
 468   */
 469  function bbp_is_reply_edit() {
 470      global $pagenow;
 471  
 472      // Assume false
 473      $retval = false;
 474  
 475      // Get the main query global
 476      $wp_query = bbp_get_wp_query();
 477  
 478      // Check query
 479      if ( ! empty( $wp_query->bbp_is_reply_edit ) && ( true === $wp_query->bbp_is_reply_edit ) ) {
 480          $retval = true;
 481  
 482      // Editing in admin
 483      } elseif ( is_admin() && ( 'post.php' === $pagenow ) && ( get_post_type() === bbp_get_reply_post_type() ) && ( ! empty( $_GET['action'] ) && ( 'edit' === $_GET['action'] ) ) ) {
 484          $retval = true;
 485      }
 486  
 487      // Filter & return
 488      return (bool) apply_filters( 'bbp_is_reply_edit', $retval );
 489  }
 490  
 491  /**
 492   * Check if current page is a reply move page
 493   *
 494   * @return bool True if it's the reply move page, false if not
 495   */
 496  function bbp_is_reply_move() {
 497  
 498      // Assume false
 499      $retval = false;
 500  
 501      // Check reply edit and GET params
 502      if ( bbp_is_reply_edit() && ! empty( $_GET['action'] ) && ( 'move' === $_GET['action'] ) ) {
 503          $retval = true;
 504      }
 505  
 506      // Filter & return
 507      return (bool) apply_filters( 'bbp_is_reply_move', $retval );
 508  }
 509  
 510  /**
 511   * Viewing a single reply
 512   *
 513   * @since 2.0.0 bbPress (r3344)
 514   *
 515   * @return bool
 516   */
 517  function bbp_is_single_reply() {
 518  
 519      // Assume false
 520      $retval = false;
 521  
 522      // Edit is not a single reply
 523      if ( bbp_is_reply_edit() ) {
 524          return false;
 525      }
 526  
 527      // Single and a match
 528      if ( is_singular( bbp_get_reply_post_type() ) || ( bbp_is_query_name( 'bbp_single_reply' ) ) ) {
 529          $retval = true;
 530      }
 531  
 532      // Filter & return
 533      return (bool) apply_filters( 'bbp_is_single_reply', $retval );
 534  }
 535  
 536  /**
 537   * Check if current page is a bbPress user's favorites page (profile page)
 538   *
 539   * @since 2.0.0 bbPress (r2652)
 540   *
 541   * @return bool True if it's the favorites page, false if not
 542   */
 543  function bbp_is_favorites() {
 544  
 545      // Assume false
 546      $retval = false;
 547  
 548      // Get the main query global
 549      $wp_query = bbp_get_wp_query();
 550  
 551      // Check query
 552      if ( ! empty( $wp_query->bbp_is_single_user_favs ) && ( true === $wp_query->bbp_is_single_user_favs ) ) {
 553          $retval = true;
 554      }
 555  
 556      // Filter & return
 557      return (bool) apply_filters( 'bbp_is_favorites', $retval );
 558  }
 559  
 560  /**
 561   * Check if current page is a bbPress user's subscriptions page (profile page)
 562   *
 563   * @since 2.0.0 bbPress (r2652)
 564   *
 565   * @return bool True if it's the subscriptions page, false if not
 566   */
 567  function bbp_is_subscriptions() {
 568  
 569      // Assume false
 570      $retval = false;
 571  
 572      // Get the main query global
 573      $wp_query = bbp_get_wp_query();
 574  
 575      // Check query
 576      if ( ! empty( $wp_query->bbp_is_single_user_subs ) && ( true === $wp_query->bbp_is_single_user_subs ) ) {
 577          $retval = true;
 578      }
 579  
 580      // Filter & return
 581      return (bool) apply_filters( 'bbp_is_subscriptions', $retval );
 582  }
 583  
 584  /**
 585   * Check if current page shows the topics created by a bbPress user (profile
 586   * page)
 587   *
 588   * @since 2.0.0 bbPress (r2688)
 589   *
 590   * @return bool True if it's the topics created page, false if not
 591   */
 592  function bbp_is_topics_created() {
 593  
 594      // Assume false
 595      $retval = false;
 596  
 597      // Get the main query global
 598      $wp_query = bbp_get_wp_query();
 599  
 600      // Check query
 601      if ( ! empty( $wp_query->bbp_is_single_user_topics ) && ( true === $wp_query->bbp_is_single_user_topics ) ) {
 602          $retval = true;
 603      }
 604  
 605      // Filter & return
 606      return (bool) apply_filters( 'bbp_is_topics_created', $retval );
 607  }
 608  
 609  /**
 610   * Check if current page shows the replies created by a bbPress user (profile
 611   * page)
 612   *
 613   * @since 2.2.0 bbPress (r4225)
 614   *
 615   * @return bool True if it's the replies created page, false if not
 616   */
 617  function bbp_is_replies_created() {
 618  
 619      // Assume false
 620      $retval = false;
 621  
 622      // Get the main query global
 623      $wp_query = bbp_get_wp_query();
 624  
 625      // Check query
 626      if ( ! empty( $wp_query->bbp_is_single_user_replies ) && ( true === $wp_query->bbp_is_single_user_replies ) ) {
 627          $retval = true;
 628      }
 629  
 630      // Filter & return
 631      return (bool) apply_filters( 'bbp_is_replies_created', $retval );
 632  }
 633  
 634  /**
 635   * Check if current page is the currently logged in users author page
 636   *
 637   * @since 2.0.0 bbPress (r2688)
 638   *
 639   * @return bool True if it's the user's home, false if not
 640   */
 641  function bbp_is_user_home() {
 642  
 643      // Assume false
 644      $retval = false;
 645  
 646      // Get the main query global
 647      $wp_query = bbp_get_wp_query();
 648  
 649      // Check query
 650      if ( ! empty( $wp_query->bbp_is_single_user_home ) && ( true === $wp_query->bbp_is_single_user_home ) ) {
 651          $retval = true;
 652      }
 653  
 654      // Filter & return
 655      return (bool) apply_filters( 'bbp_is_user_home', $retval );
 656  }
 657  
 658  /**
 659   * Check if current page is the currently logged in users author edit page
 660   *
 661   * @since 2.1.0 bbPress (r3918)
 662   *
 663   * @return bool True if it's the user's home, false if not
 664   */
 665  function bbp_is_user_home_edit() {
 666  
 667      // Assume false
 668      $retval = false;
 669  
 670      if ( bbp_is_user_home() && bbp_is_single_user_edit() ) {
 671          $retval = true;
 672      }
 673  
 674      // Filter & return
 675      return (bool) apply_filters( 'bbp_is_user_home_edit', $retval );
 676  }
 677  
 678  /**
 679   * Check if current page is a user profile page
 680   *
 681   * @since 2.0.0 bbPress (r2688)
 682   *
 683   * @return bool True if it's a user's profile page, false if not
 684   */
 685  function bbp_is_single_user() {
 686  
 687      // Assume false
 688      $retval = false;
 689  
 690      // Get the main query global
 691      $wp_query = bbp_get_wp_query();
 692  
 693      // Check query
 694      if ( ! empty( $wp_query->bbp_is_single_user ) && ( true === $wp_query->bbp_is_single_user ) ) {
 695          $retval = true;
 696      }
 697  
 698      // Filter & return
 699      return (bool) apply_filters( 'bbp_is_single_user', $retval );
 700  }
 701  
 702  /**
 703   * Check if current page is a user profile edit page
 704   *
 705   * @since 2.0.0 bbPress (r2688)
 706   *
 707   * @return bool True if it's a user's profile edit page, false if not
 708   */
 709  function bbp_is_single_user_edit() {
 710  
 711      // Assume false
 712      $retval = false;
 713  
 714      // Get the main query global
 715      $wp_query = bbp_get_wp_query();
 716  
 717      // Check query
 718      if ( ! empty( $wp_query->bbp_is_single_user_edit ) && ( true === $wp_query->bbp_is_single_user_edit ) ) {
 719          $retval = true;
 720      }
 721  
 722      // Filter & return
 723      return (bool) apply_filters( 'bbp_is_single_user_edit', $retval );
 724  }
 725  
 726  /**
 727   * Check if current page is a user profile page
 728   *
 729   * @since 2.2.0 bbPress (r4225)
 730   *
 731   * @return bool True if it's a user's profile page, false if not
 732   */
 733  function bbp_is_single_user_profile() {
 734  
 735      // Assume false
 736      $retval = false;
 737  
 738      // Get the main query global
 739      $wp_query = bbp_get_wp_query();
 740  
 741      // Check query
 742      if ( ! empty( $wp_query->bbp_is_single_user_profile ) && ( true === $wp_query->bbp_is_single_user_profile ) ) {
 743          $retval = true;
 744      }
 745  
 746      // Filter & return
 747      return (bool) apply_filters( 'bbp_is_single_user_profile', $retval );
 748  }
 749  
 750  /**
 751   * Check if current page is a user topics created page
 752   *
 753   * @since 2.2.0 bbPress (r4225)
 754   *
 755   * @return bool True if it's a user's topics page, false if not
 756   */
 757  function bbp_is_single_user_topics() {
 758  
 759      // Assume false
 760      $retval = false;
 761  
 762      // Get the main query global
 763      $wp_query = bbp_get_wp_query();
 764  
 765      // Check query
 766      if ( ! empty( $wp_query->bbp_is_single_user_topics ) && ( true === $wp_query->bbp_is_single_user_topics ) ) {
 767          $retval = true;
 768      }
 769  
 770      // Filter & return
 771      return (bool) apply_filters( 'bbp_is_single_user_topics', $retval );
 772  }
 773  
 774  /**
 775   * Check if current page is a user replies created page
 776   *
 777   * @since 2.2.0 bbPress (r4225)
 778   *
 779   * @return bool True if it's a user's replies page, false if not
 780   */
 781  function bbp_is_single_user_replies() {
 782  
 783      // Assume false
 784      $retval = false;
 785  
 786      // Get the main query global
 787      $wp_query = bbp_get_wp_query();
 788  
 789      // Check query
 790      if ( ! empty( $wp_query->bbp_is_single_user_replies ) && ( true === $wp_query->bbp_is_single_user_replies ) ) {
 791          $retval = true;
 792      }
 793  
 794      // Filter & return
 795      return (bool) apply_filters( 'bbp_is_single_user_replies', $retval );
 796  }
 797  
 798  /**
 799   * Check if current page is a user engagements page
 800   *
 801   * @since 2.6.0 bbPress (r6320)
 802   *
 803   * @return bool True if it's a user's replies page, false if not
 804   */
 805  function bbp_is_single_user_engagements() {
 806  
 807      // Assume false
 808      $retval = false;
 809  
 810      // Get the main query global
 811      $wp_query = bbp_get_wp_query();
 812  
 813      // Check query
 814      if ( ! empty( $wp_query->bbp_is_single_user_engagements ) && ( true === $wp_query->bbp_is_single_user_engagements ) ) {
 815          $retval = true;
 816      }
 817  
 818      // Filter & return
 819      return (bool) apply_filters( 'bbp_is_single_user_engagements', $retval );
 820  }
 821  
 822  /**
 823   * Check if current page is a view page
 824   *
 825   * @since 2.0.0 bbPress (r2789)
 826   *
 827   * @global WP_Query $wp_query To check if WP_Query::bbp_is_view is true
 828   * @return bool Is it a view page?
 829   */
 830  function bbp_is_single_view() {
 831  
 832      // Assume false
 833      $retval = false;
 834  
 835      // Get the main query global
 836      $wp_query = bbp_get_wp_query();
 837  
 838      // Check query
 839      if ( ! empty( $wp_query->bbp_is_view ) && ( true === $wp_query->bbp_is_view ) ) {
 840          $retval = true;
 841      }
 842  
 843      // Check query name
 844      if ( empty( $retval ) && bbp_is_query_name( 'bbp_single_view' ) ) {
 845          $retval = true;
 846      }
 847  
 848      // Filter & return
 849      return (bool) apply_filters( 'bbp_is_single_view', $retval );
 850  }
 851  
 852  /**
 853   * Check if current page is a search page
 854   *
 855   * @since 2.3.0 bbPress (r4579)
 856   *
 857   * @global WP_Query $wp_query To check if WP_Query::bbp_is_search is true
 858   * @return bool Is it a search page?
 859   */
 860  function bbp_is_search() {
 861  
 862      // Bail if search is disabled
 863      if ( ! bbp_allow_search() ) {
 864          return false;
 865      }
 866  
 867      // Assume false
 868      $retval = false;
 869  
 870      // Get the main query global
 871      $wp_query = bbp_get_wp_query();
 872  
 873      // Get the rewrite ID (one time, to avoid repeated calls)
 874      $rewrite_id = bbp_get_search_rewrite_id();
 875  
 876      // Check query
 877      if ( ! empty( $wp_query->bbp_is_search ) && ( true === $wp_query->bbp_is_search ) ) {
 878          $retval = true;
 879      }
 880  
 881      // Check query name
 882      if ( empty( $retval ) && bbp_is_query_name( $rewrite_id ) ) {
 883          $retval = true;
 884      }
 885  
 886      // Check $_GET
 887      if ( empty( $retval ) && isset( $_REQUEST[ $rewrite_id ] ) && empty( $_REQUEST[ $rewrite_id ] ) ) {
 888          $retval = true;
 889      }
 890  
 891      // Filter & return
 892      return (bool) apply_filters( 'bbp_is_search', $retval );
 893  }
 894  
 895  /**
 896   * Check if current page is a search results page
 897   *
 898   * @since 2.4.0 bbPress (r4919)
 899   *
 900   * @global WP_Query $wp_query To check if WP_Query::bbp_is_search is true
 901   * @return bool Is it a search page?
 902   */
 903  function bbp_is_search_results() {
 904  
 905      // Bail if search is disabled
 906      if ( ! bbp_allow_search() ) {
 907          return false;
 908      }
 909  
 910      // Assume false
 911      $retval = false;
 912  
 913      // Get the main query global
 914      $wp_query = bbp_get_wp_query();
 915  
 916      // Check query
 917      if ( ! empty( $wp_query->bbp_search_terms ) ) {
 918          $retval = true;
 919      }
 920  
 921      // Check query name
 922      if ( empty( $retval ) && bbp_is_query_name( 'bbp_search_results' ) ) {
 923          $retval = true;
 924      }
 925  
 926      // Check $_REQUEST
 927      if ( empty( $retval ) && ! empty( $_REQUEST[ bbp_get_search_rewrite_id() ] ) ) {
 928          $retval = true;
 929      }
 930  
 931      // Filter & return
 932      return (bool) apply_filters( 'bbp_is_search_results', $retval );
 933  }
 934  
 935  /**
 936   * Check if current page is an edit page
 937   *
 938   * @since 2.1.0 bbPress (r3585)
 939   *
 940   * @return bool True if it's the edit page, false if not
 941   */
 942  function bbp_is_edit() {
 943  
 944      // Assume false
 945      $retval = false;
 946  
 947      // Get the main query global
 948      $wp_query = bbp_get_wp_query();
 949  
 950      // Check query
 951      if ( ! empty( $wp_query->bbp_is_edit ) && ( $wp_query->bbp_is_edit === true ) ) {
 952          $retval = true;
 953      }
 954  
 955      // Filter & return
 956      return (bool) apply_filters( 'bbp_is_edit', $retval );
 957  }
 958  
 959  /**
 960   * Use the above is_() functions to output a body class for each scenario
 961   *
 962   * @since 2.0.0 bbPress (r2926)
 963   *
 964   * @param array $wp_classes
 965   * @param array $custom_classes
 966   * @return array Body Classes
 967   */
 968  function bbp_body_class( $wp_classes, $custom_classes = false ) {
 969  
 970      $bbp_classes = array();
 971  
 972      /** Archives **************************************************************/
 973  
 974      if ( bbp_is_forum_archive() ) {
 975          $bbp_classes[] = bbp_get_forum_post_type() . '-archive';
 976  
 977      } elseif ( bbp_is_topic_archive() ) {
 978          $bbp_classes[] = bbp_get_topic_post_type() . '-archive';
 979  
 980      /** Topic Tags ************************************************************/
 981  
 982      } elseif ( bbp_is_topic_tag() ) {
 983          $bbp_classes[] = bbp_get_topic_tag_tax_id();
 984          $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-' . bbp_get_topic_tag_slug();
 985          $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-' . bbp_get_topic_tag_id();
 986      } elseif ( bbp_is_topic_tag_edit() ) {
 987          $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-edit';
 988          $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-' . bbp_get_topic_tag_slug() . '-edit';
 989          $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-' . bbp_get_topic_tag_id()   . '-edit';
 990  
 991      /** Components ************************************************************/
 992  
 993      } elseif ( bbp_is_single_forum() ) {
 994          $bbp_classes[] = bbp_get_forum_post_type();
 995  
 996      } elseif ( bbp_is_single_topic() ) {
 997          $bbp_classes[] = bbp_get_topic_post_type();
 998  
 999      } elseif ( bbp_is_single_reply() ) {
1000          $bbp_classes[] = bbp_get_reply_post_type();
1001  
1002      } elseif ( bbp_is_topic_edit() ) {
1003          $bbp_classes[] = bbp_get_topic_post_type() . '-edit';
1004  
1005      } elseif ( bbp_is_topic_merge() ) {
1006          $bbp_classes[] = bbp_get_topic_post_type() . '-merge';
1007  
1008      } elseif ( bbp_is_topic_split() ) {
1009          $bbp_classes[] = bbp_get_topic_post_type() . '-split';
1010  
1011      } elseif ( bbp_is_reply_edit() ) {
1012          $bbp_classes[] = bbp_get_reply_post_type() . '-edit';
1013  
1014      } elseif ( bbp_is_reply_move() ) {
1015          $bbp_classes[] = bbp_get_reply_post_type() . '-move';
1016  
1017      } elseif ( bbp_is_single_view() ) {
1018          $bbp_classes[] = 'bbp-view';
1019          $bbp_classes[] = 'bbp-view-' . bbp_get_view_id();
1020  
1021      /** User ******************************************************************/
1022  
1023      } elseif ( bbp_is_single_user_edit() ) {
1024          $bbp_classes[] = 'bbp-user-edit';
1025          $bbp_classes[] = 'single';
1026          $bbp_classes[] = 'singular';
1027  
1028      } elseif ( bbp_is_single_user() ) {
1029          $bbp_classes[] = 'bbp-user-page';
1030          $bbp_classes[] = 'single';
1031          $bbp_classes[] = 'singular';
1032  
1033      } elseif ( bbp_is_user_home() ) {
1034          $bbp_classes[] = 'bbp-user-home';
1035          $bbp_classes[] = 'single';
1036          $bbp_classes[] = 'singular';
1037  
1038      } elseif ( bbp_is_user_home_edit() ) {
1039          $bbp_classes[] = 'bbp-user-home-edit';
1040          $bbp_classes[] = 'single';
1041          $bbp_classes[] = 'singular';
1042  
1043      } elseif ( bbp_is_topics_created() ) {
1044          $bbp_classes[] = 'bbp-topics-created';
1045          $bbp_classes[] = 'single';
1046          $bbp_classes[] = 'singular';
1047  
1048      } elseif ( bbp_is_replies_created() ) {
1049          $bbp_classes[] = 'bbp-replies-created';
1050          $bbp_classes[] = 'single';
1051          $bbp_classes[] = 'singular';
1052  
1053      } elseif ( bbp_is_favorites() ) {
1054          $bbp_classes[] = 'bbp-favorites';
1055          $bbp_classes[] = 'single';
1056          $bbp_classes[] = 'singular';
1057  
1058      } elseif ( bbp_is_subscriptions() ) {
1059          $bbp_classes[] = 'bbp-subscriptions';
1060          $bbp_classes[] = 'single';
1061          $bbp_classes[] = 'singular';
1062  
1063      /** Search ****************************************************************/
1064  
1065      } elseif ( bbp_is_search() ) {
1066          $bbp_classes[] = 'bbp-search';
1067          $bbp_classes[] = 'forum-search';
1068  
1069      } elseif ( bbp_is_search_results() ) {
1070          $bbp_classes[] = 'bbp-search-results';
1071          $bbp_classes[] = 'forum-search-results';
1072  
1073      /** Shortcodes ************************************************************/
1074  
1075      } elseif ( bbp_has_shortcode() ) {
1076          $bbp_classes[] = 'bbp-shortcode';
1077      }
1078  
1079      /** Clean up **************************************************************/
1080  
1081      // Add bbPress class if we are within a bbPress page
1082      if ( ! empty( $bbp_classes ) ) {
1083          $bbp_classes[] = 'bbpress';
1084      }
1085  
1086      // Merge WP classes with bbPress classes and remove any duplicates
1087      $classes = array_unique( array_merge( (array) $bbp_classes, (array) $wp_classes ) );
1088  
1089      // Deprecated filter (do not use)
1090      $classes = apply_filters( 'bbp_get_the_body_class', $classes, $bbp_classes, $wp_classes, $custom_classes );
1091  
1092      // Filter & return
1093      return (array) apply_filters( 'bbp_body_class', $classes, $bbp_classes, $wp_classes, $custom_classes );
1094  }
1095  
1096  /**
1097   * Check if text contains a bbPress shortcode.
1098   *
1099   * Loops through registered bbPress shortcodes and keeps track of which ones
1100   * were used in a blob of text. If no text is passed, the current global post
1101   * content is assumed.
1102   *
1103   * A preliminary strpos() is performed before looping through each shortcode, to
1104   * prevent unnecessarily processing.
1105   *
1106   * @since 2.6.0
1107   *
1108   * @param string $text
1109   * @return bool
1110   */
1111  function bbp_has_shortcode( $text = '' ) {
1112  
1113      // Default return value
1114      $retval = false;
1115      $found  = array();
1116  
1117      // Fallback to global post_content
1118      if ( empty( $text ) && is_singular() ) {
1119          $text = bbp_get_global_post_field( 'post_content', 'raw' );
1120      }
1121  
1122      // Skip if empty, or string doesn't contain the bbPress shortcode prefix
1123      if ( ! empty( $text ) && ( false !== strpos( $text, '[bbp' ) ) ) {
1124  
1125          // Get possible shortcodes
1126          $codes = array_keys( bbpress()->shortcodes->codes );
1127  
1128          // Loop through codes
1129          foreach ( $codes as $code ) {
1130  
1131              // Looking for shortcode in text
1132              if ( has_shortcode( $text, $code ) ) {
1133                  $retval  = true;
1134                  $found[] = $code;
1135              }
1136          }
1137      }
1138  
1139      // Filter & return
1140      return (bool) apply_filters( 'bbp_has_shortcode', $retval, $found, $text );
1141  }
1142  
1143  /**
1144   * Use the above is_() functions to return if in any bbPress page
1145   *
1146   * @since 2.0.0 bbPress (r3344)
1147   *
1148   * @return bool In a bbPress page
1149   */
1150  function is_bbpress() {
1151  
1152      // Default to false
1153      $retval = false;
1154  
1155      // Bail if main query has not been populated.
1156      if ( ! bbp_get_wp_query() ) {
1157          _doing_it_wrong( __FUNCTION__, esc_html__( 'Conditional query tags do not work before the query is run. Before then, they always return false.', 'bbpress' ), '2.7.0' );
1158          return $retval;
1159      }
1160  
1161      /** Archives **************************************************************/
1162  
1163      if ( bbp_is_forum_archive() ) {
1164          $retval = true;
1165  
1166      } elseif ( bbp_is_topic_archive() ) {
1167          $retval = true;
1168  
1169      /** Topic Tags ************************************************************/
1170  
1171      } elseif ( bbp_is_topic_tag() ) {
1172          $retval = true;
1173  
1174      } elseif ( bbp_is_topic_tag_edit() ) {
1175          $retval = true;
1176  
1177      /** Components ************************************************************/
1178  
1179      } elseif ( bbp_is_single_forum() ) {
1180          $retval = true;
1181  
1182      } elseif ( bbp_is_single_topic() ) {
1183          $retval = true;
1184  
1185      } elseif ( bbp_is_single_reply() ) {
1186          $retval = true;
1187  
1188      } elseif ( bbp_is_topic_edit() ) {
1189          $retval = true;
1190  
1191      } elseif ( bbp_is_topic_merge() ) {
1192          $retval = true;
1193  
1194      } elseif ( bbp_is_topic_split() ) {
1195          $retval = true;
1196  
1197      } elseif ( bbp_is_reply_edit() ) {
1198          $retval = true;
1199  
1200      } elseif ( bbp_is_reply_move() ) {
1201          $retval = true;
1202  
1203      } elseif ( bbp_is_single_view() ) {
1204          $retval = true;
1205  
1206      /** User ******************************************************************/
1207  
1208      } elseif ( bbp_is_single_user_edit() ) {
1209          $retval = true;
1210  
1211      } elseif ( bbp_is_single_user() ) {
1212          $retval = true;
1213  
1214      } elseif ( bbp_is_user_home() ) {
1215          $retval = true;
1216  
1217      } elseif ( bbp_is_user_home_edit() ) {
1218          $retval = true;
1219  
1220      } elseif ( bbp_is_topics_created() ) {
1221          $retval = true;
1222  
1223      } elseif ( bbp_is_replies_created() ) {
1224          $retval = true;
1225  
1226      } elseif ( bbp_is_favorites() ) {
1227          $retval = true;
1228  
1229      } elseif ( bbp_is_subscriptions() ) {
1230          $retval = true;
1231  
1232      /** Search ****************************************************************/
1233  
1234      } elseif ( bbp_is_search() ) {
1235          $retval = true;
1236  
1237      } elseif ( bbp_is_search_results() ) {
1238          $retval = true;
1239  
1240      /** Shortcodes ************************************************************/
1241  
1242      } elseif ( bbp_has_shortcode() ) {
1243          $retval = true;
1244      }
1245  
1246      /** Done ******************************************************************/
1247  
1248      // Filter & return
1249      return (bool) apply_filters( 'is_bbpress', $retval );
1250  }
1251  
1252  /** Forms *********************************************************************/
1253  
1254  /**
1255   * Output the login form action url
1256   *
1257   * @since 2.0.0 bbPress (r2815)
1258   *
1259   * @param array $args This function supports these arguments:
1260   *  - action: The action being taken
1261   *  - context: The context the action is being taken from
1262   */
1263  function bbp_wp_login_action( $args = array() ) {
1264      echo esc_url( bbp_get_wp_login_action( $args ) );
1265  }
1266  
1267      /**
1268       * Return the login form action url
1269       *
1270       * @since 2.6.0 bbPress (r5684)
1271       *
1272       * @param array $args This function supports these arguments:
1273       *  - action: The action being taken
1274       *  - context: The context the action is being taken from
1275       */
1276  	function bbp_get_wp_login_action( $args = array() ) {
1277  
1278          // Parse arguments against default values
1279          $r = bbp_parse_args( $args, array(
1280              'action'  => '',
1281              'context' => '',
1282              'url'     => 'wp-login.php'
1283          ), 'login_action' );
1284  
1285          // Add action as query arg
1286          $login_url = ! empty( $r['action'] )
1287              ? add_query_arg( array( 'action' => $r['action'] ), $r['url'] )
1288              : $r['url'];
1289  
1290          $login_url = site_url( $login_url, $r['context'] );
1291  
1292          // Filter & return
1293          return apply_filters( 'bbp_get_wp_login_action', $login_url, $r, $args );
1294      }
1295  
1296  /**
1297   * Output hidden request URI field for user forms.
1298   *
1299   * The referer link is the current Request URI from the server super global. To
1300   * check the field manually, use bbp_get_redirect_to().
1301   *
1302   * @since 2.0.0 bbPress (r2815)
1303   *
1304   * @param string $redirect_to Pass a URL to redirect to
1305   */
1306  function bbp_redirect_to_field( $redirect_to = '' ) {
1307  
1308      // Make sure we are directing somewhere
1309      if ( empty( $redirect_to ) ) {
1310          if ( isset( $_SERVER['REQUEST_URI'] ) ) {
1311              $redirect_to = bbp_get_url_scheme() . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
1312          } else {
1313              $redirect_to = wp_get_referer();
1314          }
1315      }
1316  
1317      // Remove loggedout query arg if it's there
1318      $redirect_to    = remove_query_arg( 'loggedout', $redirect_to );
1319      $redirect_field = '<input type="hidden" id="bbp_redirect_to" name="redirect_to" value="' . esc_url( $redirect_to ) . '" />';
1320  
1321      // Filter & return
1322      echo apply_filters( 'bbp_redirect_to_field', $redirect_field, $redirect_to );
1323  }
1324  
1325  /**
1326   * Echo sanitized $_REQUEST value.
1327   *
1328   * Use the $input_type parameter to properly process the value. This
1329   * ensures correct sanitization of the value for the receiving input.
1330   *
1331   * @since 2.0.0 bbPress (r2815)
1332   *
1333   * @param string $request Name of $_REQUEST to look for
1334   * @param string $input_type Type of input. Default: text. Accepts:
1335   *                            textarea|password|select|radio|checkbox
1336   */
1337  function bbp_sanitize_val( $request = '', $input_type = 'text' ) {
1338      echo bbp_get_sanitize_val( $request, $input_type );
1339  }
1340      /**
1341       * Return sanitized $_REQUEST value.
1342       *
1343       * Use the $input_type parameter to properly process the value. This
1344       * ensures correct sanitization of the value for the receiving input.
1345       *
1346       * @since 2.0.0 bbPress (r2815)
1347       *
1348       * @param string $request Name of $_REQUEST to look for
1349       * @param string $input_type Type of input. Default: text. Accepts:
1350       *                            textarea|password|select|radio|checkbox
1351       *
1352       * @return string Sanitized value ready for screen display
1353       */
1354  	function bbp_get_sanitize_val( $request = '', $input_type = 'text' ) {
1355  
1356          // Check that requested
1357          if ( empty( $_REQUEST[ $request ] ) ) {
1358              return false;
1359          }
1360  
1361          // Set request varaible
1362          $pre_ret_val = $_REQUEST[ $request ];
1363  
1364          // Treat different kinds of fields in different ways
1365          switch ( $input_type ) {
1366              case 'text'     :
1367              case 'textarea' :
1368                  $retval = esc_attr( wp_unslash( $pre_ret_val ) );
1369                  break;
1370  
1371              case 'password' :
1372              case 'select'   :
1373              case 'radio'    :
1374              case 'checkbox' :
1375              default :
1376                  $retval = esc_attr( $pre_ret_val );
1377                  break;
1378          }
1379  
1380          // Filter & return
1381          return apply_filters( 'bbp_get_sanitize_val', $retval, $request, $input_type );
1382      }
1383  
1384  /**
1385   * Output the current tab index of a given form
1386   *
1387   * Use this function to handle the tab indexing of user facing forms within a
1388   * template file. Calling this function will automatically increment the global
1389   * tab index by default.
1390   *
1391   * @since 2.0.0 bbPress (r2810)
1392   *
1393   * @deprecated 2.6.0 bbPress (r5561)
1394   *
1395   * @link https://bbpress.trac.wordpress.org/attachment/ticket/2714 Trac Ticket
1396   * @param int $auto_increment Optional. Default true. Set to false to prevent
1397   *                             increment
1398   */
1399  function bbp_tab_index( $auto_increment = true ) {
1400      echo bbp_get_tab_index( $auto_increment );
1401  }
1402  
1403      /**
1404       * Return the current tab index of a given form
1405       *
1406       * Use this function to handle the tab indexing of user facing forms
1407       * within a template file. Calling this function will automatically
1408       * increment the global tab index by default.
1409       *
1410       * @since 2.0.0 bbPress (r2810)
1411       *
1412       * @deprecated 2.6.0 bbPress (r5561)
1413       *
1414       * @link https://bbpress.trac.wordpress.org/attachment/ticket/2714 Trac Ticket
1415       * @param int $auto_increment Optional. Default true. Set to false to
1416       *                             prevent the increment
1417       * @return int $bbp->tab_index The global tab index
1418       */
1419  	function bbp_get_tab_index( $auto_increment = true ) {
1420          $bbp = bbpress();
1421  
1422          if ( true === $auto_increment ) {
1423              ++$bbp->tab_index;
1424          }
1425  
1426          // Filter & return
1427          return apply_filters( 'bbp_get_tab_index', (int) $bbp->tab_index );
1428      }
1429  
1430  /**
1431   * Output a "tabindex" attribute for an element, if an index was passed.
1432   *
1433   * This helper function is in use, but it is generally considered impolite to
1434   * override the "tabindex" attribute beyond what the browser naturally assigns.
1435   *
1436   * Most internal usages pass `false` which results in no attribute being used.
1437   *
1438   * @since 2.6.0 bbPress (r6424)
1439   *
1440   * @param mixed $tab False to skip, any integer to use
1441   */
1442  function bbp_tab_index_attribute( $tab = false ) {
1443      echo bbp_get_tab_index_attribute( $tab );
1444  }
1445  
1446      /**
1447       * Return a "tabindex" attribute for an element, if an index was passed.
1448       *
1449       * This helper function is in use, but it is generally considered impolite to
1450       * override the "tabindex" attribute beyond what the browser naturally assigns.
1451       *
1452       * Most internal usages pass `false` which results in no attribute being used.
1453       *
1454       * @since 2.6.0 bbPress (r6424)
1455       *
1456       * @param mixed $tab False to skip, any integer to use
1457       *
1458       * @return string
1459       */
1460  	function bbp_get_tab_index_attribute( $tab = false ) {
1461  
1462          // Get attribute
1463          $attr = is_numeric( $tab )
1464              ? ' tabindex="' . (int) $tab . '"'
1465              : '';
1466  
1467          // Filter & return
1468          return apply_filters( 'bbp_get_tab_index_attribute', $attr, $tab );
1469      }
1470  
1471  /**
1472   * Output a select box allowing to pick which forum/topic a new topic/reply
1473   * belongs in.
1474   *
1475   * Can be used for any post type, but is mostly used for topics and forums.
1476   *
1477   * @since 2.0.0 bbPress (r2746)
1478   *
1479   * @param array $args See {@link bbp_get_dropdown()} for arguments
1480   */
1481  function bbp_dropdown( $args = array() ) {
1482      echo bbp_get_dropdown( $args );
1483  }
1484      /**
1485       * Return a select box allowing to pick which forum/topic a new
1486       * topic/reply belongs in.
1487       *
1488       * @since 2.0.0 bbPress (r2746)
1489       *
1490       * @param array $args The function supports these args:
1491       *  - post_type: Post type, defaults to bbp_get_forum_post_type() (bbp_forum)
1492       *  - selected: Selected ID, to not have any value as selected, pass
1493       *               anything smaller than 0 (due to the nature of select
1494       *               box, the first value would of course be selected -
1495       *               though you can have that as none (pass 'show_none' arg))
1496       *  - orderby: Defaults to 'menu_order title'
1497       *  - post_parent: Post parent. Defaults to 0
1498       *  - post_status: Which all post_statuses to find in? Can be an array
1499       *                  or CSV of publish, category, closed, private, spam,
1500       *                  trash (based on post type) - if not set, these are
1501       *                  automatically determined based on the post_type
1502       *  - posts_per_page: Retrieve all forums/topics. Defaults to -1 to get
1503       *                     all posts
1504       *  - walker: Which walker to use? Defaults to
1505       *             {@link BBP_Walker_Dropdown}
1506       *  - select_id: ID of the select box. Defaults to 'bbp_forum_id'
1507       *  - tab: Deprecated. Tabindex value. False or integer
1508       *  - options_only: Show only <options>? No <select>?
1509       *  - show_none: Boolean or String __( '&mdash; No Forum &mdash;', 'bbpress' )
1510       *  - disable_categories: Disable forum categories and closed forums?
1511       *                         Defaults to true. Only for forums and when
1512       * @return string The dropdown
1513       */
1514  	function bbp_get_dropdown( $args = array() ) {
1515  
1516          // Setup return value
1517          $retval = '';
1518  
1519          /** Arguments *********************************************************/
1520  
1521          // Parse arguments against default values
1522          $r = bbp_parse_args( $args, array(
1523  
1524              // Support for get_posts()
1525              'post_type'          => bbp_get_forum_post_type(),
1526              'post_parent'        => null,
1527              'post_status'        => null,
1528              'selected'           => 0,
1529              'include'            => array(),
1530              'exclude'            => array(),
1531              'numberposts'        => -1,
1532              'orderby'            => 'menu_order title',
1533              'order'              => 'ASC',
1534  
1535              // Preloaded content
1536              'posts'              => array(),
1537  
1538              // Custom hierarchy walkers
1539              'walker'             => '',
1540  
1541              // Output-related
1542              'select_id'          => 'bbp_forum_id',
1543              'select_class'       => 'bbp_dropdown',
1544              'tab'                => false,
1545              'options_only'       => false,
1546              'show_none'          => false,
1547              'disable_categories' => true,
1548              'disabled'           => ''
1549          ), 'get_dropdown' );
1550  
1551          // Fallback to our walker
1552          if ( empty( $r['walker'] ) ) {
1553              $r['walker']            = new BBP_Walker_Dropdown();
1554              $r['walker']->tree_type = $r['post_type'];
1555          }
1556  
1557          // Force 0
1558          if ( is_numeric( $r['selected'] ) && ( $r['selected'] < 0 ) ) {
1559              $r['selected'] = 0;
1560          }
1561  
1562          // Force array
1563          if ( ! empty( $r['include'] ) && ! is_array( $r['include'] ) ) {
1564              $r['include'] = explode( ',', $r['include'] );
1565          }
1566  
1567          // Force array
1568          if ( ! empty( $r['exclude'] ) && ! is_array( $r['exclude'] ) ) {
1569              $r['exclude'] = explode( ',', $r['exclude'] );
1570          }
1571  
1572          /** Setup Posts *******************************************************/
1573  
1574          /**
1575           * Allow passing of custom posts data
1576           *
1577           * @see bbp_get_reply_to_dropdown() as an example
1578           */
1579          if ( empty( $r['posts'] ) ) {
1580              $r['posts'] = get_posts( array(
1581                  'post_type'   => $r['post_type'],
1582                  'post_status' => $r['post_status'],
1583                  'post_parent' => $r['post_parent'],
1584                  'include'     => $r['include'],
1585                  'exclude'     => $r['exclude'],
1586                  'numberposts' => $r['numberposts'],
1587                  'orderby'     => $r['orderby'],
1588                  'order'       => $r['order'],
1589              ) );
1590          }
1591  
1592          /** Drop Down *********************************************************/
1593  
1594          // Build the opening tag for the select element
1595          if ( empty( $r['options_only'] ) ) {
1596  
1597              // Should this select appear disabled?
1598              $disabled  = disabled( isset( bbpress()->options[ $r['disabled'] ] ), true, false );
1599  
1600              // Setup the tab index attribute
1601              $tab       = ! empty( $r['tab'] ) ? ' tabindex="' . intval( $r['tab'] ) . '"' : '';
1602  
1603              // Open the select tag
1604              $retval   .= '<select name="' . esc_attr( $r['select_id'] ) . '" id="' . esc_attr( $r['select_id'] ) . '" class="' . esc_attr( $r['select_class'] ) . '"' . $disabled . $tab . '>' . "\n";
1605          }
1606  
1607          // Display a leading 'no-value' option, with or without custom text
1608          if ( ! empty( $r['show_none'] ) || ! empty( $r['none_found'] ) ) {
1609  
1610              // Open the 'no-value' option tag
1611              $retval .= "\t<option value=\"\" class=\"level-0\">";
1612  
1613              // Use deprecated 'none_found' first for backpat
1614              if ( ! empty( $r['none_found'] ) && is_string( $r['none_found'] ) ) {
1615                  $retval .= esc_html( $r['none_found'] );
1616  
1617              // Use 'show_none' second
1618              } elseif ( ! empty( $r['show_none'] ) && is_string( $r['show_none'] ) ) {
1619                  $retval .= esc_html( $r['show_none'] );
1620  
1621              // Otherwise, make some educated guesses
1622              } else {
1623  
1624                  // Switch the response based on post type
1625                  switch ( $r['post_type'] ) {
1626  
1627                      // Topics
1628                      case bbp_get_topic_post_type() :
1629                          $retval .= esc_html__( 'No topics available', 'bbpress' );
1630                          break;
1631  
1632                      // Forums
1633                      case bbp_get_forum_post_type() :
1634                          $retval .= esc_html__( 'No forums available', 'bbpress' );
1635                          break;
1636  
1637                      // Any other
1638                      default :
1639                          $retval .= esc_html__( 'None available', 'bbpress' );
1640                          break;
1641                  }
1642              }
1643  
1644              // Close the 'no-value' option tag
1645              $retval .= '</option>';
1646          }
1647  
1648          // Items found so walk the tree
1649          if ( ! empty( $r['posts'] ) ) {
1650              $retval .= walk_page_dropdown_tree( $r['posts'], 0, $r );
1651          }
1652  
1653          // Close the selecet tag
1654          if ( empty( $r['options_only'] ) ) {
1655              $retval .= '</select>';
1656          }
1657  
1658          // Filter & return
1659          return apply_filters( 'bbp_get_dropdown', $retval, $r, $args );
1660      }
1661  
1662  /**
1663   * Output the required hidden fields when creating/editing a forum
1664   *
1665   * @since 2.1.0 bbPress (r3553)
1666   */
1667  function bbp_forum_form_fields() {
1668  
1669      if ( bbp_is_forum_edit() ) : ?>
1670  
1671          <input type="hidden" name="action"       id="bbp_post_action" value="bbp-edit-forum" />
1672          <input type="hidden" name="bbp_forum_id" id="bbp_forum_id"    value="<?php bbp_forum_id(); ?>" />
1673  
1674          <?php if ( current_user_can( 'unfiltered_html' ) ) :
1675              wp_nonce_field( 'bbp-unfiltered-html-forum_' . bbp_get_forum_id(), '_bbp_unfiltered_html_forum', false );
1676          endif; ?>
1677  
1678          <?php wp_nonce_field( 'bbp-edit-forum_' . bbp_get_forum_id() );
1679  
1680      else :
1681  
1682          if ( bbp_is_single_forum() ) : ?>
1683  
1684              <input type="hidden" name="bbp_forum_parent_id" id="bbp_forum_parent_id" value="<?php bbp_forum_parent_id(); ?>" />
1685  
1686          <?php endif; ?>
1687  
1688          <input type="hidden" name="action" id="bbp_post_action" value="bbp-new-forum" />
1689  
1690          <?php if ( current_user_can( 'unfiltered_html' ) ) :
1691              wp_nonce_field( 'bbp-unfiltered-html-forum_new', '_bbp_unfiltered_html_forum', false );
1692          endif; ?>
1693  
1694          <?php wp_nonce_field( 'bbp-new-forum' );
1695  
1696      endif;
1697  }
1698  
1699  /**
1700   * Output the required hidden fields when creating/editing a topic
1701   *
1702   * @since 2.0.0 bbPress (r2753)
1703   */
1704  function bbp_topic_form_fields() {
1705  
1706      if ( bbp_is_topic_edit() ) : ?>
1707  
1708          <input type="hidden" name="action"       id="bbp_post_action" value="bbp-edit-topic" />
1709          <input type="hidden" name="bbp_topic_id" id="bbp_topic_id"    value="<?php bbp_topic_id(); ?>" />
1710  
1711          <?php if ( current_user_can( 'unfiltered_html' ) ) :
1712              wp_nonce_field( 'bbp-unfiltered-html-topic_' . bbp_get_topic_id(), '_bbp_unfiltered_html_topic', false );
1713          endif; ?>
1714  
1715          <?php wp_nonce_field( 'bbp-edit-topic_' . bbp_get_topic_id() );
1716  
1717      else :
1718  
1719          if ( bbp_is_single_forum() ) : ?>
1720  
1721              <input type="hidden" name="bbp_forum_id" id="bbp_forum_id" value="<?php bbp_forum_id(); ?>" />
1722  
1723          <?php endif; ?>
1724  
1725          <input type="hidden" name="action" id="bbp_post_action" value="bbp-new-topic" />
1726  
1727          <?php if ( current_user_can( 'unfiltered_html' ) ) :
1728              wp_nonce_field( 'bbp-unfiltered-html-topic_new', '_bbp_unfiltered_html_topic', false );
1729          endif; ?>
1730  
1731          <?php wp_nonce_field( 'bbp-new-topic' );
1732  
1733      endif;
1734  }
1735  
1736  /**
1737   * Output the required hidden fields when creating/editing a reply
1738   *
1739   * @since 2.0.0 bbPress (r2753)
1740   */
1741  function bbp_reply_form_fields() {
1742  
1743      if ( bbp_is_reply_edit() ) : ?>
1744  
1745          <input type="hidden" name="bbp_reply_id"    id="bbp_reply_id"    value="<?php bbp_reply_id(); ?>" />
1746          <input type="hidden" name="action"          id="bbp_post_action" value="bbp-edit-reply" />
1747  
1748          <?php if ( current_user_can( 'unfiltered_html' ) ) :
1749              wp_nonce_field( 'bbp-unfiltered-html-reply_' . bbp_get_reply_id(), '_bbp_unfiltered_html_reply', false );
1750          endif; ?>
1751  
1752          <?php wp_nonce_field( 'bbp-edit-reply_' . bbp_get_reply_id() );
1753  
1754      else : ?>
1755  
1756          <input type="hidden" name="bbp_topic_id"    id="bbp_topic_id"    value="<?php bbp_topic_id(); ?>" />
1757          <input type="hidden" name="bbp_reply_to"    id="bbp_reply_to"    value="<?php bbp_form_reply_to(); ?>" />
1758          <input type="hidden" name="action"          id="bbp_post_action" value="bbp-new-reply" />
1759  
1760          <?php if ( current_user_can( 'unfiltered_html' ) ) :
1761              wp_nonce_field( 'bbp-unfiltered-html-reply_' . bbp_get_topic_id(), '_bbp_unfiltered_html_reply', false );
1762          endif; ?>
1763  
1764          <?php wp_nonce_field( 'bbp-new-reply' );
1765  
1766          // Show redirect field if not viewing a specific topic
1767          if ( bbp_is_query_name( 'bbp_single_topic' ) ) :
1768              $redirect_to = apply_filters( 'bbp_reply_form_redirect_to', get_permalink() );
1769              bbp_redirect_to_field( $redirect_to );
1770          endif;
1771      endif;
1772  }
1773  
1774  /**
1775   * Output the required hidden fields when editing a user
1776   *
1777   * @since 2.0.0 bbPress (r2690)
1778   */
1779  function bbp_edit_user_form_fields() {
1780  ?>
1781  
1782      <input type="hidden" name="action"  id="bbp_post_action" value="bbp-update-user" />
1783      <input type="hidden" name="user_id" id="user_id"         value="<?php bbp_displayed_user_id(); ?>" />
1784  
1785      <?php wp_nonce_field( 'update-user_' . bbp_get_displayed_user_id() );
1786  }
1787  
1788  /**
1789   * Merge topic form fields
1790   *
1791   * Output the required hidden fields when merging a topic
1792   *
1793   * @since 2.0.0 bbPress (r2756)
1794   */
1795  function bbp_merge_topic_form_fields() {
1796  ?>
1797  
1798      <input type="hidden" name="action"       id="bbp_post_action" value="bbp-merge-topic" />
1799      <input type="hidden" name="bbp_topic_id" id="bbp_topic_id"    value="<?php bbp_topic_id(); ?>" />
1800  
1801      <?php wp_nonce_field( 'bbp-merge-topic_' . bbp_get_topic_id() );
1802  }
1803  
1804  /**
1805   * Split topic form fields
1806   *
1807   * Output the required hidden fields when splitting a topic
1808   *
1809   * @since 2.0.0 bbPress (r2756)
1810   */
1811  function bbp_split_topic_form_fields() {
1812  ?>
1813  
1814      <input type="hidden" name="action"       id="bbp_post_action" value="bbp-split-topic" />
1815      <input type="hidden" name="bbp_reply_id" id="bbp_reply_id"    value="<?php echo intval( $_GET['reply_id'] ); ?>" />
1816  
1817      <?php wp_nonce_field( 'bbp-split-topic_' . bbp_get_topic_id() );
1818  }
1819  
1820  /**
1821   * Move reply form fields
1822   *
1823   * Output the required hidden fields when moving a reply
1824   */
1825  function bbp_move_reply_form_fields() {
1826  ?>
1827  
1828      <input type="hidden" name="action"       id="bbp_post_action" value="bbp-move-reply" />
1829      <input type="hidden" name="bbp_reply_id" id="bbp_reply_id"    value="<?php echo intval( $_GET['reply_id'] ); ?>" />
1830  
1831      <?php wp_nonce_field( 'bbp-move-reply_' . bbp_get_reply_id() );
1832  }
1833  
1834  /**
1835   * Output a textarea or TinyMCE if enabled
1836   *
1837   * @since 2.1.0 bbPress (r3586)
1838   *
1839   * @param array $args
1840   */
1841  function bbp_the_content( $args = array() ) {
1842      echo bbp_get_the_content( $args );
1843  }
1844      /**
1845       * Return a textarea or TinyMCE if enabled
1846       *
1847       * @since 2.1.0 bbPress (r3586)
1848       *
1849       * @param array $args
1850       *
1851       * @return string HTML from output buffer
1852       */
1853  	function bbp_get_the_content( $args = array() ) {
1854  
1855          // Parse arguments against default values
1856          $r = bbp_parse_args( $args, array(
1857              'context'           => 'topic',
1858              'before'            => '<div class="bbp-the-content-wrapper">',
1859              'after'             => '</div>',
1860              'wpautop'           => true,
1861              'media_buttons'     => false,
1862              'textarea_rows'     => '12',
1863              'tabindex'          => false,
1864              'tabfocus_elements' => 'bbp_topic_title,bbp_topic_tags',
1865              'editor_class'      => 'bbp-the-content',
1866              'tinymce'           => false,
1867              'teeny'             => true,
1868              'quicktags'         => true,
1869              'dfw'               => false
1870          ), 'get_the_content' );
1871  
1872          // If using tinymce, remove our escaping and trust tinymce
1873          if ( bbp_use_wp_editor() && ( false !== $r['tinymce'] ) ) {
1874              remove_filter( 'bbp_get_form_forum_content', 'esc_textarea' );
1875              remove_filter( 'bbp_get_form_topic_content', 'esc_textarea' );
1876              remove_filter( 'bbp_get_form_reply_content', 'esc_textarea' );
1877          }
1878  
1879          // Assume we are not editing
1880          $post_content = call_user_func( 'bbp_get_form_' . $r['context'] . '_content' );
1881  
1882          // Start an output buffor
1883          ob_start();
1884  
1885          // Output something before the editor
1886          if ( ! empty( $r['before'] ) ) {
1887              echo $r['before'];
1888          }
1889  
1890          // Use TinyMCE if available
1891          if ( bbp_use_wp_editor() ) :
1892  
1893              // Enable additional TinyMCE plugins before outputting the editor
1894              add_filter( 'tiny_mce_plugins',   'bbp_get_tiny_mce_plugins'   );
1895              add_filter( 'teeny_mce_plugins',  'bbp_get_tiny_mce_plugins'   );
1896              add_filter( 'teeny_mce_buttons',  'bbp_get_teeny_mce_buttons'  );
1897              add_filter( 'quicktags_settings', 'bbp_get_quicktags_settings' );
1898  
1899              // Output the editor
1900              wp_editor( $post_content, 'bbp_' . $r['context'] . '_content', array(
1901                  'wpautop'           => $r['wpautop'],
1902                  'media_buttons'     => $r['media_buttons'],
1903                  'textarea_rows'     => $r['textarea_rows'],
1904                  'tabindex'          => $r['tabindex'],
1905                  'tabfocus_elements' => $r['tabfocus_elements'],
1906                  'editor_class'      => $r['editor_class'],
1907                  'tinymce'           => $r['tinymce'],
1908                  'teeny'             => $r['teeny'],
1909                  'quicktags'         => $r['quicktags'],
1910                  'dfw'               => $r['dfw'],
1911              ) );
1912  
1913              // Remove additional TinyMCE plugins after outputting the editor
1914              remove_filter( 'tiny_mce_plugins',   'bbp_get_tiny_mce_plugins'   );
1915              remove_filter( 'teeny_mce_plugins',  'bbp_get_tiny_mce_plugins'   );
1916              remove_filter( 'teeny_mce_buttons',  'bbp_get_teeny_mce_buttons'  );
1917              remove_filter( 'quicktags_settings', 'bbp_get_quicktags_settings' );
1918  
1919          /**
1920           * Fallback to normal textarea.
1921           *
1922           * Note that we do not use esc_textarea() here to prevent double
1923           * escaping the editable output, mucking up existing content.
1924           */
1925          else : ?>
1926  
1927              <textarea id="bbp_<?php echo esc_attr( $r['context'] ); ?>_content" class="<?php echo esc_attr( $r['editor_class'] ); ?>" name="bbp_<?php echo esc_attr( $r['context'] ); ?>_content" cols="60" rows="<?php echo esc_attr( $r['textarea_rows'] ); ?>" <?php bbp_tab_index_attribute( $r['tabindex'] ); ?>><?php echo $post_content; ?></textarea>
1928  
1929          <?php endif;
1930  
1931          // Output something after the editor
1932          if ( ! empty( $r['after'] ) ) {
1933              echo $r['after'];
1934          }
1935  
1936          // Put the output into a usable variable
1937          $output = ob_get_clean();
1938  
1939          // Filter & return
1940          return apply_filters( 'bbp_get_the_content', $output, $args, $post_content );
1941      }
1942  
1943  /**
1944   * Edit TinyMCE plugins to match core behaviour
1945   *
1946   * @since 2.3.0 bbPress (r4574)
1947   *
1948   * @param array $plugins
1949   * @see tiny_mce_plugins, teeny_mce_plugins
1950   * @return array
1951   */
1952  function bbp_get_tiny_mce_plugins( $plugins = array() ) {
1953  
1954      // Unset fullscreen
1955      foreach ( $plugins as $key => $value ) {
1956          if ( 'fullscreen' === $value ) {
1957              unset( $plugins[ $key ] );
1958              break;
1959          }
1960      }
1961  
1962      // Add the tabfocus plugin
1963      $plugins[] = 'tabfocus';
1964  
1965      // Filter & return
1966      return apply_filters( 'bbp_get_tiny_mce_plugins', $plugins );
1967  }
1968  
1969  /**
1970   * Edit TeenyMCE buttons to match allowedtags
1971   *
1972   * @since 2.3.0 bbPress (r4605)
1973   *
1974   * @param array $buttons
1975   * @see teeny_mce_buttons
1976   * @return array
1977   */
1978  function bbp_get_teeny_mce_buttons( $buttons = array() ) {
1979  
1980      // Remove some buttons from TeenyMCE
1981      $buttons = array_diff( $buttons, array(
1982          'underline',
1983          'justifyleft',
1984          'justifycenter',
1985          'justifyright'
1986      ) );
1987  
1988      // Images
1989      array_push( $buttons, 'image' );
1990  
1991      // Filter & return
1992      return apply_filters( 'bbp_get_teeny_mce_buttons', $buttons );
1993  }
1994  
1995  /**
1996   * Edit TinyMCE quicktags buttons to match allowedtags
1997   *
1998   * @since 2.3.0 bbPress (r4606)
1999   *
2000   * @param array $settings
2001   * @see quicktags_settings
2002   * @return array Quicktags settings
2003   */
2004  function bbp_get_quicktags_settings( $settings = array() ) {
2005  
2006      // Get buttons out of settings
2007      $buttons_array = explode( ',', $settings['buttons'] );
2008  
2009      // Diff the ones we don't want out
2010      $buttons = array_diff( $buttons_array, array(
2011          'ins',
2012          'more',
2013          'spell'
2014      ) );
2015  
2016      // Put them back into a string in the $settings array
2017      $settings['buttons'] = implode( ',', $buttons );
2018  
2019      // Filter & return
2020      return apply_filters( 'bbp_get_quicktags_settings', $settings );
2021  }
2022  
2023  /** Views *********************************************************************/
2024  
2025  /**
2026   * Output the view id
2027   *
2028   * @since 2.0.0 bbPress (r2789)
2029   *
2030   * @param string $view Optional. View id
2031   */
2032  function bbp_view_id( $view = '' ) {
2033      echo bbp_get_view_id( $view );
2034  }
2035  
2036      /**
2037       * Get the view id
2038       *
2039       * Use view id if supplied, otherwise bbp_get_view_rewrite_id() query var.
2040       *
2041       * @since 2.0.0 bbPress (r2789)
2042       *
2043       * @param string $view Optional. View id.
2044       * @return bool|string ID on success, false on failure
2045       */
2046  	function bbp_get_view_id( $view = '' ) {
2047          $bbp = bbpress();
2048  
2049          // User supplied string
2050          if ( ! empty( $view ) ) {
2051              $view_id = sanitize_key( $view );
2052  
2053          // Current view ID
2054          } elseif ( ! empty( $bbp->current_view_id ) ) {
2055              $view_id = $bbp->current_view_id;
2056  
2057          // Querying for view
2058          } else {
2059              $view_id = get_query_var( bbp_get_view_rewrite_id() );
2060          }
2061  
2062          // Filter & return
2063          return apply_filters( 'bbp_get_view_id', $view_id, $view );
2064      }
2065  
2066  /**
2067   * Output the view name aka title
2068   *
2069   * @since 2.0.0 bbPress (r2789)
2070   *
2071   * @param string $view Optional. View id
2072   */
2073  function bbp_view_title( $view = '' ) {
2074      echo bbp_get_view_title( $view );
2075  }
2076  
2077      /**
2078       * Get the view name aka title
2079       *
2080       * If a view id is supplied, that is used. Otherwise the bbp_view
2081       * query var is checked for.
2082       *
2083       * @since 2.0.0 bbPress (r2789)
2084       *
2085       * @param string $view Optional. View id
2086       * @return bool|string Title on success, false on failure
2087       */
2088  	function bbp_get_view_title( $view = '' ) {
2089          $bbp = bbpress();
2090  
2091          $view = bbp_get_view_id( $view );
2092          if ( empty( $view ) ) {
2093              return false;
2094          }
2095  
2096          return $bbp->views[ $view ]['title'];
2097      }
2098  
2099  /**
2100   * Output the view url
2101   *
2102   * @since 2.0.0 bbPress (r2789)
2103   *
2104   * @param string $view Optional. View id
2105   */
2106  function bbp_view_url( $view = false ) {
2107      echo esc_url( bbp_get_view_url( $view ) );
2108  }
2109      /**
2110       * Return the view url
2111       *
2112       * @since 2.0.0 bbPress (r2789)
2113       *
2114       * @param string $view Optional. View id
2115       *                        used view id
2116       * @return string View url (or home url if the view was not found)
2117       */
2118  	function bbp_get_view_url( $view = false ) {
2119  
2120          $view = bbp_get_view_id( $view );
2121          if ( empty( $view ) ) {
2122              return home_url();
2123          }
2124  
2125          // Pretty permalinks
2126          if ( bbp_use_pretty_urls() ) {
2127  
2128              // Run through home_url()
2129              $url = trailingslashit( bbp_get_root_url() . bbp_get_view_slug() ) . $view;
2130              $url = user_trailingslashit( $url );
2131              $url = home_url( $url );
2132  
2133          // Unpretty permalinks
2134          } else {
2135              $url = add_query_arg( array(
2136                  bbp_get_view_rewrite_id() => $view
2137              ), home_url( '/' ) );
2138          }
2139  
2140          // Filter & return
2141          return apply_filters( 'bbp_get_view_link', $url, $view );
2142      }
2143  
2144  /** Query *********************************************************************/
2145  
2146  /**
2147   * Check the passed parameter against the current _bbp_query_name
2148   *
2149   * @since 2.0.0 bbPress (r2980)
2150   *
2151   * @return bool True if match, false if not
2152   */
2153  function bbp_is_query_name( $name = '' ) {
2154      return (bool) ( bbp_get_query_name() === $name );
2155  }
2156  
2157  /**
2158   * Get the '_bbp_query_name' setting
2159   *
2160   * @since 2.0.0 bbPress (r2695)
2161   *
2162   * @return string To return the query var value
2163   */
2164  function bbp_get_query_name() {
2165      return get_query_var( '_bbp_query_name' );
2166  }
2167  
2168  /**
2169   * Set the '_bbp_query_name' setting to $name
2170   *
2171   * @since 2.0.0 bbPress (r2692)
2172   *
2173   * @param string $name What to set the query var to
2174   */
2175  function bbp_set_query_name( $name = '' ) {
2176      set_query_var( '_bbp_query_name', $name );
2177  }
2178  
2179  /**
2180   * Used to clear the '_bbp_query_name' setting
2181   *
2182   * @since 2.0.0 bbPress (r2692)
2183   *
2184   */
2185  function bbp_reset_query_name() {
2186      bbp_set_query_name();
2187  }
2188  
2189  /** Breadcrumbs ***************************************************************/
2190  
2191  /**
2192   * Output the page title as a breadcrumb
2193   *
2194   * @since 2.0.0 bbPress (r2589)
2195   *
2196   * @param string $sep Separator. Defaults to '&larr;'
2197   * @param bool $current_page Include the current item
2198   * @param bool $root Include the root page if one exists
2199   */
2200  function bbp_title_breadcrumb( $args = array() ) {
2201      echo bbp_get_breadcrumb( $args );
2202  }
2203  
2204  /**
2205   * Output a breadcrumb
2206   *
2207   * @since 2.0.0 bbPress (r2589)
2208   *
2209   * @param string $sep Separator. Defaults to '&larr;'
2210   * @param bool $current_page Include the current item
2211   * @param bool $root Include the root page if one exists
2212   */
2213  function bbp_breadcrumb( $args = array() ) {
2214      echo bbp_get_breadcrumb( $args );
2215  }
2216      /**
2217       * Return a breadcrumb ( forum -> topic -> reply )
2218       *
2219       * @since 2.0.0 bbPress (r2589)
2220       *
2221       * @param string $sep Separator. Defaults to '&larr;'
2222       * @param bool $current_page Include the current item
2223       * @param bool $root Include the root page if one exists
2224       *
2225       * @return string Breadcrumbs
2226       */
2227  	function bbp_get_breadcrumb( $args = array() ) {
2228  
2229          // Turn off breadcrumbs
2230          if ( apply_filters( 'bbp_no_breadcrumb', is_front_page() ) ) {
2231              return;
2232          }
2233  
2234          // Define variables
2235          $front_id         = $root_id                                 = 0;
2236          $ancestors        = $crumbs           = $tag_data            = array();
2237          $pre_root_text    = $pre_front_text   = $pre_current_text    = '';
2238          $pre_include_root = $pre_include_home = $pre_include_current = true;
2239  
2240          /** Home Text *********************************************************/
2241  
2242          // No custom home text
2243          if ( empty( $args['home_text'] ) ) {
2244  
2245              $front_id = get_option( 'page_on_front' );
2246  
2247              // Set home text to page title
2248              if ( ! empty( $front_id ) ) {
2249                  $pre_front_text = get_the_title( $front_id );
2250  
2251              // Default to 'Home'
2252              } else {
2253                  $pre_front_text = esc_html__( 'Home', 'bbpress' );
2254              }
2255          }
2256  
2257          /** Root Text *********************************************************/
2258  
2259          // No custom root text
2260          if ( empty( $args['root_text'] ) ) {
2261              $page = bbp_get_page_by_path( bbp_get_root_slug() );
2262              if ( ! empty( $page ) ) {
2263                  $root_id = $page->ID;
2264              }
2265              $pre_root_text = bbp_get_forum_archive_title();
2266          }
2267  
2268          /** Includes **********************************************************/
2269  
2270          // Root slug is also the front page
2271          if ( ! empty( $front_id ) && ( $front_id === $root_id ) ) {
2272              $pre_include_root = false;
2273          }
2274  
2275          // Don't show root if viewing forum archive
2276          if ( bbp_is_forum_archive() ) {
2277              $pre_include_root = false;
2278          }
2279  
2280          // Don't show root if viewing page in place of forum archive
2281          if ( ! empty( $root_id ) && ( ( is_single() || is_page() ) && ( $root_id === get_the_ID() ) ) ) {
2282              $pre_include_root = false;
2283          }
2284  
2285          /** Current Text ******************************************************/
2286  
2287          // Search page
2288          if ( bbp_is_search() ) {
2289              $pre_current_text = bbp_get_search_title();
2290  
2291          // Forum archive
2292          } elseif ( bbp_is_forum_archive() ) {
2293              $pre_current_text = bbp_get_forum_archive_title();
2294  
2295          // Topic archive
2296          } elseif ( bbp_is_topic_archive() ) {
2297              $pre_current_text = bbp_get_topic_archive_title();
2298  
2299          // View
2300          } elseif ( bbp_is_single_view() ) {
2301              $pre_current_text = bbp_get_view_title();
2302  
2303          // Single Forum
2304          } elseif ( bbp_is_single_forum() ) {
2305              $pre_current_text = bbp_get_forum_title();
2306  
2307          // Single Topic
2308          } elseif ( bbp_is_single_topic() ) {
2309              $pre_current_text = bbp_get_topic_title();
2310  
2311          // Single Topic
2312          } elseif ( bbp_is_single_reply() ) {
2313              $pre_current_text = bbp_get_reply_title();
2314  
2315          // Topic Tag (or theme compat topic tag)
2316          } elseif ( bbp_is_topic_tag() || ( get_query_var( 'bbp_topic_tag' ) && ! bbp_is_topic_tag_edit() ) ) {
2317  
2318              // Always include the tag name
2319              $tag_data[] = bbp_get_topic_tag_name();
2320  
2321              // If capable, include a link to edit the tag
2322              if ( current_user_can( 'manage_topic_tags' ) ) {
2323                  $tag_data[] = '<a href="' . esc_url( bbp_get_topic_tag_edit_link() ) . '" class="bbp-edit-topic-tag-link">' . esc_html__( '(Edit)', 'bbpress' ) . '</a>';
2324              }
2325  
2326              // Implode the results of the tag data
2327              $pre_current_text = sprintf( esc_html__( 'Topic Tag: %s', 'bbpress' ), implode( ' ', $tag_data ) );
2328  
2329          // Edit Topic Tag
2330          } elseif ( bbp_is_topic_tag_edit() ) {
2331              $pre_current_text = esc_html__( 'Edit', 'bbpress' );
2332  
2333          // Single
2334          } else {
2335              $pre_current_text = get_the_title();
2336          }
2337  
2338          /** Parse Args ********************************************************/
2339  
2340          // Parse args
2341          $r = bbp_parse_args( $args, array(
2342  
2343              // HTML
2344              'before'          => '<div class="bbp-breadcrumb"><p>',
2345              'after'           => '</p></div>',
2346  
2347              // Separator
2348              'sep'             => is_rtl() ? __( '&lsaquo;', 'bbpress' ) : __( '&rsaquo;', 'bbpress' ),
2349              'pad_sep'         => 1,
2350              'sep_before'      => '<span class="bbp-breadcrumb-sep">',
2351              'sep_after'       => '</span>',
2352  
2353              // Crumbs
2354              'crumb_before'    => '',
2355              'crumb_after'     => '',
2356  
2357              // Home
2358              'include_home'    => $pre_include_home,
2359              'home_text'       => $pre_front_text,
2360  
2361              // Forum root
2362              'include_root'    => $pre_include_root,
2363              'root_text'       => $pre_root_text,
2364  
2365              // Current
2366              'include_current' => $pre_include_current,
2367              'current_text'    => $pre_current_text,
2368              'current_before'  => '<span class="bbp-breadcrumb-current">',
2369              'current_after'   => '</span>',
2370          ), 'get_breadcrumb' );
2371  
2372          /** Ancestors *********************************************************/
2373  
2374          // Get post ancestors
2375          if ( is_singular() || bbp_is_forum_edit() || bbp_is_topic_edit() || bbp_is_reply_edit() ) {
2376              $ancestors = array_reverse( (array) get_post_ancestors( get_the_ID() ) );
2377          }
2378  
2379          // Do we want to include a link to home?
2380          if ( ! empty( $r['include_home'] ) || empty( $r['home_text'] ) ) {
2381              $crumbs[] = '<a href="' . esc_url( home_url() ) . '" class="bbp-breadcrumb-home">' . $r['home_text'] . '</a>';
2382          }
2383  
2384          // Do we want to include a link to the forum root?
2385          if ( ! empty( $r['include_root'] ) || empty( $r['root_text'] ) ) {
2386  
2387              // Page exists at root slug path, so use its permalink
2388              $page = bbp_get_page_by_path( bbp_get_root_slug() );
2389              if ( ! empty( $page ) ) {
2390                  $root_url = get_permalink( $page->ID );
2391  
2392              // Use the root slug
2393              } else {
2394                  $root_url = get_post_type_archive_link( bbp_get_forum_post_type() );
2395              }
2396  
2397              // Add the breadcrumb
2398              $crumbs[] = '<a href="' . esc_url( $root_url ) . '" class="bbp-breadcrumb-root">' . $r['root_text'] . '</a>';
2399          }
2400  
2401          // Ancestors exist
2402          if ( ! empty( $ancestors ) ) {
2403  
2404              // Loop through parents
2405              foreach ( (array) $ancestors as $parent_id ) {
2406  
2407                  // Parents
2408                  $parent = get_post( $parent_id );
2409  
2410                  // Skip parent if empty or error
2411                  if ( empty( $parent ) || is_wp_error( $parent ) ) {
2412                      continue;
2413                  }
2414  
2415                  // Switch through post_type to ensure correct filters are applied
2416                  switch ( $parent->post_type ) {
2417  
2418                      // Forum
2419                      case bbp_get_forum_post_type() :
2420                          $crumbs[] = '<a href="' . esc_url( bbp_get_forum_permalink( $parent->ID ) ) . '" class="bbp-breadcrumb-forum">' . bbp_get_forum_title( $parent->ID ) . '</a>';
2421                          break;
2422  
2423                      // Topic
2424                      case bbp_get_topic_post_type() :
2425                          $crumbs[] = '<a href="' . esc_url( bbp_get_topic_permalink( $parent->ID ) ) . '" class="bbp-breadcrumb-topic">' . bbp_get_topic_title( $parent->ID ) . '</a>';
2426                          break;
2427  
2428                      // Reply (Note: not in most themes)
2429                      case bbp_get_reply_post_type() :
2430                          $crumbs[] = '<a href="' . esc_url( bbp_get_reply_permalink( $parent->ID ) ) . '" class="bbp-breadcrumb-reply">' . bbp_get_reply_title( $parent->ID ) . '</a>';
2431                          break;
2432  
2433                      // WordPress Post/Page/Other
2434                      default :
2435                          $crumbs[] = '<a href="' . esc_url( get_permalink( $parent->ID ) ) . '" class="bbp-breadcrumb-item">' . get_the_title( $parent->ID ) . '</a>';
2436                          break;
2437                  }
2438              }
2439  
2440          // Edit topic tag
2441          } elseif ( bbp_is_topic_tag_edit() ) {
2442              $crumbs[] = '<a href="' . esc_url( get_term_link( bbp_get_topic_tag_id(), bbp_get_topic_tag_tax_id() ) ) . '" class="bbp-breadcrumb-topic-tag">' . sprintf( esc_html__( 'Topic Tag: %s', 'bbpress' ), bbp_get_topic_tag_name() ) . '</a>';
2443  
2444          // Search
2445          } elseif ( bbp_is_search() && bbp_get_search_terms() ) {
2446              $crumbs[] = '<a href="' . esc_url( bbp_get_search_url() ) . '" class="bbp-breadcrumb-search">' . esc_html__( 'Search', 'bbpress' ) . '</a>';
2447          }
2448  
2449          /** Current ***********************************************************/
2450  
2451          // Add current page to breadcrumb
2452          if ( ! empty( $r['include_current'] ) || empty( $r['current_text'] ) ) {
2453              $crumbs[] = $r['current_before'] . $r['current_text'] . $r['current_after'];
2454          }
2455  
2456          /** Separator *********************************************************/
2457  
2458          // Wrap the separator in before/after before padding and filter
2459          if ( ! empty( $r['sep'] ) ) {
2460              $sep = $r['sep_before'] . $r['sep'] . $r['sep_after'];
2461          } else {
2462              $sep = '';
2463          }
2464  
2465          // Pad the separator
2466          if ( ! empty( $r['pad_sep'] ) ) {
2467              if ( function_exists( 'mb_strlen' ) ) {
2468                  $sep = str_pad( $sep, mb_strlen( $sep ) + ( (int) $r['pad_sep'] * 2 ), ' ', STR_PAD_BOTH );
2469              } else {
2470                  $sep = str_pad( $sep, strlen( $sep ) + ( (int) $r['pad_sep'] * 2 ), ' ', STR_PAD_BOTH );
2471              }
2472          }
2473  
2474          /** Finish Up *********************************************************/
2475  
2476          // Filter the separator and breadcrumb
2477          $sep    = apply_filters( 'bbp_breadcrumb_separator', $sep    );
2478          $crumbs = apply_filters( 'bbp_breadcrumbs',          $crumbs );
2479  
2480          // Build the trail
2481          $trail  = ! empty( $crumbs ) ? ( $r['before'] . $r['crumb_before'] . implode( $sep . $r['crumb_after'] . $r['crumb_before'], $crumbs ) . $r['crumb_after'] . $r['after'] ) : '';
2482  
2483          // Filter & return
2484          return apply_filters( 'bbp_get_breadcrumb', $trail, $crumbs, $r, $args );
2485      }
2486  
2487  /** Topic Tags ***************************************************************/
2488  
2489  /**
2490   * Output all of the allowed tags in HTML format with attributes.
2491   *
2492   * This is useful for displaying in the post area, which elements and
2493   * attributes are supported. As well as any plugins which want to display it.
2494   *
2495   * @since 2.0.0 bbPress (r2780)
2496   */
2497  function bbp_allowed_tags() {
2498      echo bbp_get_allowed_tags();
2499  }
2500      /**
2501       * Display all of the allowed tags in HTML format with attributes.
2502       *
2503       * This is useful for displaying in the post area, which elements and
2504       * attributes are supported. As well as any plugins which want to display it.
2505       *
2506       * @since 2.0.0 bbPress (r2780)
2507       *
2508       * @return string HTML allowed tags entity encoded.
2509       */
2510  	function bbp_get_allowed_tags() {
2511  
2512          $allowed = '';
2513  
2514          foreach ( (array) bbp_kses_allowed_tags() as $tag => $attributes ) {
2515              $allowed .= '<' . $tag;
2516              if ( 0 < count( $attributes ) ) {
2517                  foreach ( array_keys( $attributes ) as $attribute ) {
2518                      $allowed .= ' ' . $attribute . '=""';
2519                  }
2520              }
2521              $allowed .= '> ';
2522          }
2523  
2524          // Filter & return
2525          return apply_filters( 'bbp_get_allowed_tags', htmlentities( $allowed ) );
2526      }
2527  
2528  /** Errors & Messages *********************************************************/
2529  
2530  /**
2531   * Display possible errors & messages inside a template file
2532   *
2533   * @since 2.0.0 bbPress (r2688)
2534   */
2535  function bbp_template_notices() {
2536  
2537      // Bail if no notices or errors
2538      if ( ! bbp_has_errors() ) {
2539          return;
2540      }
2541  
2542      // Define local variable(s)
2543      $errors = $messages = array();
2544  
2545      // Get bbPress
2546      $bbp = bbpress();
2547  
2548      // Loop through notices
2549      foreach ( $bbp->errors->get_error_codes() as $code ) {
2550  
2551          // Get notice severity
2552          $severity = $bbp->errors->get_error_data( $code );
2553  
2554          // Loop through notices and separate errors from messages
2555          foreach ( $bbp->errors->get_error_messages( $code ) as $error ) {
2556              if ( 'message' === $severity ) {
2557                  $messages[] = $error;
2558              } else {
2559                  $errors[]   = $error;
2560              }
2561          }
2562      }
2563  
2564      // Display errors first...
2565      if ( ! empty( $errors ) ) : ?>
2566  
2567          <div class="bbp-template-notice error" role="alert" tabindex="-1">
2568              <ul>
2569                  <li><?php echo implode( "</li>\n<li>", $errors ); ?></li>
2570              </ul>
2571          </div>
2572  
2573      <?php endif;
2574  
2575      // ...and messages last
2576      if ( ! empty( $messages ) ) : ?>
2577  
2578          <div class="bbp-template-notice">
2579              <ul>
2580                  <li><?php echo implode( "</li>\n<li>", $messages ); ?></li>
2581              </ul>
2582          </div>
2583  
2584      <?php endif;
2585  }
2586  
2587  /** Login/logout/register/lost pass *******************************************/
2588  
2589  /**
2590   * Output the logout link
2591   *
2592   * @since 2.0.0 bbPress (r2827)
2593   *
2594   * @param string $redirect_to Redirect to url
2595   */
2596  function bbp_logout_link( $redirect_to = '' ) {
2597      echo bbp_get_logout_link( $redirect_to );
2598  }
2599      /**
2600       * Return the logout link
2601       *
2602       * @since 2.0.0 bbPress (r2827)
2603       *
2604       * @param string $redirect_to Redirect to url
2605       *                        redirect to url
2606       * @return string The logout link
2607       */
2608  	function bbp_get_logout_link( $redirect_to = '' ) {
2609  
2610          // Build the link
2611          $link = '<a href="' . wp_logout_url( $redirect_to ) . '" class="button logout-link">' . esc_html__( 'Log Out', 'bbpress' ) . '</a>';
2612  
2613          // Filter & return
2614          return apply_filters( 'bbp_get_logout_link', $link, $redirect_to );
2615      }
2616  
2617  /** Title *********************************************************************/
2618  
2619  /**
2620   * Custom page title for bbPress pages
2621   *
2622   * @since 2.0.0 bbPress (r2788)
2623   *
2624   * @param string $title Optional. The title (not used).
2625   * @param string $sep Optional, default is '&raquo;'. How to separate the
2626   *                     various items within the page title.
2627   * @param string $seplocation Optional. Direction to display title, 'right'.
2628   *                        separator and separator location
2629   * @return string The title
2630   */
2631  function bbp_title( $title = '', $sep = '&raquo;', $seplocation = '' ) {
2632  
2633      // Title array
2634      $new_title = array();
2635  
2636      /** Archives **************************************************************/
2637  
2638      // Forum Archive
2639      if ( bbp_is_forum_archive() ) {
2640          $new_title['text'] = bbp_get_forum_archive_title();
2641  
2642      // Topic Archive
2643      } elseif ( bbp_is_topic_archive() ) {
2644          $new_title['text'] = bbp_get_topic_archive_title();
2645  
2646      /** Edit ******************************************************************/
2647  
2648      // Forum edit page
2649      } elseif ( bbp_is_forum_edit() ) {
2650          $new_title['text']   = bbp_get_forum_title();
2651          $new_title['format'] = esc_attr__( 'Forum Edit: %s', 'bbpress' );
2652  
2653      // Topic edit page
2654      } elseif ( bbp_is_topic_edit() ) {
2655          $new_title['text']   = bbp_get_topic_title();
2656          $new_title['format'] = esc_attr__( 'Topic Edit: %s', 'bbpress' );
2657  
2658      // Reply edit page
2659      } elseif ( bbp_is_reply_edit() ) {
2660          $new_title['text']   = bbp_get_reply_title();
2661          $new_title['format'] = esc_attr__( 'Reply Edit: %s', 'bbpress' );
2662  
2663      // Topic tag edit page
2664      } elseif ( bbp_is_topic_tag_edit() ) {
2665          $new_title['text']   = bbp_get_topic_tag_name();
2666          $new_title['format'] = esc_attr__( 'Topic Tag Edit: %s', 'bbpress' );
2667  
2668      /** Singles ***************************************************************/
2669  
2670      // Forum page
2671      } elseif ( bbp_is_single_forum() ) {
2672          $new_title['text']   = bbp_get_forum_title();
2673          $new_title['format'] = esc_attr__( 'Forum: %s', 'bbpress' );
2674  
2675      // Topic page
2676      } elseif ( bbp_is_single_topic() ) {
2677          $new_title['text']   = bbp_get_topic_title();
2678          $new_title['format'] = esc_attr__( 'Topic: %s', 'bbpress' );
2679  
2680      // Replies
2681      } elseif ( bbp_is_single_reply() ) {
2682          $new_title['text']   = bbp_get_reply_title();
2683  
2684      // Topic tag page
2685      } elseif ( bbp_is_topic_tag() || get_query_var( 'bbp_topic_tag' ) ) {
2686          $new_title['text']   = bbp_get_topic_tag_name();
2687          $new_title['format'] = esc_attr__( 'Topic Tag: %s', 'bbpress' );
2688  
2689      /** Users *****************************************************************/
2690  
2691      // Profile page
2692      } elseif ( bbp_is_single_user() ) {
2693  
2694          // Is user viewing their own profile?
2695          $is_user_home = bbp_is_user_home();
2696  
2697          // User topics created
2698          if ( bbp_is_single_user_topics() ) {
2699              if ( true === $is_user_home ) {
2700                  $new_title['text'] = esc_attr__( 'Your Topics', 'bbpress' );
2701              } else {
2702                  $new_title['text'] = get_userdata( bbp_get_user_id() )->display_name;
2703                  /* translators: user's display name */
2704                  $new_title['format'] = esc_attr__( "%s's Topics", 'bbpress' );
2705              }
2706  
2707          // User replies created
2708          } elseif ( bbp_is_single_user_replies() ) {
2709              if ( true === $is_user_home ) {
2710                  $new_title['text'] = esc_attr__( 'Your Replies', 'bbpress' );
2711              } else {
2712                  $new_title['text'] = get_userdata( bbp_get_user_id() )->display_name;
2713                  /* translators: user's display name */
2714                  $new_title['format'] = esc_attr__( "%s's Replies", 'bbpress' );
2715              }
2716  
2717          // User favorites
2718          } elseif ( bbp_is_favorites() ) {
2719              if ( true === $is_user_home ) {
2720                  $new_title['text'] = esc_attr__( 'Your Favorites', 'bbpress' );
2721              } else {
2722                  $new_title['text'] = get_userdata( bbp_get_user_id() )->display_name;
2723                  /* translators: user's display name */
2724                  $new_title['format'] = esc_attr__( "%s's Favorites", 'bbpress' );
2725              }
2726  
2727          // User subscriptions
2728          } elseif ( bbp_is_subscriptions() ) {
2729              if ( true === $is_user_home ) {
2730                  $new_title['text'] = esc_attr__( 'Your Subscriptions', 'bbpress' );
2731              } else {
2732                  $new_title['text'] = get_userdata( bbp_get_user_id() )->display_name;
2733                  /* translators: user's display name */
2734                  $new_title['format'] = esc_attr__( "%s's Subscriptions", 'bbpress' );
2735              }
2736  
2737          // User "home"
2738          } else {
2739              if ( true === $is_user_home ) {
2740                  $new_title['text'] = esc_attr__( 'Your Profile', 'bbpress' );
2741              } else {
2742                  $new_title['text'] = get_userdata( bbp_get_user_id() )->display_name;
2743                  /* translators: user's display name */
2744                  $new_title['format'] = esc_attr__( "%s's Profile", 'bbpress' );
2745              }
2746          }
2747  
2748      // Profile edit page
2749      } elseif ( bbp_is_single_user_edit() ) {
2750  
2751          // Current user
2752          if ( bbp_is_user_home_edit() ) {
2753              $new_title['text']   = esc_attr__( 'Edit Your Profile', 'bbpress' );
2754  
2755          // Other user
2756          } else {
2757              $new_title['text']   = get_userdata( bbp_get_user_id() )->display_name;
2758              $new_title['format'] = esc_attr__( "Edit %s's Profile", 'bbpress' );
2759          }
2760  
2761      /** Views *****************************************************************/
2762  
2763      // Views
2764      } elseif ( bbp_is_single_view() ) {
2765          $new_title['text']   = bbp_get_view_title();
2766          $new_title['format'] = esc_attr__( 'View: %s', 'bbpress' );
2767  
2768      /** Search ****************************************************************/
2769  
2770      // Search
2771      } elseif ( bbp_is_search() ) {
2772          $new_title['text'] = bbp_get_search_title();
2773      }
2774  
2775      // This filter is deprecated. Use 'bbp_before_title_parse_args' instead.
2776      $new_title = apply_filters( 'bbp_raw_title_array', $new_title );
2777  
2778      // Set title array defaults
2779      $new_title = bbp_parse_args( $new_title, array(
2780          'text'   => $title,
2781          'format' => '%s'
2782      ), 'title' );
2783  
2784      // Get the formatted raw title
2785      $new_title = sprintf( $new_title['format'], $new_title['text'] );
2786  
2787      // Filter the raw title
2788      $new_title = apply_filters( 'bbp_raw_title', $new_title, $sep, $seplocation );
2789  
2790      // Compare new title with original title
2791      if ( $new_title === $title ) {
2792          return $title;
2793      }
2794  
2795      // Temporary separator, for accurate flipping, if necessary
2796      $t_sep  = '%WP_TITILE_SEP%';
2797      $prefix = '';
2798  
2799      if ( ! empty( $new_title ) ) {
2800          $prefix = " $sep ";
2801      }
2802  
2803      // sep on right, so reverse the order
2804      if ( 'right' === $seplocation ) {
2805          $new_title_array = array_reverse( explode( $t_sep, $new_title ) );
2806          $new_title       = implode( " $sep ", $new_title_array ) . $prefix;
2807  
2808      // sep on left, do not reverse
2809      } else {
2810          $new_title_array = explode( $t_sep, $new_title );
2811          $new_title       = $prefix . implode( " $sep ", $new_title_array );
2812      }
2813  
2814      // Filter & return
2815      return apply_filters( 'bbp_title', $new_title, $sep, $seplocation );
2816  }


Generated: Thu Jul 9 01:01:21 2020 Cross-referenced by PHPXref 0.7.1