Skip to content

Commit 1c8be4a

Browse files
committed
Don't run the filters if there is nothing to validate (no input/ouput or no schema)
1 parent 19a5d11 commit 1c8be4a

File tree

1 file changed

+39
-39
lines changed

1 file changed

+39
-39
lines changed

src/wp-includes/abilities-api/class-wp-ability.php

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -464,32 +464,32 @@ public function validate_input( $input = null ) {
464464
$input_schema = $this->get_input_schema();
465465
if ( empty( $input_schema ) ) {
466466
if ( null === $input ) {
467-
$is_valid = true;
468-
} else {
469-
$is_valid = new WP_Error(
470-
'ability_missing_input_schema',
471-
sprintf(
472-
/* translators: %s ability name. */
473-
__( 'Ability "%s" does not define an input schema required to validate the provided input.' ),
474-
esc_html( $this->name )
475-
)
476-
);
467+
return true;
477468
}
469+
470+
return new WP_Error(
471+
'ability_missing_input_schema',
472+
sprintf(
473+
/* translators: %s ability name. */
474+
__( 'Ability "%s" does not define an input schema required to validate the provided input.' ),
475+
esc_html( $this->name )
476+
)
477+
);
478+
}
479+
480+
$valid_input = rest_validate_value_from_schema( $input, $input_schema, 'input' );
481+
if ( is_wp_error( $valid_input ) ) {
482+
$is_valid = new WP_Error(
483+
'ability_invalid_input',
484+
sprintf(
485+
/* translators: %1$s ability name, %2$s error message. */
486+
__( 'Ability "%1$s" has invalid input. Reason: %2$s' ),
487+
esc_html( $this->name ),
488+
$valid_input->get_error_message()
489+
)
490+
);
478491
} else {
479-
$valid_input = rest_validate_value_from_schema( $input, $input_schema, 'input' );
480-
if ( is_wp_error( $valid_input ) ) {
481-
$is_valid = new WP_Error(
482-
'ability_invalid_input',
483-
sprintf(
484-
/* translators: %1$s ability name, %2$s error message. */
485-
__( 'Ability "%1$s" has invalid input. Reason: %2$s' ),
486-
esc_html( $this->name ),
487-
$valid_input->get_error_message()
488-
)
489-
);
490-
} else {
491-
$is_valid = true;
492-
}
492+
$is_valid = true;
493493
}
494494

495495
/**
@@ -584,22 +584,22 @@ protected function do_execute( $input = null ) {
584584
protected function validate_output( $output ) {
585585
$output_schema = $this->get_output_schema();
586586
if ( empty( $output_schema ) ) {
587-
$is_valid = true;
587+
return true;
588+
}
589+
590+
$valid_output = rest_validate_value_from_schema( $output, $output_schema, 'output' );
591+
if ( is_wp_error( $valid_output ) ) {
592+
$is_valid = new WP_Error(
593+
'ability_invalid_output',
594+
sprintf(
595+
/* translators: %1$s ability name, %2$s error message. */
596+
__( 'Ability "%1$s" has invalid output. Reason: %2$s' ),
597+
esc_html( $this->name ),
598+
$valid_output->get_error_message()
599+
)
600+
);
588601
} else {
589-
$valid_output = rest_validate_value_from_schema( $output, $output_schema, 'output' );
590-
if ( is_wp_error( $valid_output ) ) {
591-
$is_valid = new WP_Error(
592-
'ability_invalid_output',
593-
sprintf(
594-
/* translators: %1$s ability name, %2$s error message. */
595-
__( 'Ability "%1$s" has invalid output. Reason: %2$s' ),
596-
esc_html( $this->name ),
597-
$valid_output->get_error_message()
598-
)
599-
);
600-
} else {
601-
$is_valid = true;
602-
}
602+
$is_valid = true;
603603
}
604604

605605
/**

0 commit comments

Comments
 (0)