Skip to content

Commit

Permalink
Fix classic mode site validation by forcing native mode
Browse files Browse the repository at this point in the history
* Only show admin URL to review results if theme support initially present.
* Skip showing table if no results obtained.
  • Loading branch information
westonruter committed Aug 28, 2018
1 parent ad7e0e2 commit 7a52751
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions includes/class-amp-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,16 @@ public function validate_site( $args, $assoc_args ) {
self::$force_crawl_urls = true;
}

if ( ! current_theme_supports( 'amp' ) ) {
$theme_support_amp = current_theme_supports( 'amp' );

if ( ! $theme_support_amp ) {
if ( self::$force_crawl_urls ) {
/*
* There is no theme support added programmatically or via options.
* So the validation taxonomy and post type would not normally be registered.
* Register them here in order to use them to crawl the site.
*/
add_theme_support( 'amp' );
AMP_Validation_Error_Taxonomy::register();
AMP_Invalid_URL_Post_Type::register();
} else {
Expand Down Expand Up @@ -232,12 +235,6 @@ public function validate_site( $args, $assoc_args ) {
self::crawl_site();
self::$wp_cli_progress->finish();

$url_more_details = add_query_arg(
'post_type',
AMP_Invalid_URL_Post_Type::POST_TYPE_SLUG,
admin_url( 'edit.php' )
);

$key_template_type = __( 'Template or content type', 'amp' );
$key_url_count = __( 'URL Count', 'amp' );
$key_validity_rate = __( 'Validity Rate', 'amp' );
Expand All @@ -251,18 +248,34 @@ public function validate_site( $args, $assoc_args ) {
);
}

if ( empty( $table_validation_by_type ) ) {
WP_CLI::error( __( 'No validation results were obtained from the URLs.', 'amp' ) );
return;
}

WP_CLI::success(
sprintf(
/* translators: $1%d is the number of URls crawled, $2%d is the number of validation issues, $3%d is the number of unaccepted issues, $4%s is the list of validation by type, $5%s is the link for more details */
__( "%3\$d crawled URLs have unaccepted issue(s) out of %2\$d total which AMP validation issue(s); %1\$d URLs were crawled. \n\nFor more details, please see: \n%4\$s \n", 'amp' ),
__( '%3$d crawled URLs have unaccepted issue(s) out of %2$d total which AMP validation issue(s); %1$d URLs were crawled.', 'amp' ),
self::$number_crawled,
self::$total_errors,
self::$unaccepted_errors,
$url_more_details
self::$unaccepted_errors
)
);

// Output a table of validity by template/content type.
if ( $theme_support_amp ) {
$url_more_details = add_query_arg(
'post_type',
AMP_Invalid_URL_Post_Type::POST_TYPE_SLUG,
admin_url( 'edit.php' )
);
/* translators: %s is the URL to the admin */
WP_CLI::line( sprintf( __( 'For more details, please see: %s', 'amp' ), $url_more_details ) );
} else {
WP_CLI::warning( __( 'You cannot currently access the detailed validation results because you have not switched to native or paired AMP template modes.', 'amp' ) );
}

WP_CLI\Utils\format_items(
'table',
$table_validation_by_type,
Expand Down

0 comments on commit 7a52751

Please sign in to comment.