] * : Maximum number of pages to scan. * * [--post-types=] * : Comma-separated post types. * * [--format=] * : Summary format: table, json, yaml. * --- * default: table * --- * * ## EXAMPLES * * wp a11ymate scan --pages=50 * * @param array $args Positional args. * @param array $assoc_args Flags. * @return void */ public function scan( $args, $assoc_args ) { unset( $args ); $over = array(); if ( ! empty( $assoc_args['pages'] ) ) { $over['max_pages'] = (int) $assoc_args['pages']; } if ( ! empty( $assoc_args['post-types'] ) ) { $over['post_types'] = array_map( 'trim', explode( ',', $assoc_args['post-types'] ) ); } \WP_CLI::log( __( 'Starting a server-pass scan (the rendered pass needs a browser, so run it from wp-admin).', 'a11ymate' ) ); $progress = null; $id = Runner::start( 'cli', false, $over ); if ( is_wp_error( $id ) ) { \WP_CLI::error( $id->get_error_message() ); } $total = Scans::get( $id )['total_pages']; if ( class_exists( '\WP_CLI\Utils' ) && function_exists( 'WP_CLI\Utils\make_progress_bar' ) ) { $progress = \WP_CLI\Utils\make_progress_bar( 'Scanning pages', $total ); } $last = 0; Runner::continue_scan( $id, static function ( $p ) use ( &$progress, &$last ) { if ( $progress && $p['server_done'] > $last ) { for ( $i = $last; $i < $p['server_done']; $i++ ) { $progress->tick(); } } $last = $p['server_done']; } ); if ( $progress ) { $progress->finish(); } $scan = Scans::get( $id ); $sum = $scan['summary']; if ( ! $sum || isset( $sum['error'] ) ) { \WP_CLI::error( $sum && isset( $sum['error'] ) ? $sum['error'] : 'The scan did not finish.' ); } \WP_CLI\Utils\format_items( isset( $assoc_args['format'] ) ? $assoc_args['format'] : 'table', array( array( 'scan' => $id, 'pages' => $sum['pages'], 'score' => $sum['score'], 'critical' => $sum['severity']['critical'], 'serious' => $sum['severity']['serious'], 'moderate' => $sum['severity']['moderate'], 'minor' => $sum['severity']['minor'], 'review' => $sum['review'], 'new' => $sum['new'], 'fixed' => $sum['fixed'], ), ), array( 'scan', 'pages', 'score', 'critical', 'serious', 'moderate', 'minor', 'review', 'new', 'fixed' ) ); \WP_CLI::success( sprintf( 'Scan %d complete. Score %d/100.', $id, $sum['score'] ) ); } /** * List issues. * * ## OPTIONS * * [--format=] * : table, csv, json, yaml, count, ids. * --- * default: table * --- * * [--state=] * : open, fixed, ignored or all. * --- * default: open * --- * * [--severity=] * : critical, serious, moderate or minor. * * [--category=] * : Category id, for example images or forms. * * [--fields=] * : Comma-separated fields. * * [--limit=] * : Maximum rows. * --- * default: 500 * --- * * ## EXAMPLES * * wp a11ymate issues --severity=critical --format=csv * * @param array $args Positional args. * @param array $assoc_args Flags. * @return void */ public function issues( $args, $assoc_args ) { unset( $args ); $limit = isset( $assoc_args['limit'] ) ? max( 1, (int) $assoc_args['limit'] ) : 500; $res = Issues::query( array( 'state' => isset( $assoc_args['state'] ) ? $assoc_args['state'] : 'open', 'severity' => isset( $assoc_args['severity'] ) ? $assoc_args['severity'] : '', 'category' => isset( $assoc_args['category'] ) ? $assoc_args['category'] : '', 'per_page' => min( 200, $limit ), ) ); $rows = $res['items']; $have = count( $rows ); for ( $p = 2; $p <= $res['pages'] && $have < $limit; $p++ ) { $more = Issues::query( array( 'state' => isset( $assoc_args['state'] ) ? $assoc_args['state'] : 'open', 'severity' => isset( $assoc_args['severity'] ) ? $assoc_args['severity'] : '', 'category' => isset( $assoc_args['category'] ) ? $assoc_args['category'] : '', 'per_page' => 200, 'page' => $p, ) ); $rows = array_merge( $rows, $more['items'] ); $have = count( $rows ); } $rows = array_slice( $rows, 0, $limit ); $out = array(); foreach ( $rows as $r ) { $out[] = array( 'id' => $r['id'], 'severity' => $r['severity'], 'category' => $r['category'], 'rule' => $r['rule_id'], 'wcag' => $r['wcag'] ? $r['wcag']['sc'] : '', 'pages' => $r['page_count'], 'state' => $r['state'], 'mode' => $r['mode'], 'selector' => $r['selector'], 'snippet' => $r['snippet'], 'url' => $r['sample_url'], ); } $fields = isset( $assoc_args['fields'] ) ? explode( ',', $assoc_args['fields'] ) : array( 'id', 'severity', 'rule', 'wcag', 'pages', 'state', 'selector' ); \WP_CLI\Utils\format_items( isset( $assoc_args['format'] ) ? $assoc_args['format'] : 'table', $out, $fields ); } /** * Show the current score. * * ## OPTIONS * * [--format=] * : table, json, yaml or just the number (value). * --- * default: table * --- * * ## EXAMPLES * * wp a11ymate score --format=value * * @param array $args Positional args. * @param array $assoc_args Flags. * @return void */ public function score( $args, $assoc_args ) { unset( $args ); $site = Score::site(); $latest = Scans::latest_complete(); if ( ! $latest ) { \WP_CLI::error( 'No scan has been run yet. Try: wp a11ymate scan' ); } $format = isset( $assoc_args['format'] ) ? $assoc_args['format'] : 'table'; if ( 'value' === $format ) { \WP_CLI::print_value( $site['score'] ); return; } $rows = array( array( 'area' => 'Overall', 'score' => $site['score'], ), ); foreach ( $site['categories'] as $id => $v ) { $rows[] = array( 'area' => $id, 'score' => $v, ); } \WP_CLI\Utils\format_items( $format, $rows, array( 'area', 'score' ) ); } /** * List the rules A11yMate checks. * * ## OPTIONS * * [--format=] * : table, csv, json. * --- * default: table * --- * * @param array $args Positional args. * @param array $assoc_args Flags. * @return void */ public function rules( $args, $assoc_args ) { unset( $args ); $rows = array(); foreach ( \A11yMate\Rules\Registry::all() as $r ) { $rows[] = array( 'id' => $r['id'], 'wcag' => $r['wcag']['sc'], 'level' => $r['wcag']['level'], 'severity' => $r['severity'], 'category' => $r['category'], 'pass' => $r['pass'], 'mode' => $r['mode'], ); } \WP_CLI\Utils\format_items( isset( $assoc_args['format'] ) ? $assoc_args['format'] : 'table', $rows, array( 'id', 'wcag', 'level', 'severity', 'category', 'pass', 'mode' ) ); } }