-
Notifications
You must be signed in to change notification settings - Fork 8
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 get-stats {{post_id}}
wp accessibility-checker delete-stats {{post_id}}
wp accessibility-checker get-site-stats
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 --stat='errors,warnings'
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'
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
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
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"
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
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
);