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


Generated: Sun Nov 17 01:01:25 2019 Cross-referenced by PHPXref 0.7.1