PluginProbe
ElasticPress / 4.4.1
ElasticPress v4.4.1
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.4.1, at includes/classes/StatusReport/ElasticPressIo.php

178 lines 3.9 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 ];
43
44 return array_values( array_filter( $groups ) );
45 }
46
47 /**
48 * Process the ElasticPress.io Autosuggest allowed parameters.
49 *
50 * @return array
51 */
52 protected function get_autosuggest_group() : array {
53 $autosuggest_feature = \ElasticPress\Features::factory()->get_registered_feature( 'autosuggest' );
54
55 if ( ! $autosuggest_feature->is_active() ) {
56 return [];
57 }
58
59 $title = __( 'Allowed Autosuggest Parameters', 'elasticpress' );
60 $allowed_params = $autosuggest_feature->epio_autosuggest_set_and_get();
61
62 if ( empty( $allowed_params ) ) {
63 $fields['not_available'] = [
64 'label' => __( 'Allowed Autosuggest Parameters', 'elasticpress' ),
65 'value' => __( 'Allowed autosuggest parameters info not available.', 'elasticpress' ),
66 ];
67
68 return [
69 'title' => $title,
70 'fields' => $fields,
71 ];
72 }
73
74 $allowed_params = wp_parse_args(
75 $allowed_params,
76 [
77 'postTypes' => [],
78 'postStatus' => [],
79 'searchFields' => [],
80 'returnFields' => '',
81 ]
82 );
83
84 $fields = [
85 'Post Types' => wp_sprintf( esc_html__( '%l', 'elasticpress' ), $allowed_params['postTypes'] ),
86 'Post Status' => wp_sprintf( esc_html__( '%l', 'elasticpress' ), $allowed_params['postStatus'] ),
87 'Search Fields' => wp_sprintf( esc_html__( '%l', 'elasticpress' ), $allowed_params['searchFields'] ),
88 'Returned Fields' => wp_sprintf( esc_html( var_export( $allowed_params['returnFields'], true ) ) ), // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export
89 ];
90
91 $formatted_fields = [];
92
93 foreach ( $fields as $label => $value ) {
94 $formatted_fields[ sanitize_title( $label ) ] = [
95 'label' => $label,
96 'value' => $value,
97 ];
98 }
99
100 return [
101 'title' => $title,
102 'fields' => $formatted_fields,
103 ];
104 }
105
106 /**
107 * Process the ElasticPress.io Instant Results templates.
108 *
109 * @return array
110 */
111 protected function get_instant_results_group() : array {
112 $instant_results_feature = \ElasticPress\Features::factory()->get_registered_feature( 'instant-results' );
113
114 if ( ! $instant_results_feature->is_active() ) {
115 return [];
116 }
117
118 $title = __( 'Instant Results Template', 'elasticpress' );
119 $fields = [];
120
121 if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
122 $sites = Utils\get_sites();
123
124 foreach ( $sites as $site ) {
125 if ( ! Utils\is_site_indexable( $site['blog_id'] ) ) {
126 continue;
127 }
128
129 switch_to_blog( $site['blog_id'] );
130
131 $field = $this->get_instant_results_field();
132 $fields = array_merge( $fields, $field );
133
134 restore_current_blog();
135 }
136 } else {
137 $fields = $this->get_instant_results_field();
138 }
139
140 return [
141 'title' => $title,
142 'fields' => $fields,
143 ];
144 }
145
146 /**
147 * Process the ElasticPress.io Instant Results template.
148 *
149 * @return array|null
150 */
151 protected function get_instant_results_field() : array {
152 $index = Indexables::factory()->get( 'post' )->get_index_name();
153
154 if ( ! $index ) {
155 return [];
156 }
157
158 $feature = new InstantResults\InstantResults();
159 $template = $feature->epio_get_search_template();
160
161 if ( is_wp_error( $template ) ) {
162 return [
163 $index => [
164 'label' => $index,
165 'value' => $template->get_error_message(),
166 ],
167 ];
168 }
169
170 return [
171 $index => [
172 'label' => $index,
173 'value' => $template,
174 ],
175 ];
176 }
177 }
178