Skip to:
Content

bbPress.org


Ignore:
Timestamp:
06/28/2024 06:06:30 PM (22 months ago)
Author:
johnjamesjacoby
Message:

Search: prevent hidden forums from appearing in results.

This change includes the following changes:

  • Removes readable perm check from bbp_has_search_results() and replaces it with public topic statuses by default, while conditionally adding private & hidden statuses if user is capable
  • Tweaks the logic inside of bbp_pre_get_posts_normalize_forum_visibility() to always handle both of its internal conditions (forum query, or any query that includes forums/topics/replies connected via meta data)
  • Tweaks output of content-search.php template part to not show the "Oh bother" error when visiting a search page for the first time
  • Adds a string feedback-no-search.php template part to address both "no results" and "no terms" conditions

These changes address some faulty search logic that was allowing hidden forums to appear in global search results to users who should not have been able to see them, while also improving the search page experience itself.

Fixes #3473.

Props wpsolr, robin-w.

In branches/2.6, for 2.6.10.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.6/src/includes/search/template.php

    r7176 r7262  
    4747    }
    4848
    49     // What are the default allowed statuses (based on user caps)
    50     if ( bbp_get_view_all() ) {
    51 
    52         // Default view=all statuses
    53         $post_statuses = array_keys( bbp_get_topic_statuses() );
    54 
    55         // Add support for private status
    56         if ( current_user_can( 'read_private_topics' ) ) {
    57             $post_statuses[] = bbp_get_private_status_id();
    58         }
    59 
    60         // Join post statuses together
    61         $default['post_status'] = $post_statuses;
    62 
    63     // Lean on the 'perm' query var value of 'readable' to provide statuses
    64     } else {
    65         $default['perm'] = 'readable';
    66     }
     49    // Default public statuses (topics coincidentally cover all post types)
     50    $post_statuses = array_keys( bbp_get_public_topic_statuses() );
     51
     52    // Add support for private status
     53    if ( current_user_can( 'read_private_topics' ) ) {
     54        $post_statuses[] = bbp_get_private_status_id();
     55    }
     56
     57    // Add support for hidden status
     58    if ( current_user_can( 'read_hidden_topics' ) ) {
     59        $post_statuses[] = bbp_get_hidden_status_id();
     60    }
     61
     62    // Join post statuses together
     63    $default['post_status'] = $post_statuses;
    6764
    6865    /** Setup *****************************************************************/
Note: See TracChangeset for help on using the changeset viewer.