diff --git a/includes/options/class-amp-options-manager.php b/includes/options/class-amp-options-manager.php index bbfbbb76f47..8f3adc564b6 100644 --- a/includes/options/class-amp-options-manager.php +++ b/includes/options/class-amp-options-manager.php @@ -718,23 +718,9 @@ public static function handle_updated_theme_support_option() { $validation = AMP_Validation_Manager::validate_url( $url ); if ( is_wp_error( $validation ) ) { - $review_messages[] = esc_html( - sprintf( - /* translators: 1: error message. 2: error code. */ - __( 'However, there was an error when checking the AMP validity for your site.', 'amp' ), - $validation->get_error_message(), - $validation->get_error_code() - ) - ); - - $error_message = $validation->get_error_message(); - if ( $error_message ) { - $review_messages[] = $error_message; - } else { - /* translators: %s is the error code */ - $review_messages[] = esc_html( sprintf( __( 'Error code: %s.', 'amp' ), $validation->get_error_code() ) ); - } - $notice_type = 'error'; + $review_messages[] = esc_html__( 'However, there was an error when checking the AMP validity for your site.', 'amp' ); + $review_messages[] = AMP_Validation_Manager::get_validate_url_error_message( $validation->get_error_code(), $validation->get_error_message() ); + $notice_type = 'error'; } elseif ( is_array( $validation ) ) { $new_errors = 0; $rejected_errors = 0; @@ -757,7 +743,7 @@ public static function handle_updated_theme_support_option() { if ( $rejected_errors > 0 ) { $notice_type = 'error'; - $message = wp_kses_post( + $message = esc_html( sprintf( /* translators: %s is count of rejected errors */ _n( @@ -772,43 +758,37 @@ public static function handle_updated_theme_support_option() { ); if ( $invalid_url_screen_url ) { - $message .= ' ' . wp_kses_post( - sprintf( - /* translators: %s is URL to review issues */ - _n( - 'Review Issue.', - 'Review Issues.', - $rejected_errors, - 'amp' - ), - esc_url( $invalid_url_screen_url ) - ) + $message .= ' ' . sprintf( + /* translators: %s is URL to review issues */ + _n( + 'Review Issue.', + 'Review Issues.', + $rejected_errors, + 'amp' + ), + esc_url( $invalid_url_screen_url ) ); } $review_messages[] = $message; } else { - $message = wp_kses_post( - sprintf( - /* translators: %s is an AMP URL */ - __( 'View an AMP version of your site.', 'amp' ), - esc_url( $url ) - ) + $message = sprintf( + /* translators: %s is an AMP URL */ + __( 'View an AMP version of your site.', 'amp' ), + esc_url( $url ) ); if ( $new_errors > 0 && $invalid_url_screen_url ) { - $message .= ' ' . wp_kses_post( - sprintf( - /* translators: 1: URL to review issues. 2: count of new errors. */ - _n( - 'Please also review %2$s issue which may need to be fixed (for one URL at least).', - 'Please also review %2$s issues which may need to be fixed (for one URL at least).', - $new_errors, - 'amp' - ), - esc_url( $invalid_url_screen_url ), - number_format_i18n( $new_errors ) - ) + $message .= ' ' . sprintf( + /* translators: 1: URL to review issues. 2: count of new errors. */ + _n( + 'Please also review %2$s issue which may need to be fixed (for one URL at least).', + 'Please also review %2$s issues which may need to be fixed (for one URL at least).', + $new_errors, + 'amp' + ), + esc_url( $invalid_url_screen_url ), + number_format_i18n( $new_errors ) ); } @@ -831,18 +811,16 @@ public static function handle_updated_theme_support_option() { } break; case AMP_Theme_Support::READER_MODE_SLUG: - $message = wp_kses_post( - sprintf( - /* translators: %s is an AMP URL */ - __( 'Reader mode activated! View the AMP version of a recent post. It is recommended that you upgrade to Standard or Transitional mode.', 'amp' ), - esc_url( $url ) - ) + $message = sprintf( + /* translators: %s is an AMP URL */ + __( 'Reader mode activated! View the AMP version of a recent post. It is recommended that you upgrade to Standard or Transitional mode.', 'amp' ), + esc_url( $url ) ); break; } if ( isset( $message ) ) { - add_settings_error( self::OPTION_NAME, 'template_mode_updated', $message, $notice_type ); + add_settings_error( self::OPTION_NAME, 'template_mode_updated', wp_kses_post( $message ), $notice_type ); } } } diff --git a/includes/validation/class-amp-validated-url-post-type.php b/includes/validation/class-amp-validated-url-post-type.php index 5e0c925dfa6..c752e49444a 100644 --- a/includes/validation/class-amp-validated-url-post-type.php +++ b/includes/validation/class-amp-validated-url-post-type.php @@ -631,17 +631,13 @@ public static function get_url_from_post( $post ) { /** * Normalize a URL for storage. * - * This ensures that query vars like utm_* and the like will not cause duplicates. * The AMP query param is removed to facilitate switching between standard and transitional. * The URL scheme is also normalized to HTTPS to help with transition from HTTP to HTTPS. * * @param string $url URL. * @return string Normalized URL. - * @global WP $wp */ protected static function normalize_url_for_storage( $url ) { - global $wp; - // Only ever store the canonical version. $url = amp_remove_endpoint( $url ); @@ -651,12 +647,11 @@ protected static function normalize_url_for_storage( $url ) { // Normalize query args, removing all that are not recognized or which are removable. $url_parts = explode( '?', $url, 2 ); if ( 2 === count( $url_parts ) ) { - parse_str( $url_parts[1], $args ); + $args = wp_parse_args( $url_parts[1] ); foreach ( wp_removable_query_args() as $removable_query_arg ) { unset( $args[ $removable_query_arg ] ); } - $args = wp_array_slice_assoc( $args, $wp->public_query_vars ); - $url = $url_parts[0]; + $url = $url_parts[0]; if ( ! empty( $args ) ) { $url = $url_parts[0] . '?' . build_query( $args ); } @@ -1231,7 +1226,7 @@ public static function handle_bulk_action( $redirect, $action, $items ) { $validity = AMP_Validation_Manager::validate_url( $url ); if ( is_wp_error( $validity ) ) { - $errors[] = $validity->get_error_code(); + $errors[] = AMP_Validation_Manager::get_validate_url_error_message( $validity->get_error_code(), $validity->get_error_message() ); continue; } @@ -1259,13 +1254,13 @@ static function( $error ) { self::URLS_TESTED => count( $items ), ]; if ( ! empty( $errors ) ) { - $args['amp_validate_error'] = $errors; + $args['amp_validate_error'] = AMP_Validation_Manager::serialize_validation_error_messages( $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 ); + return add_query_arg( rawurlencode_deep( $args ), $redirect ); } /** @@ -1278,14 +1273,23 @@ public static function print_admin_notice() { return; } - if ( isset( $_GET['amp_validate_error'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended - $error_codes = array_unique( array_map( 'sanitize_key', (array) $_GET['amp_validate_error'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended - foreach ( $error_codes as $error_code ) { - printf( - '
%s
%s