[ 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      // Default classes
 971      $bbp_classes = array( 'no-js' );
 972  
 973      /** Archives **************************************************************/
 974  
 975      if ( bbp_is_forum_archive() ) {
 976          $bbp_classes[] = bbp_get_forum_post_type() . '-archive';
 977  
 978      } elseif ( bbp_is_topic_archive() ) {
 979          $bbp_classes[] = bbp_get_topic_post_type() . '-archive';
 980  
 981      /** Topic Tags ************************************************************/
 982  
 983      } elseif ( bbp_is_topic_tag() ) {
 984          $bbp_classes[] = bbp_get_topic_tag_tax_id();
 985          $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-' . bbp_get_topic_tag_slug();
 986          $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-' . bbp_get_topic_tag_id();
 987      } elseif ( bbp_is_topic_tag_edit() ) {
 988          $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-edit';
 989          $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-' . bbp_get_topic_tag_slug() . '-edit';
 990          $bbp_classes[] = bbp_get_topic_tag_tax_id() . '-' . bbp_get_topic_tag_id()   . '-edit';
 991  
 992      /** Components ************************************************************/
 993  
 994      } elseif ( bbp_is_single_forum() ) {
 995          $bbp_classes[] = bbp_get_forum_post_type();
 996  
 997      } elseif ( bbp_is_single_topic() ) {
 998          $bbp_classes[] = bbp_get_topic_post_type();
 999  
1000      } elseif ( bbp_is_single_reply() ) {
1001          $bbp_classes[] = bbp_get_reply_post_type();
1002  
1003      } elseif ( bbp_is_topic_edit() ) {
1004          $bbp_classes[] = bbp_get_topic_post_type() . '-edit';
1005  
1006      } elseif ( bbp_is_topic_merge() ) {
1007          $bbp_classes[] = bbp_get_topic_post_type() . '-merge';
1008  
1009      } elseif ( bbp_is_topic_split() ) {
1010          $bbp_classes[] = bbp_get_topic_post_type() . '-split';
1011  
1012      } elseif ( bbp_is_reply_edit() ) {
1013          $bbp_classes[] = bbp_get_reply_post_type() . '-edit';
1014  
1015      } elseif ( bbp_is_reply_move() ) {
1016          $bbp_classes[] = bbp_get_reply_post_type() . '-move';
1017  
1018      } elseif ( bbp_is_single_view() ) {
1019          $bbp_classes[] = 'bbp-view';
1020          $bbp_classes[] = 'bbp-view-' . bbp_get_view_id();
1021  
1022      /** User ******************************************************************/
1023  
1024      } elseif ( bbp_is_single_user_edit() ) {
1025          $bbp_classes[] = 'bbp-user-edit';
1026          $bbp_classes[] = 'single';
1027          $bbp_classes[] = 'singular';
1028  
1029      } elseif ( bbp_is_single_user() ) {
1030          $bbp_classes[] = 'bbp-user-page';
1031          $bbp_classes[] = 'single';
1032          $bbp_classes[] = 'singular';
1033  
1034      } elseif ( bbp_is_user_home() ) {
1035          $bbp_classes[] = 'bbp-user-home';
1036          $bbp_classes[] = 'single';
1037          $bbp_classes[] = 'singular';
1038  
1039      } elseif ( bbp_is_user_home_edit() ) {
1040          $bbp_classes[] = 'bbp-user-home-edit';
1041          $bbp_classes[] = 'single';
1042          $bbp_classes[] = 'singular';
1043  
1044      } elseif ( bbp_is_topics_created() ) {
1045          $bbp_classes[] = 'bbp-topics-created';
1046          $bbp_classes[] = 'single';
1047          $bbp_classes[] = 'singular';
1048  
1049      } elseif ( bbp_is_replies_created() ) {
1050          $bbp_classes[] = 'bbp-replies-created';
1051          $bbp_classes[] = 'single';
1052          $bbp_classes[] = 'singular';
1053  
1054      } elseif ( bbp_is_favorites() ) {
1055          $bbp_classes[] = 'bbp-favorites';
1056          $bbp_classes[] = 'single';
1057          $bbp_classes[] = 'singular';
1058  
1059      } elseif ( bbp_is_subscriptions() ) {
1060          $bbp_classes[] = 'bbp-subscriptions';
1061          $bbp_classes[] = 'single';
1062          $bbp_classes[] = 'singular';
1063  
1064      /** Search ****************************************************************/
1065  
1066      } elseif ( bbp_is_search() ) {
1067          $bbp_classes[] = 'bbp-search';
1068          $bbp_classes[] = 'forum-search';
1069  
1070      } elseif ( bbp_is_search_results() ) {
1071          $bbp_classes[] = 'bbp-search-results';
1072          $bbp_classes[] = 'forum-search-results';
1073  
1074      /** Shortcodes ************************************************************/
1075  
1076      } elseif ( bbp_has_shortcode() ) {
1077          $bbp_classes[] = 'bbp-shortcode';
1078      }
1079  
1080      /** Clean up **************************************************************/
1081  
1082      // Add bbPress class if we are within a bbPress page
1083      if ( ! empty( $bbp_classes ) ) {
1084          $bbp_classes[] = 'bbpress';
1085      }
1086  
1087      // Merge WP classes with bbPress classes and remove any duplicates
1088      $classes = array_unique( array_merge( (array) $bbp_classes, (array) $wp_classes ) );
1089  
1090      // Deprecated filter (do not use)
1091      $classes = apply_filters( 'bbp_get_the_body_class', $classes, $bbp_classes, $wp_classes, $custom_classes );
1092  
1093      // Filter & return
1094      return (array) apply_filters( 'bbp_body_class', $classes, $bbp_classes, $wp_classes, $custom_classes );
1095  }
1096  
1097  /**
1098   * Check if text contains a bbPress shortcode.
1099   *
1100   * Loops through registered bbPress shortcodes and keeps track of which ones
1101   * were used in a blob of text. If no text is passed, the current global post
1102   * content is assumed.
1103   *
1104   * A preliminary strpos() is performed before looping through each shortcode, to
1105   * prevent unnecessarily processing.
1106   *
1107   * @since 2.6.0
1108   *
1109   * @param string $text
1110   * @return bool
1111   */
1112  function bbp_has_shortcode( $text = '' ) {
1113  
1114      // Default return value
1115      $retval = false;
1116      $found  = array();
1117  
1118      // Fallback to global post_content
1119      if ( empty( $text ) && is_singular() ) {
1120          $text = bbp_get_global_post_field( 'post_content', 'raw' );
1121      }
1122  
1123      // Skip if empty, or string doesn't contain the bbPress shortcode prefix
1124      if ( ! empty( $text ) && ( false !== strpos( $text, '[bbp' ) ) ) {
1125  
1126          // Get possible shortcodes
1127          $codes = array_keys( bbpress()->shortcodes->codes );
1128  
1129          // Loop through codes
1130          foreach ( $codes as $code ) {
1131  
1132              // Looking for shortcode in text
1133              if ( has_shortcode( $text, $code ) ) {
1134                  $retval  = true;
1135                  $found[] = $code;
1136              }
1137          }
1138      }
1139  
1140      // Filter & return
1141      return (bool) apply_filters( 'bbp_has_shortcode', $retval, $found, $text );
1142  }
1143  
1144  /**
1145   * Use the above is_() functions to return if in any bbPress page
1146   *
1147   * @since 2.0.0 bbPress (r3344)
1148   *
1149   * @return bool In a bbPress page
1150   */
1151  function is_bbpress() {
1152  
1153      // Default to false
1154      $retval = false;
1155  
1156      // Bail if main query has not been populated.
1157      if ( ! bbp_get_wp_query() ) {
1158          _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' );
1159          return $retval;
1160      }
1161  
1162      /** Archives **************************************************************/
1163  
1164      if ( bbp_is_forum_archive() ) {
1165          $retval = true;
1166  
1167      } elseif ( bbp_is_topic_archive() ) {
1168          $retval = true;
1169  
1170      /** Topic Tags ************************************************************/
1171  
1172      } elseif ( bbp_is_topic_tag() ) {
1173          $retval = true;
1174  
1175      } elseif ( bbp_is_topic_tag_edit() ) {
1176          $retval = true;
1177  
1178      /** Components ************************************************************/
1179  
1180      } elseif ( bbp_is_single_forum() ) {
1181          $retval = true;
1182  
1183      } elseif ( bbp_is_single_topic() ) {
1184          $retval = true;
1185  
1186      } elseif ( bbp_is_single_reply() ) {
1187          $retval = true;
1188  
1189      } elseif ( bbp_is_topic_edit() ) {
1190          $retval = true;
1191  
1192      } elseif ( bbp_is_topic_merge() ) {
1193          $retval = true;
1194  
1195      } elseif ( bbp_is_topic_split() ) {
1196          $retval = true;
1197  
1198      } elseif ( bbp_is_reply_edit() ) {
1199          $retval = true;
1200  
1201      } elseif ( bbp_is_reply_move() ) {
1202          $retval = true;
1203  
1204      } elseif ( bbp_is_single_view() ) {
1205          $retval = true;
1206  
1207      /** User ******************************************************************/
1208  
1209      } elseif ( bbp_is_single_user_edit() ) {
1210          $retval = true;
1211  
1212      } elseif ( bbp_is_single_user() ) {
1213          $retval = true;
1214  
1215      } elseif ( bbp_is_user_home() ) {
1216          $retval = true;
1217  
1218      } elseif ( bbp_is_user_home_edit() ) {
1219          $retval = true;
1220  
1221      } elseif ( bbp_is_topics_created() ) {
1222          $retval = true;
1223  
1224      } elseif ( bbp_is_replies_created() ) {
1225          $retval = true;
1226  
1227      } elseif ( bbp_is_favorites() ) {
1228          $retval = true;
1229  
1230      } elseif ( bbp_is_subscriptions() ) {
1231          $retval = true;
1232  
1233      /** Search ****************************************************************/
1234  
1235      } elseif ( bbp_is_search() ) {
1236          $retval = true;
1237  
1238      } elseif ( bbp_is_search_results() ) {
1239          $retval = true;
1240  
1241      /** Shortcodes ************************************************************/
1242  
1243      } elseif ( bbp_has_shortcode() ) {
1244          $retval = true;
1245      }
1246  
1247      /** Done ******************************************************************/
1248  
1249      // Filter & return
1250      return (bool) apply_filters( 'is_bbpress', $retval );
1251  }
1252  
1253  /** Forms *********************************************************************/
1254  
1255  /**
1256   * Output the login form action url
1257   *
1258   * @since 2.0.0 bbPress (r2815)
1259   *
1260   * @param array $args This function supports these arguments:
1261   *  - action: The action being taken
1262   *  - context: The context the action is being taken from
1263   */
1264  function bbp_wp_login_action( $args = array() ) {
1265      echo esc_url( bbp_get_wp_login_action( $args ) );
1266  }
1267  
1268      /**
1269       * Return the login form action url
1270       *
1271       * @since 2.6.0 bbPress (r5684)
1272       *
1273       * @param array $args This function supports these arguments:
1274       *  - action: The action being taken
1275       *  - context: The context the action is being taken from
1276       */
1277  	function bbp_get_wp_login_action( $args = array() ) {
1278  
1279          // Parse arguments against default values
1280          $r = bbp_parse_args( $args, array(
1281              'action'  => '',
1282              'context' => '',
1283              'url'     => 'wp-login.php'
1284          ), 'login_action' );
1285  
1286          // Add action as query arg
1287          $login_url = ! empty( $r['action'] )
1288              ? add_query_arg( array( 'action' => $r['action'] ), $r['url'] )
1289              : $r['url'];
1290  
1291          $login_url = site_url( $login_url, $r['context'] );
1292  
1293          // Filter & return
1294          return apply_filters( 'bbp_get_wp_login_action', $login_url, $r, $args );
1295      }
1296  
1297  /**
1298   * Output hidden request URI field for user forms.
1299   *
1300   * The referer link is the current Request URI from the server super global. To
1301   * check the field manually, use bbp_get_redirect_to().
1302   *
1303   * @since 2.0.0 bbPress (r2815)
1304   *
1305   * @param string $redirect_to Pass a URL to redirect to
1306   */
1307  function bbp_redirect_to_field( $redirect_to = '' ) {
1308  
1309      // Make sure we are directing somewhere
1310      if ( empty( $redirect_to ) ) {
1311          if ( isset( $_SERVER['REQUEST_URI'] ) ) {
1312              $redirect_to = bbp_get_url_scheme() . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
1313          } else {
1314              $redirect_to = wp_get_referer();
1315          }
1316      }
1317  
1318      // Remove loggedout query arg if it's there
1319      $redirect_to    = remove_query_arg( 'loggedout', $redirect_to );
1320      $redirect_field = '<input type="hidden" id="bbp_redirect_to" name="redirect_to" value="' . esc_url( $redirect_to ) . '" />';
1321  
1322      // Filter & return
1323      echo apply_filters( 'bbp_redirect_to_field', $redirect_field, $redirect_to );
1324  }
1325  
1326  /**
1327   * Echo sanitized $_REQUEST value.
1328   *
1329   * Use the $input_type parameter to properly process the value. This
1330   * ensures correct sanitization of the value for the receiving input.
1331   *
1332   * @since 2.0.0 bbPress (r2815)
1333   *
1334   * @param string $request Name of $_REQUEST to look for
1335   * @param string $input_type Type of input. Default: text. Accepts:
1336   *                            textarea|password|select|radio|checkbox
1337   */
1338  function bbp_sanitize_val( $request = '', $input_type = 'text' ) {
1339      echo bbp_get_sanitize_val( $request, $input_type );
1340  }
1341      /**
1342       * Return sanitized $_REQUEST value.
1343       *
1344       * Use the $input_type parameter to properly process the value. This
1345       * ensures correct sanitization of the value for the receiving input.
1346       *
1347       * @since 2.0.0 bbPress (r2815)
1348       *
1349       * @param string $request Name of $_REQUEST to look for
1350       * @param string $input_type Type of input. Default: text. Accepts:
1351       *                            textarea|password|select|radio|checkbox
1352       *
1353       * @return string Sanitized value ready for screen display
1354       */
1355  	function bbp_get_sanitize_val( $request = '', $input_type = 'text' ) {
1356  
1357          // Check that requested
1358          if ( empty( $_REQUEST[ $request ] ) ) {
1359              return false;
1360          }
1361  
1362          // Set request varaible
1363          $pre_ret_val = $_REQUEST[ $request ];
1364  
1365          // Treat different kinds of fields in different ways
1366          switch ( $input_type ) {
1367              case 'text'     :
1368              case 'textarea' :
1369                  $retval = esc_attr( wp_unslash( $pre_ret_val ) );
1370                  break;
1371  
1372              case 'password' :
1373              case 'select'   :
1374              case 'radio'    :
1375              case 'checkbox' :
1376              default :
1377                  $retval = esc_attr( $pre_ret_val );
1378                  break;
1379          }
1380  
1381          // Filter & return
1382          return apply_filters( 'bbp_get_sanitize_val', $retval, $request, $input_type );
1383      }
1384  
1385  /**
1386   * Output the current tab index of a given form
1387   *
1388   * Use this function to handle the tab indexing of user facing forms within a
1389   * template file. Calling this function will automatically increment the global
1390   * tab index by default.
1391   *
1392   * @since 2.0.0 bbPress (r2810)
1393   *
1394   * @deprecated 2.6.0 bbPress (r5561)
1395   *
1396   * @link https://bbpress.trac.wordpress.org/attachment/ticket/2714 Trac Ticket
1397   * @param int $auto_increment Optional. Default true. Set to false to prevent
1398   *                             increment
1399   */
1400  function bbp_tab_index( $auto_increment = true ) {
1401      echo bbp_get_tab_index( $auto_increment );
1402  }
1403  
1404      /**
1405       * Return the current tab index of a given form
1406       *
1407       * Use this function to handle the tab indexing of user facing forms
1408       * within a template file. Calling this function will automatically
1409       * increment the global tab index by default.
1410       *
1411       * @since 2.0.0 bbPress (r2810)
1412       *
1413       * @deprecated 2.6.0 bbPress (r5561)
1414       *
1415       * @link https://bbpress.trac.wordpress.org/attachment/ticket/2714 Trac Ticket
1416       * @param int $auto_increment Optional. Default true. Set to false to
1417       *                             prevent the increment
1418       * @return int $bbp->tab_index The global tab index
1419       */
1420  	function bbp_get_tab_index( $auto_increment = true ) {
1421          $bbp = bbpress();
1422  
1423          if ( true === $auto_increment ) {
1424              ++$bbp->tab_index;
1425          }
1426  
1427          // Filter & return
1428          return apply_filters( 'bbp_get_tab_index', (int) $bbp->tab_index );
1429      }
1430  
1431  /**
1432   * Output a "tabindex" attribute for an element, if an index was passed.
1433   *
1434   * This helper function is in use, but it is generally considered impolite to
1435   * override the "tabindex" attribute beyond what the browser naturally assigns.
1436   *
1437   * Most internal usages pass `false` which results in no attribute being used.
1438   *
1439   * @since 2.6.0 bbPress (r6424)
1440   *
1441   * @param mixed $tab False to skip, any integer to use
1442   */
1443  function bbp_tab_index_attribute( $tab = false ) {
1444      echo bbp_get_tab_index_attribute( $tab );
1445  }
1446  
1447      /**
1448       * Return a "tabindex" attribute for an element, if an index was passed.
1449       *
1450       * This helper function is in use, but it is generally considered impolite to
1451       * override the "tabindex" attribute beyond what the browser naturally assigns.
1452       *
1453       * Most internal usages pass `false` which results in no attribute being used.
1454       *
1455       * @since 2.6.0 bbPress (r6424)
1456       *
1457       * @param mixed $tab False to skip, any integer to use
1458       *
1459       * @return string
1460       */
1461  	function bbp_get_tab_index_attribute( $tab = false ) {
1462  
1463          // Get attribute
1464          $attr = is_numeric( $tab )
1465              ? ' tabindex="' . (int) $tab . '"'
1466              : '';
1467  
1468          // Filter & return
1469          return apply_filters( 'bbp_get_tab_index_attribute', $attr, $tab );
1470      }
1471  
1472  /**
1473   * Output a select box allowing to pick which forum/topic a new topic/reply
1474   * belongs in.
1475   *
1476   * Can be used for any post type, but is mostly used for topics and forums.
1477   *
1478   * @since 2.0.0 bbPress (r2746)
1479   *
1480   * @param array $args See {@link bbp_get_dropdown()} for arguments
1481   */
1482  function bbp_dropdown( $args = array() ) {
1483      echo bbp_get_dropdown( $args );
1484  }
1485      /**
1486       * Return a select box allowing to pick which forum/topic a new
1487       * topic/reply belongs in.
1488       *
1489       * @since 2.0.0 bbPress (r2746)
1490       *
1491       * @param array $args The function supports these args:
1492       *  - post_type: Post type, defaults to bbp_get_forum_post_type() (bbp_forum)
1493       *  - selected: Selected ID, to not have any value as selected, pass
1494       *               anything smaller than 0 (due to the nature of select
1495       *               box, the first value would of course be selected -
1496       *               though you can have that as none (pass 'show_none' arg))
1497       *  - orderby: Defaults to 'menu_order title'
1498       *  - post_parent: Post parent. Defaults to 0
1499       *  - post_status: Which all post_statuses to find in? Can be an array
1500       *                  or CSV of publish, category, closed, private, spam,
1501       *                  trash (based on post type) - if not set, these are
1502       *                  automatically determined based on the post_type
1503       *  - posts_per_page: Retrieve all forums/topics. Defaults to -1 to get
1504       *                     all posts
1505       *  - walker: Which walker to use? Defaults to
1506       *             {@link BBP_Walker_Dropdown}
1507       *  - select_id: ID of the select box. Defaults to 'bbp_forum_id'
1508       *  - tab: Deprecated. Tabindex value. False or integer
1509       *  - options_only: Show only <options>? No <select>?
1510       *  - show_none: Boolean or String __( '&mdash; No Forum &mdash;', 'bbpress' )
1511       *  - disable_categories: Disable forum categories and closed forums?
1512       *                         Defaults to true. Only for forums and when
1513       * @return string The dropdown
1514       */
1515  	function bbp_get_dropdown( $args = array() ) {
1516  
1517          // Setup return value
1518          $retval = '';
1519  
1520          /** Arguments *********************************************************/
1521  
1522          // Parse arguments against default values
1523          $r = bbp_parse_args( $args, array(
1524  
1525              // Support for get_posts()
1526              'post_type'          => bbp_get_forum_post_type(),
1527              'post_parent'        => null,
1528              'post_status'        => null,
1529              'selected'           => 0,
1530              'include'            => array(),
1531              'exclude'            => array(),
1532              'numberposts'        => -1,
1533              'orderby'            => 'menu_order title',
1534              'order'              => 'ASC',
1535  
1536              // Preloaded content
1537              'posts'              => array(),
1538  
1539              // Custom hierarchy walkers
1540              'walker'             => '',
1541  
1542              // Output-related
1543              'select_id'          => 'bbp_forum_id',
1544              'select_class'       => 'bbp_dropdown',
1545              'tab'                => false,
1546              'options_only'       => false,
1547              'show_none'          => false,
1548              'disable_categories' => true,
1549              'disabled'           => ''
1550          ), 'get_dropdown' );
1551  
1552          // Fallback to our walker
1553          if ( empty( $r['walker'] ) ) {
1554              $r['walker']            = new BBP_Walker_Dropdown();
1555              $r['walker']->tree_type = $r['post_type'];
1556          }
1557  
1558          // Force 0
1559          if ( is_numeric( $r['selected'] ) && ( $r['selected'] < 0 ) ) {
1560              $r['selected'] = 0;
1561          }
1562  
1563          // Force array
1564          if ( ! empty( $r['include'] ) && ! is_array( $r['include'] ) ) {
1565              $r['include'] = explode( ',', $r['include'] );
1566          }
1567  
1568          // Force array
1569          if ( ! empty( $r['exclude'] ) && ! is_array( $r['exclude'] ) ) {
1570              $r['exclude'] = explode( ',', $r['exclude'] );
1571          }
1572  
1573          /** Setup Posts *******************************************************/
1574  
1575          /**
1576           * Allow passing of custom posts data
1577           *
1578           * @see bbp_get_reply_to_dropdown() as an example
1579           */
1580          if ( empty( $r['posts'] ) ) {
1581              $r['posts'] = get_posts( array(
1582                  'post_type'   => $r['post_type'],
1583                  'post_status' => $r['post_status'],
1584                  'post_parent' => $r['post_parent'],
1585                  'include'     => $r['include'],
1586                  'exclude'     => $r['exclude'],
1587                  'numberposts' => $r['numberposts'],
1588                  'orderby'     => $r['orderby'],
1589                  'order'       => $r['order'],
1590              ) );
1591          }
1592  
1593          /** Drop Down *********************************************************/
1594  
1595          // Build the opening tag for the select element
1596          if ( empty( $r['options_only'] ) ) {
1597  
1598              // Should this select appear disabled?
1599              $disabled  = disabled( isset( bbpress()->options[ $r['disabled'] ] ), true, false );
1600  
1601              // Setup the tab index attribute
1602              $tab       = ! empty( $r['tab'] ) ? ' tabindex="' . intval( $r['tab'] ) . '"' : '';
1603  
1604              // Open the select tag
1605              $retval   .= '<select name="' . esc_attr( $r['select_id'] ) . '" id="' . esc_attr( $r['select_id'] ) . '" class="' . esc_attr( $r['select_class'] ) . '"' . $disabled . $tab . '>' . "\n";
1606          }
1607  
1608          // Display a leading 'no-value' option, with or without custom text
1609          if ( ! empty( $r['show_none'] ) || ! empty( $r['none_found'] ) ) {
1610  
1611              // Open the 'no-value' option tag
1612              $retval .= "\t<option value=\"\" class=\"level-0\">";
1613  
1614              // Use deprecated 'none_found' first for backpat
1615              if ( ! empty( $r['none_found'] ) && is_string( $r['none_found'] ) ) {
1616                  $retval .= esc_html( $r['none_found'] );
1617  
1618              // Use 'show_none' second
1619              } elseif ( ! empty( $r['show_none'] ) && is_string( $r['show_none'] ) ) {
1620                  $retval .= esc_html( $r['show_none'] );
1621  
1622              // Otherwise, make some educated guesses
1623              } else {
1624  
1625                  // Switch the response based on post type
1626                  switch ( $r['post_type'] ) {
1627  
1628                      // Topics
1629                      case bbp_get_topic_post_type() :
1630                          $retval .= esc_html__( 'No topics available', 'bbpress' );
1631                          break;
1632  
1633                      // Forums
1634                      case bbp_get_forum_post_type() :
1635                          $retval .= esc_html__( 'No forums available', 'bbpress' );
1636                          break;
1637  
1638                      // Any other
1639                      default :
1640                          $retval .= esc_html__( 'None available', 'bbpress' );
1641                          break;
1642                  }
1643              }
1644  
1645              // Close the 'no-value' option tag
1646              $retval .= '</option>';
1647          }
1648  
1649          // Items found so walk the tree
1650          if ( ! empty( $r['posts'] ) ) {
1651              $retval .= walk_page_dropdown_tree( $r['posts'], 0, $r );
1652          }
1653  
1654          // Close the selecet tag
1655          if ( empty( $r['options_only'] ) ) {
1656              $retval .= '</select>';
1657          }
1658  
1659          // Filter & return
1660          return apply_filters( 'bbp_get_dropdown', $retval, $r, $args );
1661      }
1662  
1663  /**
1664   * Output the required hidden fields when creating/editing a forum
1665   *
1666   * @since 2.1.0 bbPress (r3553)
1667   */
1668  function bbp_forum_form_fields() {
1669  
1670      if ( bbp_is_forum_edit() ) : ?>
1671  
1672          <input type="hidden" name="action"       id="bbp_post_action" value="bbp-edit-forum" />
1673          <input type="hidden" name="bbp_forum_id" id="bbp_forum_id"    value="<?php bbp_forum_id(); ?>" />
1674  
1675          <?php if ( current_user_can( 'unfiltered_html' ) ) :
1676              wp_nonce_field( 'bbp-unfiltered-html-forum_' . bbp_get_forum_id(), '_bbp_unfiltered_html_forum', false );
1677          endif; ?>
1678  
1679          <?php wp_nonce_field( 'bbp-edit-forum_' . bbp_get_forum_id() );
1680  
1681      else :
1682  
1683          if ( bbp_is_single_forum() ) : ?>
1684  
1685              <input type="hidden" name="bbp_forum_parent_id" id="bbp_forum_parent_id" value="<?php bbp_forum_parent_id(); ?>" />
1686  
1687          <?php endif; ?>
1688  
1689          <input type="hidden" name="action" id="bbp_post_action" value="bbp-new-forum" />
1690  
1691          <?php if ( current_user_can( 'unfiltered_html' ) ) :
1692              wp_nonce_field( 'bbp-unfiltered-html-forum_new', '_bbp_unfiltered_html_forum', false );
1693          endif; ?>
1694  
1695          <?php wp_nonce_field( 'bbp-new-forum' );
1696  
1697      endif;
1698  }
1699  
1700  /**
1701   * Output the required hidden fields when creating/editing a topic
1702   *
1703   * @since 2.0.0 bbPress (r2753)
1704   */
1705  function bbp_topic_form_fields() {
1706  
1707      if ( bbp_is_topic_edit() ) : ?>
1708  
1709          <input type="hidden" name="action"       id="bbp_post_action" value="bbp-edit-topic" />
1710          <input type="hidden" name="bbp_topic_id" id="bbp_topic_id"    value="<?php bbp_topic_id(); ?>" />
1711  
1712          <?php if ( current_user_can( 'unfiltered_html' ) ) :
1713              wp_nonce_field( 'bbp-unfiltered-html-topic_' . bbp_get_topic_id(), '_bbp_unfiltered_html_topic', false );
1714          endif; ?>
1715  
1716          <?php wp_nonce_field( 'bbp-edit-topic_' . bbp_get_topic_id() );
1717  
1718      else :
1719  
1720          if ( bbp_is_single_forum() ) : ?>
1721  
1722              <input type="hidden" name="bbp_forum_id" id="bbp_forum_id" value="<?php bbp_forum_id(); ?>" />
1723  
1724          <?php endif; ?>
1725  
1726          <input type="hidden" name="action" id="bbp_post_action" value="bbp-new-topic" />
1727  
1728          <?php if ( current_user_can( 'unfiltered_html' ) ) :
1729              wp_nonce_field( 'bbp-unfiltered-html-topic_new', '_bbp_unfiltered_html_topic', false );
1730          endif; ?>
1731  
1732          <?php wp_nonce_field( 'bbp-new-topic' );
1733  
1734      endif;
1735  }
1736  
1737  /**
1738   * Output the required hidden fields when creating/editing a reply
1739   *
1740   * @since 2.0.0 bbPress (r2753)
1741   */
1742  function bbp_reply_form_fields() {
1743  
1744      if ( bbp_is_reply_edit() ) : ?>
1745  
1746          <input type="hidden" name="bbp_reply_id"    id="bbp_reply_id"    value="<?php bbp_reply_id(); ?>" />
1747          <input type="hidden" name="action"          id="bbp_post_action" value="bbp-edit-reply" />
1748  
1749          <?php if ( current_user_can( 'unfiltered_html' ) ) :
1750              wp_nonce_field( 'bbp-unfiltered-html-reply_' . bbp_get_reply_id(), '_bbp_unfiltered_html_reply', false );
1751          endif; ?>
1752  
1753          <?php wp_nonce_field( 'bbp-edit-reply_' . bbp_get_reply_id() );
1754  
1755      else : ?>
1756  
1757          <input type="hidden" name="bbp_topic_id"    id="bbp_topic_id"    value="<?php bbp_topic_id(); ?>" />
1758          <input type="hidden" name="bbp_reply_to"    id="bbp_reply_to"    value="<?php bbp_form_reply_to(); ?>" />
1759          <input type="hidden" name="action"          id="bbp_post_action" value="bbp-new-reply" />
1760  
1761          <?php if ( current_user_can( 'unfiltered_html' ) ) :
1762              wp_nonce_field( 'bbp-unfiltered-html-reply_' . bbp_get_topic_id(), '_bbp_unfiltered_html_reply', false );
1763          endif; ?>
1764  
1765          <?php wp_nonce_field( 'bbp-new-reply' );
1766  
1767          // Show redirect field if not viewing a specific topic
1768          if ( bbp_is_query_name( 'bbp_single_topic' ) ) :
1769              $redirect_to = apply_filters( 'bbp_reply_form_redirect_to', get_permalink() );
1770              bbp_redirect_to_field( $redirect_to );
1771          endif;
1772      endif;
1773  }
1774  
1775  /**
1776   * Output the required hidden fields when editing a user
1777   *
1778   * @since 2.0.0 bbPress (r2690)
1779   */
1780  function bbp_edit_user_form_fields() {
1781  ?>
1782  
1783      <input type="hidden" name="action"  id="bbp_post_action" value="bbp-update-user" />
1784      <input type="hidden" name="user_id" id="user_id"         value="<?php bbp_displayed_user_id(); ?>" />
1785  
1786      <?php wp_nonce_field( 'update-user_' . bbp_get_displayed_user_id() );
1787  }
1788  
1789  /**
1790   * Merge topic form fields
1791   *
1792   * Output the required hidden fields when merging a topic
1793   *
1794   * @since 2.0.0 bbPress (r2756)
1795   */
1796  function bbp_merge_topic_form_fields() {
1797  ?>
1798  
1799      <input type="hidden" name="action"       id="bbp_post_action" value="bbp-merge-topic" />
1800      <input type="hidden" name="bbp_topic_id" id="bbp_topic_id"    value="<?php bbp_topic_id(); ?>" />
1801  
1802      <?php wp_nonce_field( 'bbp-merge-topic_' . bbp_get_topic_id() );
1803  }
1804  
1805  /**
1806   * Split topic form fields
1807   *
1808   * Output the required hidden fields when splitting a topic
1809   *
1810   * @since 2.0.0 bbPress (r2756)
1811   */
1812  function bbp_split_topic_form_fields() {
1813  ?>
1814  
1815      <input type="hidden" name="action"       id="bbp_post_action" value="bbp-split-topic" />
1816      <input type="hidden" name="bbp_reply_id" id="bbp_reply_id"    value="<?php echo intval( $_GET['reply_id'] ); ?>" />
1817  
1818      <?php wp_nonce_field( 'bbp-split-topic_' . bbp_get_topic_id() );
1819  }
1820  
1821  /**
1822   * Move reply form fields
1823   *
1824   * Output the required hidden fields when moving a reply
1825   */
1826  function bbp_move_reply_form_fields() {
1827  ?>
1828  
1829      <input type="hidden" name="action"       id="bbp_post_action" value="bbp-move-reply" />
1830      <input type="hidden" name="bbp_reply_id" id="bbp_reply_id"    value="<?php echo intval( $_GET['reply_id'] ); ?>" />
1831  
1832      <?php wp_nonce_field( 'bbp-move-reply_' . bbp_get_reply_id() );
1833  }
1834  
1835  /**
1836   * Output a textarea or TinyMCE if enabled
1837   *
1838   * @since 2.1.0 bbPress (r3586)
1839   *
1840   * @param array $args
1841   */
1842  function bbp_the_content( $args = array() ) {
1843      echo bbp_get_the_content( $args );
1844  }
1845      /**
1846       * Return a textarea or TinyMCE if enabled
1847       *
1848       * @since 2.1.0 bbPress (r3586)
1849       *
1850       * @param array $args
1851       *
1852       * @return string HTML from output buffer
1853       */
1854  	function bbp_get_the_content( $args = array() ) {
1855  
1856          // Parse arguments against default values
1857          $r = bbp_parse_args( $args, array(
1858              'context'           => 'topic',
1859              'before'            => '<div class="bbp-the-content-wrapper">',
1860              'after'             => '</div>',
1861              'wpautop'           => true,
1862              'media_buttons'     => false,
1863              'textarea_rows'     => '12',
1864              'tabindex'          => false,
1865              'tabfocus_elements' => 'bbp_topic_title,bbp_topic_tags',
1866              'editor_class'      => 'bbp-the-content',
1867              'tinymce'           => false,
1868              'teeny'             => true,
1869              'quicktags'         => true,
1870              'dfw'               => false
1871          ), 'get_the_content' );
1872  
1873          // If using tinymce, remove our escaping and trust tinymce
1874          if ( bbp_use_wp_editor() && ( false !== $r['tinymce'] ) ) {
1875              remove_filter( 'bbp_get_form_forum_content', 'esc_textarea' );
1876              remove_filter( 'bbp_get_form_topic_content', 'esc_textarea' );
1877              remove_filter( 'bbp_get_form_reply_content', 'esc_textarea' );
1878          }
1879  
1880          // Assume we are not editing
1881          $post_content = call_user_func( 'bbp_get_form_' . $r['context'] . '_content' );
1882  
1883          // Start an output buffor
1884          ob_start();
1885  
1886          // Output something before the editor
1887          if ( ! empty( $r['before'] ) ) {
1888              echo $r['before'];
1889          }
1890  
1891          // Use TinyMCE if available
1892          if ( bbp_use_wp_editor() ) :
1893  
1894              // Enable additional TinyMCE plugins before outputting the editor
1895              add_filter( 'tiny_mce_plugins',   'bbp_get_tiny_mce_plugins'   );
1896              add_filter( 'teeny_mce_plugins',  'bbp_get_tiny_mce_plugins'   );
1897              add_filter( 'teeny_mce_buttons',  'bbp_get_teeny_mce_buttons'  );
1898              add_filter( 'quicktags_settings', 'bbp_get_quicktags_settings' );
1899  
1900              // Output the editor
1901              wp_editor( $post_content, 'bbp_' . $r['context'] . '_content', array(
1902                  'wpautop'           => $r['wpautop'],
1903                  'media_buttons'     => $r['media_buttons'],
1904                  'textarea_rows'     => $r['textarea_rows'],
1905                  'tabindex'          => $r['tabindex'],
1906                  'tabfocus_elements' => $r['tabfocus_elements'],
1907                  'editor_class'      => $r['editor_class'],
1908                  'tinymce'           => $r['tinymce'],
1909                  'teeny'             => $r['teeny'],
1910                  'quicktags'         => $r['quicktags'],
1911                  'dfw'               => $r['dfw'],
1912              ) );
1913  
1914              // Remove additional TinyMCE plugins after outputting the editor
1915              remove_filter( 'tiny_mce_plugins',   'bbp_get_tiny_mce_plugins'   );
1916              remove_filter( 'teeny_mce_plugins',  'bbp_get_tiny_mce_plugins'   );
1917              remove_filter( 'teeny_mce_buttons',  'bbp_get_teeny_mce_buttons'  );
1918              remove_filter( 'quicktags_settings', 'bbp_get_quicktags_settings' );
1919  
1920          /**
1921           * Fallback to normal textarea.
1922           *
1923           * Note that we do not use esc_textarea() here to prevent double
1924           * escaping the editable output, mucking up existing content.
1925           */
1926          else : ?>
1927  
1928              <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>
1929  
1930          <?php endif;
1931  
1932          // Output something after the editor
1933          if ( ! empty( $r['after'] ) ) {
1934              echo $r['after'];
1935          }
1936  
1937          // Put the output into a usable variable
1938          $output = ob_get_clean();
1939  
1940          // Filter & return
1941          return apply_filters( 'bbp_get_the_content', $output, $args, $post_content );
1942      }
1943  
1944  /**
1945   * Edit TinyMCE plugins to match core behaviour
1946   *
1947   * @since 2.3.0 bbPress (r4574)
1948   *
1949   * @param array $plugins
1950   * @see tiny_mce_plugins, teeny_mce_plugins
1951   * @return array
1952   */
1953  function bbp_get_tiny_mce_plugins( $plugins = array() ) {
1954  
1955      // Unset fullscreen
1956      foreach ( $plugins as $key => $value ) {
1957          if ( 'fullscreen' === $value ) {
1958              unset( $plugins[ $key ] );
1959              break;
1960          }
1961      }
1962  
1963      // Add the tabfocus plugin
1964      $plugins[] = 'tabfocus';
1965  
1966      // Filter & return
1967      return apply_filters( 'bbp_get_tiny_mce_plugins', $plugins );
1968  }
1969  
1970  /**
1971   * Edit TeenyMCE buttons to match allowedtags
1972   *
1973   * @since 2.3.0 bbPress (r4605)
1974   *
1975   * @param array $buttons
1976   * @see teeny_mce_buttons
1977   * @return array
1978   */
1979  function bbp_get_teeny_mce_buttons( $buttons = array() ) {
1980  
1981      // Remove some buttons from TeenyMCE
1982      $buttons = array_diff( $buttons, array(
1983          'underline',
1984          'justifyleft',
1985          'justifycenter',
1986          'justifyright'
1987      ) );
1988  
1989      // Images
1990      array_push( $buttons, 'image' );
1991  
1992      // Filter & return
1993      return apply_filters( 'bbp_get_teeny_mce_buttons', $buttons );
1994  }
1995  
1996  /**
1997   * Edit TinyMCE quicktags buttons to match allowedtags
1998   *
1999   * @since 2.3.0 bbPress (r4606)
2000   *
2001   * @param array $settings
2002   * @see quicktags_settings
2003   * @return array Quicktags settings
2004   */
2005  function bbp_get_quicktags_settings( $settings = array() ) {
2006  
2007      // Get buttons out of settings
2008      $buttons_array = explode( ',', $settings['buttons'] );
2009  
2010      // Diff the ones we don't want out
2011      $buttons = array_diff( $buttons_array, array(
2012          'ins',
2013          'more',
2014          'spell'
2015      ) );
2016  
2017      // Put them back into a string in the $settings array
2018      $settings['buttons'] = implode( ',', $buttons );
2019  
2020      // Filter & return
2021      return apply_filters( 'bbp_get_quicktags_settings', $settings );
2022  }
2023  
2024  /** Views *********************************************************************/
2025  
2026  /**
2027   * Output the view id
2028   *
2029   * @since 2.0.0 bbPress (r2789)
2030   *
2031   * @param string $view Optional. View id
2032   */
2033  function bbp_view_id( $view = '' ) {
2034      echo bbp_get_view_id( $view );
2035  }
2036  
2037      /**
2038       * Get the view id
2039       *
2040       * Use view id if supplied, otherwise bbp_get_view_rewrite_id() query var.
2041       *
2042       * @since 2.0.0 bbPress (r2789)
2043       *
2044       * @param string $view Optional. View id.
2045       * @return bool|string ID on success, false on failure
2046       */
2047  	function bbp_get_view_id( $view = '' ) {
2048          $bbp = bbpress();
2049  
2050          // User supplied string
2051          if ( ! empty( $view ) && is_string( $view ) ) {
2052              $view_id = $view;
2053  
2054          // Current view ID
2055          } elseif ( ! empty( $bbp->current_view_id ) ) {
2056              $view_id = $bbp->current_view_id;
2057  
2058          // Querying for view
2059          } else {
2060              $view_id = get_query_var( bbp_get_view_rewrite_id() );
2061          }
2062  
2063          // Filter & return
2064          return apply_filters( 'bbp_get_view_id', $view_id, $view );
2065      }
2066  
2067  /**
2068   * Output the view name aka title
2069   *
2070   * @since 2.0.0 bbPress (r2789)
2071   *
2072   * @param string $view Optional. View id
2073   */
2074  function bbp_view_title( $view = '' ) {
2075      echo bbp_get_view_title( $view );
2076  }
2077  
2078      /**
2079       * Get the view name aka title
2080       *
2081       * If a view id is supplied, that is used. Otherwise the bbp_view
2082       * query var is checked for.
2083       *
2084       * @since 2.0.0 bbPress (r2789)
2085       *
2086       * @param string $view Optional. View id
2087       * @return bool|string Title on success, false on failure
2088       */
2089  	function bbp_get_view_title( $view = '' ) {
2090          $bbp = bbpress();
2091  
2092          $view = bbp_get_view_id( $view );
2093          if ( empty( $view ) ) {
2094              return false;
2095          }
2096  
2097          return $bbp->views[ $view ]['title'];
2098      }
2099  
2100  /**
2101   * Output the view url
2102   *
2103   * @since 2.0.0 bbPress (r2789)
2104   *
2105   * @param string $view Optional. View id
2106   */
2107  function bbp_view_url( $view = false ) {
2108      echo esc_url( bbp_get_view_url( $view ) );
2109  }
2110      /**
2111       * Return the view url
2112       *
2113       * @since 2.0.0 bbPress (r2789)
2114       *
2115       * @param string $view Optional. View id
2116       *                        used view id
2117       * @return string View url (or home url if the view was not found)
2118       */
2119  	function bbp_get_view_url( $view = false ) {
2120  
2121          $view = bbp_get_view_id( $view );
2122          if ( empty( $view ) ) {
2123              return home_url();
2124          }
2125  
2126          // Pretty permalinks
2127          if ( bbp_use_pretty_urls() ) {
2128  
2129              // Run through home_url()
2130              $url = trailingslashit( bbp_get_root_url() . bbp_get_view_slug() ) . $view;
2131              $url = user_trailingslashit( $url );
2132              $url = home_url( $url );
2133  
2134          // Unpretty permalinks
2135          } else {
2136              $url = add_query_arg( array(
2137                  bbp_get_view_rewrite_id() => $view
2138              ), home_url( '/' ) );
2139          }
2140  
2141          // Filter & return
2142          return apply_filters( 'bbp_get_view_link', $url, $view );
2143      }
2144  
2145  /** Query *********************************************************************/
2146  
2147  /**
2148   * Check the passed parameter against the current _bbp_query_name
2149   *
2150   * @since 2.0.0 bbPress (r2980)
2151   *
2152   * @return bool True if match, false if not
2153   */
2154  function bbp_is_query_name( $name = '' ) {
2155      return (bool) ( bbp_get_query_name() === $name );
2156  }
2157  
2158  /**
2159   * Get the '_bbp_query_name' setting
2160   *
2161   * @since 2.0.0 bbPress (r2695)
2162   *
2163   * @return string To return the query var value
2164   */
2165  function bbp_get_query_name() {
2166      return get_query_var( '_bbp_query_name' );
2167  }
2168  
2169  /**
2170   * Set the '_bbp_query_name' setting to $name
2171   *
2172   * @since 2.0.0 bbPress (r2692)
2173   *
2174   * @param string $name What to set the query var to
2175   */
2176  function bbp_set_query_name( $name = '' ) {
2177      set_query_var( '_bbp_query_name', $name );
2178  }
2179  
2180  /**
2181   * Used to clear the '_bbp_query_name' setting
2182   *
2183   * @since 2.0.0 bbPress (r2692)
2184   *
2185   */
2186  function bbp_reset_query_name() {
2187      bbp_set_query_name();
2188  }
2189  
2190  /** Breadcrumbs ***************************************************************/
2191  
2192  /**
2193   * Output the page title as a breadcrumb
2194   *
2195   * @since 2.0.0 bbPress (r2589)
2196   *
2197   * @param string $sep Separator. Defaults to '&larr;'
2198   * @param bool $current_page Include the current item
2199   * @param bool $root Include the root page if one exists
2200   */
2201  function bbp_title_breadcrumb( $args = array() ) {
2202      echo bbp_get_breadcrumb( $args );
2203  }
2204  
2205  /**
2206   * Output a breadcrumb
2207   *
2208   * @since 2.0.0 bbPress (r2589)
2209   *
2210   * @param string $sep Separator. Defaults to '&larr;'
2211   * @param bool $current_page Include the current item
2212   * @param bool $root Include the root page if one exists
2213   */
2214  function bbp_breadcrumb( $args = array() ) {
2215      echo bbp_get_breadcrumb( $args );
2216  }
2217      /**
2218       * Return a breadcrumb ( forum -> topic -> reply )
2219       *
2220       * @since 2.0.0 bbPress (r2589)
2221       *
2222       * @param string $sep Separator. Defaults to '&larr;'
2223       * @param bool $current_page Include the current item
2224       * @param bool $root Include the root page if one exists
2225       *
2226       * @return string Breadcrumbs
2227       */
2228  	function bbp_get_breadcrumb( $args = array() ) {
2229  
2230          // Turn off breadcrumbs
2231          if ( apply_filters( 'bbp_no_breadcrumb', is_front_page() ) ) {
2232              return;
2233          }
2234  
2235          // Define variables
2236          $front_id         = $root_id                                 = 0;
2237          $ancestors        = $crumbs           = $tag_data            = array();
2238          $pre_root_text    = $pre_front_text   = $pre_current_text    = '';
2239          $pre_include_root = $pre_include_home = $pre_include_current = true;
2240  
2241          /** Home Text *********************************************************/
2242  
2243          // No custom home text
2244          if ( empty( $args['home_text'] ) ) {
2245  
2246              $front_id = get_option( 'page_on_front' );
2247  
2248              // Set home text to page title
2249              if ( ! empty( $front_id ) ) {
2250                  $pre_front_text = get_the_title( $front_id );
2251  
2252              // Default to 'Home'
2253              } else {
2254                  $pre_front_text = esc_html__( 'Home', 'bbpress' );
2255              }
2256          }
2257  
2258          /** Root Text *********************************************************/
2259  
2260          // No custom root text
2261          if ( empty( $args['root_text'] ) ) {
2262              $page = bbp_get_page_by_path( bbp_get_root_slug() );
2263              if ( ! empty( $page ) ) {
2264                  $root_id = $page->ID;
2265              }
2266              $pre_root_text = bbp_get_forum_archive_title();
2267          }
2268  
2269          /** Includes **********************************************************/
2270  
2271          // Root slug is also the front page
2272          if ( ! empty( $front_id ) && ( $front_id === $root_id ) ) {
2273              $pre_include_root = false;
2274          }
2275  
2276          // Don't show root if viewing forum archive
2277          if ( bbp_is_forum_archive() ) {
2278              $pre_include_root = false;
2279          }
2280  
2281          // Don't show root if viewing page in place of forum archive
2282          if ( ! empty( $root_id ) && ( ( is_single() || is_page() ) && ( $root_id === get_the_ID() ) ) ) {
2283              $pre_include_root = false;
2284          }
2285  
2286          /** Current Text ******************************************************/
2287  
2288          // Search page
2289          if ( bbp_is_search() ) {
2290              $pre_current_text = bbp_get_search_title();
2291  
2292          // Forum archive
2293          } elseif ( bbp_is_forum_archive() ) {
2294              $pre_current_text = bbp_get_forum_archive_title();
2295  
2296          // Topic archive
2297          } elseif ( bbp_is_topic_archive() ) {
2298              $pre_current_text = bbp_get_topic_archive_title();
2299  
2300          // View
2301          } elseif ( bbp_is_single_view() ) {
2302              $pre_current_text = bbp_get_view_title();
2303  
2304          // Single Forum
2305          } elseif ( bbp_is_single_forum() ) {
2306              $pre_current_text = bbp_get_forum_title();
2307  
2308          // Single Topic
2309          } elseif ( bbp_is_single_topic() ) {
2310              $pre_current_text = bbp_get_topic_title();
2311  
2312          // Single Topic
2313          } elseif ( bbp_is_single_reply() ) {
2314              $pre_current_text = bbp_get_reply_title();
2315  
2316          // Topic Tag (or theme compat topic tag)
2317          } elseif ( bbp_is_topic_tag() || ( get_query_var( 'bbp_topic_tag' ) && ! bbp_is_topic_tag_edit() ) ) {
2318  
2319              // Always include the tag name
2320              $tag_data[] = bbp_get_topic_tag_name();
2321  
2322              // If capable, include a link to edit the tag
2323              if ( current_user_can( 'manage_topic_tags' ) ) {
2324                  $tag_data[] = '<a href="' . esc_url( bbp_get_topic_tag_edit_link() ) . '" class="bbp-edit-topic-tag-link">' . esc_html__( '(Edit)', 'bbpress' ) . '</a>';
2325              }
2326  
2327              // Implode the results of the tag data
2328              $pre_current_text = sprintf( esc_html__( 'Topic Tag: %s', 'bbpress' ), implode( ' ', $tag_data ) );
2329  
2330          // Edit Topic Tag
2331          } elseif ( bbp_is_topic_tag_edit() ) {
2332              $pre_current_text = esc_html__( 'Edit', 'bbpress' );
2333  
2334          // Single
2335          } else {
2336              $pre_current_text = get_the_title();
2337          }
2338  
2339          /** Parse Args ********************************************************/
2340  
2341          // Parse args
2342          $r = bbp_parse_args( $args, array(
2343  
2344              // HTML
2345              'before'          => '<div class="bbp-breadcrumb"><p>',
2346              'after'           => '</p></div>',
2347  
2348              // Separator
2349              'sep'             => is_rtl() ? __( '&lsaquo;', 'bbpress' ) : __( '&rsaquo;', 'bbpress' ),
2350              'pad_sep'         => 1,
2351              'sep_before'      => '<span class="bbp-breadcrumb-sep">',
2352              'sep_after'       => '</span>',
2353  
2354              // Crumbs
2355              'crumb_before'    => '',
2356              'crumb_after'     => '',
2357  
2358              // Home
2359              'include_home'    => $pre_include_home,
2360              'home_text'       => $pre_front_text,
2361  
2362              // Forum root
2363              'include_root'    => $pre_include_root,
2364              'root_text'       => $pre_root_text,
2365  
2366              // Current
2367              'include_current' => $pre_include_current,
2368              'current_text'    => $pre_current_text,
2369              'current_before'  => '<span class="bbp-breadcrumb-current">',
2370              'current_after'   => '</span>',
2371          ), 'get_breadcrumb' );
2372  
2373          /** Ancestors *********************************************************/
2374  
2375          // Get post ancestors
2376          if ( is_singular() || bbp_is_forum_edit() || bbp_is_topic_edit() || bbp_is_reply_edit() ) {
2377              $ancestors = array_reverse( (array) get_post_ancestors( get_the_ID() ) );
2378          }
2379  
2380          // Do we want to include a link to home?
2381          if ( ! empty( $r['include_home'] ) || empty( $r['home_text'] ) ) {
2382              $crumbs[] = '<a href="' . esc_url( home_url() ) . '" class="bbp-breadcrumb-home">' . $r['home_text'] . '</a>';
2383          }
2384  
2385          // Do we want to include a link to the forum root?
2386          if ( ! empty( $r['include_root'] ) || empty( $r['root_text'] ) ) {
2387  
2388              // Page exists at root slug path, so use its permalink
2389              $page = bbp_get_page_by_path( bbp_get_root_slug() );
2390              if ( ! empty( $page ) ) {
2391                  $root_url = get_permalink( $page->ID );
2392  
2393              // Use the root slug
2394              } else {
2395                  $root_url = get_post_type_archive_link( bbp_get_forum_post_type() );
2396              }
2397  
2398              // Add the breadcrumb
2399              $crumbs[] = '<a href="' . esc_url( $root_url ) . '" class="bbp-breadcrumb-root">' . $r['root_text'] . '</a>';
2400          }
2401  
2402          // Ancestors exist
2403          if ( ! empty( $ancestors ) ) {
2404  
2405              // Loop through parents
2406              foreach ( (array) $ancestors as $parent_id ) {
2407  
2408                  // Parents
2409                  $parent = get_post( $parent_id );
2410  
2411                  // Skip parent if empty or error
2412                  if ( empty( $parent ) || is_wp_error( $parent ) ) {
2413                      continue;
2414                  }
2415  
2416                  // Switch through post_type to ensure correct filters are applied
2417                  switch ( $parent->post_type ) {
2418  
2419                      // Forum
2420                      case bbp_get_forum_post_type() :
2421                          $crumbs[] = '<a href="' . esc_url( bbp_get_forum_permalink( $parent->ID ) ) . '" class="bbp-breadcrumb-forum">' . bbp_get_forum_title( $parent->ID ) . '</a>';
2422                          break;
2423  
2424                      // Topic
2425                      case bbp_get_topic_post_type() :
2426                          $crumbs[] = '<a href="' . esc_url( bbp_get_topic_permalink( $parent->ID ) ) . '" class="bbp-breadcrumb-topic">' . bbp_get_topic_title( $parent->ID ) . '</a>';
2427                          break;
2428  
2429                      // Reply (Note: not in most themes)
2430                      case bbp_get_reply_post_type() :
2431                          $crumbs[] = '<a href="' . esc_url( bbp_get_reply_permalink( $parent->ID ) ) . '" class="bbp-breadcrumb-reply">' . bbp_get_reply_title( $parent->ID ) . '</a>';
2432                          break;
2433  
2434                      // WordPress Post/Page/Other
2435                      default :
2436                          $crumbs[] = '<a href="' . esc_url( get_permalink( $parent->ID ) ) . '" class="bbp-breadcrumb-item">' . get_the_title( $parent->ID ) . '</a>';
2437                          break;
2438                  }
2439              }
2440  
2441          // Edit topic tag
2442          } elseif ( bbp_is_topic_tag_edit() ) {
2443              $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>';
2444  
2445          // Search
2446          } elseif ( bbp_is_search() && bbp_get_search_terms() ) {
2447              $crumbs[] = '<a href="' . esc_url( bbp_get_search_url() ) . '" class="bbp-breadcrumb-search">' . esc_html__( 'Search', 'bbpress' ) . '</a>';
2448          }
2449  
2450          /** Current ***********************************************************/
2451  
2452          // Add current page to breadcrumb
2453          if ( ! empty( $r['include_current'] ) || empty( $r['current_text'] ) ) {
2454              $crumbs[] = $r['current_before'] . $r['current_text'] . $r['current_after'];
2455          }
2456  
2457          /** Separator *********************************************************/
2458  
2459          // Wrap the separator in before/after before padding and filter
2460          if ( ! empty( $r['sep'] ) ) {
2461              $sep = $r['sep_before'] . $r['sep'] . $r['sep_after'];
2462          } else {
2463              $sep = '';
2464          }
2465  
2466          // Pad the separator
2467          if ( ! empty( $r['pad_sep'] ) ) {
2468              if ( function_exists( 'mb_strlen' ) ) {
2469                  $sep = str_pad( $sep, mb_strlen( $sep ) + ( (int) $r['pad_sep'] * 2 ), ' ', STR_PAD_BOTH );
2470              } else {
2471                  $sep = str_pad( $sep, strlen( $sep ) + ( (int) $r['pad_sep'] * 2 ), ' ', STR_PAD_BOTH );
2472              }
2473          }
2474  
2475          /** Finish Up *********************************************************/
2476  
2477          // Filter the separator and breadcrumb
2478          $sep    = apply_filters( 'bbp_breadcrumb_separator', $sep    );
2479          $crumbs = apply_filters( 'bbp_breadcrumbs',          $crumbs );
2480  
2481          // Build the trail
2482          $trail  = ! empty( $crumbs ) ? ( $r['before'] . $r['crumb_before'] . implode( $sep . $r['crumb_after'] . $r['crumb_before'], $crumbs ) . $r['crumb_after'] . $r['after'] ) : '';
2483  
2484          // Filter & return
2485          return apply_filters( 'bbp_get_breadcrumb', $trail, $crumbs, $r, $args );
2486      }
2487  
2488  /** Topic Tags ***************************************************************/
2489  
2490  /**
2491   * Output all of the allowed tags in HTML format with attributes.
2492   *
2493   * This is useful for displaying in the post area, which elements and
2494   * attributes are supported. As well as any plugins which want to display it.
2495   *
2496   * @since 2.0.0 bbPress (r2780)
2497   */
2498  function bbp_allowed_tags() {
2499      echo bbp_get_allowed_tags();
2500  }
2501      /**
2502       * Display all of the allowed tags in HTML format with attributes.
2503       *
2504       * This is useful for displaying in the post area, which elements and
2505       * attributes are supported. As well as any plugins which want to display it.
2506       *
2507       * @since 2.0.0 bbPress (r2780)
2508       *
2509       * @return string HTML allowed tags entity encoded.
2510       */
2511  	function bbp_get_allowed_tags() {
2512  
2513          $allowed = '';
2514  
2515          foreach ( (array) bbp_kses_allowed_tags() as $tag => $attributes ) {
2516              $allowed .= '<' . $tag;
2517              if ( 0 < count( $attributes ) ) {
2518                  foreach ( array_keys( $attributes ) as $attribute ) {
2519                      $allowed .= ' ' . $attribute . '=""';
2520                  }
2521              }
2522              $allowed .= '> ';
2523          }
2524  
2525          // Filter & return
2526          return apply_filters( 'bbp_get_allowed_tags', htmlentities( $allowed ) );
2527      }
2528  
2529  /** Errors & Messages *********************************************************/
2530  
2531  /**
2532   * Display possible errors & messages inside a template file
2533   *
2534   * @since 2.0.0 bbPress (r2688)
2535   */
2536  function bbp_template_notices() {
2537  
2538      // Bail if no notices or errors
2539      if ( ! bbp_has_errors() ) {
2540          return;
2541      }
2542  
2543      // Define local variable(s)
2544      $errors = $messages = array();
2545  
2546      // Get bbPress
2547      $bbp = bbpress();
2548  
2549      // Loop through notices
2550      foreach ( $bbp->errors->get_error_codes() as $code ) {
2551  
2552          // Get notice severity
2553          $severity = $bbp->errors->get_error_data( $code );
2554  
2555          // Loop through notices and separate errors from messages
2556          foreach ( $bbp->errors->get_error_messages( $code ) as $error ) {
2557              if ( 'message' === $severity ) {
2558                  $messages[] = $error;
2559              } else {
2560                  $errors[]   = $error;
2561              }
2562          }
2563      }
2564  
2565      // Display errors first...
2566      if ( ! empty( $errors ) ) : ?>
2567  
2568          <div class="bbp-template-notice error" role="alert" tabindex="-1">
2569              <ul>
2570                  <li><?php echo implode( "</li>\n<li>", $errors ); ?></li>
2571              </ul>
2572          </div>
2573  
2574      <?php endif;
2575  
2576      // ...and messages last
2577      if ( ! empty( $messages ) ) : ?>
2578  
2579          <div class="bbp-template-notice">
2580              <ul>
2581                  <li><?php echo implode( "</li>\n<li>", $messages ); ?></li>
2582              </ul>
2583          </div>
2584  
2585      <?php endif;
2586  }
2587  
2588  /** Login/logout/register/lost pass *******************************************/
2589  
2590  /**
2591   * Output the logout link
2592   *
2593   * @since 2.0.0 bbPress (r2827)
2594   *
2595   * @param string $redirect_to Redirect to url
2596   */
2597  function bbp_logout_link( $redirect_to = '' ) {
2598      echo bbp_get_logout_link( $redirect_to );
2599  }
2600      /**
2601       * Return the logout link
2602       *
2603       * @since 2.0.0 bbPress (r2827)
2604       *
2605       * @param string $redirect_to Redirect to url
2606       *                        redirect to url
2607       * @return string The logout link
2608       */
2609  	function bbp_get_logout_link( $redirect_to = '' ) {
2610  
2611          // Build the link
2612          $link = '<a href="' . wp_logout_url( $redirect_to ) . '" class="button logout-link">' . esc_html__( 'Log Out', 'bbpress' ) . '</a>';
2613  
2614          // Filter & return
2615          return apply_filters( 'bbp_get_logout_link', $link, $redirect_to );
2616      }
2617  
2618  /** Title *********************************************************************/
2619  
2620  /**
2621   * Custom page title for bbPress pages
2622   *
2623   * @since 2.0.0 bbPress (r2788)
2624   *
2625   * @param string $title Optional. The title (not used).
2626   * @param string $sep Optional, default is '&raquo;'. How to separate the
2627   *                     various items within the page title.
2628   * @param string $seplocation Optional. Direction to display title, 'right'.
2629   *                        separator and separator location
2630   * @return string The title
2631   */
2632  function bbp_title( $title = '', $sep = '&raquo;', $seplocation = '' ) {
2633  
2634      // Title array
2635      $new_title = array();
2636  
2637      /** Archives **************************************************************/
2638  
2639      // Forum Archive
2640      if ( bbp_is_forum_archive() ) {
2641          $new_title['text'] = bbp_get_forum_archive_title();
2642  
2643      // Topic Archive
2644      } elseif ( bbp_is_topic_archive() ) {
2645          $new_title['text'] = bbp_get_topic_archive_title();
2646  
2647      /** Edit ******************************************************************/
2648  
2649      // Forum edit page
2650      } elseif ( bbp_is_forum_edit() ) {
2651          $new_title['text']   = bbp_get_forum_title();
2652          $new_title['format'] = esc_attr__( 'Forum Edit: %s', 'bbpress' );
2653  
2654      // Topic edit page
2655      } elseif ( bbp_is_topic_edit() ) {
2656          $new_title['text']   = bbp_get_topic_title();
2657          $new_title['format'] = esc_attr__( 'Topic Edit: %s', 'bbpress' );
2658  
2659      // Reply edit page
2660      } elseif ( bbp_is_reply_edit() ) {
2661          $new_title['text']   = bbp_get_reply_title();
2662          $new_title['format'] = esc_attr__( 'Reply Edit: %s', 'bbpress' );
2663  
2664      // Topic tag edit page
2665      } elseif ( bbp_is_topic_tag_edit() ) {
2666          $new_title['text']   = bbp_get_topic_tag_name();
2667          $new_title['format'] = esc_attr__( 'Topic Tag Edit: %s', 'bbpress' );
2668  
2669      /** Singles ***************************************************************/
2670  
2671      // Forum page
2672      } elseif ( bbp_is_single_forum() ) {
2673          $new_title['text']   = bbp_get_forum_title();
2674          $new_title['format'] = esc_attr__( 'Forum: %s', 'bbpress' );
2675  
2676      // Topic page
2677      } elseif ( bbp_is_single_topic() ) {
2678          $new_title['text']   = bbp_get_topic_title();
2679          $new_title['format'] = esc_attr__( 'Topic: %s', 'bbpress' );
2680  
2681      // Replies
2682      } elseif ( bbp_is_single_reply() ) {
2683          $new_title['text']   = bbp_get_reply_title();
2684  
2685      // Topic tag page
2686      } elseif ( bbp_is_topic_tag() || get_query_var( 'bbp_topic_tag' ) ) {
2687          $new_title['text']   = bbp_get_topic_tag_name();
2688          $new_title['format'] = esc_attr__( 'Topic Tag: %s', 'bbpress' );
2689  
2690      /** Users *****************************************************************/
2691  
2692      // Profile page
2693      } elseif ( bbp_is_single_user() ) {
2694  
2695          // Is user viewing their own profile?
2696          $is_user_home = bbp_is_user_home();
2697  
2698          // User topics created
2699          if ( bbp_is_single_user_topics() ) {
2700              if ( true === $is_user_home ) {
2701                  $new_title['text'] = esc_attr__( 'Your Topics', 'bbpress' );
2702              } else {
2703                  $new_title['text'] = get_userdata( bbp_get_user_id() )->display_name;
2704                  /* translators: user's display name */
2705                  $new_title['format'] = esc_attr__( "%s's Topics", 'bbpress' );
2706              }
2707  
2708          // User replies created
2709          } elseif ( bbp_is_single_user_replies() ) {
2710              if ( true === $is_user_home ) {
2711                  $new_title['text'] = esc_attr__( 'Your Replies', 'bbpress' );
2712              } else {
2713                  $new_title['text'] = get_userdata( bbp_get_user_id() )->display_name;
2714                  /* translators: user's display name */
2715                  $new_title['format'] = esc_attr__( "%s's Replies", 'bbpress' );
2716              }
2717  
2718          // User favorites
2719          } elseif ( bbp_is_favorites() ) {
2720              if ( true === $is_user_home ) {
2721                  $new_title['text'] = esc_attr__( 'Your Favorites', 'bbpress' );
2722              } else {
2723                  $new_title['text'] = get_userdata( bbp_get_user_id() )->display_name;
2724                  /* translators: user's display name */
2725                  $new_title['format'] = esc_attr__( "%s's Favorites", 'bbpress' );
2726              }
2727  
2728          // User subscriptions
2729          } elseif ( bbp_is_subscriptions() ) {
2730              if ( true === $is_user_home ) {
2731                  $new_title['text'] = esc_attr__( 'Your Subscriptions', 'bbpress' );
2732              } else {
2733                  $new_title['text'] = get_userdata( bbp_get_user_id() )->display_name;
2734                  /* translators: user's display name */
2735                  $new_title['format'] = esc_attr__( "%s's Subscriptions", 'bbpress' );
2736              }
2737  
2738          // User "home"
2739          } else {
2740              if ( true === $is_user_home ) {
2741                  $new_title['text'] = esc_attr__( 'Your Profile', 'bbpress' );
2742              } else {
2743                  $new_title['text'] = get_userdata( bbp_get_user_id() )->display_name;
2744                  /* translators: user's display name */
2745                  $new_title['format'] = esc_attr__( "%s's Profile", 'bbpress' );
2746              }
2747          }
2748  
2749      // Profile edit page
2750      } elseif ( bbp_is_single_user_edit() ) {
2751  
2752          // Current user
2753          if ( bbp_is_user_home_edit() ) {
2754              $new_title['text']   = esc_attr__( 'Edit Your Profile', 'bbpress' );
2755  
2756          // Other user
2757          } else {
2758              $new_title['text']   = get_userdata( bbp_get_user_id() )->display_name;
2759              $new_title['format'] = esc_attr__( "Edit %s's Profile", 'bbpress' );
2760          }
2761  
2762      /** Views *****************************************************************/
2763  
2764      // Views
2765      } elseif ( bbp_is_single_view() ) {
2766          $new_title['text']   = bbp_get_view_title();
2767          $new_title['format'] = esc_attr__( 'View: %s', 'bbpress' );
2768  
2769      /** Search ****************************************************************/
2770  
2771      // Search
2772      } elseif ( bbp_is_search() ) {
2773          $new_title['text'] = bbp_get_search_title();
2774      }
2775  
2776      // This filter is deprecated. Use 'bbp_before_title_parse_args' instead.
2777      $new_title = apply_filters( 'bbp_raw_title_array', $new_title );
2778  
2779      // Set title array defaults
2780      $new_title = bbp_parse_args( $new_title, array(
2781          'text'   => $title,
2782          'format' => '%s'
2783      ), 'title' );
2784  
2785      // Get the formatted raw title
2786      $new_title = sprintf( $new_title['format'], $new_title['text'] );
2787  
2788      // Filter the raw title
2789      $new_title = apply_filters( 'bbp_raw_title', $new_title, $sep, $seplocation );
2790  
2791      // Compare new title with original title
2792      if ( $new_title === $title ) {
2793          return $title;
2794      }
2795  
2796      // Temporary separator, for accurate flipping, if necessary
2797      $t_sep  = '%WP_TITILE_SEP%';
2798      $prefix = '';
2799  
2800      if ( ! empty( $new_title ) ) {
2801          $prefix = " $sep ";
2802      }
2803  
2804      // sep on right, so reverse the order
2805      if ( 'right' === $seplocation ) {
2806          $new_title_array = array_reverse( explode( $t_sep, $new_title ) );
2807          $new_title       = implode( " $sep ", $new_title_array ) . $prefix;
2808  
2809      // sep on left, do not reverse
2810      } else {
2811          $new_title_array = explode( $t_sep, $new_title );
2812          $new_title       = $prefix . implode( " $sep ", $new_title_array );
2813      }
2814  
2815      // Filter & return
2816      return apply_filters( 'bbp_title', $new_title, $sep, $seplocation );
2817  }


Generated: Sun Oct 24 01:00:49 2021 Cross-referenced by PHPXref 0.7.1