PluginProbe
Commerce7 for WordPress / trunk
Commerce7 for WordPress vtrunk
1.8.1 1.8.0 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.1.0 1.1.1 1.1.3 1.2.0 1.2.1 1.2.2 1.2.3 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.3.4 1.3.5 1.4.0 1.4.1 All 37 releases
wp-commerce7 / includes / health-check.php

health-check.php in Commerce7 for WordPress trunk, at includes/health-check.php

359 lines 11.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Site Health Integration
4 *
5 * @package wp-commerce7
6 * @author Michael Bourne
7 * @license GPL3
8 * @link https://ursa6.com
9 * @since 1.5.5
10 */
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 return;
14 }
15
16 /**
17 * Add Commerce7 specific health checks
18 */
19 add_filter( 'site_status_tests', 'c7wp_add_health_checks' );
20 function c7wp_add_health_checks( $tests ) {
21 $tests['direct']['c7wp_tenant_configured'] = array(
22 'label' => __( 'Commerce7 Tenant ID is configured', 'wp-commerce7' ),
23 'test' => 'c7wp_test_tenant_configured',
24 );
25
26 $tests['direct']['c7wp_required_pages'] = array(
27 'label' => __( 'Commerce7 required pages exist', 'wp-commerce7' ),
28 'test' => 'c7wp_test_required_pages',
29 );
30
31 $tests['direct']['c7wp_page_content'] = array(
32 'label' => __( 'Commerce7 pages have proper content', 'wp-commerce7' ),
33 'test' => 'c7wp_test_page_content',
34 );
35
36 $tests['direct']['c7wp_permalinks'] = array(
37 'label' => __( 'WordPress permalinks are configured', 'wp-commerce7' ),
38 'test' => 'c7wp_test_permalinks',
39 );
40
41 $options = get_option( 'c7wp_settings' );
42 if ( isset( $options['c7wp_enable_product_reviews'] ) && 'yes' === $options['c7wp_enable_product_reviews'] ) {
43 $tests['direct']['c7wp_product_reviews'] = array(
44 'label' => __( 'Commerce7 Product Reviews embed', 'wp-commerce7' ),
45 'test' => 'c7wp_test_product_reviews',
46 );
47 }
48
49 return $tests;
50 }
51
52 /**
53 * Test Product Reviews embed prerequisites when the feature is enabled.
54 */
55 function c7wp_test_product_reviews() {
56 $options = get_option( 'c7wp_settings' );
57 $tenant_id = isset( $options['c7wp_tenant'] ) ? $options['c7wp_tenant'] : '';
58
59 $result = array(
60 'label' => __( 'Commerce7 Product Reviews embed is configured', 'wp-commerce7' ),
61 'status' => 'good',
62 'badge' => array(
63 'label' => __( 'Commerce7', 'wp-commerce7' ),
64 'color' => 'blue',
65 ),
66 'description' => sprintf(
67 '<p>%s</p>',
68 __( 'Product Reviews embed is enabled with a Tenant ID. Install and configure the Product Reviews app in Commerce7 admin, then confirm stars and reviews appear on product and collection pages.', 'wp-commerce7' )
69 ),
70 'test' => 'c7wp_product_reviews',
71 );
72
73 if ( empty( $tenant_id ) ) {
74 $result['status'] = 'critical';
75 $result['label'] = __( 'Product Reviews embed requires a Tenant ID', 'wp-commerce7' );
76 $result['description'] = sprintf(
77 '<p>%s</p>',
78 __( 'Product Reviews is enabled but no Tenant ID is configured. Add your Tenant ID or disable the Product Reviews embed in plugin settings.', 'wp-commerce7' )
79 );
80 $result['actions'] = sprintf(
81 '<p><a href="%s">%s</a></p>',
82 esc_url( admin_url( 'admin.php?page=commerce7' ) ),
83 __( 'Configure Commerce7 Settings', 'wp-commerce7' )
84 );
85 } else {
86 $result['status'] = 'recommended';
87 $result['label'] = __( 'Commerce7 Product Reviews app setup', 'wp-commerce7' );
88 $result['description'] = sprintf(
89 '<p>%s</p>',
90 __( 'Confirm the Product Reviews Commerce7 app is installed for this tenant, settings are saved in the app iframe, and product/collection page slugs match your Custom Front-end Routes.', 'wp-commerce7' )
91 );
92 }
93
94 return $result;
95 }
96
97 /**
98 * Test if tenant ID is configured
99 */
100 function c7wp_test_tenant_configured() {
101 $options = get_option( 'c7wp_settings' );
102 $tenant_id = isset( $options['c7wp_tenant'] ) ? $options['c7wp_tenant'] : '';
103
104 $result = array(
105 'label' => __( 'Commerce7 Tenant ID is configured', 'wp-commerce7' ),
106 'status' => 'good',
107 'badge' => array(
108 'label' => __( 'Commerce7', 'wp-commerce7' ),
109 'color' => 'blue',
110 ),
111 'description' => sprintf(
112 '<p>%s</p>',
113 __( 'Your Commerce7 Tenant ID is properly configured.', 'wp-commerce7' )
114 ),
115 'test' => 'c7wp_tenant_configured',
116 );
117
118 if ( empty( $tenant_id ) ) {
119 $result['status'] = 'critical';
120 $result['label'] = __( 'Commerce7 Tenant ID is not configured', 'wp-commerce7' );
121 $result['description'] = sprintf(
122 '<p>%s</p>',
123 __( 'You need to configure your Commerce7 Tenant ID in the plugin settings for the integration to work properly.', 'wp-commerce7' )
124 );
125 $result['actions'] = sprintf(
126 '<p><a href="%s">%s</a></p>',
127 esc_url( admin_url( 'admin.php?page=commerce7' ) ),
128 __( 'Configure Commerce7 Settings', 'wp-commerce7' )
129 );
130 }
131
132 return $result;
133 }
134
135 /**
136 * Test if required pages exist
137 */
138 function c7wp_test_required_pages() {
139 $options = get_option( 'c7wp_settings' );
140
141 if ( isset( $options['c7wp_frontend_routes'] ) && 'yes' === $options['c7wp_enable_custom_routes'] ) {
142 $required_pages = array_values( $options['c7wp_frontend_routes'] );
143 } else {
144 $required_pages = array( 'profile', 'collection', 'product', 'club', 'checkout', 'cart', 'reservation' );
145 }
146
147 $missing_pages = array();
148 foreach ( $required_pages as $page_slug ) {
149 if ( ! get_page_by_path( $page_slug, 'ARRAY_N', 'page' ) ) {
150 $missing_pages[] = $page_slug;
151 }
152 }
153
154 $result = array(
155 'label' => __( 'Commerce7 required pages exist', 'wp-commerce7' ),
156 'status' => 'good',
157 'badge' => array(
158 'label' => __( 'Commerce7', 'wp-commerce7' ),
159 'color' => 'blue',
160 ),
161 'description' => sprintf(
162 '<p>%s</p>',
163 __( 'All required Commerce7 pages are present.', 'wp-commerce7' )
164 ),
165 'test' => 'c7wp_required_pages',
166 );
167
168 if ( ! empty( $missing_pages ) ) {
169 $result['status'] = 'critical';
170 $result['label'] = __( 'Commerce7 required pages are missing', 'wp-commerce7' );
171 $result['description'] = sprintf(
172 '<p>%s</p><ul><li>%s</li></ul>',
173 __( 'The following required pages are missing:', 'wp-commerce7' ),
174 implode( '</li><li>', array_map( 'esc_html', $missing_pages ) )
175 );
176 $result['actions'] = sprintf(
177 '<p><a href="%s">%s</a></p>',
178 esc_url( admin_url( 'admin.php?page=commerce7' ) ),
179 __( 'Configure Commerce7 Settings', 'wp-commerce7' )
180 );
181 }
182
183 return $result;
184 }
185
186 /**
187 * Test if pages have proper content
188 */
189 function c7wp_test_page_content() {
190 $options = get_option( 'c7wp_settings' );
191
192 if ( isset( $options['c7wp_frontend_routes'] ) && 'yes' === $options['c7wp_enable_custom_routes'] ) {
193 $required_pages = array_values( $options['c7wp_frontend_routes'] );
194 } else {
195 $required_pages = array( 'profile', 'collection', 'product', 'club', 'checkout', 'cart', 'reservation' );
196 }
197
198 $c7wp_instance = C7WP::getInstance();
199 $pages_without_content = array();
200
201 foreach ( $required_pages as $page_slug ) {
202 $page = get_page_by_path( $page_slug, 'ARRAY_N', 'page' );
203 if ( $page && ! $c7wp_instance->page_has_c7_content( $page[0] ) ) {
204 $pages_without_content[] = $page_slug;
205 }
206 }
207
208 $result = array(
209 'label' => __( 'Commerce7 pages have proper content', 'wp-commerce7' ),
210 'status' => 'good',
211 'badge' => array(
212 'label' => __( 'Commerce7', 'wp-commerce7' ),
213 'color' => 'blue',
214 ),
215 'description' => sprintf(
216 '<p>%s</p>',
217 __( 'All Commerce7 pages contain the required content blocks.', 'wp-commerce7' )
218 ),
219 'test' => 'c7wp_page_content',
220 );
221
222 if ( ! empty( $pages_without_content ) ) {
223 $result['status'] = 'recommended';
224 $result['label'] = __( 'Some Commerce7 pages may be missing proper content', 'wp-commerce7' );
225 $result['description'] = sprintf(
226 '<p>%s</p><ul><li>%s</li></ul><p>%s</p>',
227 __( 'The following pages may not have the required Commerce7 content blocks:', 'wp-commerce7' ),
228 implode( '</li><li>', array_map( 'esc_html', $pages_without_content ) ),
229 __( 'Make sure these pages contain the default Commerce7 block or c7-content div.', 'wp-commerce7' )
230 );
231 $result['actions'] = sprintf(
232 '<p><a href="%s">%s</a></p>',
233 esc_url( admin_url( 'edit.php?post_type=page' ) ),
234 __( 'Edit Pages', 'wp-commerce7' )
235 );
236 }
237
238 return $result;
239 }
240
241 /**
242 * Test if permalinks are configured
243 */
244 function c7wp_test_permalinks() {
245 $permalink_structure = get_option( 'permalink_structure' );
246
247 $result = array(
248 'label' => __( 'WordPress permalinks are configured', 'wp-commerce7' ),
249 'status' => 'good',
250 'badge' => array(
251 'label' => __( 'Commerce7', 'wp-commerce7' ),
252 'color' => 'blue',
253 ),
254 'description' => sprintf(
255 '<p>%s</p>',
256 __( 'WordPress permalinks are properly configured for Commerce7 integration.', 'wp-commerce7' )
257 ),
258 'test' => 'c7wp_permalinks',
259 );
260
261 if ( empty( $permalink_structure ) ) {
262 $result['status'] = 'critical';
263 $result['label'] = __( 'WordPress permalinks are not configured', 'wp-commerce7' );
264 $result['description'] = sprintf(
265 '<p>%s</p>',
266 __( 'Commerce7 requires pretty permalinks to be enabled. Please configure your permalink structure.', 'wp-commerce7' )
267 );
268 $result['actions'] = sprintf(
269 '<p><a href="%s">%s</a></p>',
270 esc_url( admin_url( 'options-permalink.php' ) ),
271 __( 'Configure Permalinks', 'wp-commerce7' )
272 );
273 }
274
275 return $result;
276 }
277
278 /**
279 * Test Commerce7 API connectivity
280 */
281 function c7wp_test_api_connectivity() {
282 $options = get_option( 'c7wp_settings' );
283 $tenant_id = isset( $options['c7wp_tenant'] ) ? $options['c7wp_tenant'] : '';
284
285 if ( empty( $tenant_id ) ) {
286 return array(
287 'label' => __( 'Commerce7 API connectivity', 'wp-commerce7' ),
288 'status' => 'critical',
289 'badge' => array(
290 'label' => __( 'Commerce7', 'wp-commerce7' ),
291 'color' => 'red',
292 ),
293 'description' => sprintf(
294 '<p>%s</p>',
295 __( 'Cannot test API connectivity without a configured Tenant ID.', 'wp-commerce7' )
296 ),
297 'test' => 'c7wp_api_connectivity',
298 );
299 }
300
301 // This would be an async test in a real implementation
302 // For now, we'll just check if the tenant ID format looks valid
303 $result = array(
304 'label' => __( 'Commerce7 API connectivity', 'wp-commerce7' ),
305 'status' => 'good',
306 'badge' => array(
307 'label' => __( 'Commerce7', 'wp-commerce7' ),
308 'color' => 'blue',
309 ),
310 'description' => sprintf(
311 '<p>%s</p>',
312 __( 'Commerce7 API connectivity appears to be working.', 'wp-commerce7' )
313 ),
314 'test' => 'c7wp_api_connectivity',
315 );
316
317 return $result;
318 }
319
320 /**
321 * Add health check info to Site Health page
322 */
323 add_filter( 'debug_information', 'c7wp_add_debug_info' );
324 function c7wp_add_debug_info( $info ) {
325 $options = get_option( 'c7wp_settings' );
326
327 $info['commerce7'] = array(
328 'label' => __( 'Commerce7 for WordPress', 'wp-commerce7' ),
329 'fields' => array(
330 'version' => array(
331 'label' => __( 'Plugin Version', 'wp-commerce7' ),
332 'value' => C7WP_VERSION,
333 ),
334 'tenant_id' => array(
335 'label' => __( 'Tenant ID', 'wp-commerce7' ),
336 'value' => isset( $options['c7wp_tenant'] ) ? $options['c7wp_tenant'] : __( 'Not configured', 'wp-commerce7' ),
337 ),
338 'widget_version' => array(
339 'label' => __( 'Widget Version', 'wp-commerce7' ),
340 'value' => isset( $options['c7wp_widget_version'] ) ? $options['c7wp_widget_version'] : 'v2',
341 ),
342 'display_cart' => array(
343 'label' => __( 'Display Cart', 'wp-commerce7' ),
344 'value' => isset( $options['c7wp_display_cart'] ) ? $options['c7wp_display_cart'] : 'no',
345 ),
346 'custom_routes' => array(
347 'label' => __( 'Custom Routes Enabled', 'wp-commerce7' ),
348 'value' => isset( $options['c7wp_enable_custom_routes'] ) ? $options['c7wp_enable_custom_routes'] : 'no',
349 ),
350 'product_reviews' => array(
351 'label' => __( 'Product Reviews Embed', 'wp-commerce7' ),
352 'value' => isset( $options['c7wp_enable_product_reviews'] ) ? $options['c7wp_enable_product_reviews'] : 'no',
353 ),
354 ),
355 );
356
357 return $info;
358 }
359