Skip to content

Commit

Permalink
Allow validation errors to be deleted which no longer have any occura…
Browse files Browse the repository at this point in the history
…nces
  • Loading branch information
westonruter committed Apr 23, 2018
1 parent 91c4bad commit 4b34bdc
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions includes/utils/class-amp-validation-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4b34bdc

Please sign in to comment.