From 4b34bdc550d0dc9209f1e9ab0b3dab0d08824564 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sun, 22 Apr 2018 21:27:03 -0700 Subject: [PATCH] Allow validation errors to be deleted which no longer have any occurances --- includes/utils/class-amp-validation-utils.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/includes/utils/class-amp-validation-utils.php b/includes/utils/class-amp-validation-utils.php index 0b1b1524d1f..b89dac1957e 100644 --- a/includes/utils/class-amp-validation-utils.php +++ b/includes/utils/class-amp-validation-utils.php @@ -1758,10 +1758,20 @@ public static function register_post_type() { return $content; }, 10, 3 ); + // Prevent user from being able to delete validation errors when they still have associated invalid URLs. + add_filter( 'user_has_cap', function( $allcaps, $caps, $args ) { + if ( isset( $args[0] ) && 'delete_term' === $args[0] && 0 !== get_term( $args[2] )->count ) { + $allcaps = array_merge( + $allcaps, + array_fill_keys( $caps, false ) + ); + } + return $allcaps; + }, 10, 3 ); + // Add row actions. add_filter( 'tag_row_actions', function( $actions, WP_Term $tag ) { if ( self::TAXONOMY_SLUG === $tag->taxonomy ) { - unset( $actions['delete'] ); $term_id = $tag->term_id; if ( self::VALIDATION_ERROR_ACKNOWLEDGED_STATUS !== $tag->term_group ) { $actions[ self::VALIDATION_ERROR_ACKNOWLEDGE_ACTION ] = sprintf( @@ -1832,7 +1842,6 @@ public static function register_post_type() { // Add bulk actions. add_filter( 'bulk_actions-edit-' . self::TAXONOMY_SLUG, function( $bulk_actions ) { - unset( $bulk_actions['delete'] ); $bulk_actions[ self::VALIDATION_ERROR_IGNORE_ACTION ] = __( 'Ignore', 'amp' ); $bulk_actions[ self::VALIDATION_ERROR_ACKNOWLEDGE_ACTION ] = __( 'Acknowledge', 'amp' ); return $bulk_actions;