-
Notifications
You must be signed in to change notification settings - Fork 384
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
Do redirect if amp comments_live_list support is not declared; vary comment success message by approval status #1029
Conversation
@westonruter you can take a look at this now. I've included #936 as well, since they are closely related. |
@DavidCramer I don't see how #936 is included here. I was expecting to see something like this: #1020 (comment) |
@westonruter - I was basing it on your second thought - #1020 (comment) |
@westonruter - I see I missed the filter, sorry. ignore me, I'll revised it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The theme support flag does not seem to work with the changes here. When I add the the comments_live_list
flag (xwp/ampnews#85) there is still a redirect.
includes/class-amp-theme-support.php
Outdated
$url = add_query_arg( 'comment', $comment->comment_ID, $url ); | ||
|
||
// Send redirect header if amp-live-list has been opted-out. | ||
if ( empty( $theme_support['comments_live_list'] ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't work because $theme_support
is an array of the args so it needs to be looking at $theme_support[0]['comments_live_list']
includes/class-amp-theme-support.php
Outdated
|
||
// Send redirect header if amp-live-list has been opted-out. | ||
if ( empty( $theme_support['comments_live_list'] ) ) { | ||
header( 'AMP-Redirect-To: ' . $url, true ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be necessary because wp_redirect()
is currently being called. It only needs to return the $url
includes/class-amp-theme-support.php
Outdated
} else { | ||
$message = __( 'Your comment has been posted, and is awaiting moderation.', 'default' ); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing phpdoc.
includes/class-amp-theme-support.php
Outdated
if ( '1' === (string) $comment->comment_approved ) { | ||
$message = __( 'Your comment has been posted and has been approved.', 'amp' ); | ||
} else { | ||
$message = __( 'Your comment has been posted, and is awaiting moderation.', 'default' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This string has the default
text domain because it is re-using a string in core:
We need it to keep it the same for it to re-use core translations.
includes/class-amp-theme-support.php
Outdated
@@ -516,7 +536,7 @@ public static function add_amp_comment_form_templates() { | |||
?> | |||
<div submit-success> | |||
<template type="amp-mustache"> | |||
<?php esc_html_e( 'Your comment has been posted, but may be subject to moderation.', 'amp' ); ?> | |||
{{{data}}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have a paragraph wrapping it, like for the error message.
includes/class-amp-theme-support.php
Outdated
@@ -516,7 +536,7 @@ public static function add_amp_comment_form_templates() { | |||
?> | |||
<div submit-success> | |||
<template type="amp-mustache"> | |||
<?php esc_html_e( 'Your comment has been posted, but may be subject to moderation.', 'amp' ); ?> | |||
{{{data}}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error handler sends back an object with an error
key. I think this should be similarly looking for an object returned with just a message
key.
includes/class-amp-theme-support.php
Outdated
// We don't need any data, so just send a success. | ||
wp_send_json_success(); | ||
}, PHP_INT_MAX ); | ||
wp_send_json_success( $message ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably apply kses to this to only allow the allowed amp-mustache markup.
includes/class-amp-theme-support.php
Outdated
} | ||
|
||
$message = apply_filters( 'amp_comment_submitted_message', $message, $comment ); | ||
|
||
// We don't need any data, so just send a success. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is no longer true.
* Explicitly limit handle_xhr_request to POST requests. * Make sure original status header is sent back in wp_die() call. * Fix reading of amp theme support flag since get_theme_support() returns an array of args. * Add missing paragraph surrounding success message template. * Fix moderation comment to ensure default core string is re-used. * Fix PHP notice in regards to additional comment_live_list theme support flag being present. * Remove obsolete comments. * Simplify success message. * Add phpdoc for amp_comment_posted_message filter. * Pass back success message in same way as error message is returned as named variable. * Add missing tests and introduce \AMP_Theme_Support::send_header() to avoid having to runInSeparateProcess.
@DavidCramer Please test these changes with the corresponding changes in the theme PR xwp/ampnews#85 Test submitting comments with the |
@westonruter Thanks for those changes. I've gone over them to get better understanding of it all. Will review and test xwp/ampnews#85 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Minor review below
includes/class-amp-theme-support.php
Outdated
if ( empty( $theme_support[0]['comments_live_list'] ) ) { | ||
|
||
// Add the comment ID to the URL to force AMP to refresh the page. | ||
$url = add_query_arg( 'comment', $comment->comment_ID, $url ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return statement can happen on this line, no need to assign it to a var.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, but the idea is that eventually this should not be necessary at all. I've opened an issue in amphtml to address this and I'll add a comment here to reference it: ampproject/amphtml#14170
includes/class-amp-theme-support.php
Outdated
* } | ||
*/ | ||
public static function handle_wp_die( $error, $title = '', $args = array() ) { | ||
$status_code = 500; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That could move in a else statement at the end of the statements below.
wp_send_json_success(); | ||
}, PHP_INT_MAX ); | ||
self::handle_xhr_headers_output(); | ||
} elseif ( ! empty( self::$purged_amp_query_vars['_wp_amp_action_xhr_converted'] ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized that we're now not properly looking at _wp_amp_action_xhr_converted
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On further thought, I don't think the logic this function cares if _wp_amp_action_xhr_converted
. If someone is implementing their own action-xhr
endpoint, then they're not going to be doing wp_redirect()
anyway, but rather should be responding with their own appropriate wp_send_json()
call.
Improve default status_code handling
fixes #1028
fixes #936