PluginProbe
ElasticPress / 4.6.0
ElasticPress v4.6.0
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
elasticpress / includes / classes / StatusReport / ElasticPressIo.php

ElasticPressIo.php in ElasticPress 4.6.0, at includes/classes/StatusReport/ElasticPressIo.php

270 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ElasticPress.io report class
4 *
5 * @since 4.4.0
6 * @package elasticpress
7 */
8
9 namespace ElasticPress\StatusReport;
10
11 use ElasticPress\Indexables;
12 use ElasticPress\Feature\InstantResults;
13 use ElasticPress\Utils;
14
15 defined( 'ABSPATH' ) || exit;
16
17 /**
18 * ElasticPressIo report class
19 *
20 * @package ElasticPress
21 */
22 class ElasticPressIo extends Report {
23
24 /**
25 * Return the report title
26 *
27 * @return string
28 */
29 public function get_title() : string {
30 return __( 'ElasticPress.io', 'elasticpress' );
31 }
32
33 /**
34 * Return the report fields
35 *
36 * @return array
37 */
38 public function get_groups() : array {
39 $groups = [
40 $this->get_autosuggest_group(),
41 $this->get_instant_results_group(),
42 $this->get_orders_search_group(),
43 ];
44
45 return array_values( array_filter( $groups ) );
46 }
47
48 /**
49 * Process the ElasticPress.io Autosuggest allowed parameters.
50 *
51 * @return array
52 */
53 protected function get_autosuggest_group() : array {
54 $autosuggest_feature = \ElasticPress\Features::factory()->get_registered_feature( 'autosuggest' );
55
56 if ( ! $autosuggest_feature->is_active() ) {
57 return [];
58 }
59
60 $title = __( 'Allowed Autosuggest Parameters', 'elasticpress' );
61 $allowed_params = $autosuggest_feature->epio_autosuggest_set_and_get();
62
63 if ( empty( $allowed_params ) ) {
64 $fields['not_available'] = [
65 'label' => __( 'Allowed Autosuggest Parameters', 'elasticpress' ),
66 'value' => __( 'Allowed autosuggest parameters info not available.', 'elasticpress' ),
67 ];
68
69 return [
70 'title' => $title,
71 'fields' => $fields,
72 ];
73 }
74
75 $allowed_params = wp_parse_args(
76 $allowed_params,
77 [
78 'postTypes' => [],
79 'postStatus' => [],
80 'searchFields' => [],
81 'returnFields' => '',
82 ]
83 );
84
85 $fields = [
86 'Post Types' => wp_sprintf( esc_html__( '%l', 'elasticpress' ), $allowed_params['postTypes'] ),
87 'Post Status' => wp_sprintf( esc_html__( '%l', 'elasticpress' ), $allowed_params['postStatus'] ),
88 'Search Fields' => wp_sprintf( esc_html__( '%l', 'elasticpress' ), $allowed_params['searchFields'] ),
89 'Returned Fields' => wp_sprintf( esc_html( var_export( $allowed_params['returnFields'], true ) ) ), // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
90 ];
91
92 $formatted_fields = [];
93
94 foreach ( $fields as $label => $value ) {
95 $formatted_fields[ sanitize_title( $label ) ] = [
96 'label' => $label,
97 'value' => $value,
98 ];
99 }
100
101 return [
102 'title' => $title,
103 'fields' => $formatted_fields,
104 ];
105 }
106
107 /**
108 * Process the ElasticPress.io Instant Results templates.
109 *
110 * @return array
111 */
112 protected function get_instant_results_group() : array {
113 $instant_results_feature = \ElasticPress\Features::factory()->get_registered_feature( 'instant-results' );
114
115 if ( ! $instant_results_feature->is_active() ) {
116 return [];
117 }
118
119 $title = __( 'Instant Results Template', 'elasticpress' );
120 $fields = [];
121
122 if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
123 $sites = Utils\get_sites();
124
125 foreach ( $sites as $site ) {
126 if ( ! Utils\is_site_indexable( $site['blog_id'] ) ) {
127 continue;
128 }
129
130 switch_to_blog( $site['blog_id'] );
131
132 $field = $this->get_instant_results_field();
133 $fields = array_merge( $fields, $field );
134
135 restore_current_blog();
136 }
137 } else {
138 $fields = $this->get_instant_results_field();
139 }
140
141 return [
142 'title' => $title,
143 'fields' => $fields,
144 ];
145 }
146
147 /**
148 * Process the ElasticPress.io Orders Search templates.
149 *
150 * @since 4.5.0
151 * @return array
152 */
153 protected function get_orders_search_group() : array {
154 $woocommerce_feature = \ElasticPress\Features::factory()->get_registered_feature( 'woocommerce' );
155
156 if ( ! $woocommerce_feature->is_active() ) {
157 return [];
158 }
159
160 if ( ! $woocommerce_feature->orders ) {
161 return [];
162 }
163
164 $title = __( 'Orders Search Template', 'elasticpress' );
165 $fields = [];
166
167 if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
168 $sites = Utils\get_sites();
169
170 foreach ( $sites as $site ) {
171 if ( ! Utils\is_site_indexable( $site['blog_id'] ) ) {
172 continue;
173 }
174
175 switch_to_blog( $site['blog_id'] );
176
177 $field = $this->get_orders_search_field();
178 $fields = array_merge( $fields, $field );
179
180 restore_current_blog();
181 }
182 } else {
183 $fields = $this->get_orders_search_field();
184 }
185
186 return [
187 'title' => $title,
188 'fields' => $fields,
189 ];
190 }
191
192 /**
193 * Process the ElasticPress.io Instant Results template.
194 *
195 * @return array
196 */
197 protected function get_instant_results_field() : array {
198 $index = Indexables::factory()->get( 'post' )->get_index_name();
199
200 if ( ! $index ) {
201 return [];
202 }
203
204 $feature = new InstantResults\InstantResults();
205 $template = $feature->epio_get_search_template();
206
207 if ( is_wp_error( $template ) ) {
208 return [
209 $index => [
210 'label' => $index,
211 'value' => $template->get_error_message(),
212 ],
213 ];
214 }
215
216 return [
217 $index => [
218 'label' => $index,
219 'value' => $template,
220 ],
221 ];
222 }
223
224 /**
225 * Return the report messages.
226 *
227 * @return array
228 * @since 4.5.0
229 */
230 public function get_messages() : array {
231 $messages = \ElasticPress\ElasticPressIo::factory()->get_endpoint_messages( true );
232 $messages = array_values( $messages );
233
234 return $messages;
235 }
236
237 /**
238 * Process the ElasticPress.io Orders Search template.
239 *
240 * @since 4.5.0
241 * @return array
242 */
243 protected function get_orders_search_field() : array {
244 $index = Indexables::factory()->get( 'post' )->get_index_name();
245
246 if ( ! $index ) {
247 return [];
248 }
249
250 $woocommerce_feature = \ElasticPress\Features::factory()->get_registered_feature( 'woocommerce' );
251 $template = $woocommerce_feature->orders->get_search_template();
252
253 if ( is_wp_error( $template ) ) {
254 return [
255 $index => [
256 'label' => $index,
257 'value' => $template->get_error_message(),
258 ],
259 ];
260 }
261
262 return [
263 $index => [
264 'label' => $index,
265 'value' => $template,
266 ],
267 ];
268 }
269 }
270