Skip to content

WP‐CLI Commands

William Patton edited this page Jul 23, 2025 · 12 revisions

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 get-stats {{post_id}}
  • wp accessibility-checker delete-stats {{post_id}}
  • wp accessibility-checker get-site-stats

The get-stats command

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'

Screenshot from 2024-07-17 13-16-11

Success: {
    "passed_tests": 93,
    "errors": 1,
    "warnings": 2,
    "ignored": 1,
    "contrast_errors": 0,
    "content_grade": 12,
    "readability": "12th",
    "simplified_summary": false
}

Filtering the results with --stat

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'

Screenshot from 2024-07-17 13-17-26

Success: {
    "errors": 1,
    "warnings": 2
}

The delete-stats command.

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

Screenshot from 2024-07-17 13-22-07

Success: Stats of 911 deleted.

The get-site-stats command.

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

Screenshot from 2025-06-30 18-03-03

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"
}

Filtering the result with --stat

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"

Screenshot from 2024-07-17 15-32-49

Success: {
    "cached_at_formatted": "June 17, 2024 at 2:32 pm",
    "distinct_errors": 103,
    "distinct_warnings": 59,
    "contrast_errors": 3
}

Ensuring you get the latest stats after changes with --clear-cache

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

Screenshot from 2024-07-17 15-32-58

Success: {
    "cached_at_formatted": "June 17, 2024 at 2:32 pm",
    "distinct_errors": 103,
    "distinct_warnings": 59,
    "contrast_errors": 3
}
Success: {
    "passed_tests": 93,
    "errors": 1,
    "warnings": 2,
    "ignored": 1,
    "contrast_errors": 0,
    "content_grade": 12,
    "readability": "12th",
    "simplified_summary": false
}

Parsing the stats programatically.

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
);

Deleting all issues for posts that are in draft status

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

Clone this wiki locally