-
Notifications
You must be signed in to change notification settings - Fork 19
WP‐CLI Commands
The plugin includes a few handy WP-CLI commands inside of it for getting access to the Accessibility Checker stats about posts or the site.
There are currently 3 commands. All that commands are subcommands of accessibility-checker root.
wp accessibility-checker cleanup-orphaned-issues [--batch=<batch>] [--sleep=<sleep>]wp accessibility-checker delete-stats [<post_id>]wp accessibility-checker get-site-stats [--stat=<stat>...] [--clear-cache]wp accessibility-checker get-stats [<post_id>] [--stat=<stat>...]
This command is used to get the Accessibility Checker stats about a specific post/page. If the post_id passed exists and has stats then they will be returned as a JSON-formatted string of results.
wp accessibility-checker get-stats 911'
Success: {
"passed_tests": 93,
"errors": 1,
"warnings": 2,
"ignored": 1,
"contrast_errors": 0,
"content_grade": 12,
"readability": "12th",
"simplified_summary": false
}You can filter the returned results by any of the valid keys exposed in the command. Pass them as a list the flag, for example to get errors and warnings only use --stat="errors,warnings".
wp accessibility-checker get-stats 911 --stat='errors,warnings'
Success: {
"errors": 1,
"warnings": 2
}This command is used to delete the Accessibility Checker stats about a specific post/page. If the post_id passed exist then it will clear the stats from it. Once stats are deleted they can't be restored, you have to scan the post again to generate new scan results.
wp accessibility-checker delete-stats 911
Success: Stats of 911 deleted.This command gets the Accessibility Checker stats for the entire site. It returns a JSON-formatted string. This data is not directly exposed in the plugin UI at the moment so it may be the most useful command for site owners or maintainers since it collates and displays data not otherwise visible as a group.
wp accessibility-checker get-site-stats
Success: {
"scannable_posts_count": 71,
"rule_count": 43,
"tests_count": 3053,
"scannable_post_types_count": 2,
"public_post_types_count": 9,
"posts_scanned": 71,
"is_truncated": false,
"posts_with_issues": 71,
"rules_failed": 35,
"rules_passed": 8,
"passed_percentage": 18.6,
"warnings": 294,
"distinct_warnings": 172,
"contrast_errors": 5,
"distinct_contrast_errors": 5,
"errors": 877,
"distinct_errors": 237,
"errors_without_contrast": 872,
"distinct_errors_without_contrast": 232,
"ignored": 0,
"distinct_ignored": 0,
"posts_without_issues": 0,
"avg_issues_per_post": 16.49,
"avg_issue_density_percentage": 6.62,
"fullscan_running": false,
"fullscan_state": "completed",
"fullscan_completed_at": 1751302072,
"cache_id": "edac_scans_stats_1.25.0_100000_summary",
"cached_at": 1751302072,
"expires_at": 1751388472,
"cache_hit": true,
"scannable_posts_count_formatted": "71",
"rule_count_formatted": "43",
"tests_count_formatted": "3,053",
"scannable_post_types_count_formatted": "2",
"public_post_types_count_formatted": "9",
"posts_scanned_formatted": "71",
"posts_with_issues_formatted": "71",
"rules_failed_formatted": "35",
"rules_passed_formatted": "8",
"warnings_formatted": "294",
"distinct_warnings_formatted": "172",
"contrast_errors_formatted": "5",
"distinct_contrast_errors_formatted": "5",
"errors_formatted": "877",
"distinct_errors_formatted": "237",
"errors_without_contrast_formatted": "872",
"distinct_errors_without_contrast_formatted": "232",
"ignored_formatted": "0",
"distinct_ignored_formatted": "0",
"posts_without_issues_formatted": "0",
"avg_issues_per_post_formatted": "16",
"fullscan_completed_at_formatted": "June 30, 2025 at 4:47 pm",
"passed_percentage_formatted": "18.6%",
"avg_issue_density_percentage_formatted": 6.62,
"cached_at_formatted": "June 30, 2025 at 4:47 pm"
}You can filter the results to show only the keys you are interested in with the --stat command.
wp accessibility-checker get-site-stats --stat="cached_at_formatted,distinct_errors,distinct_warnings,contrast_errors"
Success: {
"cached_at_formatted": "June 17, 2024 at 2:32 pm",
"distinct_errors": 103,
"distinct_warnings": 59,
"contrast_errors": 3
}
If you make changes to the site and need to check the latest numbers there may be times where you see cached data rather than latest. The command returns a value to show the last cache time and you can clear the cache with the --clear-cache flag, noticing the time change.
wp accessibility-checker get-site-stats --stat="cached_at_formatted,distinct_errors,distinct_warnings,contrast_errors" --clear-cache
Success: {
"cached_at_formatted": "June 17, 2024 at 2:32 pm",
"distinct_errors": 103,
"distinct_warnings": 59,
"contrast_errors": 3
}
If you need to integrate stats to your dashboard in some way then you can programatically parse the command results.
Using PHP you can pass the output through code like this to get a PHP array where $stats is the output captured from running the command:
$stats_array = json_decode(
html_entity_decode(
str_replace( 'Success: ', '', $stats )
),
true
);Accessibility Checker plugin has a feature which handled cleaning up orphaned issues where the post IDs don't exist anymore.
It runs once a day but there may be times you want to run it on demand. A CLI command is provided for those time with a few configuration flags.
By default it will process batches of 50 posts. You can increase or reduce that number as needed. You can also set a sleep value which will add a sleep gap of that many seconds between deletions (useful on servers that may be under stress or have limited resources).
wp accessibility-checker cleanup-orphaned-issues
root@4ef3d30ad06c:/var/www/html# wp accessibility-checker cleanup-orphaned-issues
Found 8 orphaned post IDs
- Deleting issues for post ID: 999996
- Deleting issues for post ID: 999995
- Deleting issues for post ID: 999994
- Deleting issues for post ID: 999993
- Deleting issues for post ID: 999974
- Deleting issues for post ID: 999935
- Deleting issues for post ID: 999911
- Deleting issues for post ID: 999915
Success: Orphaned issues cleanup complete. 8 post(s) processed.You can alter the batch size to be larger or smaller and add a sleep (set in seconds, you can use 2 or part seconds like 0.5 for a half second.
wp accessibility-checker cleanup-orphaned-issues --batch=5 --sleep=2
root@4ef3d30ad06c:/var/www/html# wp accessibility-checker cleanup-orphaned-issues --batch=5 --sleep=2
Found 5 orphaned post IDs
- Deleting issues for post ID: 999996
- Deleting issues for post ID: 999995
- Deleting issues for post ID: 999994
- Deleting issues for post ID: 999993
- Deleting issues for post ID: 999974
Success: Orphaned issues cleanup complete. 5 post(s) processed.
A few times we have been asked to skip drafts in the scanner or to help find issues for only published posts. We can use the default wp-cli commands to find all posts in draft status and pipe that through to the plugin's stats delete command to clear out any issues for any post in draft status.
wp post list --post_type=any --post_status=draft --format=ids | xargs -n1 wp accessibility-checker delete-stats