PluginProbe
Parse.ly / 3.24.3
Parse.ly v3.24.3
3.24.3 3.24.2 3.24.1 3.24.0 3.23.7 3.23.6 3.23.5 3.23.4 3.23.3 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.17.0 3.18.0 3.18.1 3.19.0 3.19.1 3.19.2 3.19.3 3.2.0 3.2.1 3.20.0 3.20.1 All 107 releases
wp-parsely / src / UI / class-site-health.php

class-site-health.php in Parse.ly 3.24.3, at src/UI/class-site-health.php

140 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * UI: Site Health
4 *
5 * Extends WordPress Core's site health with the plugin's debug information.
6 *
7 * @package Parsely
8 * @since 3.4.0
9 */
10
11 declare(strict_types=1);
12
13 namespace Parsely\UI;
14
15 use Parsely\Parsely;
16
17 /**
18 * Provides debug information about the plugin.
19 *
20 * @since 3.4.0
21 *
22 * @phpstan-type Site_Health_Info array{
23 * parsely?: Parsely_Health_Info
24 * }
25 *
26 * @phpstan-type Parsely_Health_Info array{
27 * label: string,
28 * description: string,
29 * show_count: bool,
30 * fields: array<string, mixed>,
31 * }
32 */
33 final class Site_Health {
34 /**
35 * Instance of Parsely class.
36 *
37 * @var Parsely
38 */
39 private $parsely;
40
41 /**
42 * Constructor.
43 *
44 * @param Parsely $parsely Instance of Parsely class.
45 */
46 public function __construct( Parsely $parsely ) {
47 $this->parsely = $parsely;
48 }
49
50 /**
51 * Registers the site health methods.
52 *
53 * @since 3.4.0
54 */
55 public function run(): void {
56 add_filter( 'site_status_tests', array( $this, 'check_site_id' ) );
57 add_filter( 'debug_information', array( $this, 'options_debug_info' ) );
58 }
59
60 /**
61 * Adds a healthcheck function that tests whether the Site ID is set or not.
62 *
63 * @since 3.4.0
64 *
65 * @param array<string, mixed> $tests An associative array of direct and asynchronous tests.
66 * @return array<string, mixed>
67 */
68 public function check_site_id( array $tests ): array {
69 $test = function () {
70 $result = array(
71 'label' => __( 'The Site ID is correctly set up', 'wp-parsely' ),
72 'status' => 'good',
73 'badge' => array(
74 'label' => 'Parse.ly',
75 'color' => 'green',
76 ),
77 'description' => sprintf(
78 '<p>%s</p>',
79 __( 'Your Site ID uniquely represents your site within Parse.ly. It is required for the tracking to work correctly.', 'wp-parsely' )
80 ),
81 'test' => 'loopback_requests',
82 );
83
84 if ( $this->parsely->site_id_is_missing() ) {
85 $result['status'] = 'critical';
86 $result['label'] = __( 'You need to provide the Site ID', 'wp-parsely' );
87 $result['actions'] = sprintf(
88 /* translators: %s: URL to the Parse.ly settings page */
89 __( 'The site ID can be set in the <a href="%s">Parse.ly Settings Page</a>.', 'wp-parsely' ),
90 esc_url( Parsely::get_settings_url() )
91 );
92 }
93
94 return $result;
95 };
96
97 /**
98 * Variable.
99 *
100 * @var array<mixed>
101 */
102 $direct = $tests['direct'];
103 $direct['parsely'] = array(
104 'label' => __( 'Parse.ly Site ID', 'wp-parsely' ),
105 'test' => $test,
106 );
107 $tests['direct'] = $direct;
108
109 return $tests;
110 }
111
112 /**
113 * Adds the Parse.ly options to core's debug information array.
114 *
115 * @since 3.4.0
116 *
117 * @param Site_Health_Info $args The debug information to be added to the core information page.
118 * @return Site_Health_Info
119 */
120 public function options_debug_info( $args ) {
121 $options = $this->parsely->get_options();
122 unset( $options['api_secret'], $options['metadata_secret'] );
123
124 $args['parsely'] = array(
125 'label' => __( 'Parse.ly Options', 'wp-parsely' ),
126 'description' => __( 'Shows the options stored in the database used by the wp-parsely plugin.', 'wp-parsely' ),
127 'show_count' => true,
128 );
129
130 foreach ( $options as $name => $value ) {
131 $args['parsely']['fields'][ $name ] = array(
132 'label' => $name,
133 'value' => $value,
134 );
135 }
136
137 return $args;
138 }
139 }
140