[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

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

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


Generated: Sat Sep 21 01:01:35 2019 Cross-referenced by PHPXref 0.7.1