Skip to:
Content

bbPress.org

Changeset 7276


Ignore:
Timestamp:
07/02/2024 04:11:29 PM (9 months ago)
Author:
johnjamesjacoby
Message:

Posts: strip "Protected/Private" for bbPress post types

This change prevents post title hints from being prepended to titles of Forums, Topics, or Replies, which was happening as a consequence of calling get_the_title() which assumes every protected/private post title needs it.

It does this by including the following code changes:

  • introduce the bbp_no_title_status_hints() filter function, which hooks into 2 WordPress filters and maybe overrides the return value
  • replace a few get_the_title() calls with get_post_field( 'post_title' ) to bypass the above filters when they would never be desirable

Committer note: this could be considered a small back-compat break (because it alters long-standing theme-side output) but ultimately it is a design decision to output all of the forum content as it was saved by the community members. Forums that prefer the old behavior can unhook bbp_no_title_status_hints and continue to customize child template parts to insert custom forum status hints.

Fixes #3602.

Location:
trunk/src/includes
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/common/template.php

    r7231 r7276  
    28452845    return apply_filters( 'bbp_title', $new_title, $sep, $seplocation );
    28462846}
     2847
     2848/**
     2849 * Removes Protected/Private post title hints.
     2850 *
     2851 * This function is hooked to 2 WordPress filters that are responsible for
     2852 * prepending hints to the beginning of Protected & Private post titles.
     2853 *
     2854 * These hints are a bit unsightly when used in functions like
     2855 * bbp_get_breadcrumb(), so we strip them back out for bbPress post types.
     2856 *
     2857 * @since 2.7.0
     2858 *
     2859 * @param string      $prepend Text displayed before a post title.
     2860 * @param int|WP_Post $post    Current post object.
     2861 *
     2862 * @return string
     2863 */
     2864function bbp_no_title_status_hints( $prepend = '', $post = 0 ) {
     2865
     2866    // Bail if empty
     2867    if ( empty( $prepend ) || empty( $post ) ) {
     2868        return $prepend;
     2869    }
     2870
     2871    // Get post type
     2872    $post_type = get_post_type( $post );
     2873
     2874    // Maybe override return value
     2875    $retval = in_array( $post_type, bbp_get_post_types(), true )
     2876        ? '%s'
     2877        : $prepend;
     2878
     2879    // Filter & return
     2880    return (string) apply_filters( 'bbp_no_special_title_formatting', $retval, $prepend, $post );
     2881}
  • trunk/src/includes/core/filters.php

    r7235 r7276  
    6464// Reply title fallback
    6565add_filter( 'the_title', 'bbp_get_reply_title_fallback', 2, 2 );
     66
     67// Special title formatting
     68add_filter( 'protected_title_format', 'bbp_no_title_status_hints', 10, 2 );
     69add_filter( 'private_title_format',   'bbp_no_title_status_hints', 10, 2 );
    6670
    6771// Avoid queries & 404s
  • trunk/src/includes/forums/template.php

    r7239 r7276  
    373373    function bbp_get_forum_title( $forum_id = 0 ) {
    374374        $forum_id = bbp_get_forum_id( $forum_id );
    375         $title    = get_the_title( $forum_id );
     375        $title    = get_post_field( 'post_title', $forum_id );
     376        $title    = apply_filters( 'the_title', $title, $forum_id );
    376377
    377378        // Filter & return
  • trunk/src/includes/replies/template.php

    r7268 r7276  
    524524    function bbp_get_reply_title( $reply_id = 0 ) {
    525525        $reply_id = bbp_get_reply_id( $reply_id );
    526         $title    = get_the_title( $reply_id );
     526        $title    = get_post_field( 'post_title', $reply_id );
     527        $title    = apply_filters( 'the_title', $title, $reply_id );
    527528
    528529        // Filter & return
     
    14011402        $reply_id = bbp_get_reply_id( $reply_id );
    14021403        $topic_id = bbp_get_reply_topic_id( $reply_id );
    1403 
    1404         // Filter & return
    1405         return apply_filters( 'bbp_get_reply_topic_title', bbp_get_topic_title( $topic_id ), $reply_id );
     1404        $title    = bbp_get_topic_title( $topic_id );
     1405
     1406        // Filter & return
     1407        return apply_filters( 'bbp_get_reply_topic_title', $title, $reply_id );
    14061408    }
    14071409
  • trunk/src/includes/topics/template.php

    r7268 r7276  
    601601    function bbp_get_topic_title( $topic_id = 0 ) {
    602602        $topic_id = bbp_get_topic_id( $topic_id );
    603         $title    = get_the_title( $topic_id );
     603        $title    = get_post_field( 'post_title', $topic_id );
     604        $title    = apply_filters( 'the_title', $title, $topic_id );
    604605
    605606        // Filter & return
Note: See TracChangeset for help on using the changeset viewer.