PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.6
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.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 / services / health-check / health-check.php

health-check.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.6, at src/services/health-check/health-check.php

77 lines 2.4 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\Services\Health_Check;
4
5 /**
6 * Abstract class for all health checks. Provides a uniform interface for the Health_Check_Integration.
7 */
8 abstract class Health_Check {
9
10 /**
11 * The prefix to add to the test identifier. Used to differentiate between Yoast's health checks, and other health checks.
12 */
13 const TEST_IDENTIFIER_PREFIX = 'yoast-';
14
15 /**
16 * The object that runs the actual health check.
17 *
18 * @var Runner_Interface
19 */
20 private $runner;
21
22 /**
23 * The health check implementation sets the runner so this class can start a health check.
24 *
25 * @param Runner_Interface $runner The health check runner.
26 * @return void
27 */
28 protected function set_runner( $runner ) {
29 $this->runner = $runner;
30 }
31
32 /**
33 * Returns the identifier of health check implementation. WordPress needs this to manage the health check (https://developer.wordpress.org/reference/hooks/site_status_tests/).
34 *
35 * @return string The identifier that WordPress requires.
36 */
37 public function get_test_identifier() {
38 $full_class_name = \get_class( $this );
39 $class_name_backslash_index = \strrpos( $full_class_name, '\\' );
40
41 $class_name = $full_class_name;
42 if ( $class_name_backslash_index ) {
43 $class_name_index = ( $class_name_backslash_index + 1 );
44 $class_name = \substr( $full_class_name, $class_name_index );
45 }
46
47 $lowercase = \strtolower( $class_name );
48 $whitespace_as_dashes = \str_replace( '_', '-', $lowercase );
49 $with_prefix = self::TEST_IDENTIFIER_PREFIX . $whitespace_as_dashes;
50 return $with_prefix;
51 }
52
53 /**
54 * Returns the name of health check implementation that the user can see. WordPress needs this to manage the health check (https://developer.wordpress.org/reference/hooks/site_status_tests/).
55 *
56 * @return string A human-readable label for the health check.
57 */
58 abstract public function get_test_label();
59
60 /**
61 * Runs the health check, and returns its result in the format that WordPress requires to show the results to the user (https://developer.wordpress.org/reference/hooks/site_status_test_result/).
62 *
63 * @return string[] The array containing a WordPress site status report.
64 */
65 public function run_and_get_result() {
66 $this->runner->run();
67 return $this->get_result();
68 }
69
70 /**
71 * Gets the result from the health check implementation.
72 *
73 * @return string[] The array containing a WordPress site status report.
74 */
75 abstract protected function get_result();
76 }
77