PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.6
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.6
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / integrations / admin / health-check-integration.php

health-check-integration.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.6, at src/integrations/admin/health-check-integration.php

106 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yoast\WP\SEO\Integrations\Admin;
4
5 use Yoast\WP\SEO\Conditionals\Admin_Conditional;
6 use Yoast\WP\SEO\Integrations\Integration_Interface;
7 use Yoast\WP\SEO\Services\Health_Check\Health_Check;
8
9 /**
10 * Integrates health checks with WordPress' Site Health.
11 */
12 class Health_Check_Integration implements Integration_Interface {
13
14 /**
15 * Contains all the health check implementations.
16 *
17 * @var Health_Check[]
18 */
19 private $health_checks = [];
20
21 /**
22 * Uses the dependency injection container to obtain all available implementations of the Health_Check interface.
23 *
24 * @param Health_Check ...$health_checks The available health checks implementations.
25 */
26 public function __construct( Health_Check ...$health_checks ) {
27 $this->health_checks = $health_checks;
28 }
29
30 /**
31 * Hooks the health checks into WordPress' site status tests.
32 *
33 * @return void
34 */
35 public function register_hooks() {
36 \add_filter( 'site_status_tests', [ $this, 'add_health_checks' ] );
37 }
38
39 /**
40 * Returns the conditionals based on which this loadable should be active.
41 *
42 * In this case: only when on an admin page.
43 *
44 * @return array The conditionals.
45 */
46 public static function get_conditionals() {
47 return [ Admin_Conditional::class ];
48 }
49
50 /**
51 * Checks if the input is a WordPress site status tests array, and adds Yoast's health checks if it is.
52 *
53 * @param string[] $tests Array containing WordPress site status tests.
54 * @return string[] Array containing WordPress site status tests with Yoast's health checks.
55 */
56 public function add_health_checks( $tests ) {
57 if ( ! $this->is_valid_site_status_tests_array( $tests ) ) {
58 return $tests;
59 }
60
61 return $this->add_health_checks_to_site_status_tests( $tests );
62 }
63
64 /**
65 * Checks if the input array is a WordPress site status tests array.
66 *
67 * @param mixed $tests Array to check.
68 * @return bool Returns true if the input array is a WordPress site status tests array.
69 */
70 private function is_valid_site_status_tests_array( $tests ) {
71 if ( ! \is_array( $tests ) ) {
72 return false;
73 }
74
75 if ( ! \array_key_exists( 'direct', $tests ) ) {
76 return false;
77 }
78
79 if ( ! \is_array( $tests['direct'] ) ) {
80 return false;
81 }
82
83 return true;
84 }
85
86 /**
87 * Adds the health checks to WordPress' site status tests.
88 *
89 * @param string[] $tests Array containing WordPress site status tests.
90 * @return string[] Array containing WordPress site status tests with Yoast's health checks.
91 */
92 private function add_health_checks_to_site_status_tests( $tests ) {
93 foreach ( $this->health_checks as $health_check ) {
94 if ( $health_check->is_excluded() ) {
95 continue;
96 }
97
98 $tests['direct'][ $health_check->get_test_identifier() ] = [
99 'test' => [ $health_check, 'run_and_get_result' ],
100 ];
101 }
102
103 return $tests;
104 }
105 }
106