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


Generated: Tue Oct 15 01:00:48 2024 Cross-referenced by PHPXref 0.7.1