bbp_is_topic_edit ) && ( $wp_query->bbp_is_topic_edit == true ) )
return true;
return false;
}
/**
* Check if current page is a topic merge page
*
* @since bbPress (r2756)
*
* @uses bbp_is_topic_edit() To check if it's a topic edit page
* @return bool True if it's the topic merge page, false if not
*/
function bbp_is_topic_merge() {
if ( bbp_is_topic_edit() && !empty( $_GET['action'] ) && ( 'merge' == $_GET['action'] ) )
return true;
return false;
}
/**
* Check if current page is a topic split page
*
* @since bbPress (r2756)
*
* @uses bbp_is_topic_edit() To check if it's a topic edit page
* @return bool True if it's the topic split page, false if not
*/
function bbp_is_topic_split() {
if ( bbp_is_topic_edit() && !empty( $_GET['action'] ) && ( 'split' == $_GET['action'] ) )
return true;
return false;
}
/**
* Check if the current page is a topic tag
*
* @since bbPress (r3311)
*
* @global bbPress $bbp
* @return bool True if it's a topic tag, false if not
*/
function bbp_is_topic_tag() {
global $bbp, $wp_query;
// Return false if editing a topic tag
if ( bbp_is_topic_tag_edit() )
return false;
if ( is_tax( bbp_get_topic_tag_tax_id() ) || !empty( $bbp->topic_query->is_tax ) || get_query_var( 'bbp_topic_tag' ) )
return true;
return false;
}
/**
* Check if the current page is editing a topic tag
*
* @since bbPress (r3346)
*
* @uses WP_Query Checks if WP_Query::bbp_is_topic_tag_edit is true
* @return bool True if editing a topic tag, false if not
*/
function bbp_is_topic_tag_edit() {
global $wp_query;
if ( !empty( $wp_query->bbp_is_topic_tag_edit ) && ( true == $wp_query->bbp_is_topic_tag_edit ) )
return true;
return false;
}
/**
* Check if the current post type is one of bbPress's
*
* @since bbPress (r3311)
*
* @uses get_post_type()
* @uses bbp_get_forum_post_type()
* @uses bbp_get_topic_post_type()
* @uses bbp_get_reply_post_type()
*
* @return bool
*/
function bbp_is_custom_post_type() {
// Current post type
$post_type = get_post_type();
// bbPress post types
$bbp_post_types = array(
bbp_get_forum_post_type(),
bbp_get_topic_post_type(),
bbp_get_reply_post_type()
);
// Viewing one of the bbPress post types
if ( in_array( $post_type, $bbp_post_types ) )
return true;
return false;
}
/**
* Check if current page is a bbPress reply
*
* @since bbPress (r2549)
*
* @param int $post_id Possible post_id to check
* @uses bbp_get_reply_post_type() To get the reply post type
* @uses get_post_type() To get the post type of the post id
* @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;
return (bool) apply_filters( 'bbp_is_reply', $retval, $post_id );
}
/**
* Check if current page is a reply edit page
*
* @since bbPress (r2753)
*
* @uses WP_Query Checks if WP_Query::bbp_is_reply_edit is true
* @return bool True if it's the reply edit page, false if not
*/
function bbp_is_reply_edit() {
global $wp_query;
if ( !empty( $wp_query->bbp_is_reply_edit ) && ( true == $wp_query->bbp_is_reply_edit ) )
return true;
return false;
}
/**
* Viewing a single reply
*
* @since bbPress (r3344)
*
* @uses is_single()
* @uses bbp_get_reply_post_type()
* @uses get_post_type()
* @uses apply_filters()
*
* @return bool
*/
function bbp_is_single_reply() {
// Assume false
$retval = false;
// Single and a match
if ( is_singular( bbp_get_reply_post_type() ) || ( bbp_is_query_name( 'bbp_single_reply' ) ) )
$retval = true;
return (bool) apply_filters( 'bbp_is_single_reply', $retval );
}
/**
* Check if current page is a bbPress user's favorites page (profile page)
*
* @since bbPress (r2652)
*
* @uses bbp_get_query_name() To get the query name
* @return bool True if it's the favorites page, false if not
*/
function bbp_is_favorites() {
$retval = bbp_is_query_name( 'bbp_user_profile_favorites' );
return (bool) apply_filters( 'bbp_is_favorites', $retval );
}
/**
* Check if current page is a bbPress user's subscriptions page (profile page)
*
* @since bbPress (r2652)
*
* @uses bbp_get_query_name() To get the query name
* @return bool True if it's the subscriptions page, false if not
*/
function bbp_is_subscriptions() {
$retval = bbp_is_query_name( 'bbp_user_profile_subscriptions' );
return (bool) apply_filters( 'bbp_is_subscriptions', $retval );
}
/**
* Check if current page shows the topics created by a bbPress user (profile
* page)
*
* @since bbPress (r2688)
*
* @uses bbp_get_query_name() To get the query name
* @return bool True if it's the topics created page, false if not
*/
function bbp_is_topics_created() {
$retval = bbp_is_query_name( 'bbp_user_profile_topics_created' );
return (bool) apply_filters( 'bbp_is_topics_created', $retval );
}
/**
* Check if current page is the currently logged in users author page
*
* @since bbPress (r2688)
*
* @uses bbPres Checks if bbPress::displayed_user is set and if
* bbPress::displayed_user::ID equals bbPress::current_user::ID
* or not
* @return bool True if it's the user's home, false if not
*/
function bbp_is_user_home() {
global $bbp;
if ( !is_user_logged_in() )
return false;
if ( empty( $bbp->displayed_user ) )
return false;
return (bool) ( bbp_get_displayed_user_id() == bbp_get_current_user_id() );
}
/**
* Check if current page is a user profile page
*
* @since bbPress (r2688)
*
* @uses WP_Query Checks if WP_Query::bbp_is_single_user is set to true
* @return bool True if it's a user's profile page, false if not
*/
function bbp_is_single_user() {
global $wp_query;
if ( !empty( $wp_query->bbp_is_single_user ) && ( true == $wp_query->bbp_is_single_user ) )
return true;
return false;
}
/**
* Check if current page is a user profile edit page
*
* @since bbPress (r2688)
*
* @uses WP_Query Checks if WP_Query::bbp_is_single_user_edit is set to true
* @return bool True if it's a user's profile edit page, false if not
*/
function bbp_is_single_user_edit() {
global $wp_query;
if ( !empty( $wp_query->bbp_is_single_user_edit ) && ( true == $wp_query->bbp_is_single_user_edit ) )
return true;
return false;
}
/**
* Check if current page is a view page
*
* @since bbPress (r2789)
*
* @global WP_Query $wp_query To check if WP_Query::bbp_is_view is true
* @uses bbp_get_query_name() To get the query name
* @return bool Is it a view page?
*/
function bbp_is_single_view() {
global $wp_query;
// Assume false
$retval = false;
// 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;
return (bool) apply_filters( 'bbp_is_single_view', $retval );
}
/**
* Use the above is_() functions to output a body class for each scenario
*
* @since bbPress (r2926)
*
* @param array $wp_classes
* @param array $custom_classes
* @uses bbp_is_single_forum()
* @uses bbp_is_single_topic()
* @uses bbp_is_topic_edit()
* @uses bbp_is_topic_merge()
* @uses bbp_is_topic_split()
* @uses bbp_is_single_reply()
* @uses bbp_is_reply_edit()
* @uses bbp_is_reply_edit()
* @uses bbp_is_single_view()
* @uses bbp_is_single_user_edit()
* @uses bbp_is_single_user()
* @uses bbp_is_user_home()
* @uses bbp_is_subscriptions()
* @uses bbp_is_favorites()
* @uses bbp_is_topics_created()
* @return array Body Classes
*/
function bbp_body_class( $wp_classes, $custom_classes = false ) {
$bbp_classes = array();
/** Archives **************************************************************/
if ( bbp_is_forum_archive() )
$bbp_classes[] = bbp_get_forum_post_type() . '-archive';
if ( bbp_is_topic_archive() )
$bbp_classes[] = bbp_get_topic_post_type() . '-archive';
/** Components ************************************************************/
if ( bbp_is_single_forum() )
$bbp_classes[] = bbp_get_forum_post_type();
if ( bbp_is_single_topic() )
$bbp_classes[] = bbp_get_topic_post_type();
if ( bbp_is_single_reply() )
$bbp_classes[] = bbp_get_reply_post_type();
if ( bbp_is_topic_edit() )
$bbp_classes[] = bbp_get_topic_post_type() . '-edit';
if ( bbp_is_topic_merge() )
$bbp_classes[] = bbp_get_topic_post_type() . '-merge';
if ( bbp_is_topic_split() )
$bbp_classes[] = bbp_get_topic_post_type() . '-split';
if ( bbp_is_reply_edit() )
$bbp_classes[] = bbp_get_reply_post_type() . '-edit';
if ( bbp_is_single_view() )
$bbp_classes[] = 'bbp-view';
/** User ******************************************************************/
if ( bbp_is_single_user_edit() ) {
$bbp_classes[] = 'bbp-user-edit';
$bbp_classes[] = 'single';
$bbp_classes[] = 'singular';
}
if ( bbp_is_single_user() ) {
$bbp_classes[] = 'bbp-user-page';
$bbp_classes[] = 'single';
$bbp_classes[] = 'singular';
}
if ( bbp_is_user_home() ) {
$bbp_classes[] = 'bbp-user-home';
$bbp_classes[] = 'single';
$bbp_classes[] = 'singular';
}
if ( bbp_is_topics_created() ) {
$bbp_classes[] = 'bbp-topics-created';
$bbp_classes[] = 'single';
$bbp_classes[] = 'singular';
}
if ( bbp_is_favorites() ) {
$bbp_classes[] = 'bbp-favorites';
$bbp_classes[] = 'single';
$bbp_classes[] = 'singular';
}
if ( bbp_is_subscriptions() ) {
$bbp_classes[] = 'bbp-subscriptions';
$bbp_classes[] = 'single';
$bbp_classes[] = 'singular';
}
/** Clean up **************************************************************/
// Add bbPress class if we are within a bbPress page
if ( !empty( $bbp_classes ) )
$bbp_classes[] = 'bbPress';
// Merge WP classes with bbPress classes
$classes = array_merge( (array) $bbp_classes, (array) $wp_classes );
// Remove any duplicates
$classes = array_unique( $classes );
return apply_filters( 'bbp_get_the_body_class', $classes, $bbp_classes, $wp_classes, $custom_classes );
}
/**
* Use the above is_() functions to return if in any bbPress page
*
* @since bbPress (r3344)
*
* @uses bbp_is_single_forum()
* @uses bbp_is_single_topic()
* @uses bbp_is_topic_edit()
* @uses bbp_is_topic_merge()
* @uses bbp_is_topic_split()
* @uses bbp_is_single_reply()
* @uses bbp_is_reply_edit()
* @uses bbp_is_reply_edit()
* @uses bbp_is_single_view()
* @uses bbp_is_single_user_edit()
* @uses bbp_is_single_user()
* @uses bbp_is_user_home()
* @uses bbp_is_subscriptions()
* @uses bbp_is_favorites()
* @uses bbp_is_topics_created()
* @return bool In a bbPress page
*/
function is_bbpress() {
// Defalt to false
$retval = false;
/** 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_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_topics_created() )
$retval = true;
elseif ( bbp_is_favorites() )
$retval = true;
elseif ( bbp_is_subscriptions() )
$retval = true;
/** Done ******************************************************************/
return apply_filters( 'is_bbpress', $retval );
}
/** Forms *********************************************************************/
/**
* Output the login form action url
*
* @since bbPress (r2815)
*
* @param string $url Pass a URL to redirect to
* @uses add_query_arg() To add a arg to the url
* @uses site_url() Toget the site url
* @uses apply_filters() Calls 'bbp_wp_login_action' with the url and args
*/
function bbp_wp_login_action( $args = '' ) {
$defaults = array (
'action' => '',
'context' => ''
);
$r = wp_parse_args( $args, $defaults );
extract( $r );
if ( !empty( $action ) )
$login_url = add_query_arg( array( 'action' => $action ), 'wp-login.php' );
else
$login_url = 'wp-login.php';
$login_url = site_url( $login_url, $context );
echo apply_filters( 'bbp_wp_login_action', $login_url, $args );
}
/**
* Output hidden request URI field for user forms.
*
* The referer link is the current Request URI from the server super global. The
* input name is '_wp_http_referer', in case you wanted to check manually.
*
* @since bbPress (r2815)
*
* @param string $url Pass a URL to redirect to
* @uses wp_get_referer() To get the referer
* @uses esc_attr() To escape the url
* @uses apply_filters() Calls 'bbp_redirect_to_field' with the referer field
* and url
*/
function bbp_redirect_to_field( $redirect_to = '' ) {
// Rejig the $redirect_to
if ( !isset( $_SERVER['REDIRECT_URL'] ) || ( !$redirect_to = home_url( $_SERVER['REDIRECT_URL'] ) ) )
$redirect_to = wp_get_referer();
// Make sure we are directing somewhere
if ( empty( $redirect_to ) )
$redirect_to = home_url( isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : '' );
// Remove loggedout query arg if it's there
$redirect_to = (string) esc_attr( remove_query_arg( 'loggedout', $redirect_to ) );
$redirect_field = '';
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 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
* @uses bbp_get_sanitize_val() To sanitize the value.
*/
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 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
* @uses esc_attr() To escape the string
* @uses apply_filters() Calls 'bbp_get_sanitize_val' with the sanitized
* value, request and input type
* @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( stripslashes( $pre_ret_val ) );
break;
case 'password' :
case 'select' :
case 'radio' :
case 'checkbox' :
default :
$retval = esc_attr( $pre_ret_val );
break;
}
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 bbPress (r2810)
*
* @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 );
}
/**
* 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 bbPress (r2810)
*
* @uses apply_filters Allows return value to be filtered
* @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 ) {
global $bbp;
if ( true === $auto_increment )
++$bbp->tab_index;
return apply_filters( 'bbp_get_tab_index', (int) $bbp->tab_index );
}
/**
* 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 bbPress (r2746)
*
* @param mixed $args See {@link bbp_get_dropdown()} for arguments
*/
function bbp_dropdown( $args = '' ) {
echo bbp_get_dropdown( $args );
}
/**
* Output a select box allowing to pick which forum/topic a new
* topic/reply belongs in.
*
* @since bbPress (r2746)
*
* @param mixed $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))
* - sort_column: Sort by? Defaults to 'menu_order, post_title'
* - child_of: Child of. 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: Tabindex value. False or integer
* - options_only: Show only ? No