Skip to content

Commit

Permalink
Eliminate soft-deprecated use of tag_row_actions filter
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Nov 12, 2019
1 parent 96267a8 commit e64154d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 65 deletions.
118 changes: 58 additions & 60 deletions includes/validation/class-amp-validation-error-taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ static function() {
);
add_filter( 'terms_clauses', [ __CLASS__, 'filter_terms_clauses_for_description_search' ], 10, 3 );
add_action( 'admin_notices', [ __CLASS__, 'add_admin_notices' ] );
add_filter( 'tag_row_actions', [ __CLASS__, 'filter_tag_row_actions' ], 10, 2 );
add_filter( self::TAXONOMY_SLUG . '_row_actions', [ __CLASS__, 'filter_tag_row_actions' ], 10, 2 );
if ( get_taxonomy( self::TAXONOMY_SLUG )->show_in_menu ) {
add_action( 'admin_menu', [ __CLASS__, 'add_admin_menu_validation_error_item' ] );
}
Expand Down Expand Up @@ -1622,69 +1622,67 @@ public static function add_admin_notices() {
public static function filter_tag_row_actions( $actions, WP_Term $tag ) {
global $pagenow;

if ( self::TAXONOMY_SLUG === $tag->taxonomy ) {
$term_id = $tag->term_id;
$term = get_term( $tag->term_id ); // We don't want filter=display given by $tag.

/*
* Hide deletion link since a validation error should only be removed once
* it no longer has an occurrence on the site. When a validated URL is re-checked
* and it no longer has this validation error, then the count will be decremented.
* When a validation error term no longer has a count, then it is hidden from the
* list table. A cron job could periodically delete terms that have no counts.
*/
unset( $actions['delete'] );

if ( 'post.php' === $pagenow ) {
$actions['details'] = sprintf(
'<button type="button" aria-label="%s" class="single-url-detail-toggle button-link">%s</button>',
esc_attr__( 'Toggle error details', 'amp' ),
esc_html__( 'Details', 'amp' )
);
} else {
$actions['details'] = sprintf(
$term_id = $tag->term_id;
$term = get_term( $tag->term_id ); // We don't want filter=display given by $tag.

/*
* Hide deletion link since a validation error should only be removed once
* it no longer has an occurrence on the site. When a validated URL is re-checked
* and it no longer has this validation error, then the count will be decremented.
* When a validation error term no longer has a count, then it is hidden from the
* list table. A cron job could periodically delete terms that have no counts.
*/
unset( $actions['delete'] );

if ( 'post.php' === $pagenow ) {
$actions['details'] = sprintf(
'<button type="button" aria-label="%s" class="single-url-detail-toggle button-link">%s</button>',
esc_attr__( 'Toggle error details', 'amp' ),
esc_html__( 'Details', 'amp' )
);
} else {
$actions['details'] = sprintf(
'<a href="%s">%s</a>',
admin_url(
add_query_arg(
[
self::TAXONOMY_SLUG => $term->name,
'post_type' => AMP_Validated_URL_Post_Type::POST_TYPE_SLUG,
],
'edit.php'
)
),
esc_html__( 'Details', 'amp' )
);
}

// Only add the 'Remove' and 'Keep' links to the index page, not the individual URL page.
if ( 'edit-tags.php' === $pagenow ) {
$sanitization = self::get_validation_error_sanitization( json_decode( $term->description, true ) );

if ( self::VALIDATION_ERROR_ACK_ACCEPTED_STATUS !== $sanitization['status'] ) {
$actions[ self::VALIDATION_ERROR_ACCEPT_ACTION ] = sprintf(
'<a href="%s">%s</a>',
admin_url(
add_query_arg(
[
self::TAXONOMY_SLUG => $term->name,
'post_type' => AMP_Validated_URL_Post_Type::POST_TYPE_SLUG,
],
'edit.php'
)
wp_nonce_url(
add_query_arg( array_merge( [ 'action' => self::VALIDATION_ERROR_ACCEPT_ACTION ], compact( 'term_id' ) ) ),
self::VALIDATION_ERROR_ACCEPT_ACTION
),
esc_html__( 'Details', 'amp' )
esc_html(
self::VALIDATION_ERROR_NEW_ACCEPTED_STATUS === $sanitization['term_status'] ? __( 'Confirm removed', 'amp' ) : __( 'Remove', 'amp' )
)
);
}

// Only add the 'Remove' and 'Keep' links to the index page, not the individual URL page.
if ( 'edit-tags.php' === $pagenow ) {
$sanitization = self::get_validation_error_sanitization( json_decode( $term->description, true ) );

if ( self::VALIDATION_ERROR_ACK_ACCEPTED_STATUS !== $sanitization['status'] ) {
$actions[ self::VALIDATION_ERROR_ACCEPT_ACTION ] = sprintf(
'<a href="%s">%s</a>',
wp_nonce_url(
add_query_arg( array_merge( [ 'action' => self::VALIDATION_ERROR_ACCEPT_ACTION ], compact( 'term_id' ) ) ),
self::VALIDATION_ERROR_ACCEPT_ACTION
),
esc_html(
self::VALIDATION_ERROR_NEW_ACCEPTED_STATUS === $sanitization['term_status'] ? __( 'Confirm removed', 'amp' ) : __( 'Remove', 'amp' )
)
);
}
if ( self::VALIDATION_ERROR_ACK_REJECTED_STATUS !== $sanitization['status'] ) {
$actions[ self::VALIDATION_ERROR_REJECT_ACTION ] = sprintf(
'<a href="%s">%s</a>',
wp_nonce_url(
add_query_arg( array_merge( [ 'action' => self::VALIDATION_ERROR_REJECT_ACTION ], compact( 'term_id' ) ) ),
self::VALIDATION_ERROR_REJECT_ACTION
),
esc_html(
self::VALIDATION_ERROR_NEW_REJECTED_STATUS === $sanitization['term_status'] ? __( 'Confirm kept', 'amp' ) : __( 'Keep', 'amp' )
)
);
}
if ( self::VALIDATION_ERROR_ACK_REJECTED_STATUS !== $sanitization['status'] ) {
$actions[ self::VALIDATION_ERROR_REJECT_ACTION ] = sprintf(
'<a href="%s">%s</a>',
wp_nonce_url(
add_query_arg( array_merge( [ 'action' => self::VALIDATION_ERROR_REJECT_ACTION ], compact( 'term_id' ) ) ),
self::VALIDATION_ERROR_REJECT_ACTION
),
esc_html(
self::VALIDATION_ERROR_NEW_REJECTED_STATUS === $sanitization['term_status'] ? __( 'Confirm kept', 'amp' ) : __( 'Keep', 'amp' )
)
);
}
}
return $actions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ public function test_add_admin_hooks() {
$this->assertEquals( 10, has_filter( 'user_has_cap', [ self::TESTED_CLASS, 'filter_user_has_cap_for_hiding_term_list_table_checkbox' ] ) );
$this->assertEquals( 10, has_filter( 'terms_clauses', [ self::TESTED_CLASS, 'filter_terms_clauses_for_description_search' ] ) );
$this->assertEquals( 10, has_action( 'admin_notices', [ self::TESTED_CLASS, 'add_admin_notices' ] ) );
$this->assertEquals( 10, has_filter( 'tag_row_actions', [ self::TESTED_CLASS, 'filter_tag_row_actions' ] ) );
$this->assertEquals( 10, has_filter( AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG . '_row_actions', [ self::TESTED_CLASS, 'filter_tag_row_actions' ] ) );
$this->assertEquals( 10, has_action( 'admin_menu', [ self::TESTED_CLASS, 'add_admin_menu_validation_error_item' ] ) );
$this->assertEquals( 10, has_filter( 'parse_term_query', [ self::TESTED_CLASS, 'parse_post_php_term_query' ] ) );
$this->assertEquals( 10, has_filter( 'manage_' . AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG . '_custom_column', [ self::TESTED_CLASS, 'filter_manage_custom_columns' ] ) );
Expand Down Expand Up @@ -990,10 +990,6 @@ public function test_filter_tag_row_actions() {
'delete' => '<a href="#">Delete</a>',
];

// When the term isn't for the invalid post type taxonomy, the actions shouldn't be altered.
$term_other_taxonomy = self::factory()->term->create_and_get();
$this->assertEquals( $initial_actions, AMP_Validation_Error_Taxonomy::filter_tag_row_actions( $initial_actions, $term_other_taxonomy ) );

// The term is for this taxonomy, so this should filter the actions.
$term_this_taxonomy = self::factory()->term->create_and_get(
[
Expand Down

0 comments on commit e64154d

Please sign in to comment.