PluginProbe
ElasticPress / 5.3.5
ElasticPress v5.3.5
5.3.5 5.3.4 3.6.5 3.6.6 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.7.0 4.7.1 4.7.2 5.0.0 5.0.1 5.0.2 All 108 releases
← All changes | includes/classes/REST/Comments.php +28 -0 5.0.05.3.5 View file →
@@ -119,8 +119,12 @@
119 119 do_action( 'ep_comment_after_search_widget', $comment_query, $request );
120 120
121 121 $return = [];
122 122 foreach ( $comment_query->comments as $comment ) {
123 + if ( ! $this->can_read_comment( $comment ) ) {
124 + continue;
125 + }
126 +
123 127 $return[ $comment->comment_ID ] = [
124 128 'id' => $comment->comment_ID,
125 129 'content' => $comment->comment_content,
126 130 'link' => get_comment_link( $comment ),
@@ -135,8 +139,32 @@
135 139 * @param {array} $return The result of fetched comments.
136 140 * @return {array} New value
137 141 */
138 142 return apply_filters( 'ep_comment_search_widget_response', $return );
143 + }
144 +
145 + /**
146 + * Whether the current user can read a comment's parent post.
147 + *
148 + * Mirrors WP_REST_Comments_Controller::check_read_post_permission() for a
149 + * collection search: password-protected parents stay hidden unless the
150 + * visitor has the password cookie or can edit the post.
151 + *
152 + * @since 5.3.5
153 + * @param \WP_Comment $comment Comment object.
154 + * @return bool
155 + */
156 + protected function can_read_comment( $comment ) {
157 + $post = get_post( (int) $comment->comment_post_ID );
158 + if ( ! $post ) {
159 + return false;
160 + }
161 +
162 + if ( post_password_required( $post ) ) {
163 + return current_user_can( 'edit_post', $post->ID );
164 + }
165 +
166 + return true;
139 167 }
140 168
141 169 /**
142 170 * Get searchable post types.