bbp_show_topics_on_root ) ) {
$retval = true;
}
// Filter & return
return (bool) apply_filters( 'bbp_is_forum_archive', $retval );
}
/**
* Viewing a single forum
*
* @since 2.0.0 bbPress (r3338)
*
* @return bool
*/
function bbp_is_single_forum() {
// Assume false
$retval = false;
// Edit is not a single forum
if ( bbp_is_forum_edit() ) {
return false;
}
// Single and a match
if ( is_singular( bbp_get_forum_post_type() ) || bbp_is_query_name( 'bbp_single_forum' ) ) {
$retval = true;
}
// Filter & return
return (bool) apply_filters( 'bbp_is_single_forum', $retval );
}
/**
* Check if current page is a forum edit page
*
* @since 2.1.0 bbPress (r3553)
*
* @return bool True if it's the forum edit page, false if not
*/
function bbp_is_forum_edit() {
global $pagenow;
// Assume false
$retval = false;
// Get the main query global
$wp_query = bbp_get_wp_query();
// Check query
if ( ! empty( $wp_query->bbp_is_forum_edit ) && ( $wp_query->bbp_is_forum_edit === true ) ) {
$retval = true;
// Editing in admin
} elseif ( is_admin() && ( 'post.php' === $pagenow ) && ( get_post_type() === bbp_get_forum_post_type() ) && ( ! empty( $_GET['action'] ) && ( 'edit' === $_GET['action'] ) ) ) {
$retval = true;
}
// Filter & return
return (bool) apply_filters( 'bbp_is_forum_edit', $retval );
}
/**
* Check if current page is a bbPress topic
*
* @since 2.0.0 bbPress (r2549)
*
* @param int $post_id Possible post_id to check
* @return bool True if it's a topic page, false if not
*/
function bbp_is_topic( $post_id = 0 ) {
// Assume false
$retval = false;
// Supplied ID is a topic
if ( ! empty( $post_id ) && ( bbp_get_topic_post_type() === get_post_type( $post_id ) ) ) {
$retval = true;
}
// Filter & return
return (bool) apply_filters( 'bbp_is_topic', $retval, $post_id );
}
/**
* Viewing a single topic
*
* @since 2.0.0 bbPress (r3338)
*
* @return bool
*/
function bbp_is_single_topic() {
// Assume false
$retval = false;
// Edit is not a single topic
if ( bbp_is_topic_edit() ) {
return false;
}
// Single and a match
if ( is_singular( bbp_get_topic_post_type() ) || bbp_is_query_name( 'bbp_single_topic' ) ) {
$retval = true;
}
// Filter & return
return (bool) apply_filters( 'bbp_is_single_topic', $retval );
}
/**
* Check if we are viewing a topic archive.
*
* @since 2.0.0 bbPress (r3251)
*
* @return bool
*/
function bbp_is_topic_archive() {
// Default to false
$retval = false;
// In topic archive
if ( is_post_type_archive( bbp_get_topic_post_type() ) || bbp_is_query_name( 'bbp_topic_archive' ) ) {
$retval = true;
}
// Filter & return
return (bool) apply_filters( 'bbp_is_topic_archive', $retval );
}
/**
* Check if current page is a topic edit page
*
* @since 2.0.0 bbPress (r2753)
*
* @return bool True if it's the topic edit page, false if not
*/
function bbp_is_topic_edit() {
global $pagenow;
// Assume false
$retval = false;
// Get the main query global
$wp_query = bbp_get_wp_query();
// Check query
if ( ! empty( $wp_query->bbp_is_topic_edit ) && ( $wp_query->bbp_is_topic_edit === true ) ) {
$retval = true;
// Editing in admin
} elseif ( is_admin() && ( 'post.php' === $pagenow ) && ( get_post_type() === bbp_get_topic_post_type() ) && ( ! empty( $_GET['action'] ) && ( 'edit' === $_GET['action'] ) ) ) {
$retval = true;
}
// Filter & return
return (bool) apply_filters( 'bbp_is_topic_edit', $retval );
}
/**
* Check if current page is a topic merge page
*
* @since 2.0.0 bbPress (r2756)
*
* @return bool True if it's the topic merge page, false if not
*/
function bbp_is_topic_merge() {
// Assume false
$retval = false;
// Check topic edit and GET params
if ( bbp_is_topic_edit() && ! empty( $_GET['action'] ) && ( 'merge' === $_GET['action'] ) ) {
return true;
}
// Filter & return
return (bool) apply_filters( 'bbp_is_topic_merge', $retval );
}
/**
* Check if current page is a topic split page
*
* @since 2.0.0 bbPress (r2756)
*
* @return bool True if it's the topic split page, false if not
*/
function bbp_is_topic_split() {
// Assume false
$retval = false;
// Check topic edit and GET params
if ( bbp_is_topic_edit() && ! empty( $_GET['action'] ) && ( 'split' === $_GET['action'] ) ) {
$retval = true;
}
// Filter & return
return (bool) apply_filters( 'bbp_is_topic_split', $retval );
}
/**
* Check if the current page is a topic tag
*
* @since 2.0.0 bbPress (r3311)
*
* @return bool True if it's a topic tag, false if not
*/
function bbp_is_topic_tag() {
// Bail if topic-tags are off
if ( ! bbp_allow_topic_tags() ) {
return false;
}
// Return false if editing a topic tag
if ( bbp_is_topic_tag_edit() ) {
return false;
}
// Assume false
$retval = false;
// Check tax and query vars
if ( is_tax( bbp_get_topic_tag_tax_id() ) || ! empty( bbpress()->topic_query->is_tax ) || get_query_var( 'bbp_topic_tag' ) ) {
$retval = true;
}
// Filter & return
return (bool) apply_filters( 'bbp_is_topic_tag', $retval );
}
/**
* Check if the current page is editing a topic tag
*
* @since 2.0.0 bbPress (r3346)
*
* @return bool True if editing a topic tag, false if not
*/
function bbp_is_topic_tag_edit() {
global $pagenow, $taxnow;
// Bail if topic-tags are off
if ( ! bbp_allow_topic_tags() ) {
return false;
}
// Assume false
$retval = false;
// Get the main query global
$wp_query = bbp_get_wp_query();
// Check query
if ( ! empty( $wp_query->bbp_is_topic_tag_edit ) && ( true === $wp_query->bbp_is_topic_tag_edit ) ) {
$retval = true;
// Editing in admin
} elseif ( is_admin() && ( 'edit-tags.php' === $pagenow ) && ( bbp_get_topic_tag_tax_id() === $taxnow ) && ( ! empty( $_GET['action'] ) && ( 'edit' === $_GET['action'] ) ) ) {
$retval = true;
}
// Filter & return
return (bool) apply_filters( 'bbp_is_topic_tag_edit', $retval );
}
/**
* Check if the current post type is one that comes with bbPress
*
* @since 2.0.0 bbPress (r3311)
*
* @param mixed $the_post Optional. Post object or post ID.
*
* @return bool
*/
function bbp_is_custom_post_type( $the_post = false ) {
// Assume false
$retval = false;
// Viewing one of the bbPress post types
if ( in_array( get_post_type( $the_post ), array(
bbp_get_forum_post_type(),
bbp_get_topic_post_type(),
bbp_get_reply_post_type()
), true ) ) {
$retval = true;
}
// Filter & return
return (bool) apply_filters( 'bbp_is_custom_post_type', $retval, $the_post );
}
/**
* Check if current page is a bbPress reply
*
* @since 2.0.0 bbPress (r2549)
*
* @param int $post_id Possible post_id to check
* @return bool True if it's a reply page, false if not
*/
function bbp_is_reply( $post_id = 0 ) {
// Assume false
$retval = false;
// Supplied ID is a reply
if ( ! empty( $post_id ) && ( bbp_get_reply_post_type() === get_post_type( $post_id ) ) ) {
$retval = true;
}
// Filter & return
return (bool) apply_filters( 'bbp_is_reply', $retval, $post_id );
}
/**
* Check if current page is a reply edit page
*
* @since 2.0.0 bbPress (r2753)
*
* @return bool True if it's the reply edit page, false if not
*/
function bbp_is_reply_edit() {
global $pagenow;
// Assume false
$retval = false;
// Get the main query global
$wp_query = bbp_get_wp_query();
// Check query
if ( ! empty( $wp_query->bbp_is_reply_edit ) && ( true === $wp_query->bbp_is_reply_edit ) ) {
$retval = true;
// Editing in admin
} elseif ( is_admin() && ( 'post.php' === $pagenow ) && ( get_post_type() === bbp_get_reply_post_type() ) && ( ! empty( $_GET['action'] ) && ( 'edit' === $_GET['action'] ) ) ) {
$retval = true;
}
// Filter & return
return (bool) apply_filters( 'bbp_is_reply_edit', $retval );
}
/**
* Check if current page is a reply move page
*
* @return bool True if it's the reply move page, false if not
*/
function bbp_is_reply_move() {
// Assume false
$retval = false;
// Check reply edit and GET params
if ( bbp_is_reply_edit() && ! empty( $_GET['action'] ) && ( 'move' === $_GET['action'] ) ) {
$retval = true;
}
// Filter & return
return (bool) apply_filters( 'bbp_is_reply_move', $retval );
}
/**
* Viewing a single reply
*
* @since 2.0.0 bbPress (r3344)
*
* @return bool
*/
function bbp_is_single_reply() {
// Assume false
$retval = false;
// Edit is not a single reply
if ( bbp_is_reply_edit() ) {
return false;
}
// Single and a match
if ( is_singular( bbp_get_reply_post_type() ) || ( bbp_is_query_name( 'bbp_single_reply' ) ) ) {
$retval = true;
}
// Filter & return
return (bool) apply_filters( 'bbp_is_single_reply', $retval );
}
/**
* Check if current page is a bbPress user's favorites page (profile page)
*
* @since 2.0.0 bbPress (r2652)
*
* @return bool True if it's the favorites page, false if not
*/
function bbp_is_favorites() {
// Assume false
$retval = false;
// Get the main query global
$wp_query = bbp_get_wp_query();
// Check query
if ( ! empty( $wp_query->bbp_is_single_user_favs ) && ( true === $wp_query->bbp_is_single_user_favs ) ) {
$retval = true;
}
// Filter & return
return (bool) apply_filters( 'bbp_is_favorites', $retval );
}
/**
* Check if current page is a bbPress user's subscriptions page (profile page)
*
* @since 2.0.0 bbPress (r2652)
*
* @return bool True if it's the subscriptions page, false if not
*/
function bbp_is_subscriptions() {
// Assume false
$retval = false;
// Get the main query global
$wp_query = bbp_get_wp_query();
// Check query
if ( ! empty( $wp_query->bbp_is_single_user_subs ) && ( true === $wp_query->bbp_is_single_user_subs ) ) {
$retval = true;
}
// Filter & return
return (bool) apply_filters( 'bbp_is_subscriptions', $retval );
}
/**
* Check if current page shows the topics created by a bbPress user (profile
* page)
*
* @since 2.0.0 bbPress (r2688)
*
* @return bool True if it's the topics created page, false if not
*/
function bbp_is_topics_created() {
// Assume false
$retval = false;
// Get the main query global
$wp_query = bbp_get_wp_query();
// Check query
if ( ! empty( $wp_query->bbp_is_single_user_topics ) && ( true === $wp_query->bbp_is_single_user_topics ) ) {
$retval = true;
}
// Filter & return
return (bool) apply_filters( 'bbp_is_topics_created', $retval );
}
/**
* Check if current page shows the replies created by a bbPress user (profile
* page)
*
* @since 2.2.0 bbPress (r4225)
*
* @return bool True if it's the replies created page, false if not
*/
function bbp_is_replies_created() {
// Assume false
$retval = false;
// Get the main query global
$wp_query = bbp_get_wp_query();
// Check query
if ( ! empty( $wp_query->bbp_is_single_user_replies ) && ( true === $wp_query->bbp_is_single_user_replies ) ) {
$retval = true;
}
// Filter & return
return (bool) apply_filters( 'bbp_is_replies_created', $retval );
}
/**
* Check if current page is the currently logged in users author page
*
* @since 2.0.0 bbPress (r2688)
*
* @return bool True if it's the user's home, false if not
*/
function bbp_is_user_home() {
// Assume false
$retval = false;
// Get the main query global
$wp_query = bbp_get_wp_query();
// Check query
if ( ! empty( $wp_query->bbp_is_single_user_home ) && ( true === $wp_query->bbp_is_single_user_home ) ) {
$retval = true;
}
// Filter & return
return (bool) apply_filters( 'bbp_is_user_home', $retval );
}
/**
* Check if current page is the currently logged in users author edit page
*
* @since 2.1.0 bbPress (r3918)
*
* @return bool True if it's the user's home, false if not
*/
function bbp_is_user_home_edit() {
// Assume false
$retval = false;
if ( bbp_is_user_home() && bbp_is_single_user_edit() ) {
$retval = true;
}
// Filter & return
return (bool) apply_filters( 'bbp_is_user_home_edit', $retval );
}
/**
* Check if current page is a user profile page
*
* @since 2.0.0 bbPress (r2688)
*
* @return bool True if it's a user's profile page, false if not
*/
function bbp_is_single_user() {
// Assume false
$retval = false;
// Get the main query global
$wp_query = bbp_get_wp_query();
// Check query
if ( ! empty( $wp_query->bbp_is_single_user ) && ( true === $wp_query->bbp_is_single_user ) ) {
$retval = true;
}
// Filter & return
return (bool) apply_filters( 'bbp_is_single_user', $retval );
}
/**
* Check if current page is a user profile edit page
*
* @since 2.0.0 bbPress (r2688)
*
* @return bool True if it's a user's profile edit page, false if not
*/
function bbp_is_single_user_edit() {
// Assume false
$retval = false;
// Get the main query global
$wp_query = bbp_get_wp_query();
// Check query
if ( ! empty( $wp_query->bbp_is_single_user_edit ) && ( true === $wp_query->bbp_is_single_user_edit ) ) {
$retval = true;
}
// Filter & return
return (bool) apply_filters( 'bbp_is_single_user_edit', $retval );
}
/**
* Check if current page is a user profile page
*
* @since 2.2.0 bbPress (r4225)
*
* @return bool True if it's a user's profile page, false if not
*/
function bbp_is_single_user_profile() {
// Assume false
$retval = false;
// Get the main query global
$wp_query = bbp_get_wp_query();
// Check query
if ( ! empty( $wp_query->bbp_is_single_user_profile ) && ( true === $wp_query->bbp_is_single_user_profile ) ) {
$retval = true;
}
// Filter & return
return (bool) apply_filters( 'bbp_is_single_user_profile', $retval );
}
/**
* Check if current page is a user topics created page
*
* @since 2.2.0 bbPress (r4225)
*
* @return bool True if it's a user's topics page, false if not
*/
function bbp_is_single_user_topics() {
// Assume false
$retval = false;
// Get the main query global
$wp_query = bbp_get_wp_query();
// Check query
if ( ! empty( $wp_query->bbp_is_single_user_topics ) && ( true === $wp_query->bbp_is_single_user_topics ) ) {
$retval = true;
}
// Filter & return
return (bool) apply_filters( 'bbp_is_single_user_topics', $retval );
}
/**
* Check if current page is a user replies created page
*
* @since 2.2.0 bbPress (r4225)
*
* @return bool True if it's a user's replies page, false if not
*/
function bbp_is_single_user_replies() {
// Assume false
$retval = false;
// Get the main query global
$wp_query = bbp_get_wp_query();
// Check query
if ( ! empty( $wp_query->bbp_is_single_user_replies ) && ( true === $wp_query->bbp_is_single_user_replies ) ) {
$retval = true;
}
// Filter & return
return (bool) apply_filters( 'bbp_is_single_user_replies', $retval );
}
/**
* Check if current page is a user engagements page
*
* @since 2.6.0 bbPress (r6320)
*
* @return bool True if it's a user's replies page, false if not
*/
function bbp_is_single_user_engagements() {
// Assume false
$retval = false;
// Get the main query global
$wp_query = bbp_get_wp_query();
// Check query
if ( ! empty( $wp_query->bbp_is_single_user_engagements ) && ( true === $wp_query->bbp_is_single_user_engagements ) ) {
$retval = true;
}
// Filter & return
return (bool) apply_filters( 'bbp_is_single_user_engagements', $retval );
}
/**
* Check if current page is a view page
*
* @since 2.0.0 bbPress (r2789)
*
* @global WP_Query $wp_query To check if WP_Query::bbp_is_view is true
* @return bool Is it a view page?
*/
function bbp_is_single_view() {
// Assume false
$retval = false;
// Get the main query global
$wp_query = bbp_get_wp_query();
// Check query
if ( ! empty( $wp_query->bbp_is_view ) && ( true === $wp_query->bbp_is_view ) ) {
$retval = true;
}
// Check query name
if ( empty( $retval ) && bbp_is_query_name( 'bbp_single_view' ) ) {
$retval = true;
}
// Filter & return
return (bool) apply_filters( 'bbp_is_single_view', $retval );
}
/**
* Check if current page is a search page
*
* @since 2.3.0 bbPress (r4579)
*
* @global WP_Query $wp_query To check if WP_Query::bbp_is_search is true
* @return bool Is it a search page?
*/
function bbp_is_search() {
// Bail if search is disabled
if ( ! bbp_allow_search() ) {
return false;
}
// Assume false
$retval = false;
// Get the main query global
$wp_query = bbp_get_wp_query();
// Get the rewrite ID (one time, to avoid repeated calls)
$rewrite_id = bbp_get_search_rewrite_id();
// Check query
if ( ! empty( $wp_query->bbp_is_search ) && ( true === $wp_query->bbp_is_search ) ) {
$retval = true;
}
// Check query name
if ( empty( $retval ) && bbp_is_query_name( $rewrite_id ) ) {
$retval = true;
}
// Check $_GET
if ( empty( $retval ) && isset( $_REQUEST[ $rewrite_id ] ) && empty( $_REQUEST[ $rewrite_id ] ) ) {
$retval = true;
}
// Filter & return
return (bool) apply_filters( 'bbp_is_search', $retval );
}
/**
* Check if current page is a search results page
*
* @since 2.4.0 bbPress (r4919)
*
* @global WP_Query $wp_query To check if WP_Query::bbp_is_search is true
* @return bool Is it a search page?
*/
function bbp_is_search_results() {
// Bail if search is disabled
if ( ! bbp_allow_search() ) {
return false;
}
// Assume false
$retval = false;
// Get the main query global
$wp_query = bbp_get_wp_query();
// Check query
if ( ! empty( $wp_query->bbp_search_terms ) ) {
$retval = true;
}
// Check query name
if ( empty( $retval ) && bbp_is_query_name( 'bbp_search_results' ) ) {
$retval = true;
}
// Check $_REQUEST
if ( empty( $retval ) && ! empty( $_REQUEST[ bbp_get_search_rewrite_id() ] ) ) {
$retval = true;
}
// Filter & return
return (bool) apply_filters( 'bbp_is_search_results', $retval );
}
/**
* Check if current page is an edit page
*
* @since 2.1.0 bbPress (r3585)
*
* @return bool True if it's the edit page, false if not
*/
function bbp_is_edit() {
// Assume false
$retval = false;
// Get the main query global
$wp_query = bbp_get_wp_query();
// Check query
if ( ! empty( $wp_query->bbp_is_edit ) && ( $wp_query->bbp_is_edit === true ) ) {
$retval = true;
}
// Filter & return
return (bool) apply_filters( 'bbp_is_edit', $retval );
}
/**
* Use the above is_() functions to output a body class for each scenario
*
* @since 2.0.0 bbPress (r2926)
*
* @param array $wp_classes
* @param array $custom_classes
* @return array Body Classes
*/
function bbp_body_class( $wp_classes = array(), $custom_classes = false ) {
// Default to no classes
$bbp_classes = array();
/** Archives **************************************************************/
if ( bbp_is_forum_archive() ) {
$bbp_classes[] = bbp_get_forum_post_type() . '-archive';
} elseif ( bbp_is_topic_archive() ) {
$bbp_classes[] = bbp_get_topic_post_type() . '-archive';
/** Topic Tags ************************************************************/
} elseif ( bbp_is_topic_tag() ) {
$bbp_classes[] = bbp_get_topic_tag_tax_id();
$bbp_classes[] = bbp_get_topic_tag_tax_id() . '-' . bbp_get_topic_tag_slug();
$bbp_classes[] = bbp_get_topic_tag_tax_id() . '-' . bbp_get_topic_tag_id();
} elseif ( bbp_is_topic_tag_edit() ) {
$bbp_classes[] = bbp_get_topic_tag_tax_id() . '-edit';
$bbp_classes[] = bbp_get_topic_tag_tax_id() . '-' . bbp_get_topic_tag_slug() . '-edit';
$bbp_classes[] = bbp_get_topic_tag_tax_id() . '-' . bbp_get_topic_tag_id() . '-edit';
/** Components ************************************************************/
} elseif ( bbp_is_single_forum() ) {
$bbp_classes[] = bbp_get_forum_post_type();
} elseif ( bbp_is_single_topic() ) {
$bbp_classes[] = bbp_get_topic_post_type();
} elseif ( bbp_is_single_reply() ) {
$bbp_classes[] = bbp_get_reply_post_type();
} elseif ( bbp_is_topic_edit() ) {
$bbp_classes[] = bbp_get_topic_post_type() . '-edit';
} elseif ( bbp_is_topic_merge() ) {
$bbp_classes[] = bbp_get_topic_post_type() . '-merge';
} elseif ( bbp_is_topic_split() ) {
$bbp_classes[] = bbp_get_topic_post_type() . '-split';
} elseif ( bbp_is_reply_edit() ) {
$bbp_classes[] = bbp_get_reply_post_type() . '-edit';
} elseif ( bbp_is_reply_move() ) {
$bbp_classes[] = bbp_get_reply_post_type() . '-move';
} elseif ( bbp_is_single_view() ) {
$bbp_classes[] = 'bbp-view';
$bbp_classes[] = 'bbp-view-' . bbp_get_view_id();
/** User ******************************************************************/
} elseif ( bbp_is_single_user_edit() ) {
$bbp_classes[] = 'bbp-user-edit';
$bbp_classes[] = 'single';
$bbp_classes[] = 'singular';
} elseif ( bbp_is_single_user() ) {
$bbp_classes[] = 'bbp-user-page';
$bbp_classes[] = 'single';
$bbp_classes[] = 'singular';
} elseif ( bbp_is_user_home() ) {
$bbp_classes[] = 'bbp-user-home';
$bbp_classes[] = 'single';
$bbp_classes[] = 'singular';
} elseif ( bbp_is_user_home_edit() ) {
$bbp_classes[] = 'bbp-user-home-edit';
$bbp_classes[] = 'single';
$bbp_classes[] = 'singular';
} elseif ( bbp_is_topics_created() ) {
$bbp_classes[] = 'bbp-topics-created';
$bbp_classes[] = 'single';
$bbp_classes[] = 'singular';
} elseif ( bbp_is_replies_created() ) {
$bbp_classes[] = 'bbp-replies-created';
$bbp_classes[] = 'single';
$bbp_classes[] = 'singular';
} elseif ( bbp_is_favorites() ) {
$bbp_classes[] = 'bbp-favorites';
$bbp_classes[] = 'single';
$bbp_classes[] = 'singular';
} elseif ( bbp_is_subscriptions() ) {
$bbp_classes[] = 'bbp-subscriptions';
$bbp_classes[] = 'single';
$bbp_classes[] = 'singular';
/** Search ****************************************************************/
} elseif ( bbp_is_search() ) {
$bbp_classes[] = 'bbp-search';
$bbp_classes[] = 'forum-search';
} elseif ( bbp_is_search_results() ) {
$bbp_classes[] = 'bbp-search-results';
$bbp_classes[] = 'forum-search-results';
/** Shortcodes ************************************************************/
} elseif ( bbp_has_shortcode() ) {
$bbp_classes[] = 'bbp-shortcode';
}
/** General ***************************************************************/
// Any page with bbPress content
if ( ! empty( $bbp_classes ) ) {
$bbp_classes[] = 'bbpress';
$bbp_classes[] = 'no-js';
}
/** Clean up **************************************************************/
// Merge WP classes with bbPress classes and remove any duplicates
$classes = array_unique( array_merge( (array) $bbp_classes, (array) $wp_classes ) );
// Deprecated filter (do not use)
$classes = apply_filters( 'bbp_get_the_body_class', $classes, $bbp_classes, $wp_classes, $custom_classes );
// Filter & return
return (array) apply_filters( 'bbp_body_class', $classes, $bbp_classes, $wp_classes, $custom_classes );
}
/**
* Output a small piece of JavaScript to replace the "bbp-no-js" body class
* with "bbp-js" to allow interactive & dynamic elements to work as intended.
*
* @since 2.6.10 bbPress (r7229)
*/
function bbp_swap_no_js_body_class() {
static $done = false;
// Bail if already done
if ( true === $done ) {
return;
}
// Mark as done
$done = true;
?>
shortcodes->codes );
// Loop through codes
foreach ( $codes as $code ) {
// Looking for shortcode in text
if ( has_shortcode( $text, $code ) ) {
$retval = true;
$found[] = $code;
}
}
}
// Filter & return
return (bool) apply_filters( 'bbp_has_shortcode', $retval, $found, $text );
}
/**
* Use the above is_() functions to return if in any bbPress page
*
* @since 2.0.0 bbPress (r3344)
*
* @return bool In a bbPress page
*/
function is_bbpress() {
// Default to false
$retval = false;
// Bail if main query has not been populated.
if ( ! bbp_get_wp_query() ) {
_doing_it_wrong( __FUNCTION__, esc_html__( 'Conditional query tags do not work before the query is run. Before then, they always return false.', 'bbpress' ), '2.7.0' );
return $retval;
}
/** Archives **************************************************************/
if ( bbp_is_forum_archive() ) {
$retval = true;
} elseif ( bbp_is_topic_archive() ) {
$retval = true;
/** Topic Tags ************************************************************/
} elseif ( bbp_is_topic_tag() ) {
$retval = true;
} elseif ( bbp_is_topic_tag_edit() ) {
$retval = true;
/** Components ************************************************************/
} elseif ( bbp_is_single_forum() ) {
$retval = true;
} elseif ( bbp_is_single_topic() ) {
$retval = true;
} elseif ( bbp_is_single_reply() ) {
$retval = true;
} elseif ( bbp_is_topic_edit() ) {
$retval = true;
} elseif ( bbp_is_topic_merge() ) {
$retval = true;
} elseif ( bbp_is_topic_split() ) {
$retval = true;
} elseif ( bbp_is_reply_edit() ) {
$retval = true;
} elseif ( bbp_is_reply_move() ) {
$retval = true;
} elseif ( bbp_is_single_view() ) {
$retval = true;
/** User ******************************************************************/
} elseif ( bbp_is_single_user_edit() ) {
$retval = true;
} elseif ( bbp_is_single_user() ) {
$retval = true;
} elseif ( bbp_is_user_home() ) {
$retval = true;
} elseif ( bbp_is_user_home_edit() ) {
$retval = true;
} elseif ( bbp_is_topics_created() ) {
$retval = true;
} elseif ( bbp_is_replies_created() ) {
$retval = true;
} elseif ( bbp_is_favorites() ) {
$retval = true;
} elseif ( bbp_is_subscriptions() ) {
$retval = true;
/** Search ****************************************************************/
} elseif ( bbp_is_search() ) {
$retval = true;
} elseif ( bbp_is_search_results() ) {
$retval = true;
/** Shortcodes ************************************************************/
} elseif ( bbp_has_shortcode() ) {
$retval = true;
}
/** Done ******************************************************************/
// Filter & return
return (bool) apply_filters( 'is_bbpress', $retval );
}
/** Forms *********************************************************************/
/**
* Output the login form action url
*
* @since 2.0.0 bbPress (r2815)
*
* @param array $args This function supports these arguments:
* - action: The action being taken
* - context: The context the action is being taken from
*/
function bbp_wp_login_action( $args = array() ) {
echo esc_url( bbp_get_wp_login_action( $args ) );
}
/**
* Return the login form action url
*
* @since 2.6.0 bbPress (r5684)
*
* @param array $args This function supports these arguments:
* - action: The action being taken
* - context: The context the action is being taken from
*/
function bbp_get_wp_login_action( $args = array() ) {
// Parse arguments against default values
$r = bbp_parse_args( $args, array(
'action' => '',
'context' => '',
'url' => 'wp-login.php'
), 'login_action' );
// Add action as query arg
$login_url = ! empty( $r['action'] )
? add_query_arg( array( 'action' => $r['action'] ), $r['url'] )
: $r['url'];
$login_url = site_url( $login_url, $r['context'] );
// Filter & return
return apply_filters( 'bbp_get_wp_login_action', $login_url, $r, $args );
}
/**
* Output hidden request URI field for user forms.
*
* The referer link is the current Request URI from the server super global. To
* check the field manually, use bbp_get_redirect_to().
*
* @since 2.0.0 bbPress (r2815)
*
* @param string $redirect_to Pass a URL to redirect to
*/
function bbp_redirect_to_field( $redirect_to = '' ) {
// Make sure we are directing somewhere
if ( empty( $redirect_to ) ) {
if ( isset( $_SERVER['REQUEST_URI'] ) ) {
$redirect_to = bbp_get_url_scheme() . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
} else {
$redirect_to = wp_get_referer();
}
}
// Remove loggedout query arg if it's there
$redirect_to = remove_query_arg( 'loggedout', $redirect_to );
$redirect_field = '';
// Filter & return
echo apply_filters( 'bbp_redirect_to_field', $redirect_field, $redirect_to );
}
/**
* Echo sanitized $_REQUEST value.
*
* Use the $input_type parameter to properly process the value. This
* ensures correct sanitization of the value for the receiving input.
*
* @since 2.0.0 bbPress (r2815)
*
* @param string $request Name of $_REQUEST to look for
* @param string $input_type Type of input. Default: text. Accepts:
* textarea|password|select|radio|checkbox
*/
function bbp_sanitize_val( $request = '', $input_type = 'text' ) {
echo bbp_get_sanitize_val( $request, $input_type );
}
/**
* Return sanitized $_REQUEST value.
*
* Use the $input_type parameter to properly process the value. This
* ensures correct sanitization of the value for the receiving input.
*
* @since 2.0.0 bbPress (r2815)
*
* @param string $request Name of $_REQUEST to look for
* @param string $input_type Type of input. Default: text. Accepts:
* textarea|password|select|radio|checkbox
*
* @return string Sanitized value ready for screen display
*/
function bbp_get_sanitize_val( $request = '', $input_type = 'text' ) {
// Check that requested
if ( empty( $_REQUEST[ $request ] ) ) {
return false;
}
// Set request varaible
$pre_ret_val = $_REQUEST[ $request ];
// Treat different kinds of fields in different ways
switch ( $input_type ) {
case 'text' :
case 'textarea' :
$retval = esc_attr( wp_unslash( $pre_ret_val ) );
break;
case 'password' :
case 'select' :
case 'radio' :
case 'checkbox' :
default :
$retval = esc_attr( $pre_ret_val );
break;
}
// Filter & return
return apply_filters( 'bbp_get_sanitize_val', $retval, $request, $input_type );
}
/**
* Output the current tab index of a given form
*
* Use this function to handle the tab indexing of user facing forms within a
* template file. Calling this function will automatically increment the global
* tab index by default.
*
* @since 2.0.0 bbPress (r2810)
*
* @deprecated 2.6.0 bbPress (r5561)
*
* @link https://bbpress.trac.wordpress.org/attachment/ticket/2714 Trac Ticket
* @param int $auto_increment Optional. Default true. Set to false to prevent
* increment
*/
function bbp_tab_index( $auto_increment = true ) {
echo bbp_get_tab_index( $auto_increment );
}
/**
* Return the current tab index of a given form
*
* Use this function to handle the tab indexing of user facing forms
* within a template file. Calling this function will automatically
* increment the global tab index by default.
*
* @since 2.0.0 bbPress (r2810)
*
* @deprecated 2.6.0 bbPress (r5561)
*
* @link https://bbpress.trac.wordpress.org/attachment/ticket/2714 Trac Ticket
* @param int $auto_increment Optional. Default true. Set to false to
* prevent the increment
* @return int $bbp->tab_index The global tab index
*/
function bbp_get_tab_index( $auto_increment = true ) {
$bbp = bbpress();
if ( true === $auto_increment ) {
++$bbp->tab_index;
}
// Filter & return
return apply_filters( 'bbp_get_tab_index', (int) $bbp->tab_index );
}
/**
* Output a "tabindex" attribute for an element, if an index was passed.
*
* This helper function is in use, but it is generally considered impolite to
* override the "tabindex" attribute beyond what the browser naturally assigns.
*
* Most internal usages pass `false` which results in no attribute being used.
*
* @since 2.6.0 bbPress (r6424)
*
* @param mixed $tab False to skip, any integer to use
*/
function bbp_tab_index_attribute( $tab = false ) {
echo bbp_get_tab_index_attribute( $tab );
}
/**
* Return a "tabindex" attribute for an element, if an index was passed.
*
* This helper function is in use, but it is generally considered impolite to
* override the "tabindex" attribute beyond what the browser naturally assigns.
*
* Most internal usages pass `false` which results in no attribute being used.
*
* @since 2.6.0 bbPress (r6424)
*
* @param mixed $tab False to skip, any integer to use
*
* @return string
*/
function bbp_get_tab_index_attribute( $tab = false ) {
// Get attribute
$attr = is_numeric( $tab )
? ' tabindex="' . (int) $tab . '"'
: '';
// Filter & return
return apply_filters( 'bbp_get_tab_index_attribute', $attr, $tab );
}
/**
* Output a select box allowing to pick which forum/topic a new topic/reply
* belongs in.
*
* Can be used for any post type, but is mostly used for topics and forums.
*
* @since 2.0.0 bbPress (r2746)
*
* @param array $args See {@link bbp_get_dropdown()} for arguments
*/
function bbp_dropdown( $args = array() ) {
echo bbp_get_dropdown( $args );
}
/**
* Return a select box allowing to pick which forum/topic a new
* topic/reply belongs in.
*
* @since 2.0.0 bbPress (r2746)
*
* @param array $args The function supports these args:
* - post_type: Post type, defaults to bbp_get_forum_post_type() (bbp_forum)
* - selected: Selected ID, to not have any value as selected, pass
* anything smaller than 0 (due to the nature of select
* box, the first value would of course be selected -
* though you can have that as none (pass 'show_none' arg))
* - orderby: Defaults to 'menu_order title'
* - post_parent: Post parent. Defaults to 0
* - post_status: Which all post_statuses to find in? Can be an array
* or CSV of publish, category, closed, private, spam,
* trash (based on post type) - if not set, these are
* automatically determined based on the post_type
* - posts_per_page: Retrieve all forums/topics. Defaults to -1 to get
* all posts
* - walker: Which walker to use? Defaults to
* {@link BBP_Walker_Dropdown}
* - select_id: ID of the select box. Defaults to 'bbp_forum_id'
* - tab: Deprecated. Tabindex value. False or integer
* - options_only: Show only ? No