Skip to content

Commit

Permalink
Use the filter 'amp_validation_error_sanitized' instead of another co…
Browse files Browse the repository at this point in the history
…nditional

As Weston mentioned, this can simply use
the filter that exists,
  • Loading branch information
kienstra committed Oct 4, 2019
1 parent 37de1c3 commit e738bcf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
9 changes: 4 additions & 5 deletions includes/validation/class-amp-validation-error-taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,11 +472,6 @@ public static function get_validation_error_sanitization( $error ) {
$forced = 'with_preview';
}

if ( isset( $_GET[ self::REJECT_ALL_VALIDATION_ERRORS_QUERY_VAR ] ) && AMP_Validation_Manager::has_cap() ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$status = self::VALIDATION_ERROR_ACK_REJECTED_STATUS;
$forced = 'with_query_var';
}

/**
* Filters whether the validation error should be sanitized.
*
Expand Down Expand Up @@ -524,6 +519,10 @@ static function( $sanitized, $error ) use ( $acceptable_errors ) {
return true;
}

if ( isset( $_GET[ self::REJECT_ALL_VALIDATION_ERRORS_QUERY_VAR ] ) && AMP_Validation_Manager::has_cap() ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
return false;
}

if ( isset( $acceptable_errors[ $error['code'] ] ) ) {
if ( true === $acceptable_errors[ $error['code'] ] ) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,11 @@ public function test_is_validation_error_sanitized_and_get_validation_error_sani
// New rejected => Ack rejected, as the query var should force this to be rejected.
$_GET[ AMP_Validation_Error_Taxonomy::REJECT_ALL_VALIDATION_ERRORS_QUERY_VAR ] = '';
wp_set_current_user( self::factory()->user->create( [ 'role' => 'administrator' ] ) );
AMP_Validation_Error_Taxonomy::accept_validation_errors( [ self::MOCK_ACCEPTABLE_ERROR => true ] );
$this->assertfalse( AMP_Validation_Error_Taxonomy::is_validation_error_sanitized( $error_foo ) );
$this->assertEquals(
[
'forced' => 'with_query_var',
'forced' => 'with_filter',
'status' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_REJECTED_STATUS,
'term_status' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_REJECTED_STATUS,
],
Expand Down

0 comments on commit e738bcf

Please sign in to comment.