Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions admin/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace EDAC\Admin;

use EDAC\Admin\SiteHealth\Information;
use EDAC\Admin\SiteHealth\Checks;
use EDAC\Admin\Purge_Post_Data;
use EDAC\Admin\Post_Save;
use EqualizeDigital\AccessibilityChecker\Admin\Upgrade_Promotion;
Expand Down Expand Up @@ -59,8 +60,11 @@
$widgets = new Widgets();
$widgets->init_hooks();

$site_health_info = new Information();
$site_health_info->init_hooks();
$site_health_info = new Information();

Check failure on line 63 in admin/class-admin.php

View workflow job for this annotation

GitHub Actions / Check code style

Tabs must be used to indent lines; spaces are not allowed

Check warning on line 63 in admin/class-admin.php

View workflow job for this annotation

GitHub Actions / Check code style

Found precision alignment of 3 spaces.
$site_health_info->init_hooks();

Check failure on line 64 in admin/class-admin.php

View workflow job for this annotation

GitHub Actions / Check code style

Tabs must be used to indent lines; spaces are not allowed

Check warning on line 64 in admin/class-admin.php

View workflow job for this annotation

GitHub Actions / Check code style

Found precision alignment of 3 spaces.

$site_health_checks = new Checks();

Check failure on line 66 in admin/class-admin.php

View workflow job for this annotation

GitHub Actions / Check code style

Tabs must be used to indent lines; spaces are not allowed

Check warning on line 66 in admin/class-admin.php

View workflow job for this annotation

GitHub Actions / Check code style

Found precision alignment of 3 spaces.
$site_health_checks->init_hooks();

Check failure on line 67 in admin/class-admin.php

View workflow job for this annotation

GitHub Actions / Check code style

Tabs must be used to indent lines; spaces are not allowed

Check warning on line 67 in admin/class-admin.php

View workflow job for this annotation

GitHub Actions / Check code style

Found precision alignment of 3 spaces.
Comment thread
pattonwebz marked this conversation as resolved.
Outdated

$upgrade_promotion = new Upgrade_Promotion();
$upgrade_promotion->init();
Expand Down
119 changes: 119 additions & 0 deletions admin/site-health/class-checks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,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 {

/**

Check failure on line 20 in admin/site-health/class-checks.php

View workflow job for this annotation

GitHub Actions / Check code style

Tabs must be used to indent lines; spaces are not allowed
* Init hooks.

Check failure on line 21 in admin/site-health/class-checks.php

View workflow job for this annotation

GitHub Actions / Check code style

Tabs must be used to indent lines; spaces are not allowed
*

Check failure on line 22 in admin/site-health/class-checks.php

View workflow job for this annotation

GitHub Actions / Check code style

Tabs must be used to indent lines; spaces are not allowed
* @return void

Check failure on line 23 in admin/site-health/class-checks.php

View workflow job for this annotation

GitHub Actions / Check code style

Tabs must be used to indent lines; spaces are not allowed
*/

Check failure on line 24 in admin/site-health/class-checks.php

View workflow job for this annotation

GitHub Actions / Check code style

Tabs must be used to indent lines; spaces are not allowed
public function init_hooks() {

Check failure on line 25 in admin/site-health/class-checks.php

View workflow job for this annotation

GitHub Actions / Check code style

Tabs must be used to indent lines; spaces are not allowed
add_filter( 'site_status_tests', [ $this, 'register_tests' ] );
}
Comment thread
pattonwebz marked this conversation as resolved.
Outdated

/**
* 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();

Check warning on line 55 in admin/site-health/class-checks.php

View workflow job for this annotation

GitHub Actions / Check code style

Equals sign not aligned with surrounding assignments; expected 4 spaces but found 2 spaces
Comment thread
pattonwebz marked this conversation as resolved.
Outdated
$errors = absint( $stats['errors'] ?? 0 );

Check warning on line 56 in admin/site-health/class-checks.php

View workflow job for this annotation

GitHub Actions / Check code style

Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space
$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();

Check warning on line 92 in admin/site-health/class-checks.php

View workflow job for this annotation

GitHub Actions / Check code style

Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space
$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',
];
}
}
Loading