Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 1364: Improved "Error isolation" view #1446

Merged
merged 17 commits into from Sep 20, 2018
Merged

Conversation

@jacobschweitzer
Copy link
Contributor

@jacobschweitzer jacobschweitzer commented Sep 19, 2018

Fixes #1364.

Details collapsed:

image

Details expanded:

image

add_filter( 'handle_bulk_actions-edit-' . self::POST_TYPE_SLUG, array( __CLASS__, 'handle_bulk_action' ), 10, 3 );
add_filter( 'handle_bulk_actions-edit-' . self::POST_TYPE_SLUG, array(
__CLASS__,
'handle_bulk_action',
Copy link
Member

@westonruter westonruter Sep 19, 2018

These can be kept on the same line as in the other examples here, no?

$description = json_decode( $error->description, true );
$sanitization = \AMP_Validation_Error_Taxonomy::get_validation_error_sanitization( $description );
$status_text = \AMP_Validation_Error_Taxonomy::get_status_text_with_icon( $sanitization['term_status'], $sanitization['forced'] );
$error_title = \AMP_Validation_Error_Taxonomy::get_error_title_from_code( $description['code'] );
Copy link
Member

@westonruter westonruter Sep 19, 2018

Good. We need to do more of this. Centralizing how we convert errors into human-readable representations.

wp_kses_post( $output )
);

$error_id = sanitize_text_field( wp_unslash( $_GET[ \AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG ] ) ); // WPCS: CSRF OK.
Copy link
Member

@westonruter westonruter Sep 19, 2018

This can be sanitize_key instead of sanitize_text_field, since it is an md5 hash.

?>
<script type="text/javascript">
jQuery( document ).ready(function() {
jQuery( 'h1.wp-heading-inline' ).html( '<?php echo wp_kses_post( $heading ); ?>' );
Copy link
Member

@westonruter westonruter Sep 19, 2018

'<?php echo wp_kses_post( $heading ); ?>' should instead be:

<?php echo wp_json_encode( $heading ); ?>

This will add the quote marks for you and escape at the same time.

* Bulk Accept Reject Single Error
* This adds functionality to the single error page where there are two buttons which allow accepting or rejecting an error.
*/
public static function bulk_accept_reject_single_error() {
Copy link
Member

@westonruter westonruter Sep 19, 2018

I don't think we need this method as we can re-use another. There is already an action for accepting or rejecting a term. For example, the row actions for a term:

image

Accept: https://src.wordpress-develop.test/wp-admin/edit-tags.php?taxonomy=amp_validation_error&post_type=amp_invalid_url&action=amp_validation_error_accept&term_id=1292&_wpnonce=cac5f31fb4
Reject: https://src.wordpress-develop.test/wp-admin/edit-tags.php?taxonomy=amp_validation_error&post_type=amp_invalid_url&action=amp_validation_error_reject&term_id=1292&_wpnonce=8001418580

Links generated here:

https://github.com/Automattic/amp-wp/blob/808a8dabc6a879e0eff9cc4e054b86b32e62f754/includes/validation/class-amp-validation-error-taxonomy.php#L1246-L1268

And handled here:

https://github.com/Automattic/amp-wp/blob/808a8dabc6a879e0eff9cc4e054b86b32e62f754/includes/validation/class-amp-validation-error-taxonomy.php#L1508-L1546

So I suggest adding to handle_validation_error_update whatever is missing, and remove bulk_accept_reject_single_error. There may not be any changes needed because that method already redirects to the referrer.

* 2. Notice with accept and reject buttons.
*/
if ( ! empty( $_GET[ \AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG ] ) && isset( $_GET['post_type'] ) && self::POST_TYPE_SLUG === $_GET['post_type'] ) { // WPCS: CSRF OK.
$error_id = sanitize_text_field( wp_unslash( $_GET[ \AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG ] ) ); // WPCS: CSRF OK.
Copy link
Member

@westonruter westonruter Sep 19, 2018

This should be sanitize_key instead, since it is an md5 hash.

*/
if ( ! empty( $_GET[ \AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG ] ) && isset( $_GET['post_type'] ) && self::POST_TYPE_SLUG === $_GET['post_type'] ) { // WPCS: CSRF OK.
$error_id = sanitize_text_field( wp_unslash( $_GET[ \AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG ] ) ); // WPCS: CSRF OK.
$error = get_term_by( 'slug', $error_id, \AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG );
Copy link
Member

@westonruter westonruter Sep 19, 2018

TODO (in #1429): Once #1429 is merged, we can use AMP_Validation_Error_Taxonomy::get_term() per 3ea0df5

return;
}

$description = json_decode( $error->description, true );
Copy link
Member

@westonruter westonruter Sep 19, 2018

TODO (in #1429): We should add a method to AMP_Validation_Error_Taxonomy which abstracts this away. As there is AMP_Validation_Error_Taxonomy::get_term() per 3ea0df5 we could have AMP_Validation_Error_Taxonomy::get_term_error() which returns the decoded json blob from a term ID or existing WP_Term.

@@ -588,6 +587,7 @@ public static function add_admin_hooks() {
add_filter( 'posts_where', array( __CLASS__, 'filter_posts_where_for_validation_error_status' ), 10, 2 );
add_filter( 'handle_bulk_actions-edit-' . self::TAXONOMY_SLUG, array( __CLASS__, 'handle_validation_error_update' ), 10, 3 );
add_action( 'load-edit-tags.php', array( __CLASS__, 'handle_inline_edit_request' ) );
add_action( 'parse_query', array( __CLASS__, 'parse_term_php_query' ) );
Copy link
Member

@westonruter westonruter Sep 19, 2018

I believe this is dead code.

@@ -631,6 +631,10 @@ public static function add_admin_hooks() {

// Override the columns displayed for the validation error terms.
add_filter( 'manage_edit-' . self::TAXONOMY_SLUG . '_columns', function( $old_columns ) {
if ( 'term' === get_current_screen()->base ) {
Copy link
Member

@westonruter westonruter Sep 19, 2018

I believe this is dead code.

);
?>
<script type="text/javascript">
jQuery( document ).ready(function() {
Copy link
Member

@westonruter westonruter Sep 19, 2018

Not a big deal, but there is a more idiomatic way to write this:

jQuery( function( $ ) {
    $( 'h1.wp-heading-inline' ).html( <?php echo wp_json_encode( $heading ); ?> );
} );

@westonruter
Copy link
Member

@westonruter westonruter commented Sep 19, 2018

@jacobschweitzer It's still failing here:

image

jacobschweitzer and others added 2 commits Sep 19, 2018
* Hide buttons entirely if sanitization is forced.
* Use flexbox to lay out the buttons.
* Add more information to explain what accept/reject mean.
@westonruter westonruter merged commit 377995f into develop Sep 20, 2018
2 checks passed
@westonruter westonruter deleted the add/1364-single-error-url branch Sep 20, 2018
@westonruter westonruter added this to the v1.0 milestone Sep 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants