/wp-content/plugins/bbpress/includes/topics/template.php
PHP | 4005 lines | 1469 code | 528 blank | 2008 comment | 245 complexity | e050cd312edaf2a6e40171f4c0b4bf6f MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, LGPL-3.0, AGPL-1.0
Large files files are truncated, but you can click here to view the full file
- <?php
-
- /**
- * bbPress Topic Template Tags
- *
- * @package bbPress
- * @subpackage TemplateTags
- */
-
- // Exit if accessed directly
- if ( !defined( 'ABSPATH' ) ) exit;
-
- /** Post Type *****************************************************************/
-
- /**
- * Output the unique id of the custom post type for topics
- *
- * @since bbPress (r2857)
- *
- * @uses bbp_get_topic_post_type() To get the topic post type
- */
- function bbp_topic_post_type() {
- echo bbp_get_topic_post_type();
- }
- /**
- * Return the unique id of the custom post type for topics
- *
- * @since bbPress (r2857)
- *
- * @uses apply_filters() Calls 'bbp_get_topic_post_type' with the topic
- * post type id
- * @return string The unique topic post type id
- */
- function bbp_get_topic_post_type() {
- return apply_filters( 'bbp_get_topic_post_type', bbpress()->topic_post_type );
- }
-
- /**
- * Return array of labels used by the topic post type
- *
- * @since bbPress (r5129)
- *
- * @return array
- */
- function bbp_get_topic_post_type_labels() {
- return apply_filters( 'bbp_get_topic_post_type_labels', array(
- 'name' => __( 'Topics', 'bbpress' ),
- 'menu_name' => __( 'Topics', 'bbpress' ),
- 'singular_name' => __( 'Topic', 'bbpress' ),
- 'all_items' => __( 'All Topics', 'bbpress' ),
- 'add_new' => __( 'New Topic', 'bbpress' ),
- 'add_new_item' => __( 'Create New Topic', 'bbpress' ),
- 'edit' => __( 'Edit', 'bbpress' ),
- 'edit_item' => __( 'Edit Topic', 'bbpress' ),
- 'new_item' => __( 'New Topic', 'bbpress' ),
- 'view' => __( 'View Topic', 'bbpress' ),
- 'view_item' => __( 'View Topic', 'bbpress' ),
- 'search_items' => __( 'Search Topics', 'bbpress' ),
- 'not_found' => __( 'No topics found', 'bbpress' ),
- 'not_found_in_trash' => __( 'No topics found in Trash', 'bbpress' ),
- 'parent_item_colon' => __( 'Forum:', 'bbpress' )
- ) );
- }
-
- /**
- * Return array of topic post type rewrite settings
- *
- * @since bbPress (r5129)
- *
- * @return array
- */
- function bbp_get_topic_post_type_rewrite() {
- return apply_filters( 'bbp_get_topic_post_type_rewrite', array(
- 'slug' => bbp_get_topic_slug(),
- 'with_front' => false
- ) );
- }
-
- /**
- * Return array of features the topic post type supports
- *
- * @since bbPress (r5129)
- *
- * @return array
- */
- function bbp_get_topic_post_type_supports() {
- return apply_filters( 'bbp_get_topic_post_type_supports', array(
- 'title',
- 'editor',
- 'revisions'
- ) );
- }
-
- /**
- * The plugin version of bbPress comes with two topic display options:
- * - Traditional: Topics are included in the reply loop (default)
- * - New Style: Topics appear as "lead" posts, ahead of replies
- *
- * @since bbPress (r2954)
- * @param $show_lead Optional. Default false
- * @return bool Yes if the topic appears as a lead, otherwise false
- */
- function bbp_show_lead_topic( $show_lead = false ) {
-
- // Never separate the lead topic in feeds
- if ( is_feed() )
- return false;
-
- return (bool) apply_filters( 'bbp_show_lead_topic', (bool) $show_lead );
- }
-
- /** Topic Loop ****************************************************************/
-
- /**
- * The main topic loop. WordPress makes this easy for us
- *
- * @since bbPress (r2485)
- *
- * @param mixed $args All the arguments supported by {@link WP_Query}
- * @uses current_user_can() To check if the current user can edit other's topics
- * @uses bbp_get_topic_post_type() To get the topic post type
- * @uses WP_Query To make query and get the topics
- * @uses is_page() To check if it's a page
- * @uses bbp_is_single_forum() To check if it's a forum
- * @uses bbp_get_forum_id() To get the forum id
- * @uses bbp_get_paged() To get the current page value
- * @uses bbp_get_super_stickies() To get the super stickies
- * @uses bbp_get_stickies() To get the forum stickies
- * @uses wpdb::get_results() To execute our query and get the results
- * @uses WP_Rewrite::using_permalinks() To check if the blog is using permalinks
- * @uses get_permalink() To get the permalink
- * @uses add_query_arg() To add custom args to the url
- * @uses apply_filters() Calls 'bbp_topics_pagination' with the pagination args
- * @uses paginate_links() To paginate the links
- * @uses apply_filters() Calls 'bbp_has_topics' with
- * bbPres::topic_query::have_posts()
- * and bbPres::topic_query
- * @return object Multidimensional array of topic information
- */
- function bbp_has_topics( $args = '' ) {
- global $wp_rewrite;
-
- /** Defaults **************************************************************/
-
- // Other defaults
- $default_topic_search = !empty( $_REQUEST['ts'] ) ? $_REQUEST['ts'] : false;
- $default_show_stickies = (bool) ( bbp_is_single_forum() || bbp_is_topic_archive() ) && ( false === $default_topic_search );
- $default_post_parent = bbp_is_single_forum() ? bbp_get_forum_id() : 'any';
-
- // Default argument array
- $default = array(
- 'post_type' => bbp_get_topic_post_type(), // Narrow query down to bbPress topics
- 'post_parent' => $default_post_parent, // Forum ID
- 'meta_key' => '_bbp_last_active_time', // Make sure topic has some last activity time
- 'orderby' => 'meta_value', // 'meta_value', 'author', 'date', 'title', 'modified', 'parent', rand',
- 'order' => 'DESC', // 'ASC', 'DESC'
- 'posts_per_page' => bbp_get_topics_per_page(), // Topics per page
- 'paged' => bbp_get_paged(), // Page Number
- 's' => $default_topic_search, // Topic Search
- 'show_stickies' => $default_show_stickies, // Ignore sticky topics?
- 'max_num_pages' => false, // Maximum number of pages to show
- );
-
- // What are the default allowed statuses (based on user caps)
- if ( bbp_get_view_all() ) {
-
- // Default view=all statuses
- $post_statuses = array(
- bbp_get_public_status_id(),
- bbp_get_closed_status_id(),
- bbp_get_spam_status_id(),
- bbp_get_trash_status_id()
- );
-
- // Add support for private status
- if ( current_user_can( 'read_private_topics' ) ) {
- $post_statuses[] = bbp_get_private_status_id();
- }
-
- // Join post statuses together
- $default['post_status'] = implode( ',', $post_statuses );
-
- // Lean on the 'perm' query var value of 'readable' to provide statuses
- } else {
- $default['perm'] = 'readable';
- }
-
- // Maybe query for topic tags
- if ( bbp_is_topic_tag() ) {
- $default['term'] = bbp_get_topic_tag_slug();
- $default['taxonomy'] = bbp_get_topic_tag_tax_id();
- }
-
- /** Setup *****************************************************************/
-
- // Parse arguments against default values
- $r = bbp_parse_args( $args, $default, 'has_topics' );
-
- // Get bbPress
- $bbp = bbpress();
-
- // Call the query
- $bbp->topic_query = new WP_Query( $r );
-
- // Set post_parent back to 0 if originally set to 'any'
- if ( 'any' === $r['post_parent'] )
- $r['post_parent'] = 0;
-
- // Limited the number of pages shown
- if ( !empty( $r['max_num_pages'] ) )
- $bbp->topic_query->max_num_pages = $r['max_num_pages'];
-
- /** Stickies **************************************************************/
-
- // Put sticky posts at the top of the posts array
- if ( !empty( $r['show_stickies'] ) && $r['paged'] <= 1 ) {
-
- // Get super stickies and stickies in this forum
- $stickies = bbp_get_super_stickies();
-
- // Get stickies for current forum
- if ( !empty( $r['post_parent'] ) ) {
- $stickies = array_merge( $stickies, bbp_get_stickies( $r['post_parent'] ) );
- }
-
- // Remove any duplicate stickies
- $stickies = array_unique( $stickies );
-
- // We have stickies
- if ( is_array( $stickies ) && !empty( $stickies ) ) {
-
- // Start the offset at -1 so first sticky is at correct 0 offset
- $sticky_offset = -1;
-
- // Loop over topics and relocate stickies to the front.
- foreach ( $stickies as $sticky_index => $sticky_ID ) {
-
- // Get the post offset from the posts array
- $post_offsets = wp_filter_object_list( $bbp->topic_query->posts, array( 'ID' => $sticky_ID ), 'OR', 'ID' );
-
- // Continue if no post offsets
- if ( empty( $post_offsets ) ) {
- continue;
- }
-
- // Loop over posts in current query and splice them into position
- foreach ( array_keys( $post_offsets ) as $post_offset ) {
- $sticky_offset++;
-
- $sticky = $bbp->topic_query->posts[$post_offset];
-
- // Remove sticky from current position
- array_splice( $bbp->topic_query->posts, $post_offset, 1 );
-
- // Move to front, after other stickies
- array_splice( $bbp->topic_query->posts, $sticky_offset, 0, array( $sticky ) );
-
- // Cleanup
- unset( $stickies[$sticky_index] );
- unset( $sticky );
- }
-
- // Cleanup
- unset( $post_offsets );
- }
-
- // Cleanup
- unset( $sticky_offset );
-
- // If any posts have been excluded specifically, Ignore those that are sticky.
- if ( !empty( $stickies ) && !empty( $r['post__not_in'] ) ) {
- $stickies = array_diff( $stickies, $r['post__not_in'] );
- }
-
- // Fetch sticky posts that weren't in the query results
- if ( !empty( $stickies ) ) {
-
- // Query to use in get_posts to get sticky posts
- $sticky_query = array(
- 'post_type' => bbp_get_topic_post_type(),
- 'post_parent' => 'any',
- 'meta_key' => '_bbp_last_active_time',
- 'orderby' => 'meta_value',
- 'order' => 'DESC',
- 'include' => $stickies
- );
-
- // Cleanup
- unset( $stickies );
-
- // Conditionally exclude private/hidden forum ID's
- $exclude_forum_ids = bbp_exclude_forum_ids( 'array' );
- if ( ! empty( $exclude_forum_ids ) ) {
- $sticky_query['post_parent__not_in'] = $exclude_forum_ids;
- }
-
- // What are the default allowed statuses (based on user caps)
- if ( bbp_get_view_all() ) {
- $sticky_query['post_status'] = $r['post_status'];
-
- // Lean on the 'perm' query var value of 'readable' to provide statuses
- } else {
- $sticky_query['post_status'] = $r['perm'];
- }
-
- // Get all stickies
- $sticky_posts = get_posts( $sticky_query );
- if ( !empty( $sticky_posts ) ) {
-
- // Get a count of the visible stickies
- $sticky_count = count( $sticky_posts );
-
- // Merge the stickies topics with the query topics .
- $bbp->topic_query->posts = array_merge( $sticky_posts, $bbp->topic_query->posts );
-
- // Adjust loop and counts for new sticky positions
- $bbp->topic_query->found_posts = (int) $bbp->topic_query->found_posts + (int) $sticky_count;
- $bbp->topic_query->post_count = (int) $bbp->topic_query->post_count + (int) $sticky_count;
-
- // Cleanup
- unset( $sticky_posts );
- }
- }
- }
- }
-
- // If no limit to posts per page, set it to the current post_count
- if ( -1 === $r['posts_per_page'] )
- $r['posts_per_page'] = $bbp->topic_query->post_count;
-
- // Add pagination values to query object
- $bbp->topic_query->posts_per_page = $r['posts_per_page'];
- $bbp->topic_query->paged = $r['paged'];
-
- // Only add pagination if query returned results
- if ( ( (int) $bbp->topic_query->post_count || (int) $bbp->topic_query->found_posts ) && (int) $bbp->topic_query->posts_per_page ) {
-
- // Limit the number of topics shown based on maximum allowed pages
- if ( ( !empty( $r['max_num_pages'] ) ) && $bbp->topic_query->found_posts > $bbp->topic_query->max_num_pages * $bbp->topic_query->post_count )
- $bbp->topic_query->found_posts = $bbp->topic_query->max_num_pages * $bbp->topic_query->post_count;
-
- // If pretty permalinks are enabled, make our pagination pretty
- if ( $wp_rewrite->using_permalinks() ) {
-
- // User's topics
- if ( bbp_is_single_user_topics() ) {
- $base = bbp_get_user_topics_created_url( bbp_get_displayed_user_id() );
-
- // User's favorites
- } elseif ( bbp_is_favorites() ) {
- $base = bbp_get_favorites_permalink( bbp_get_displayed_user_id() );
-
- // User's subscriptions
- } elseif ( bbp_is_subscriptions() ) {
- $base = bbp_get_subscriptions_permalink( bbp_get_displayed_user_id() );
-
- // Root profile page
- } elseif ( bbp_is_single_user() ) {
- $base = bbp_get_user_profile_url( bbp_get_displayed_user_id() );
-
- // View
- } elseif ( bbp_is_single_view() ) {
- $base = bbp_get_view_url();
-
- // Topic tag
- } elseif ( bbp_is_topic_tag() ) {
- $base = bbp_get_topic_tag_link();
-
- // Page or single post
- } elseif ( is_page() || is_single() ) {
- $base = get_permalink();
-
- // Forum archive
- } elseif ( bbp_is_forum_archive() ) {
- $base = bbp_get_forums_url();
-
- // Topic archive
- } elseif ( bbp_is_topic_archive() ) {
- $base = bbp_get_topics_url();
-
- // Default
- } else {
- $base = get_permalink( (int) $r['post_parent'] );
- }
-
- // Use pagination base
- $base = trailingslashit( $base ) . user_trailingslashit( $wp_rewrite->pagination_base . '/%#%/' );
-
- // Unpretty pagination
- } else {
- $base = add_query_arg( 'paged', '%#%' );
- }
-
- // Pagination settings with filter
- $bbp_topic_pagination = apply_filters( 'bbp_topic_pagination', array (
- 'base' => $base,
- 'format' => '',
- 'total' => $r['posts_per_page'] === $bbp->topic_query->found_posts ? 1 : ceil( (int) $bbp->topic_query->found_posts / (int) $r['posts_per_page'] ),
- 'current' => (int) $bbp->topic_query->paged,
- 'prev_text' => is_rtl() ? '→' : '←',
- 'next_text' => is_rtl() ? '←' : '→',
- 'mid_size' => 1
- ) );
-
- // Add pagination to query object
- $bbp->topic_query->pagination_links = paginate_links( $bbp_topic_pagination );
-
- // Remove first page from pagination
- $bbp->topic_query->pagination_links = str_replace( $wp_rewrite->pagination_base . "/1/'", "'", $bbp->topic_query->pagination_links );
- }
-
- // Return object
- return apply_filters( 'bbp_has_topics', $bbp->topic_query->have_posts(), $bbp->topic_query );
- }
-
- /**
- * Whether there are more topics available in the loop
- *
- * @since bbPress (r2485)
- *
- * @uses WP_Query bbPress::topic_query::have_posts()
- * @return object Topic information
- */
- function bbp_topics() {
-
- // Put into variable to check against next
- $have_posts = bbpress()->topic_query->have_posts();
-
- // Reset the post data when finished
- if ( empty( $have_posts ) )
- wp_reset_postdata();
-
- return $have_posts;
- }
-
- /**
- * Loads up the current topic in the loop
- *
- * @since bbPress (r2485)
- *
- * @uses WP_Query bbPress::topic_query::the_post()
- * @return object Topic information
- */
- function bbp_the_topic() {
- return bbpress()->topic_query->the_post();
- }
-
- /**
- * Output the topic id
- *
- * @since bbPress (r2485)
- *
- * @uses bbp_get_topic_id() To get the topic id
- */
- function bbp_topic_id( $topic_id = 0) {
- echo bbp_get_topic_id( $topic_id );
- }
- /**
- * Return the topic id
- *
- * @since bbPress (r2485)
- *
- * @param $topic_id Optional. Used to check emptiness
- * @uses bbPress::topic_query::post::ID To get the topic id
- * @uses bbp_is_topic() To check if the search result is a topic
- * @uses bbp_is_single_topic() To check if it's a topic page
- * @uses bbp_is_topic_edit() To check if it's a topic edit page
- * @uses bbp_is_single_reply() To check if it it's a reply page
- * @uses bbp_is_reply_edit() To check if it's a reply edit page
- * @uses bbp_get_reply_topic_edit() To get the reply topic id
- * @uses get_post_field() To get the post's post type
- * @uses WP_Query::post::ID To get the topic id
- * @uses bbp_get_topic_post_type() To get the topic post type
- * @uses apply_filters() Calls 'bbp_get_topic_id' with the topic id and
- * supplied topic id
- * @return int The topic id
- */
- function bbp_get_topic_id( $topic_id = 0 ) {
- global $wp_query;
-
- $bbp = bbpress();
-
- // Easy empty checking
- if ( !empty( $topic_id ) && is_numeric( $topic_id ) ) {
- $bbp_topic_id = $topic_id;
-
- // Currently inside a topic loop
- } elseif ( !empty( $bbp->topic_query->in_the_loop ) && isset( $bbp->topic_query->post->ID ) ) {
- $bbp_topic_id = $bbp->topic_query->post->ID;
-
- // Currently inside a search loop
- } elseif ( !empty( $bbp->search_query->in_the_loop ) && isset( $bbp->search_query->post->ID ) && bbp_is_topic( $bbp->search_query->post->ID ) ) {
- $bbp_topic_id = $bbp->search_query->post->ID;
-
- // Currently viewing/editing a topic, likely alone
- } elseif ( ( bbp_is_single_topic() || bbp_is_topic_edit() ) && !empty( $bbp->current_topic_id ) ) {
- $bbp_topic_id = $bbp->current_topic_id;
-
- // Currently viewing/editing a topic, likely in a loop
- } elseif ( ( bbp_is_single_topic() || bbp_is_topic_edit() ) && isset( $wp_query->post->ID ) ) {
- $bbp_topic_id = $wp_query->post->ID;
-
- // Currently viewing/editing a reply
- } elseif ( bbp_is_single_reply() || bbp_is_reply_edit() ) {
- $bbp_topic_id = bbp_get_reply_topic_id();
-
- // Fallback
- } else {
- $bbp_topic_id = 0;
- }
-
- return (int) apply_filters( 'bbp_get_topic_id', (int) $bbp_topic_id, $topic_id );
- }
-
- /**
- * Gets a topic
- *
- * @since bbPress (r2787)
- *
- * @param int|object $topic Topic id or topic object
- * @param string $output Optional. OBJECT, ARRAY_A, or ARRAY_N. Default = OBJECT
- * @param string $filter Optional Sanitation filter. See {@link sanitize_post()}
- * @uses get_post() To get the topic
- * @uses apply_filters() Calls 'bbp_get_topic' with the topic, output type and
- * sanitation filter
- * @return mixed Null if error or topic (in specified form) if success
- */
- function bbp_get_topic( $topic, $output = OBJECT, $filter = 'raw' ) {
-
- // Use topic ID
- if ( empty( $topic ) || is_numeric( $topic ) )
- $topic = bbp_get_topic_id( $topic );
-
- // Attempt to load the topic
- $topic = get_post( $topic, OBJECT, $filter );
- if ( empty( $topic ) )
- return $topic;
-
- // Bail if post_type is not a topic
- if ( $topic->post_type !== bbp_get_topic_post_type() )
- return null;
-
- // Tweak the data type to return
- if ( $output === OBJECT ) {
- return $topic;
-
- } elseif ( $output === ARRAY_A ) {
- $_topic = get_object_vars( $topic );
- return $_topic;
-
- } elseif ( $output === ARRAY_N ) {
- $_topic = array_values( get_object_vars( $topic ) );
- return $_topic;
-
- }
-
- return apply_filters( 'bbp_get_topic', $topic, $output, $filter );
- }
-
- /**
- * Output the link to the topic in the topic loop
- *
- * @since bbPress (r2485)
- *
- * @param int $topic_id Optional. Topic id
- * @param $string $redirect_to Optional. Pass a redirect value for use with
- * shortcodes and other fun things.
- * @uses bbp_get_topic_permalink() To get the topic permalink
- */
- function bbp_topic_permalink( $topic_id = 0, $redirect_to = '' ) {
- echo esc_url( bbp_get_topic_permalink( $topic_id, $redirect_to ) );
- }
- /**
- * Return the link to the topic
- *
- * @since bbPress (r2485)
- *
- * @param int $topic_id Optional. Topic id
- * @param $string $redirect_to Optional. Pass a redirect value for use with
- * shortcodes and other fun things.
- * @uses bbp_get_topic_id() To get the topic id
- * @uses get_permalink() To get the topic permalink
- * @uses esc_url_raw() To clean the redirect_to url
- * @uses apply_filters() Calls 'bbp_get_topic_permalink' with the link
- * and topic id
- * @return string Permanent link to topic
- */
- function bbp_get_topic_permalink( $topic_id = 0, $redirect_to = '' ) {
- $topic_id = bbp_get_topic_id( $topic_id );
-
- // Use the redirect address
- if ( !empty( $redirect_to ) ) {
- $topic_permalink = esc_url_raw( $redirect_to );
-
- // Use the topic permalink
- } else {
- $topic_permalink = get_permalink( $topic_id );
- }
-
- return apply_filters( 'bbp_get_topic_permalink', $topic_permalink, $topic_id );
- }
-
- /**
- * Output the title of the topic
- *
- * @since bbPress (r2485)
- *
- * @param int $topic_id Optional. Topic id
- * @uses bbp_get_topic_title() To get the topic title
- */
- function bbp_topic_title( $topic_id = 0 ) {
- echo bbp_get_topic_title( $topic_id );
- }
- /**
- * Return the title of the topic
- *
- * @since bbPress (r2485)
- *
- * @param int $topic_id Optional. Topic id
- * @uses bbp_get_topic_id() To get the topic id
- * @uses get_the_title() To get the title
- * @uses apply_filters() Calls 'bbp_get_topic_title' with the title and
- * topic id
- * @return string Title of topic
- */
- function bbp_get_topic_title( $topic_id = 0 ) {
- $topic_id = bbp_get_topic_id( $topic_id );
- $title = get_the_title( $topic_id );
-
- return apply_filters( 'bbp_get_topic_title', $title, $topic_id );
- }
-
- /**
- * Output the topic archive title
- *
- * @since bbPress (r3249)
- *
- * @param string $title Default text to use as title
- */
- function bbp_topic_archive_title( $title = '' ) {
- echo bbp_get_topic_archive_title( $title );
- }
- /**
- * Return the topic archive title
- *
- * @since bbPress (r3249)
- *
- * @param string $title Default text to use as title
- *
- * @uses bbp_get_page_by_path() Check if page exists at root path
- * @uses get_the_title() Use the page title at the root path
- * @uses get_post_type_object() Load the post type object
- * @uses bbp_get_topic_post_type() Get the topic post type ID
- * @uses get_post_type_labels() Get labels for topic post type
- * @uses apply_filters() Allow output to be manipulated
- *
- * @return string The topic archive title
- */
- function bbp_get_topic_archive_title( $title = '' ) {
-
- // If no title was passed
- if ( empty( $title ) ) {
-
- // Set root text to page title
- $page = bbp_get_page_by_path( bbp_get_topic_archive_slug() );
- if ( !empty( $page ) ) {
- $title = get_the_title( $page->ID );
-
- // Default to topic post type name label
- } else {
- $tto = get_post_type_object( bbp_get_topic_post_type() );
- $title = $tto->labels->name;
- }
- }
-
- return apply_filters( 'bbp_get_topic_archive_title', $title );
- }
-
- /**
- * Output the content of the topic
- *
- * @since bbPress (r2780)
- *
- * @param int $topic_id Optional. Topic id
- * @uses bbp_get_topic_content() To get the topic content
- */
- function bbp_topic_content( $topic_id = 0 ) {
- echo bbp_get_topic_content( $topic_id );
- }
- /**
- * Return the content of the topic
- *
- * @since bbPress (r2780)
- *
- * @param int $topic_id Optional. Topic id
- * @uses bbp_get_topic_id() To get the topic id
- * @uses post_password_required() To check if the topic requires pass
- * @uses get_the_password_form() To get the password form
- * @uses get_post_field() To get the content post field
- * @uses apply_filters() Calls 'bbp_get_topic_content' with the content
- * and topic id
- * @return string Content of the topic
- */
- function bbp_get_topic_content( $topic_id = 0 ) {
- $topic_id = bbp_get_topic_id( $topic_id );
-
- // Check if password is required
- if ( post_password_required( $topic_id ) )
- return get_the_password_form();
-
- $content = get_post_field( 'post_content', $topic_id );
-
- return apply_filters( 'bbp_get_topic_content', $content, $topic_id );
- }
-
- /**
- * Output the excerpt of the topic
- *
- * @since bbPress (r2780)
- *
- * @param int $topic_id Optional. Topic id
- * @param int $length Optional. Length of the excerpt. Defaults to 100 letters
- * @uses bbp_get_topic_excerpt() To get the topic excerpt
- */
- function bbp_topic_excerpt( $topic_id = 0, $length = 100 ) {
- echo bbp_get_topic_excerpt( $topic_id, $length );
- }
- /**
- * Return the excerpt of the topic
- *
- * @since bbPress (r2780)
- *
- * @param int $topic_id Optional. topic id
- * @param int $length Optional. Length of the excerpt. Defaults to 100
- * letters
- * @uses bbp_get_topic_id() To get the topic id
- * @uses get_post_field() To get the excerpt
- * @uses bbp_get_topic_content() To get the topic content
- * @uses apply_filters() Calls 'bbp_get_topic_excerpt' with the excerpt,
- * topic id and length
- * @return string topic Excerpt
- */
- function bbp_get_topic_excerpt( $topic_id = 0, $length = 100 ) {
- $topic_id = bbp_get_topic_id( $topic_id );
- $length = (int) $length;
- $excerpt = get_post_field( 'post_excerpt', $topic_id );
-
- if ( empty( $excerpt ) ) {
- $excerpt = bbp_get_topic_content( $topic_id );
- }
-
- $excerpt = trim( strip_tags( $excerpt ) );
-
- // Multibyte support
- if ( function_exists( 'mb_strlen' ) ) {
- $excerpt_length = mb_strlen( $excerpt );
- } else {
- $excerpt_length = strlen( $excerpt );
- }
-
- if ( !empty( $length ) && ( $excerpt_length > $length ) ) {
- $excerpt = substr( $excerpt, 0, $length - 1 );
- $excerpt .= '…';
- }
-
- return apply_filters( 'bbp_get_topic_excerpt', $excerpt, $topic_id, $length );
- }
-
- /**
- * Output the post date and time of a topic
- *
- * @since bbPress (r4155)
- *
- * @param int $topic_id Optional. Topic id.
- * @param bool $humanize Optional. Humanize output using time_since
- * @param bool $gmt Optional. Use GMT
- * @uses bbp_get_topic_post_date() to get the output
- */
- function bbp_topic_post_date( $topic_id = 0, $humanize = false, $gmt = false ) {
- echo bbp_get_topic_post_date( $topic_id, $humanize, $gmt );
- }
- /**
- * Return the post date and time of a topic
- *
- * @since bbPress (r4155)
- *
- * @param int $topic_id Optional. Topic id.
- * @param bool $humanize Optional. Humanize output using time_since
- * @param bool $gmt Optional. Use GMT
- * @uses bbp_get_topic_id() To get the topic id
- * @uses get_post_time() to get the topic post time
- * @uses bbp_get_time_since() to maybe humanize the topic post time
- * @return string
- */
- function bbp_get_topic_post_date( $topic_id = 0, $humanize = false, $gmt = false ) {
- $topic_id = bbp_get_topic_id( $topic_id );
-
- // 4 days, 4 hours ago
- if ( !empty( $humanize ) ) {
- $gmt_s = !empty( $gmt ) ? 'U' : 'G';
- $date = get_post_time( $gmt_s, $gmt, $topic_id );
- $time = false; // For filter below
- $result = bbp_get_time_since( $date );
-
- // August 4, 2012 at 2:37 pm
- } else {
- $date = get_post_time( get_option( 'date_format' ), $gmt, $topic_id, true );
- $time = get_post_time( get_option( 'time_format' ), $gmt, $topic_id, true );
- $result = sprintf( _x( '%1$s at %2$s', 'date at time', 'bbpress' ), $date, $time );
- }
-
- return apply_filters( 'bbp_get_topic_post_date', $result, $topic_id, $humanize, $gmt, $date, $time );
- }
-
- /**
- * Output pagination links of a topic within the topic loop
- *
- * @since bbPress (r2966)
- *
- * @param mixed $args See {@link bbp_get_topic_pagination()}
- * @uses bbp_get_topic_pagination() To get the topic pagination links
- */
- function bbp_topic_pagination( $args = '' ) {
- echo bbp_get_topic_pagination( $args );
- }
- /**
- * Returns pagination links of a topic within the topic loop
- *
- * @since bbPress (r2966)
- *
- * @param mixed $args This function supports these arguments:
- * - topic_id: Topic id
- * - before: Before the links
- * - after: After the links
- * @uses bbp_get_topic_id() To get the topic id
- * @uses WP_Rewrite::using_permalinks() To check if the blog is using
- * permalinks
- * @uses user_trailingslashit() To add a trailing slash
- * @uses trailingslashit() To add a trailing slash
- * @uses get_permalink() To get the permalink of the topic
- * @uses add_query_arg() To add query args
- * @uses bbp_get_topic_reply_count() To get topic reply count
- * @uses bbp_show_topic_lead() Are we showing the topic as a lead?
- * @uses get_option() To get replies per page option
- * @uses paginate_links() To paginate the links
- * @uses apply_filters() Calls 'bbp_get_topic_pagination' with the links
- * and arguments
- * @return string Pagination links
- */
- function bbp_get_topic_pagination( $args = '' ) {
- global $wp_rewrite;
-
- // Bail if threading replies
- if ( bbp_thread_replies() ) {
- return;
- }
-
- // Parse arguments against default values
- $r = bbp_parse_args( $args, array(
- 'topic_id' => bbp_get_topic_id(),
- 'before' => '<span class="bbp-topic-pagination">',
- 'after' => '</span>',
- ), 'get_topic_pagination' );
-
- // If pretty permalinks are enabled, make our pagination pretty
- if ( $wp_rewrite->using_permalinks() ) {
- $base = trailingslashit( get_permalink( $r['topic_id'] ) ) . user_trailingslashit( $wp_rewrite->pagination_base . '/%#%/' );
- } else {
- $base = add_query_arg( 'paged', '%#%', get_permalink( $r['topic_id'] ) );
- }
-
- // Get total and add 1 if topic is included in the reply loop
- $total = bbp_get_topic_reply_count( $r['topic_id'], true );
-
- // Bump if topic is in loop
- if ( !bbp_show_lead_topic() )
- $total++;
-
- // Pagination settings
- $pagination = array(
- 'base' => $base,
- 'format' => '',
- 'total' => ceil( (int) $total / (int) bbp_get_replies_per_page() ),
- 'current' => 0,
- 'prev_next' => false,
- 'mid_size' => 2,
- 'end_size' => 3,
- 'add_args' => ( bbp_get_view_all() ) ? array( 'view' => 'all' ) : false
- );
-
- // Add pagination to query object
- $pagination_links = paginate_links( $pagination );
- if ( !empty( $pagination_links ) ) {
-
- // Remove first page from pagination
- if ( $wp_rewrite->using_permalinks() ) {
- $pagination_links = str_replace( $wp_rewrite->pagination_base . '/1/', '', $pagination_links );
- } else {
- $pagination_links = str_replace( '&paged=1', '', $pagination_links );
- }
-
- // Add before and after to pagination links
- $pagination_links = $r['before'] . $pagination_links . $r['after'];
- }
-
- return apply_filters( 'bbp_get_topic_pagination', $pagination_links, $args );
- }
-
- /**
- * Append revisions to the topic content
- *
- * @since bbPress (r2782)
- *
- * @param string $content Optional. Content to which we need to append the revisions to
- * @param int $topic_id Optional. Topic id
- * @uses bbp_get_topic_revision_log() To get the topic revision log
- * @uses apply_filters() Calls 'bbp_topic_append_revisions' with the processed
- * content, original content and topic id
- * @return string Content with the revisions appended
- */
- function bbp_topic_content_append_revisions( $content = '', $topic_id = 0 ) {
-
- // Bail if in admin or feed
- if ( is_admin() || is_feed() )
- return;
-
- // Validate the ID
- $topic_id = bbp_get_topic_id( $topic_id );
-
- return apply_filters( 'bbp_topic_append_revisions', $content . bbp_get_topic_revision_log( $topic_id ), $content, $topic_id );
- }
-
- /**
- * Output the revision log of the topic
- *
- * @since bbPress (r2782)
- *
- * @param int $topic_id Optional. Topic id
- * @uses bbp_get_topic_revision_log() To get the topic revision log
- */
- function bbp_topic_revision_log( $topic_id = 0 ) {
- echo bbp_get_topic_revision_log( $topic_id );
- }
- /**
- * Return the formatted revision log of the topic
- *
- * @since bbPress (r2782)
- *
- * @param int $topic_id Optional. Topic id
- * @uses bbp_get_topic_id() To get the topic id
- * @uses bbp_get_topic_revisions() To get the topic revisions
- * @uses bbp_get_topic_raw_revision_log() To get the raw revision log
- * @uses bbp_get_topic_author_display_name() To get the topic author
- * @uses bbp_get_author_link() To get the topic author link
- * @uses bbp_convert_date() To convert the date
- * @uses bbp_get_time_since() To get the time in since format
- * @uses apply_filters() Calls 'bbp_get_topic_revision_log' with the
- * log and topic id
- * @return string Revision log of the topic
- */
- function bbp_get_topic_revision_log( $topic_id = 0 ) {
- // Create necessary variables
- $topic_id = bbp_get_topic_id( $topic_id );
- $revision_log = bbp_get_topic_raw_revision_log( $topic_id );
-
- if ( empty( $topic_id ) || empty( $revision_log ) || !is_array( $revision_log ) )
- return false;
-
- $revisions = bbp_get_topic_revisions( $topic_id );
- if ( empty( $revisions ) )
- return false;
-
- $r = "\n\n" . '<ul id="bbp-topic-revision-log-' . esc_attr( $topic_id ) . '" class="bbp-topic-revision-log">' . "\n\n";
-
- // Loop through revisions
- foreach ( (array) $revisions as $revision ) {
-
- if ( empty( $revision_log[$revision->ID] ) ) {
- $author_id = $revision->post_author;
- $reason = '';
- } else {
- $author_id = $revision_log[$revision->ID]['author'];
- $reason = $revision_log[$revision->ID]['reason'];
- }
-
- $author = bbp_get_author_link( array( 'size' => 14, 'link_text' => bbp_get_topic_author_display_name( $revision->ID ), 'post_id' => $revision->ID ) );
- $since = bbp_get_time_since( bbp_convert_date( $revision->post_modified ) );
-
- $r .= "\t" . '<li id="bbp-topic-revision-log-' . esc_attr( $topic_id ) . '-item-' . esc_attr( $revision->ID ) . '" class="bbp-topic-revision-log-item">' . "\n";
- if ( !empty( $reason ) ) {
- $r .= "\t\t" . sprintf( __( 'This topic was modified %1$s by %2$s. Reason: %3$s', 'bbpress' ), esc_html( $since ), $author, esc_html( $reason ) ) . "\n";
- } else {
- $r .= "\t\t" . sprintf( __( 'This topic was modified %1$s by %2$s.', 'bbpress' ), esc_html( $since ), $author ) . "\n";
- }
- $r .= "\t" . '</li>' . "\n";
-
- }
-
- $r .= "\n" . '</ul>' . "\n\n";
-
- return apply_filters( 'bbp_get_topic_revision_log', $r, $topic_id );
- }
- /**
- * Return the raw revision log of the topic
- *
- * @since bbPress (r2782)
- *
- * @param int $topic_id Optional. Topic id
- * @uses bbp_get_topic_id() To get the topic id
- * @uses get_post_meta() To get the revision log meta
- * @uses apply_filters() Calls 'bbp_get_topic_raw_revision_log'
- * with the log and topic id
- * @return string Raw revision log of the topic
- */
- function bbp_get_topic_raw_revision_log( $topic_id = 0 ) {
- $topic_id = bbp_get_topic_id( $topic_id );
-
- $revision_log = get_post_meta( $topic_id, '_bbp_revision_log', true );
- $revision_log = empty( $revision_log ) ? array() : $revision_log;
-
- return apply_filters( 'bbp_get_topic_raw_revision_log', $revision_log, $topic_id );
- }
-
- /**
- * Return the revisions of the topic
- *
- * @since bbPress (r2782)
- *
- * @param int $topic_id Optional. Topic id
- * @uses bbp_get_topic_id() To get the topic id
- * @uses wp_get_post_revisions() To get the topic revisions
- * @uses apply_filters() Calls 'bbp_get_topic_revisions'
- * with the revisions and topic id
- * @return string Topic revisions
- */
- function bbp_get_topic_revisions( $topic_id = 0 ) {
- $topic_id = bbp_get_topic_id( $topic_id );
- $revisions = wp_get_post_revisions( $topic_id, array( 'order' => 'ASC' ) );
-
- return apply_filters( 'bbp_get_topic_revisions', $revisions, $topic_id );
- }
-
- /**
- * Return the revision count of the topic
- *
- * @since bbPress (r2782)
- *
- * @param int $topic_id Optional. Topic id
- * @uses bbp_get_topic_revisions() To get the topic revisions
- * @uses apply_filters() Calls 'bbp_get_topic_revision_count'
- * with the revision count and topic id
- * @return string Topic revision count
- */
- function bbp_get_topic_revision_count( $topic_id = 0, $integer = false ) {
- $count = (int) count( bbp_get_topic_revisions( $topic_id ) );
- $filter = ( true === $integer ) ? 'bbp_get_topic_revision_count_int' : 'bbp_get_topic_revision_count';
-
- return apply_filters( $filter, $count, $topic_id );
- }
-
- /**
- * Output the status of the topic
- *
- * @since bbPress (r2667)
- *
- * @param int $topic_id Optional. Topic id
- * @uses bbp_get_topic_status() To get the topic status
- */
- function bbp_topic_status( $topic_id = 0 ) {
- echo bbp_get_topic_status( $topic_id );
- }
- /**
- * Return the status of the topic
- *
- * @since bbPress (r2667)
- *
- * @param int $topic_id Optional. Topic id
- * @uses bbp_get_topic_id() To get the topic id
- * @uses get_post_status() To get the topic status
- * @uses apply_filters() Calls 'bbp_get_topic_status' with the status
- * and topic id
- * @return string Status of topic
- */
- function bbp_get_topic_status( $topic_id = 0 ) {
- $topic_id = bbp_get_topic_id( $topic_id );
-
- return apply_filters( 'bbp_get_topic_status', get_post_status( $topic_id ), $topic_id );
- }
-
- /**
- * Is the topic open to new replies?
- *
- * @since bbPress (r2727)
- *
- * @uses bbp_get_topic_status()
- *
- * @param int $topic_id Optional. Topic id
- * @uses bbp_is_topic_closed() To check if the topic is closed
- * @return bool True if open, false if closed.
- */
- function bbp_is_topic_open( $topic_id = 0 ) {
- return !bbp_is_topic_closed( $topic_id );
- }
-
- /**
- * Is the topic closed to new replies?
- *
- * @since bbPress (r2746)
- *
- * @param int $topic_id Optional. Topic id
- * @uses bbp_get_topic_status() To get the topic status
- * @uses apply_filters() Calls 'bbp_is_topic_closed' with the topic id
- *
- * @return bool True if closed, false if not.
- */
- function bbp_is_topic_closed( $topic_id = 0 ) {
- $closed = bbp_get_topic_status( $topic_id ) === bbp_get_closed_status_id();
- return (bool) apply_filters( 'bbp_is_topic_closed', (bool) $closed, $topic_id );
- }
-
- /**
- * Is the topic a sticky or super sticky?
- *
- * @since bbPress (r2754)
- *
- * @param int $topic_id Optional. Topic id
- * @param int $check_super Optional. If set to true and if the topic is not a
- * normal sticky, it is checked if it is a super
- * sticky or not. Defaults to true.
- * @uses bbp_get_topic_id() To get the topic id
- * @uses bbp_get_topic_forum_id() To get the topic forum id
- * @uses bbp_get_stickies() To get the stickies
- * @uses bbp_is_topic_super_sticky() To check if the topic is a super sticky
- * @return bool True if sticky or super sticky, false if not.
- */
- function bbp_is_topic_sticky( $topic_id = 0, $check_super = true ) {
- $topic_id = bbp_get_topic_id( $topic_id );
- $forum_id = bbp_get_topic_forum_id( $topic_id );
- $stickies = bbp_get_stickies( $forum_id );
-
- if ( in_array( $topic_id, $stickies ) || ( !empty( $check_super ) && bbp_is_topic_super_sticky( $topic_id ) ) )
- return true;
-
- return false;
- }
-
- /**
- * Is the topic a super sticky?
- *
- * @since bbPress (r2754)
- *
- * @param int $topic_id Optional. Topic id
- * @uses bbp_get_topic_id() To get the topic id
- * @uses bbp_get_super_stickies() To get the super stickies
- * @return bool True if super sticky, false if not.
- */
- function bbp_is_topic_super_sticky( $topic_id = 0 ) {
- $topic_id = bbp_get_topic_id( $topic_id );
- $stickies = bbp_get_super_stickies( $topic_id );
-
- return in_array( $topic_id, $stickies );
- }
-
- /**
- * Is the topic not spam or deleted?
- *
- * @since bbPress (r3496)
- *
- * @param int $topic_id Optional. Topic id
- * @uses bbp_get_topic_id() To get the topic id
- * @uses bbp_get_topic_status() To get the topic status
- * @uses apply_filters() Calls 'bbp_is_topic_published' with the topic id
- * @return bool True if published, false if not.
- */
- function bbp_is_topic_published( $topic_id = 0 ) {
- $topic_status = bbp_get_topic_status( bbp_get_topic_id( $topic_id ) ) === bbp_get_public_status_id();
- return (bool) apply_filters( 'bbp_is_topic_published', (bool) $topic_status, $topic_id );
- }
-
- /**
- * Is the topic marked as spam?
- *
- * @since bbPress (r2727)
- *
- * @param int $topic_id Optional. Topic id
- * @uses bbp_get_topic_id() To get the topic id
- * @uses bbp_get_topic_status() To get the topic status
- * @uses apply_filters() Calls 'bbp_is_topic_spam' with the topic id
- * @return bool True if spam, false if not.
- */
- function bbp_is_topic_spam( $topic_id = 0 ) {
- $topic_status = bbp_get_topic_status( bbp_get_topic_id( $topic_id ) ) === bbp_get_spam_status_id();
- return (bool) apply_filters( 'bbp_is_topic_spam', (bool) $topic_status, $topic_id );
- }
-
- /**
- * Is the topic trashed?
- *
- * @since bbPress (r2888)
- *
- * @param int $topic_id Optional. Topic id
- * @uses bbp_get_topic_id() To get the topic id
- * @uses bbp_get_topic_status() To get the topic status
- * @uses apply_filters() Calls 'bbp_is_topic_trash' with the topic id
- * @return bool True if trashed, false if not.
- */
- function bbp_is_topic_trash( $topic_id = 0 ) {
- $topic_status = bbp_get_topic_status( bbp_get_topic_id( $topic_id ) ) === bbp_get_trash_status_id();
- return (bool) apply_filters( 'bbp_is_topic_trash', (bool) $topic_status, $topic_id );
- }
-
- /**
- * Is the posted by an anonymous user?
- *
- * @since bbPress (r2753)
- *
- * @param int $topic_id Optional. Topic id
- * @uses bbp_get_topic_id() To get the topic id
- * @uses bbp_get_topic_author_id() To get the topic author id
- * @uses get_post_meta() To get the anonymous user name and email meta
- * @uses apply_filters() Calls 'bbp_is_topic_anonymous' with the topic id
- * @return bool True if the post is by an anonymous user, false if not.
- */
- function bbp_is_topic_anonymous( $topic_id = 0 ) {
- $topic_id = bbp_get_topic_id( $topic_id );
- $retval = false;
-
- if ( !bbp_get_topic_author_id( $topic_id ) )
- $retval = true;
-
- elseif ( get_post_meta( $topic_id, '_bbp_anonymous_name', true ) )
- $retval = true;
-
- elseif ( get_post_meta( $topic_id, '_bbp_anonymous_email', true ) )
- $retval = true;
-
- // The topic is by an anonymous user
- return (bool) apply_filters( 'bbp_is_topic_anonymous', $retval, $topic_id );
- }
-
- /**
- * Deprecated. Use bbp_topic_author_display_name() instead.
- *
- * Output the author of the topic.
- *
- * @since bbPress (r2590)
- * @deprecated bbPress (r5119)
- *
- * @param int $topic_id Optional. Topic id
- * @uses bbp_get_topic_author() To get the topic author
- */
- function bbp_topic_author( $topic_id = 0 ) {
- echo bbp_get_topic_author( $topic_id );
- }
- /**
- * Deprecated. Use bbp_get_topic_author_display_name() instead.
- *
- * Return the author of the topic
- *
- * @since bbPress (r2590)
- * @deprecated bbPress (r5119)
- *
- * @param int $topic_id Optional. Topic id
- * @uses bbp_get_topic_id() To get the topic id
- * @uses bbp_is_topic_anonymous() To check if the topic is by an
- * anonymous user
- * @uses bbp_get_topic_author_id() To get the topic author id
- * @uses get_the_author_meta() To get the display name of the author
- * @uses get_post_meta() To get the name of the anonymous poster
- * @uses apply_filters() Calls 'bbp_get_topic_author' with the author
- * and topic id
- * @return string Author of topic
- */
- function bbp_get_topic_author( $topic_id = 0 ) {
- $topic_id = bbp_get_topic_id( $topic_id );
-
- if ( !bbp_is_topic_anonymous( $topic_id ) ) {
- $author = get_the_author_meta( 'display_name', bbp_get_topic_author_id( $topic_id ) );
- } else {
- $author = get_post_meta( $topic_id, '_bbp_anonymous_name', true );
- }
-
- return apply_filters( 'bbp_get_topic_author', $author, $topic_id );
- }
-
- /**
- * Output the author ID of the topic
- *
- * @since bbPress (r2590)
- *
- * @param int $topic_id Optional. Topic id
- * @uses bbp_get_topic_author_id() To get the topic author id
- */
- function bbp_topic_author_id( $topic_id = 0 ) {
- echo bbp_get_topic_author_id( $topic_id );
- }
- /**
- * Return the author ID of the topic
- *
- * @since bbPress (r2590)
- *
- * @param int $topic_id Optional. Topic id
- * @uses bbp_get_topic_id() To get the topic id
- * @uses get_post_field() To get the topic author id
- * @uses apply_filters() Calls 'bbp_get_topic_author_id' with the author
- * id and topic id
- * @return string Author of topic
- */
- function bbp_get_topic_author_id( $topic_id = 0 ) {
- $topic_id = bbp_get_topic_id( $topic_id );
- $author_id = get_post_field( 'post_author', $topic_id );
-
- return (int) apply_filters( 'bbp_get_topic_author_id', (int) $author_id, $topic_id );
- }
-
- /**
- * Output the author display_name of the topic
- *
- * @since bbPress (r2590)
- *
- * @param int $topic_id Optional. Topic id
- * @uses bbp_get_topic_author_display_name() To get the topic author's display
- * name
- */
- function bbp_topic_author_display_name( $topic_id = 0 ) {
- echo bbp_get_topic_author_display_name( $topic_id );
- }
- /**
- * Return the author display_name of the topic
- *
- * @since bbPress (r2485)
- *
- * @param int $topic_id Optional. Topic id
- * @uses bbp_get_topic_id() To get the topic id
- * @uses bbp_is_topic_anonymous() To check if the topic is by an
- * anonymous user
- * @uses bbp_get_topic_author_id() To get the topic author id
- * @uses get_the_author_meta() To get the author meta
- * @uses get_post_meta() To get the anonymous user name
- * @uses apply_filters() Calls 'bbp_get_topic_author_id' with the
- * display name and topic id
- * @return string Topic's author's display name
- */
- function bbp_get_topic_author_display_name( $topic_id = 0 ) {
- $topic_id = bbp_get_topic_id( $topic_id );
-
- // Check for anonymous user
- if ( !bbp_is_topic_anonymous( $topic_id ) ) {
-
- // Get the author ID
- $author_id = bbp_get_topic_author_id( $topic_id );
-
- // Try to get a display name
- $author_name = get_the_author_meta( 'display_name', $author_id );
-
- // Fall back to user login
- if ( empty( $author_name ) ) {
- $author_name = get_the_author_meta( 'user_login', $author_id );
- }
-
- // User does not have an account
- } else {
- $author_name = get_post_meta( $topic_id, '_bbp_anonymous_name', true );
- }
-
- // If nothing could be found anywhere, use Anonymous
- if ( empty( $author_name ) )
- $author_name = __( 'Anonymous', 'bbpress' );
-
- // Encode possible UTF8 display names
- if ( seems_utf8( $author_name ) === false )
- $author_name = utf8_encode( $author_name );
-
- return apply_filters( 'bbp_get_topic_author_display_name', $author_name, $topic_id );
- }
-
- /**
- * Output the author avatar of the topic
- *
- * @since bbPress (r2590)
- *
- * @param int $topic_id Optional. Topic id
- * @param int $size Optional. Avatar size. Defaults to 40
- * @uses bbp_get_topic_author_avatar() To get the topic author avatar
- */
- function bbp_topic_author_avatar( $topic_id = 0, $size = 40 ) {
- echo bbp_get_topic_author_avatar( $topic_id, $size );
- }
- /**
- * Return the author avatar of the topic
- *
- * @since bbPress (r2590)
- *
- * @param int $topic_id Optional. Topic id
- * @param int $size Optional. Avatar size. Defaults to 40
- * @uses bbp_get_topic_id() To get the topic id
- * @uses bbp_is_topic_anonymous() To check if the topic is by an
- * anonymous user
- * @uses bbp_get_topic_author_id() To get the topic author id
- * @uses get_post_meta() To get the anonymous user's email
- * @uses get_avatar() To get the avatar
- * @uses apply_filters() Calls 'bbp_get_topic_author_avatar' with the
- * avatar, topic id and size
- * @return string Avatar of the author of the topic
- */
- function bbp_get_topic_author_avatar( $topic_id = 0, $size = 40 ) {
- $author_avatar = '';
-
- $topic_id = bbp_get_topic_id( $topic_id );
- if ( !empty( $topic_id ) ) {
- if ( !bbp_is_topic_anonymous( $topic_id ) ) {
- $author_avatar = get_avatar( bbp_get_topic_author_id( $topic_id ), $size );
- } else {
- $author_avatar = get_avatar( get_post_meta( $topic_id, '_bbp_anonymous_email', true ), $size );
- }
- }
-
- return apply_filters( 'bbp_get_topic_author_avatar', $author_avatar, $topic_id, $size );
- }
-
- /**
- * Output the author link of the topic
- *
- * @since bbPress (r2717)
- *
- * @param mixed|int $args If it is an integer, it is used as topic_id. Optional.
- * @uses bbp_get_topic_author_link() To get the topic author link
- */
- function bbp_topic_author_link( $args = '' ) {
- echo bbp_get_topic_author_link( $args );
- }
- /**
- * Return the author link of the topic
- *
- * @since bbPress (r2717)
- *
- * @param mixed|int $args If it is an integer, it is used as topic id.
- * Optional.
- * @uses bbp_get_topic_id() To get the topic id
- * @uses bbp_get_topic_author_display_name() To get the topic author
- * @uses bbp_is_topic_anonymous() To check if the topic is by an
- * anonymous user
- * @uses bbp_get_topic_author_url() To get the topic author url
- * @uses bbp_get_topic_author_avatar() To get the topic author avatar
- * @uses bbp_get_topic_author_display_name() To get the topic author display
- * name
- * @uses bbp_get_user_display_role() To get the topic author display role
- * @uses bbp_get_topic_author_id() To get the topic author id
- * @uses apply_filters() Calls 'bbp_get_topic_author_link' with the link
- * and args
- * @return string Author link of topic
- */
- function bbp_get_topic_author_link( $args = '' ) {
-
- // Parse arguments against default values
- $r = bbp_parse_args( $args, array(
- 'post_id' => 0,
- 'link_title' => '',
- 'type' => 'both',
- 'size' => 80,
- 'sep' => ' ',
- 'show_role' => false
- ), 'get_topic_author_link' );
-
- // Used as topic_id
- if ( is_numeric( $args ) ) …
Large files files are truncated, but you can click here to view the full file