Skip to content

Commit

Permalink
Always hide validation errors which lack any URLs; eliminate unusable…
Browse files Browse the repository at this point in the history
… delete bulk action
  • Loading branch information
westonruter committed May 29, 2018
1 parent 2b1985a commit 5e12fa1
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions includes/validation/class-amp-validation-error-taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,13 @@ public static function prepare_validation_error_taxonomy_term( $error ) {
* Args passed into wp_count_terms().
*
* @type int|null $group Term group.
* @type bool $ignore_empty Accept terms that are no longer associated with any URLs. Default false.
* }
* @return int Term count.
*/
public static function get_validation_error_count( $args = array() ) {
$args = array_merge(
array(
'group' => null,
'ignore_empty' => false,
'group' => null,
),
$args
);
Expand Down Expand Up @@ -365,7 +363,15 @@ public static function add_admin_hooks() {
return $query_vars;
} );

// Filter amp_validation_error term query by term group when requested.
// Always exclude taxonomy terms when they have empty counts.
add_filter( 'get_terms_args', function( $args, $taxonomies ) {
if ( array( AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG ) === $taxonomies ) {
$args['hide_empty'] = true;
}
return $args;
}, 10, 2 );

// Default ordering terms by ID descending so that new terms appear at the top.
add_filter( 'get_terms_defaults', function( $args, $taxonomies ) {
if ( array( AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG ) === $taxonomies ) {
$args['orderby'] = 'term_id';
Expand All @@ -376,6 +382,7 @@ public static function add_admin_hooks() {

// Add bulk actions.
add_filter( 'bulk_actions-edit-' . self::TAXONOMY_SLUG, function( $bulk_actions ) {
unset( $bulk_actions['delete'] );
$bulk_actions[ self::VALIDATION_ERROR_ACCEPT_ACTION ] = __( 'Accept', 'amp' );
$bulk_actions[ self::VALIDATION_ERROR_REJECT_ACTION ] = __( 'Reject', 'amp' );
return $bulk_actions;
Expand Down Expand Up @@ -564,8 +571,7 @@ public static function filter_tag_row_actions( $actions, WP_Term $tag ) {
public static function add_admin_menu_validation_error_item() {
$menu_item_label = esc_html__( 'Validation Errors', 'amp' );
$new_error_count = self::get_validation_error_count( array(
'group' => self::VALIDATION_ERROR_NEW_STATUS,
'ignore_empty' => true,
'group' => self::VALIDATION_ERROR_NEW_STATUS,
) );
if ( $new_error_count ) {
$menu_item_label .= ' <span class="awaiting-mod"><span class="pending-count">' . esc_html( number_format_i18n( $new_error_count ) ) . '</span></span>';
Expand Down

0 comments on commit 5e12fa1

Please sign in to comment.