| @@ -62,13 +62,9 @@ | ||
| 62 | 62 | |
| 63 | 63 | // Determine which post types to query. An explicit single post type narrows |
| 64 | 64 | // the search; 'all' (or no value) searches the whole forum: forums, topics |
| 65 | 65 | // and replies, so content matches from any of them are returned. |
| 66 | - // Only public post types may be searched; anything else falls back to the | |
| 67 | - // forum-wide search instead of exposing non-public content. | |
| 68 | - $post_type_object = ( ! empty( $post_type ) && 'all' !== $post_type ) ? get_post_type_object( $post_type ) : null; | |
| 69 | - | |
| 70 | - if ( $post_type_object && $post_type_object->public ) { | |
| 66 | + if ( ! empty( $post_type ) && 'all' !== $post_type ) { | |
| 71 | 67 | $query_post_types = array( $post_type ); |
| 72 | 68 | } elseif ( class_exists( 'bbPress' ) ) { |
| 73 | 69 | $query_post_types = array( 'forum', 'topic', 'reply' ); |
| 74 | 70 | } else { |
| @@ -75,20 +71,13 @@ | ||
| 75 | 71 | $query_post_types = array( 'post' ); |
| 76 | 72 | } |
| 77 | 73 | |
| 78 | 74 | // Determine which statuses to include. bbPress stores closed topics with the |
| 79 | - // 'closed' post status, which WP_Query's default 'publish'-only behavior skips. | |
| 80 | - // Private/hidden forums are only searchable by users allowed to read them. | |
| 75 | + // 'closed' post status (and uses 'private'/'hidden' for restricted forums), | |
| 76 | + // none of which are returned by WP_Query's default 'publish'-only behavior. | |
| 77 | + // Include the publicly viewable bbPress statuses so closed topics still match. | |
| 81 | 78 | if ( class_exists( 'bbPress' ) ) { |
| 82 | - $query_post_status = array( 'publish', 'closed' ); | |
| 83 | - | |
| 84 | - if ( current_user_can( 'read_private_forums' ) ) { | |
| 85 | - $query_post_status[] = 'private'; | |
| 86 | - } | |
| 87 | - | |
| 88 | - if ( current_user_can( 'read_hidden_forums' ) ) { | |
| 89 | - $query_post_status[] = 'hidden'; | |
| 90 | - } | |
| 79 | + $query_post_status = array( 'publish', 'closed', 'private', 'hidden' ); | |
| 91 | 80 | } else { |
| 92 | 81 | $query_post_status = array( 'publish' ); |
| 93 | 82 | } |
| 94 | 83 | |
| @@ -114,14 +103,13 @@ | ||
| 114 | 103 | add_filter( 'posts_search', $bbpc_search_clause, 999, 2 ); |
| 115 | 104 | |
| 116 | 105 | // Main results query. |
| 117 | 106 | $results = new \WP_Query( array( |
| 118 | - 'post_type' => $query_post_types, | |
| 119 | - 'post_status' => $query_post_status, | |
| 120 | - 's' => $keyword, | |
| 121 | - 'posts_per_page' => 10, | |
| 122 | - 'bbpc_ajax_search' => true, | |
| 123 | - 'update_post_term_cache' => false, | |
| 107 | + 'post_type' => $query_post_types, | |
| 108 | + 'post_status' => $query_post_status, | |
| 109 | + 's' => $keyword, | |
| 110 | + 'posts_per_page' => 10, | |
| 111 | + 'bbpc_ajax_search' => true, | |
| 124 | 112 | ) ); |
| 125 | 113 | |
| 126 | 114 | remove_filter( 'posts_search', $bbpc_search_clause, 999 ); |
| 127 | 115 | |