-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathclass-checks.php
More file actions
119 lines (106 loc) · 4.9 KB
/
Copy pathclass-checks.php
File metadata and controls
119 lines (106 loc) · 4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
/**
* Site Health status checks for Accessibility Checker.
*
* @since 1.29.0
* @package Accessibility_Checker
*/
namespace EDAC\Admin\SiteHealth;
use EDAC\Admin\Scans_Stats;
/**
* Adds Site Health tests for Accessibility Checker.
*
* @since 1.29.0
*/
class Checks {
/**
* Init hooks.
*
* @return void
*/
public function init_hooks() {
add_filter( 'site_status_tests', [ $this, 'register_tests' ] );
}
/**
* Register our tests with Site Health.
*
* @param array $tests Existing tests.
* @return array
*/
public function register_tests( array $tests ): array {
$tests['direct']['edac_issues'] = [
'label' => __( 'Accessibility issues', 'accessibility-checker' ),
'test' => [ $this, 'test_for_issues' ],
];
$tests['direct']['edac_scanned'] = [
'label' => __( 'Content checked for accessibility', 'accessibility-checker' ),
'test' => [ $this, 'test_content_scanned' ],
];
return $tests;
}
/**
* Test if there are accessibility issues on the site.
*
* @return array
*/
public function test_for_issues(): array {
$stats = ( new Scans_Stats( 60 * 5 ) )->summary();
$errors = absint( $stats['errors'] ?? 0 );
$warnings = absint( $stats['warnings'] ?? 0 );
if ( $errors > 0 || $warnings > 0 ) {
return [
'status' => 'recommended',
'label' => __( 'Accessibility issues detected', 'accessibility-checker' ),
'description' => sprintf(
// translators: 1: error count, 2: warning count.
__( 'Accessibility Checker has detected %1$d errors and %2$d warnings.', 'accessibility-checker' ),
$errors,
$warnings
),
'actions' => sprintf(
'<p><a href="%1$s" class="button button-primary">%2$s</a></p>',
esc_url( admin_url( 'admin.php?page=accessibility_checker_issues' ) ),
esc_html__( 'View issues', 'accessibility-checker' )
),
'test' => 'edac_issues',
];
}
return [
'status' => 'good',
'label' => __( 'No accessibility issues detected', 'accessibility-checker' ),
'description' => __( 'Accessibility Checker has not found any issues in scanned content.', 'accessibility-checker' ),
'test' => 'edac_issues',
];
}
/**
* Test if any posts have been scanned.
*
* @return array
*/
public function test_content_scanned(): array {
$stats = ( new Scans_Stats( 60 * 5 ) )->summary();
$scanned = absint( $stats['posts_scanned'] ?? 0 );
if ( 0 === $scanned ) {
return [
'status' => 'recommended',
'label' => __( 'Content has not been checked', 'accessibility-checker' ),
'description' => __( 'No posts have been scanned yet. Run a full site scan to begin checking your content for accessibility issues.', 'accessibility-checker' ),
'actions' => sprintf(
'<p><a href="%1$s" class="button button-primary">%2$s</a></p>',
esc_url( admin_url( 'admin.php?page=accessibility_checker_full_site_scan' ) ),
esc_html__( 'Start full site scan', 'accessibility-checker' )
),
'test' => 'edac_scanned',
];
}
return [
'status' => 'good',
'label' => __( 'Content is being checked', 'accessibility-checker' ),
'description' => sprintf(
_n( 'Accessibility Checker has scanned %d post.', 'Accessibility Checker has scanned %d posts.', $scanned, 'accessibility-checker' ),
$scanned
),
'test' => 'edac_scanned',
];
}
}