] * : table, csv, json or count. * --- * default: table * --- * * @param array $args Arguments. * @param array $assoc_args Options. */ public function report( $args, $assoc_args ) { $rows = array(); foreach ( ( new Accesswell_Report() )->pages() as $page ) { $rows[] = array( 'path' => $page['path'], 'errors' => $page['errors'], 'warnings' => $page['warnings'], 'notices' => $page['notices'], 'checked' => $page['checked_at'], ); } $this->output( $rows, array( 'path', 'errors', 'warnings', 'notices', 'checked' ), $assoc_args ); } /** * Problems across the site, by rule. * * ## OPTIONS * * [--format=] * : table, csv, json or count. * --- * default: table * --- * * @param array $args Arguments. * @param array $assoc_args Options. */ public function problems( $args, $assoc_args ) { $rows = array(); foreach ( ( new Accesswell_Report() )->by_rule() as $id => $group ) { $rows[] = array( 'rule' => $id, 'impact' => $group['rule']['impact'], 'wcag' => $group['rule']['wcag'], 'found' => $group['count'], 'pages' => count( $group['pages'] ), ); } $this->output( $rows, array( 'rule', 'impact', 'wcag', 'found', 'pages' ), $assoc_args ); } /** * Images without alternative text: in the Media Library, or in content. * * ## OPTIONS * * * : library or content. * * [--fix] * : With "content", copy the Media Library text into the content images. * * [--format=] * : table, csv, json or count. * --- * default: table * --- * * @param array $args Arguments. * @param array $assoc_args Options. */ public function images( $args, $assoc_args ) { if ( 'library' === $args[0] ) { $this->output( Accesswell_Alt::missing_in_library(), array( 'id', 'title', 'file' ), $assoc_args ); return; } if ( 'content' !== $args[0] ) { WP_CLI::error( 'Use "library" or "content".' ); } $gaps = Accesswell_Alt::content_gaps(); if ( ! empty( $assoc_args['fix'] ) ) { $total = 0; foreach ( $gaps as $gap ) { if ( $gap['fixable'] ) { $result = Accesswell_Alt::fix_post( $gap['id'] ); $total += is_wp_error( $result ) ? 0 : (int) $result; } } WP_CLI::success( sprintf( '%d images updated. Each post keeps a revision.', $total ) ); return; } $this->output( $gaps, array( 'id', 'title', 'type', 'fixable', 'missing' ), $assoc_args ); } /** * @param array $rows Rows. * @param array $fields Fields. * @param array $assoc_args Options. */ private function output( $rows, $fields, $assoc_args ) { $format = isset( $assoc_args['format'] ) ? $assoc_args['format'] : 'table'; if ( 'count' === $format ) { WP_CLI::log( (string) count( $rows ) ); return; } WP_CLI\Utils\format_items( $format, $rows, $fields ); } }