/wp-content/plugins/bbpress/includes/common/template-tags.php
PHP | 2581 lines | 981 code | 480 blank | 1120 comment | 244 complexity | d845eb1757e3406416cef352542ad724 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, AGPL-1.0, LGPL-3.0, LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * bbPress Common Template Tags
- *
- * Common template tags are ones that are used by more than one component, like
- * forums, topics, replies, users, topic tags, etc...
- *
- * @package bbPress
- * @subpackage TemplateTags
- */
- // Exit if accessed directly
- if ( !defined( 'ABSPATH' ) ) exit;
- /** URLs **********************************************************************/
- /**
- * Ouput the forum URL
- *
- * @since bbPress (r3979)
- *
- * @uses bbp_get_forums_url() To get the forums URL
- * @param string $path Additional path with leading slash
- */
- function bbp_forums_url( $path = '/' ) {
- echo bbp_get_forums_url( $path );
- }
- /**
- * Return the forum URL
- *
- * @since bbPress (r3979)
- *
- * @uses home_url() To get the home URL
- * @uses bbp_get_root_slug() To get the forum root location
- * @param string $path Additional path with leading slash
- */
- function bbp_get_forums_url( $path = '/' ) {
- return home_url( bbp_get_root_slug() . $path );
- }
- /**
- * Ouput the forum URL
- *
- * @since bbPress (r3979)
- *
- * @uses bbp_get_topics_url() To get the topics URL
- * @param string $path Additional path with leading slash
- */
- function bbp_topics_url( $path = '/' ) {
- echo bbp_get_topics_url( $path );
- }
- /**
- * Return the forum URL
- *
- * @since bbPress (r3979)
- *
- * @uses home_url() To get the home URL
- * @uses bbp_get_topic_archive_slug() To get the topics archive location
- * @param string $path Additional path with leading slash
- * @return The URL to the topics archive
- */
- function bbp_get_topics_url( $path = '/' ) {
- return home_url( bbp_get_topic_archive_slug() . $path );
- }
- /** Add-on Actions ************************************************************/
- /**
- * Add our custom head action to wp_head
- *
- * @since bbPress (r2464)
- *
- * @uses do_action() Calls 'bbp_head'
- */
- function bbp_head() {
- do_action( 'bbp_head' );
- }
- /**
- * Add our custom head action to wp_head
- *
- * @since bbPress (r2464)
- *
- * @uses do_action() Calls 'bbp_footer'
- */
- function bbp_footer() {
- do_action( 'bbp_footer' );
- }
- /** is_ ***********************************************************************/
- /**
- * Check if current site is public
- *
- * @since bbPress (r3398)
- *
- * @param int $site_id
- * @uses get_current_blog_id()
- * @uses get_blog_option()
- * @uses apply_filters()
- * @return bool True if site is public, false if private
- */
- function bbp_is_site_public( $site_id = 0 ) {
- // Get the current site ID
- if ( empty( $site_id ) )
- $site_id = get_current_blog_id();
- // Get the site visibility setting
- $public = get_blog_option( $site_id, 'blog_public', 1 );
- return (bool) apply_filters( 'bbp_is_site_public', $public, $site_id );
- }
- /**
- * Check if current page is a bbPress forum
- *
- * @since bbPress (r2549)
- *
- * @param int $post_id Possible post_id to check
- * @uses bbp_get_forum_post_type() To get the forum post type
- * @return bool True if it's a forum page, false if not
- */
- function bbp_is_forum( $post_id = 0 ) {
- // Assume false
- $retval = false;
- // Supplied ID is a forum
- if ( !empty( $post_id ) && ( bbp_get_forum_post_type() == get_post_type( $post_id ) ))
- $retval = true;
- return (bool) apply_filters( 'bbp_is_forum', $retval, $post_id );
- }
- /**
- * Check if we are viewing a forum archive.
- *
- * @since bbPress (r3251)
- *
- * @uses is_post_type_archive() To check if we are looking at the forum archive
- * @uses bbp_get_forum_post_type() To get the forum post type ID
- *
- * @return bool
- */
- function bbp_is_forum_archive() {
- // Default to false
- $retval = false;
- // In forum archive
- if ( is_post_type_archive( bbp_get_forum_post_type() ) || bbp_is_query_name( 'bbp_forum_archive' ) )
- $retval = true;
- return (bool) apply_filters( 'bbp_is_forum_archive', $retval );
- }
- /**
- * Viewing a single forum
- *
- * @since bbPress (r3338)
- *
- * @uses is_single()
- * @uses bbp_get_forum_post_type()
- * @uses get_post_type()
- * @uses apply_filters()
- *
- * @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;
- return (bool) apply_filters( 'bbp_is_single_forum', $retval );
- }
- /**
- * Check if current page is a forum edit page
- *
- * @since bbPress (r3553)
- *
- * @uses WP_Query Checks if WP_Query::bbp_is_forum_edit is true
- * @return bool True if it's the forum edit page, false if not
- */
- function bbp_is_forum_edit() {
- global $wp_query, $pagenow;
- // Assume false
- $retval = false;
- // 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;
- return (bool) apply_filters( 'bbp_is_forum_edit', $retval );
- }
- /**
- * Check if current page is a bbPress topic
- *
- * @since bbPress (r2549)
- *
- * @param int $post_id Possible post_id to check
- * @uses bbp_get_topic_post_type() To get the topic post type
- * @uses get_post_type() To get the post type of the post id
- * @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;
- return (bool) apply_filters( 'bbp_is_topic', $retval, $post_id );
- }
- /**
- * Viewing a single topic
- *
- * @since bbPress (r3338)
- *
- * @uses is_single()
- * @uses bbp_get_topic_post_type()
- * @uses get_post_type()
- * @uses apply_filters()
- *
- * @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;
- return (bool) apply_filters( 'bbp_is_single_topic', $retval );
- }
- /**
- * Check if we are viewing a topic archive.
- *
- * @since bbPress (r3251)
- *
- * @uses is_post_type_archive() To check if we are looking at the topic archive
- * @uses bbp_get_topic_post_type() To get the topic post type ID
- *
- * @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;
- return (bool) apply_filters( 'bbp_is_topic_archive', $retval );
- }
- /**
- * Check if current page is a topic edit page
- *
- * @since bbPress (r2753)
- *
- * @uses WP_Query Checks if WP_Query::bbp_is_topic_edit is true
- * @return bool True if it's the topic edit page, false if not
- */
- function bbp_is_topic_edit() {
- global $wp_query, $pagenow;
- // Assume false
- $retval = false;
- // 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;
- return (bool) apply_filters( 'bbp_is_topic_edit', $retval );
- }
- /**
- * 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() {
- // Assume false
- $retval = false;
- // Check topic edit and GET params
- if ( bbp_is_topic_edit() && !empty( $_GET['action'] ) && ( 'merge' == $_GET['action'] ) )
- return true;
- return (bool) apply_filters( 'bbp_is_topic_merge', $retval );
- }
- /**
- * 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() {
- // Assume false
- $retval = false;
- // Check topic edit and GET params
- if ( bbp_is_topic_edit() && !empty( $_GET['action'] ) && ( 'split' == $_GET['action'] ) )
- $retval = true;
- return (bool) apply_filters( 'bbp_is_topic_split', $retval );
- }
- /**
- * Check if the current page is a topic tag
- *
- * @since 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;
- return (bool) apply_filters( 'bbp_is_topic_tag', $retval );
- }
- /**
- * 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, $pagenow, $taxnow;
- // Bail if topic-tags are off
- if ( ! bbp_allow_topic_tags() )
- return false;
- // Assume false
- $retval = false;
- // 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;
- return (bool) apply_filters( 'bbp_is_topic_tag_edit', $retval );
- }
- /**
- * Check if the current post type is one of bbPress's
- *
- * @since bbPress (r3311)
- *
- * @param mixed $the_post Optional. Post object or post ID.
- * @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( $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()
- ) ) )
- $retval = true;
- return (bool) apply_filters( 'bbp_is_custom_post_type', $retval, $the_post );
- }
- /**
- * 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, $pagenow;
- // Assume false
- $retval = false;
- // 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;
- return (bool) apply_filters( 'bbp_is_reply_edit', $retval );
- }
- /**
- * Check if current page is a reply move page
- *
- * @uses bbp_is_reply_move() To check if it's 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;
- return (bool) apply_filters( 'bbp_is_reply_move', $retval );
- }
- /**
- * 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;
- // 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;
- 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)
- *
- * @return bool True if it's the favorites page, false if not
- */
- function bbp_is_favorites() {
- global $wp_query;
- // Assume false
- $retval = false;
- // Check query
- if ( !empty( $wp_query->bbp_is_single_user_favs ) && ( true == $wp_query->bbp_is_single_user_favs ) )
- $retval = true;
- return (bool) apply_filters( 'bbp_is_favorites', $retval );
- }
- /**
- * Check if current page is a bbPress user's subscriptions page (profile page)
- *
- * @since bbPress (r2652)
- *
- * @return bool True if it's the subscriptions page, false if not
- */
- function bbp_is_subscriptions() {
- global $wp_query;
- // Assume false
- $retval = false;
- // Check query
- if ( !empty( $wp_query->bbp_is_single_user_subs ) && ( true == $wp_query->bbp_is_single_user_subs ) )
- $retval = true;
- 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)
- *
- * @return bool True if it's the topics created page, false if not
- */
- function bbp_is_topics_created() {
- global $wp_query;
- // Assume false
- $retval = false;
- // Check query
- if ( !empty( $wp_query->bbp_is_single_user_topics ) && ( true == $wp_query->bbp_is_single_user_topics ) )
- $retval = true;
- return (bool) apply_filters( 'bbp_is_topics_created', $retval );
- }
- /**
- * Check if current page shows the topics created by a bbPress user (profile
- * page)
- *
- * @since bbPress (r4225)
- *
- * @return bool True if it's the topics created page, false if not
- */
- function bbp_is_replies_created() {
- global $wp_query;
- // Assume false
- $retval = false;
- // Check query
- if ( !empty( $wp_query->bbp_is_single_user_replies ) && ( true == $wp_query->bbp_is_single_user_replies ) )
- $retval = true;
- return (bool) apply_filters( 'bbp_is_replies_created', $retval );
- }
- /**
- * Check if current page is the currently logged in users author page
- *
- * @since bbPress (r2688)
- * @uses bbp_is_single_user() Check query variable
- * @uses is_user_logged_in() Must be logged in to be home
- * @uses bbp_get_displayed_user_id()
- * @uses bbp_get_current_user_id()
- * @return bool True if it's the user's home, false if not
- */
- function bbp_is_user_home() {
- global $wp_query;
- // Assume false
- $retval = false;
- // Check query
- if ( !empty( $wp_query->bbp_is_single_user_home ) && ( true == $wp_query->bbp_is_single_user_home ) )
- $retval = true;
- return (bool) apply_filters( 'bbp_is_user_home', $retval );
- }
- /**
- * Check if current page is the currently logged in users author edit page
- *
- * @since bbPress (r3918)
- * @uses bbp_is_single_user_edit() Check query variable
- * @uses is_user_logged_in() Must be logged in to be home
- * @uses bbp_get_displayed_user_id()
- * @uses bbp_get_current_user_id()
- * @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;
- return (bool) apply_filters( 'bbp_is_user_home_edit', $retval );
- }
- /**
- * 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;
- // Assume false
- $retval = false;
- // Check query
- if ( !empty( $wp_query->bbp_is_single_user ) && ( true == $wp_query->bbp_is_single_user ) )
- $retval = true;
- return (bool) apply_filters( 'bbp_is_single_user', $retval );
- }
- /**
- * 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;
- // Assume false
- $retval = false;
- // Check query
- if ( !empty( $wp_query->bbp_is_single_user_edit ) && ( true == $wp_query->bbp_is_single_user_edit ) )
- $retval = true;
- return (bool) apply_filters( 'bbp_is_single_user_edit', $retval );
- }
- /**
- * Check if current page is a user profile page
- *
- * @since bbPress (r4225)
- *
- * @uses WP_Query Checks if WP_Query::bbp_is_single_user_profile is set to true
- * @return bool True if it's a user's profile page, false if not
- */
- function bbp_is_single_user_profile() {
- global $wp_query;
- // Assume false
- $retval = false;
- // Check query
- if ( !empty( $wp_query->bbp_is_single_user_profile ) && ( true == $wp_query->bbp_is_single_user_profile ) )
- $retval = true;
- return (bool) apply_filters( 'bbp_is_single_user_profile', $retval );
- }
- /**
- * Check if current page is a user topics created page
- *
- * @since bbPress (r4225)
- *
- * @uses WP_Query Checks if WP_Query::bbp_is_single_user_topics is set to true
- * @return bool True if it's a user's topics page, false if not
- */
- function bbp_is_single_user_topics() {
- global $wp_query;
- // Assume false
- $retval = false;
- // Check query
- if ( !empty( $wp_query->bbp_is_single_user_topics ) && ( true == $wp_query->bbp_is_single_user_topics ) )
- $retval = true;
- return (bool) apply_filters( 'bbp_is_single_user_topics', $retval );
- }
- /**
- * Check if current page is a user replies created page
- *
- * @since bbPress (r4225)
- *
- * @uses WP_Query Checks if WP_Query::bbp_is_single_user_replies is set to true
- * @return bool True if it's a user's replies page, false if not
- */
- function bbp_is_single_user_replies() {
- global $wp_query;
- // Assume false
- $retval = false;
- // Check query
- if ( !empty( $wp_query->bbp_is_single_user_replies ) && ( true == $wp_query->bbp_is_single_user_replies ) )
- $retval = true;
- return (bool) apply_filters( 'bbp_is_single_user_replies', $retval );
- }
- /**
- * 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_is_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 );
- }
- /**
- * Check if current page is a search page
- *
- * @since bbPress (r4579)
- *
- * @global WP_Query $wp_query To check if WP_Query::bbp_is_search is true
- * @uses bbp_is_query_name() To get the query name
- * @return bool Is it a search page?
- */
- function bbp_is_search() {
- global $wp_query;
- // Assume false
- $retval = false;
- // 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( 'bbp_search' ) )
- $retval = true;
- // Check $_GET
- if ( empty( $retval ) && isset( $_GET[bbp_get_search_rewrite_id()] ) )
- $retval = true;
- return (bool) apply_filters( 'bbp_is_search', $retval );
- }
- /**
- * Check if current page is an edit page
- *
- * @since bbPress (r3585)
- *
- * @uses WP_Query Checks if WP_Query::bbp_is_edit is true
- * @return bool True if it's the edit page, false if not
- */
- function bbp_is_edit() {
- global $wp_query;
- // Assume false
- $retval = false;
- // Check query
- if ( !empty( $wp_query->bbp_is_edit ) && ( $wp_query->bbp_is_edit == true ) )
- $retval = true;
- return (bool) apply_filters( 'bbp_is_edit', $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_move()
- * @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()
- * @uses bbp_is_forum_archive()
- * @uses bbp_is_topic_archive()
- * @uses bbp_is_topic_tag()
- * @uses bbp_is_topic_tag_edit()
- * @uses bbp_get_topic_tag_tax_id()
- * @uses bbp_get_topic_tag_slug()
- * @uses bbp_get_topic_tag_id()
- * @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';
- } 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';
- /** 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_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';
- }
- /** 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 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 );
- return apply_filters( 'bbp_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_move()
- * @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_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_favorites() ) {
- $retval = true;
- } elseif ( bbp_is_subscriptions() ) {
- $retval = true;
- /** Search ****************************************************************/
- } elseif ( bbp_is_search() ) {
- $retval = true;
- }
- /** Done ******************************************************************/
- return (bool) 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 = '' ) {
- // Parse arguments against default values
- $r = bbp_parse_args( $args, array(
- 'action' => '',
- 'context' => ''
- ), 'login_action' );
- // Add action as query arg
- if ( !empty( $r['action'] ) ) {
- $login_url = add_query_arg( array( 'action' => $r['action'] ), 'wp-login.php' );
- // No query arg
- } else {
- $login_url = 'wp-login.php';
- }
- $login_url = site_url( $login_url, $r['context'] );
- echo apply_filters( 'bbp_wp_login_action', $login_url, $r );
- }
- /**
- * 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 bbPress (r2815)
- *
- * @param string $redirect_to 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', passes field and 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 = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
- } else {
- $redirect_to = wp_get_referer();
- }
- }
- // Remove loggedout query arg if it's there
- $redirect_to = (string) esc_attr( remove_query_arg( 'loggedout', $redirect_to ) );
- $redirect_field = '<input type="hidden" id="bbp_redirect_to" name="redirect_to" value="' . $redirect_to . '" />';
- 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 ) {
- $bbp = bbpress();
- 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'
- * - 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: Tabindex value. False or integer
- * - options_only: Show only <options>? No <select>?
- * - show_none: False or something like __( '(No Forum)', 'bbpress' ),
- * will have value=""
- * - none_found: False or something like
- * __( 'No forums to post to!', 'bbpress' )
- * - disable_categories: Disable forum categories and closed forums?
- * Defaults to true. Only for forums and when
- * the category option is displayed.
- * @uses BBP_Walker_Dropdown() As the default walker to generate the
- * dropdown
- * @uses current_user_can() To check if the current user can read
- * private forums
- * @uses bbp_get_forum_post_type() To get the forum post type
- * @uses bbp_get_topic_post_type() To get the topic post type
- * @uses walk_page_dropdown_tree() To generate the dropdown using the
- * walker
- * @uses apply_filters() Calls 'bbp_get_dropdown' with the dropdown
- * and args
- * @return string The dropdown
- */
- function bbp_get_dropdown( $args = '' ) {
- /** Arguments *********************************************************/
- // Parse arguments against default values
- $r = bbp_parse_args( $args, array(
- 'post_type' => bbp_get_forum_post_type(),
- 'selected' => 0,
- 'sort_column' => 'menu_order',
- 'exclude' => array(),
- 'post_parent' => null,
- 'numberposts' => -1,
- 'orderby' => 'menu_order',
- 'order' => 'ASC',
- 'walker' => '',
- // Output-related
- 'select_id' => 'bbp_forum_id',
- 'tab' => bbp_get_tab_index(),
- 'options_only' => false,
- 'show_none' => false,
- 'none_found' => false,
- 'disable_categories' => true,
- 'disabled' => ''
- ), 'get_dropdown' );
- if ( empty( $r['walker'] ) ) {
- $r['walker'] = new BBP_Walker_Dropdown();
- $r['walker']->tree_type = $r['post_type'];
- }
- // Force 0
- if ( is_numeric( $r['selected'] ) && $r['selected'] < 0 ) {
- $r['selected'] = 0;
- }
- // Force array
- if ( !empty( $r['exclude'] ) && !is_array( $r['exclude'] ) ) {
- $r['exclude'] = explode( ',', $r['exclude'] );
- }
- /** Post Status *******************************************************/
- // Define local variable(s)
- $post_stati = array();
- // Public
- $post_stati[] = bbp_get_public_status_id();
- // Forums
- if ( bbp_get_forum_post_type() == $r['post_type'] ) {
- // Private forums
- if ( current_user_can( 'read_private_forums' ) ) {
- $post_stati[] = bbp_get_private_status_id();
- }
- // Hidden forums
- if ( current_user_can( 'read_hidden_forums' ) ) {
- $post_stati[] = bbp_get_hidden_status_id();
- }
- }
- // Setup the post statuses
- $r['post_status'] = implode( ',', $post_stati );
- /** Setup variables ***************************************************/
- $name = esc_attr( $r['select_id'] );
- $select_id = $name;
- $tab = (int) $r['tab'];
- $retval = '';
- $disabled = disabled( isset( bbpress()->options[$r['disabled']] ), true, false );
- $post_arr = array(
- 'post_type' => $r['post_type'],
- 'post_status' => $r['post_status'],
- 'sort_column' => $r['sort_column'],
- 'exclude' => $r['exclude'],
- 'post_parent' => $r['post_parent'],
- 'numberposts' => $r['numberposts'],
- 'orderby' => $r['orderby'],
- 'order' => $r['order'],
- 'walker' => $r['walker'],
- 'disable_categories' => $r['disable_categories']
- );
- $posts = get_posts( $post_arr );
- /** Drop Down *********************************************************/
- // Items found
- if ( !empty( $posts ) ) {
- if ( empty( $r['options_only'] ) ) {
- $tab = !empty( $tab ) ? ' tabindex="' . $tab . '"' : '';
- $retval .= '<select name="' . $name . '" id="' . $select_id . '"' . $tab . $disabled . '>' . "\n";
- }
- $retval .= !empty( $r['show_none'] ) ? "\t<option value=\"\" class=\"level-0\">" . $r['show_none'] . '</option>' : '';
- $retval .= walk_page_dropdown_tree( $posts, 0, $r );
- if ( empty( $r['options_only'] ) ) {
- $retval .= '</select>';
- }
- // No items found - Display feedback if no custom message was passed
- } elseif ( empty( $r['none_found'] ) ) {
- // Switch the response based on post type
- switch ( $r['post_type'] ) {
- // Topics
- case bbp_get_topic_post_type() :
- $retval = __( 'No topics available', 'bbpress' );
- break;
- // Forums
- case bbp_get_forum_post_type() :
- $retval = __( 'No forums available', 'bbpress' );
- break;
- // Any other
- default :
- $retval = __( 'None available', 'bbpress' );
- break;
- }
- }
- return apply_filters( 'bbp_get_dropdown', $retval, $r );
- }
- /**
- * Output the required hidden fields when creating/editing a forum
- *
- * @since bbPress (r3553)
- *
- * @uses bbp_is_forum_edit() To check if it's the forum edit page
- * @uses wp_nonce_field() To generate hidden nonce fields
- * @uses bbp_forum_id() To output the forum id
- * @uses bbp_is_single_forum() To check if it's a forum page
- * @uses bbp_forum_id() To output the forum id
- */
- function bbp_forum_form_fields() {
- if ( bbp_is_forum_edit() ) : ?>
- <input type="hidden" name="action" id="bbp_post_action" value="bbp-edit-forum" />
- <input type="hidden" name="bbp_forum_id" id="bbp_forum_id" value="<?php bbp_forum_id(); ?>" />
- <?php
- if ( current_user_can( 'unfiltered_html' ) )
- wp_nonce_field( 'bbp-unfiltered-html-forum_' . bbp_get_forum_id(), '_bbp_unfiltered_html_forum', false );
- ?>
- <?php wp_nonce_field( 'bbp-edit-forum_' . bbp_get_forum_id() );
- else :
- if ( bbp_is_single_forum() ) : ?>
- <input type="hidden" name="bbp_forum_parent_id" id="bbp_forum_parent_id" value="<?php bbp_forum_parent_id(); ?>" />
- <?php endif; ?>
- <input type="hidden" name="action" id="bbp_post_action" value="bbp-new-forum" />
- <?php
- if ( current_user_can( 'unfiltered_html' ) )
- wp_nonce_field( 'bbp-unfiltered-html-forum_new', '_bbp_unfiltered_html_forum', false );
- ?>
- <?php wp_nonce_field( 'bbp-new-forum' );
- endif;
- }
- /**
- * Output the required hidden fields when creating/editing a topic
- *
- * @since bbPress (r2753)
- *
- * @uses bbp_is_topic_edit() To check if it's the topic edit page
- * @uses wp_nonce_field() To generate hidden nonce fields
- * @uses bbp_topic_id() To output the topic id
- * @uses bbp_is_single_forum() To check if it's a forum page
- * @uses bbp_forum_id() To output the forum id
- */
- function bbp_topic_form_fields() {
- if ( bbp_is_topic_edit() ) : ?>
- <input type="hidden" name="action" id="bbp_post_action" value="bbp-edit-topic" />
- <input type="hidden" name="bbp_topic_id" id="bbp_topic_id" value="<?php bbp_topic_id(); ?>" />
- <?php
- if ( current_user_can( 'unfiltered_html' ) )
- wp_nonce_field( 'bbp-unfiltered-html-topic_' . bbp_get_topic_id(), '_bbp_unfiltered_html_topic', false );
- ?>
- <?php wp_nonce_field( 'bbp-edit-topic_' . bbp_get_topic_id() );
- else :
- if ( bbp_is_single_forum() ) : ?>
- <input type="hidden" name="bbp_forum_id" id="bbp_forum_id" value="<?php bbp_forum_id(); ?>" />
- <?php endif; ?>
- <input type="hidden" name="action" id="bbp_post_action" value="bbp-new-topic" />
- <?php if ( current_user_can( 'unfiltered_html' ) )
- wp_nonce_field( 'bbp-unfiltered-html-topic_new', '_bbp_unfiltered_html_topic', false ); ?>
- <?php wp_nonce_field( 'bbp-new-topic' );
- endif;
- }
- /**
- * Output the required hidden fields when creating/editing a reply
- *
- * @since bbPress (r2753)
- *
- * @uses bbp_is_reply_edit() To check if it's the reply edit page
- * @uses wp_nonce_field() To generate hidden nonce fields
- * @uses bbp_reply_id() To output the reply id
- * @uses bbp_topic_id() To output the topic id
- * @uses bbp_forum_id() To output the forum id
- */
- function bbp_reply_form_fields() {
- if ( bbp_is_reply_edit() ) : ?>
- <input type="hidden" name="bbp_reply_title" id="bbp_reply_title" value="<?php bbp_reply_title(); ?>" />
- <input type="hidden" name="bbp_reply_id" id="bbp_reply_id" value="<?php bbp_reply_id(); ?>" />
- <input type="hidden" name="action" id="bbp_post_action" value="bbp-edit-reply" />
- <?php if ( current_user_can( 'unfiltered_html' ) )
- wp_nonce_field( 'bbp-unfiltered-html-reply_' . bbp_get_reply_id(), '_bbp_unfiltered_html_reply', false ); ?>
- <?php wp_nonce_field( 'bbp-edit-reply_' . bbp_get_reply_id() );
- else : ?>
- <input type="hidden" name="bbp_reply_title" id="bbp_reply_title" value="<?php printf( __( 'Reply To: %s', 'bbpress' ), bbp_get_topic_title() ); ?>" />
- <input type="hidden" name="bbp_topic_id" id="bbp_topic_id" value="<?php bbp_topic_id(); ?>" />
- <input type="hidden" name="action" id="bbp_post_action" value="bbp-new-reply" />
- <?php if ( current_user_can( 'unfiltered_html' ) )
- wp_nonce_field( 'bbp-unfiltered-html-reply_' . bbp_get_topic_id(), '_bbp_unfiltered_html_reply', false ); ?>
- <?php wp_nonce_field( 'bbp-new-reply' );
- // Show redirect field if not viewing a specific topic
- if ( bbp_is_query_name( 'bbp_single_topic' ) ) :
- bbp_redirect_to_field( get_permalink() );
- endif;
- endif;
- }
- /**
- * Output the required hidden fields when editing a user
- *
- * @since bbPress (r2690)
- *
- * @uses bbp_displayed_user_id() To output the displayed user id
- * @uses wp_nonce_field() To generate a hidden nonce field
- * @uses wp_referer_field() To generate a hidden referer field
- */
- function bbp_edit_user_form_fields() {
- ?>
- <input type="hidden" name="action" id="bbp_post_action" value="bbp-update-user" />
- <input type="hidden" name="user_id" id="user_id" value="<?php bbp_displayed_user_id(); ?>" />
- <?php wp_nonce_field( 'update-user_' . bbp_get_displayed_user_id() );
- }
- /**
- * Merge topic form fields
- *
- * Output the required hidden fields when merging a topic
- *
- * @since bbPress (r2756)
- *
- * @uses wp_nonce_field() To generate a hidden nonce field
- * @uses bbp_topic_id() To output the topic id
- */
- function bbp_merge_topic_form_fields() {
- ?>
- <input type="hidden" name="action" id="bbp_post_action" value="bbp-merge-topic" />
- <input type="hidden" name="bbp_topic_id" id="bbp_topic_id" value="<?php bbp_topic_id(); ?>" />
- <?php wp_nonce_field( 'bbp-merge-topic_' . bbp_get_topic_id() );
- }
- /**
- * Split topic form fields
- *
- * Output the required hidden fields when splitting a topic
- *
- * @since bbPress (r2756)
- *
- * @uses wp_nonce_field() To generate a hidden nonce field
- */
- function bbp_split_topic_form_fields() {
- ?>
- <input type="hidden" name="action" id="bbp_post_action" value="bbp-split-topic" />
- <input type="hidden" name="bbp_reply_id" id="bbp_reply_id" value="<?php echo absint( $_GET['reply_id'] ); ?>" />
- <?php wp_nonce_field( 'bbp-split-topic_' . bbp_get_topic_id() );
- }
- /**
- * Move reply form fields
- *
- * Output the required hidden fields when moving a reply
- *
- * @uses wp_nonce_field() To generate a hidden nonce field
- */
- function bbp_move_reply_form_fields() {
- ?>
- <input type="hidden" name="action" id="bbp_post_action" value="bbp-move-reply" />
- <input type="hidden" name="bbp_reply_id" id="bbp_reply_id" value="<?php echo absint( $_GET['reply_id'] ); ?>" />
- <?php wp_nonce_field( 'bbp-move-reply_' . bbp_get_reply_id() );
- }
- /**
- * Output a textarea or TinyMCE if enabled
- *
- * @since bbPress (r3586)
- *
- * @param array $args
- * @uses bbp_get_the_content() To return the content to output
- */
- function bbp_the_content( $args = array() ) {
- echo bbp_get_the_content( $args );
- }
- /**
- * Return a textarea or TinyMCE if enabled
- *
- * @since bbPress (r3586)
- *
- * @param array $args
- *
- * @uses apply_filter() To filter args and output
- * @uses wp_parse_pargs() To compare args
- * @uses bbp_use_wp_editor() To see if WP editor is in use
- * @uses bbp_is_edit() To see if we are editing something
- * @uses wp_editor() To output the WordPress editor
- *
- * @return string HTML from output buffer
- */
- function bbp_get_the_content( $args = array() ) {
- // Parse arguments against default values
- $r = bbp_parse_args( $args, array(
- 'context' => 'topic',
- 'before' => '<div class="bbp-the-content-wrapper">',
- 'after' => '</div>',
- 'wpautop' => true,
- 'media_buttons' => false,
- 'textarea_rows' => '12',
- 'tabindex' => bbp_get_tab_index(),
- 'tabfocus_elements' => 'bbp_topic_title,bbp_topic_tags',
- 'editor_class' => 'bbp-the-content',
- 'tinymce' => false,
- 'teeny' => true,
- 'quicktags' => true,
- 'dfw' => false
- ), 'get_the_content' );
- // If using tinymce, remove our escaping and trust tinymce
- if ( bbp_use_wp_editor() && ( true === $r['tinymce'] ) ) {
- remove_filter( 'bbp_get_form_forum_content', 'esc_textarea' );
- remove_filter( 'bbp_get_form_topic_content', 'esc_textarea' );
- remove_filter( 'bbp_get_form_reply_content', 'esc_textarea' );
- }
- // Assume we are not editing
- $post_content = call_user_func( 'bbp_get_form_' . $r['context'] . '_content' );
- // Start an output buffor
- ob_start();
- // Output something before the editor
- if ( !empty( $r['before'] ) ) {
- echo $r['before'];
- }
- // Use TinyMCE if available
- if ( bbp_use_wp_editor() ) :
- // Enable additional TinyMCE plugins before outputting the editor
- add_filter( 'tiny_mce_plugins', 'bbp_get_tiny_mce_plugins' );
- add_filter( 'teeny_mce_plugins', 'bbp_get_tiny_mce_plugins' );
- add_filter( 'teeny_mce_buttons', 'bbp_get_teeny_mce_buttons' );
- add_filter( 'quicktags_settings', 'bbp_get_quicktags_settings' );
- // Output the editor
- wp_editor( $post_content, 'bbp_' . $r['context'] . '_content', array(
- 'wpautop' => $r['wpautop'],
- 'media_buttons' => $r['media_buttons'],
- 'textarea_rows' => $r['textarea_rows'],
- 'tabindex' => $r['tabindex'],
- 'tabfocus_elements' => $r['tabfocus_elements'],
- 'editor_class' => $r['editor_class'],
- 'tinymce' => $r['tinymce'],
- 'teeny' => $r['teeny'],
- 'quicktags' => $r['quicktags'],
- 'dfw' => $r['dfw'],
- ) );
- // Remove additional TinyMCE plugins after outputting the editor
- remove_filter( 'tiny_mce_plugins', 'bbp_get_tiny_mce_plugins' );
- remove_filter( 'teeny_mce_plugins', 'bbp_get_tiny_mce_plugins' );
- remove_filter( 'teeny_mce_buttons', 'bbp_get_teeny_mce_buttons' );
- remove_filter( 'quicktags_settings', 'bbp_get_quicktags_settings' );
- /**
- * Fallback to normal textarea.
- *
- * Note that we do not use esc_textarea() here to prevent double
- * escaping the editable output, mucking up existing content.
- */
- else : ?>
- <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'] ); ?>" tabindex="<?php echo esc_attr( $r['tabindex'] ); ?>"><?php echo $post_content; ?></textarea>
- <?php endif;
- // Output something after the editor
- if ( !empty( $r['after'] ) ) {
- echo $r['after'];
- }
- // Put the output into a usable variable
- $output = ob_get_contents();
- // Flush the output buffer
- ob_end_clean();
- return apply_filters( 'bbp_get_the_content', $output, $args, $post_content );
- }
- /**
- * Edit TinyMCE plugins to match core behaviour
- *
- * @since bbPress (r4574)
- *
- * @param array $plugins
- * @see tiny_mce_plugins, teeny_mce_plugins
- * @return array
- */
- function bbp_get_tiny_mce_plugins( $plugins = array() ) {
- // Unset fullscreen
- foreach ( $plugins as $key => $value ) {
- if ( 'fullscreen' == $value ) {
- unset( $plugins[$key] );
- break;
- }
- }
- // Add the tabfocus plugin
- $plugins[] = 'tabfocus';
- return…
Large files files are truncated, but you can click here to view the full file