Skip to content

Commit d4d44b3

Browse files
committed
Add granularity to validate cap checks
1 parent 98794c4 commit d4d44b3

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,7 +1522,7 @@ public static function handle_validate_request() {
15221522
throw new Exception( 'invalid_post' );
15231523
}
15241524
if ( ! current_user_can( 'edit_post', $post->ID ) ) {
1525-
throw new Exception( 'unauthorized' );
1525+
throw new Exception( __( 'Unable to access validated URL screen.', 'amp' ) );
15261526
}
15271527
$url = self::get_url_from_post( $post );
15281528
} elseif ( isset( $_GET['url'] ) ) {
@@ -1531,8 +1531,8 @@ public static function handle_validate_request() {
15311531
throw new Exception( 'illegal_url' );
15321532
}
15331533
// Don't let non-admins create new amp_validated_url posts.
1534-
if ( ! current_user_can( 'manage_options' ) ) {
1535-
throw new Exception( 'unauthorized' );
1534+
if ( ! current_user_can( get_post_type_object( self::POST_TYPE_SLUG )->cap->edit_posts ) ) {
1535+
throw new Exception( __( 'Unable to access validated URL screen.', 'amp' ) );
15361536
}
15371537
}
15381538

@@ -1560,6 +1560,9 @@ public static function handle_validate_request() {
15601560
throw new Exception( AMP_Validation_Manager::get_validate_url_error_message( $stored->get_error_code(), $stored->get_error_message() ) );
15611561
}
15621562
$redirect = get_edit_post_link( $stored, 'raw' );
1563+
if ( empty( $redirect ) ) {
1564+
throw new Exception( __( 'Unable to access validated URL screen.', 'amp' ) );
1565+
}
15631566

15641567
$error_count = count(
15651568
array_filter(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ public static function get_amp_validity_rest_field( $post_data, $field_name, $re
840840
* @return boolean $has_cap Whether the current user has the capability.
841841
*/
842842
public static function has_cap() {
843-
return current_user_can( 'edit_posts' );
843+
return current_user_can( get_post_type_object( AMP_Validated_URL_Post_Type::POST_TYPE_SLUG )->cap->edit_posts );
844844
}
845845

846846
/**

0 commit comments

Comments
 (0)