diff --git a/includes/validation/class-amp-invalid-url-post-type.php b/includes/validation/class-amp-invalid-url-post-type.php index 61c8df8232d..f420eb5da5a 100644 --- a/includes/validation/class-amp-invalid-url-post-type.php +++ b/includes/validation/class-amp-invalid-url-post-type.php @@ -137,6 +137,7 @@ public static function add_admin_hooks() { $query_vars[] = 'amp_taxonomy_terms_updated'; $query_vars[] = self::REMAINING_ERRORS; $query_vars[] = 'amp_urls_tested'; + $query_vars[] = 'amp_validate_error'; return $query_vars; } ); } @@ -681,6 +682,9 @@ public static function handle_bulk_action( $redirect, $action, $items ) { return $redirect; } $remaining_invalid_urls = array(); + + $errors = array(); + foreach ( $items as $item ) { $post = get_post( $item ); if ( empty( $post ) ) { @@ -693,8 +697,9 @@ public static function handle_bulk_action( $redirect, $action, $items ) { } $validity = AMP_Validation_Manager::validate_url( $url ); - if ( ! is_array( $validity ) ) { - continue; // @todo Count this error. + if ( is_wp_error( $validity ) ) { + $errors[] = $validity->get_error_code(); + continue; } self::store_validation_errors( $validity['validation_errors'], $validity['url'], $post ); @@ -705,10 +710,15 @@ public static function handle_bulk_action( $redirect, $action, $items ) { // Get the URLs that still have errors after rechecking. $args = array( - self::URLS_TESTED => count( $items ), - self::REMAINING_ERRORS => empty( $remaining_invalid_urls ) ? '0' : '1', + self::URLS_TESTED => count( $items ), ); + if ( ! empty( $errors ) ) { + $args['amp_validate_error'] = $errors; + } else { + $args[ self::REMAINING_ERRORS ] = count( $remaining_invalid_urls ); + } + $redirect = remove_query_arg( wp_removable_query_args(), $redirect ); return add_query_arg( $args, $redirect ); } @@ -722,6 +732,31 @@ public static function print_admin_notice() { return; } + if ( isset( $_GET['amp_validate_error'] ) ) { // WPCS: CSRF OK. + $error_codes = array_unique( array_map( 'sanitize_key', (array) $_GET['amp_validate_error'] ) ); // WPCS: CSRF OK. + foreach ( $error_codes as $error_code ) { + switch ( $error_code ) { + case 'http_request_failed': + $message = __( 'Failed to fetch URL(s) to validate. This may be due to a request timeout.', 'amp' ); + break; + case '404': + $message = __( 'The fetched URL(s) was not found. It may have been deleted. If so, you can trash this.', 'amp' ); + break; + case '500': + $message = __( 'An internal server error occurred when fetching the URL.', 'amp' ); + break; + default: + /* translators: %s is error code */ + $message = sprintf( __( 'Unable to validate the URL(s); error code is %s.', 'amp' ), $error_code ); // Note that $error_code has been sanitized with sanitize_key(); will be escaped below as well. + } + printf( + '
%s