Skip to content

Commit 9737cd7

Browse files
committed
Ensure auto-accepting sanitization is always performed for stories; simplify warning notice
1 parent bbc6f0f commit 9737cd7

File tree

4 files changed

+60
-49
lines changed

4 files changed

+60
-49
lines changed

assets/src/block-validation/helpers/index.js

+47-44
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ export const updateValidationErrors = () => {
154154
export const maybeDisplayNotice = () => {
155155
const { getValidationErrors, isSanitizationAutoAccepted, getReviewLink } = select( 'amp/block-validation' );
156156
const { createWarningNotice } = dispatch( 'core/notices' );
157+
const { getCurrentPost } = select( 'core/editor' );
157158

158159
const validationErrors = getValidationErrors();
159160
const validationErrorCount = validationErrors.length;
@@ -174,54 +175,56 @@ export const maybeDisplayNotice = () => {
174175
const blockValidationErrors = validationErrors.filter( ( { clientId } ) => clientId );
175176
const blockValidationErrorCount = blockValidationErrors.length;
176177

177-
if ( blockValidationErrorCount > 0 ) {
178-
noticeMessage += ' ' + sprintf(
179-
/* translators: %s: number of block errors. */
180-
_n(
181-
'%s issue is directly due to content here.',
182-
'%s issues are directly due to content here.',
183-
blockValidationErrorCount,
184-
'amp'
185-
),
186-
blockValidationErrorCount
187-
);
188-
} else if ( validationErrors.length === 1 ) {
189-
noticeMessage += ' ' + __( 'The issue is not directly due to content here.', 'amp' );
190-
} else {
191-
noticeMessage += ' ' + __( 'The issues are not directly due to content here.', 'amp' );
192-
}
193-
194-
noticeMessage += ' ';
195-
196-
if ( isSanitizationAutoAccepted() ) {
197-
const rejectedBlockValidationErrors = blockValidationErrors.filter( ( error ) => {
198-
return (
199-
VALIDATION_ERROR_NEW_REJECTED_STATUS === error.status ||
200-
VALIDATION_ERROR_ACK_REJECTED_STATUS === error.status
201-
);
202-
} );
203-
204-
const rejectedValidationErrors = validationErrors.filter( ( error ) => {
205-
return (
206-
VALIDATION_ERROR_NEW_REJECTED_STATUS === error.status ||
207-
VALIDATION_ERROR_ACK_REJECTED_STATUS === error.status
178+
if ( 'amp_story' !== getCurrentPost().type ) {
179+
if ( blockValidationErrorCount > 0 ) {
180+
noticeMessage += ' ' + sprintf(
181+
/* translators: %s: number of block errors. */
182+
_n(
183+
'%s issue is directly due to content here.',
184+
'%s issues are directly due to content here.',
185+
blockValidationErrorCount,
186+
'amp'
187+
),
188+
blockValidationErrorCount
208189
);
209-
} );
210-
211-
const totalRejectedErrorsCount = rejectedBlockValidationErrors.length + rejectedValidationErrors.length;
190+
} else if ( validationErrors.length === 1 ) {
191+
noticeMessage += ' ' + __( 'The issue is not directly due to content here.', 'amp' );
192+
} else {
193+
noticeMessage += ' ' + __( 'The issues are not directly due to content here.', 'amp' );
194+
}
212195

213-
if ( totalRejectedErrorsCount === 0 ) {
214-
noticeMessage += __( 'However, your site is configured to automatically accept sanitization of the offending markup.', 'amp' );
196+
noticeMessage += ' ';
197+
198+
if ( isSanitizationAutoAccepted() ) {
199+
const rejectedBlockValidationErrors = blockValidationErrors.filter( ( error ) => {
200+
return (
201+
VALIDATION_ERROR_NEW_REJECTED_STATUS === error.status ||
202+
VALIDATION_ERROR_ACK_REJECTED_STATUS === error.status
203+
);
204+
} );
205+
206+
const rejectedValidationErrors = validationErrors.filter( ( error ) => {
207+
return (
208+
VALIDATION_ERROR_NEW_REJECTED_STATUS === error.status ||
209+
VALIDATION_ERROR_ACK_REJECTED_STATUS === error.status
210+
);
211+
} );
212+
213+
const totalRejectedErrorsCount = rejectedBlockValidationErrors.length + rejectedValidationErrors.length;
214+
215+
if ( totalRejectedErrorsCount === 0 ) {
216+
noticeMessage += __( 'However, your site is configured to automatically accept sanitization of the offending markup.', 'amp' );
217+
} else {
218+
noticeMessage += _n(
219+
'Your site is configured to automatically accept sanitization errors, but this error could be from when auto-acceptance was not selected, or from manually rejecting an error.',
220+
'Your site is configured to automatically accept sanitization errors, but these errors could be from when auto-acceptance was not selected, or from manually rejecting an error.',
221+
validationErrors.length,
222+
'amp'
223+
);
224+
}
215225
} else {
216-
noticeMessage += _n(
217-
'Your site is configured to automatically accept sanitization errors, but this error could be from when auto-acceptance was not selected, or from manually rejecting an error.',
218-
'Your site is configured to automatically accept sanitization errors, but these errors could be from when auto-acceptance was not selected, or from manually rejecting an error.',
219-
validationErrors.length,
220-
'amp'
221-
);
226+
noticeMessage += __( 'Non-accepted validation errors prevent AMP from being served, and the user will be redirected to the non-AMP version.', 'amp' );
222227
}
223-
} else {
224-
noticeMessage += __( 'Non-accepted validation errors prevent AMP from being served, and the user will be redirected to the non-AMP version.', 'amp' );
225228
}
226229

227230
const options = {

includes/class-amp-theme-support.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ public static function read_theme_support() {
306306
self::$support_added_via_theme = $is_paired ? self::TRANSITIONAL_MODE_SLUG : self::STANDARD_MODE_SLUG;
307307

308308
/*
309-
* If the theme has transitional support, allow the user to opt for AMP first mode via an option, since a theme
309+
* If the theme has transitional support, allow the user to opt for AMP-first mode via an option, since a theme
310310
* in transitional mode entails that it supports serving templates as both AMP and non-AMP, and this it is
311311
* able to serve AMP-first pages just as well as paired pages. Otherwise, consider that the the mode was
312312
* not set at all via option.
@@ -411,7 +411,7 @@ public static function ensure_proper_amp_location( $exit = true ) {
411411

412412
if ( amp_is_canonical() || is_singular( AMP_Story_Post_Type::POST_TYPE_SLUG ) ) {
413413
/*
414-
* When AMP first/canonical, then when there is an /amp/ endpoint or ?amp URL param,
414+
* When AMP-first/canonical, then when there is an /amp/ endpoint or ?amp URL param,
415415
* then a redirect needs to be done to the URL without any AMP indicator in the URL.
416416
* Permanent redirect is used for unauthenticated users since switching between modes
417417
* should happen infrequently. For admin users, this is kept temporary to allow them
@@ -2119,7 +2119,7 @@ public static function prepare_response( $response, $args = array() ) {
21192119

21202120
if ( $blocking_error_count > 0 && ! AMP_Validation_Manager::should_validate_response() ) {
21212121
/*
2122-
* In AMP first, strip html@amp attribute to prevent GSC from complaining about a validation error
2122+
* In AMP-first, strip html@amp attribute to prevent GSC from complaining about a validation error
21232123
* already surfaced inside of WordPress. This is intended to not serve dirty AMP, but rather a
21242124
* non-AMP document (intentionally not valid AMP) that contains the AMP runtime and AMP components.
21252125
*/

includes/validation/class-amp-validated-url-post-type.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,14 @@ public static function store_validation_errors( $validation_errors, $url, $args
661661
);
662662
}
663663

664+
$is_story = (
665+
isset( $args['queried_object'], $args['queried_object']['type'], $args['queried_object']['id'] )
666+
&&
667+
'post' === $args['queried_object']['type']
668+
&&
669+
AMP_Story_Post_Type::POST_TYPE_SLUG === get_post_type( $args['queried_object']['id'] )
670+
);
671+
664672
/*
665673
* The details for individual validation errors is stored in the amp_validation_error taxonomy terms.
666674
* The post content just contains the slugs for these terms and the sources for the given instance of
@@ -714,7 +722,7 @@ public static function store_validation_errors( $validation_errors, $url, $args
714722
'term_group' => $sanitization['status'],
715723
)
716724
);
717-
} elseif ( AMP_Validation_Manager::is_sanitization_auto_accepted() ) {
725+
} elseif ( AMP_Validation_Manager::is_sanitization_auto_accepted() || $is_story ) {
718726
$term_data['term_group'] = AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_ACCEPTED_STATUS;
719727
wp_update_term(
720728
$term_id,

includes/validation/class-amp-validation-manager.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2029,7 +2029,7 @@ public static function enqueue_block_validation() {
20292029
$enabled_status = $status_and_errors['status'];
20302030

20312031
$data = array(
2032-
'isSanitizationAutoAccepted' => self::is_sanitization_auto_accepted(),
2032+
'isSanitizationAutoAccepted' => self::is_sanitization_auto_accepted() || AMP_Story_Post_Type::POST_TYPE_SLUG === get_post_type(),
20332033
'possibleStatuses' => array( AMP_Post_Meta_Box::ENABLED_STATUS, AMP_Post_Meta_Box::DISABLED_STATUS ),
20342034
'defaultStatus' => $enabled_status,
20352035
);

0 commit comments

Comments
 (0)