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/Feature/Comments/Comments.php +31 -133 4.6.05.3.5 View file →
@@ -7,19 +7,27 @@
7 7 */
8 8
9 9 namespace ElasticPress\Feature\Comments;
10 10
11 -use ElasticPress\Feature as Feature;
12 -use ElasticPress\Indexables as Indexables;
13 -use ElasticPress\Indexable as Indexable;
14 -use ElasticPress\Features as Features;
15 -use ElasticPress\FeatureRequirementsStatus as FeatureRequirementsStatus;
11 +use ElasticPress\Feature;
12 +use ElasticPress\FeatureRequirementsStatus;
13 +use ElasticPress\Features;
14 +use ElasticPress\Indexable;
15 +use ElasticPress\Indexables;
16 16 use ElasticPress\Utils;
17 +use ElasticPress\REST;
17 18
18 19 /**
19 20 * Comments feature class
20 21 */
21 22 class Comments extends Feature {
23 + /**
24 + * Whether the feature should be always visible in the dashboard
25 + *
26 + * @since 5.0.0
27 + * @var boolean
28 + */
29 + protected $is_visible = false;
22 30
23 31 /**
24 32 * Initialize feature, setting it's config
25 33 *
@@ -27,19 +35,27 @@
27 35 */
28 36 public function __construct() {
29 37 $this->slug = 'comments';
30 38
31 - $this->title = esc_html__( 'Comments', 'elasticpress' );
39 + $this->requires_install_reindex = true;
32 40
33 - $this->summary = __( 'Improve comment search relevancy and query performance.', 'elasticpress' );
41 + Indexables::factory()->register( new Indexable\Comment\Comment(), false );
34 42
35 - $this->docs_url = __( 'https://elasticpress.zendesk.com/hc/en-us/articles/360050447492-Configuring-ElasticPress-via-the-Plugin-Dashboard#comments', 'elasticpress' );
43 + parent::__construct();
44 + }
36 45
37 - $this->requires_install_reindex = true;
46 + /**
47 + * Sets i18n strings.
48 + *
49 + * @return void
50 + * @since 5.2.0
51 + */
52 + public function set_i18n_strings(): void {
53 + $this->title = esc_html__( 'Comments', 'elasticpress' );
38 54
39 - Indexables::factory()->register( new Indexable\Comment\Comment(), false );
55 + $this->summary = '<p>' . __( 'This feature will empower your website to overcome traditional WordPress comment search and query limitations that can present themselves at scale. This feature is only needed if you are using <code>WP_Comment_Query</code> directly.', 'elasticpress' ) . '</p>';
40 56
41 - parent::__construct();
57 + $this->docs_url = __( 'https://www.elasticpress.io/resources/articles/configuring-elasticpress-via-the-plugin-dashboard/#comments', 'elasticpress' );
42 58 }
43 59
44 60 /**
45 61 * Setup search functionality
@@ -87,19 +103,8 @@
87 103 add_filter( 'ep_elasticpress_enabled', [ $this, 'integrate_search_queries' ], 10, 2 );
88 104 }
89 105
90 106 /**
91 - * Output feature box long text
92 - *
93 - * @since 3.6.0
94 - */
95 - public function output_feature_box_long() {
96 - ?>
97 - <p><?php esc_html_e( 'This feature will empower your website to overcome traditional WordPress comment search and query limitations that can present themselves at scale.', 'elasticpress' ); ?></p>
98 - <?php
99 - }
100 -
101 - /**
102 107 * Enable integration on search queries
103 108 *
104 109 * @param bool $enabled Whether EP is enabled
105 110 * @param \WP_Comment_Query $query Current query object.
@@ -126,9 +131,9 @@
126 131 * @since 3.6.0
127 132 * @return FeatureRequirementsStatus
128 133 */
129 134 public function requirements_status() {
130 - $status = new FeatureRequirementsStatus( 1 );
135 + $status = new FeatureRequirementsStatus( 1, null, $this );
131 136
132 137 return $status;
133 138 }
134 139
@@ -146,120 +151,13 @@
146 151 *
147 152 * @since 3.6.0
148 153 */
149 154 public function rest_api_init() {
150 - register_rest_route(
151 - 'elasticpress/v1',
152 - 'comments',
153 - [
154 - 'methods' => 'GET',
155 - 'callback' => [ $this, 'handle_comments_search' ],
156 - 'permission_callback' => '__return_true',
157 - 'args' => [
158 - 's' => [
159 - 'validate_callback' => function ( $param ) {
160 - return ! empty( $param );
161 - },
162 - 'required' => true,
163 - ],
164 - 'post_type' => [
165 - 'validate_callback' => function ( $param ) {
166 - return ! empty( $param );
167 - },
168 - ],
169 - ],
170 - ]
171 - );
155 + $controller = new REST\Comments();
156 + $controller->register_routes();
172 157 }
173 158
174 159 /**
175 - * Handles the search for comments
176 - *
177 - * @since 3.6.0
178 - * @param \WP_REST_Request $request Rest request
179 - * @return array
180 - */
181 - public function handle_comments_search( $request ) {
182 - $search = $request->get_param( 's' );
183 -
184 - if ( empty( $search ) ) {
185 - return new \WP_Error( 400 );
186 - }
187 -
188 - $post_type_filter = explode( ',', $request->get_param( 'post_type' ) );
189 - $searchable_post_types = array_filter(
190 - Features::factory()->get_registered_feature( 'search' )->get_searchable_post_types(),
191 - function ( $post_type ) {
192 - return post_type_supports( $post_type, 'comments' );
193 - }
194 - );
195 -
196 - if ( ! empty( $post_type_filter ) && is_array( $searchable_post_types ) ) {
197 - $post_type_filter = array_intersect( $post_type_filter, $searchable_post_types );
198 - }
199 -
200 - $default_args = [
201 - 'status' => 'approve',
202 - 'search' => $search,
203 - 'type' => Indexables::factory()->get( 'comment' )->get_indexable_comment_types(),
204 - 'post_type' => empty( $post_type_filter ) ? $searchable_post_types : $post_type_filter,
205 - 'post_status' => 'publish',
206 - 'number' => 5,
207 - ];
208 -
209 - /**
210 - * Filter to args used in WP_Comment_Query in Widget Search Comment
211 - *
212 - * @hook ep_comment_search_widget_args
213 - * @since 3.6.0
214 - * @param {array} $default_args Defaults args
215 - * @return {array} New value
216 - */
217 - $args = apply_filters( 'ep_comment_search_widget_args', $default_args );
218 -
219 - /**
220 - * Fires before the comment query is executed.
221 - *
222 - * @hook ep_comment_pre_search_widget
223 - * @since 3.6.0
224 - * @param {array} $args Args passed to `WP_Comment_Query`.
225 - * @param {WP_REST_Request} $request Rest request.
226 - */
227 - do_action( 'ep_comment_pre_search_widget', $args, $request );
228 -
229 - $comment_query = new \WP_Comment_Query( $args );
230 -
231 - /**
232 - * Fires after the comment query is executed.
233 - *
234 - * @hook ep_comment_after_search_widget
235 - * @since 3.6.0
236 - * @param {WP_Comment_Query} $comment_query WP_Comment_Query object.
237 - * @param {WP_REST_Request} $request Rest request.
238 - */
239 - do_action( 'ep_comment_after_search_widget', $comment_query, $request );
240 -
241 - $return = [];
242 - foreach ( $comment_query->comments as $comment ) {
243 - $return[ $comment->comment_ID ] = [
244 - 'id' => $comment->comment_ID,
245 - 'content' => $comment->comment_content,
246 - 'link' => get_comment_link( $comment ),
247 - ];
248 - }
249 -
250 - /**
251 - * Filters the comments response
252 - *
253 - * @hook ep_comment_search_widget_response
254 - * @since 3.6.0
255 - * @param {array} $return The result of fetched comments.
256 - * @return {array} New value
257 - */
258 - return apply_filters( 'ep_comment_search_widget_response', $return );
259 - }
260 -
261 - /**
262 160 * Get a list of searchable post types that support comments.
263 161 *
264 162 * @return array Array of post type labels keyed by post type.
265 163 * @since 4.4.0
@@ -269,9 +167,9 @@
269 167
270 168 $post_types = Features::factory()->get_registered_feature( 'search' )->get_searchable_post_types();
271 169 $post_types = array_filter(
272 170 $post_types,
273 - function( $post_type ) {
171 + function ( $post_type ) {
274 172 return post_type_supports( $post_type, 'comments' );
275 173 }
276 174 );
277 175