-
Notifications
You must be signed in to change notification settings - Fork 383
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
Add amp-live-list comments #909
Conversation
As discussed, to fully support comments in the AMP plugin for WordPress, the The ordering of WP comments is configurable in the admin: For the immediate term we'll be forcing the option to be “newer” and display a notice: So when <div class="notice notice-info inline"><p><?php echo wp_kses_post( __( 'Note: AMP does not yet <a href="https://github.com/ampproject/amphtml/issues/5396" target="_blank">support ascending</a> comments with newer entries appearing at the bottom.', 'amp' ) ); ?></p></div> |
…dd/amp-live-list-comments
amp.php
Outdated
* @param string $message The error message to send. | ||
*/ | ||
function amp_send_error_json( $message ) { | ||
header( 'HTTP/1.1 400 BAD REQUEST' ); |
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.
You can use status_header( 400 )
instead.
amp.php
Outdated
*/ | ||
function amp_send_error_json( $message ) { | ||
header( 'HTTP/1.1 400 BAD REQUEST' ); | ||
wp_send_json( array( 'error' => strip_tags( $message, 'strong' ) ) ); |
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.
No need to strip_tags()
here, as amp-mustache
will escape properly and allow formatting as may be desired.
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.
@westonruter I used striptags because amp-mustache
takes the text from element so it doesn't go deeper. meaning that anything within child elements are totally removed. So <p><strong>ERROR</strong>:Comment is empty.</p>
becomes :Comment is empty
I think we could get all the basic formatting tags in a striptags. Which should work.
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 to know. Thanks for sharing.
amp.php
Outdated
*/ | ||
function amp_send_error_json( $message ) { | ||
header( 'HTTP/1.1 400 BAD REQUEST' ); | ||
wp_send_json( array( 'error' => strip_tags( $message, 'strong' ) ) ); |
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.
Note that a WP_Error
instance can be passed to wp_die()
, so that needs to be accounted for.
amp.php
Outdated
|
||
// Add amp comment hooks. | ||
add_filter( 'comment_post_redirect', 'amp_comment_post_handler', PHP_INT_MAX, 2 ); | ||
add_filter( 'wp_die_handler', 'amp_set_comment_submit_die_handler' ); |
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.
Now that PHP 5.3 is the minimum requirement, we can use closures here to prevent the proliferation of one-liner functions. So this can be:
add_filter( 'wp_die_handler', function() {
return function( $error ) {
status_header( 400 );
if ( is_wp_error( $error ) ) {
$error = $error->get_error_message();
}
wp_send_json( compact( 'error' ) );
};
} );
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.
awesome! I forgot that the min version was increased. great news!
amp.php
Outdated
function amp_hook_comments_maybe() { | ||
|
||
$method = filter_input( INPUT_SERVER, 'REQUEST_METHOD', FILTER_SANITIZE_STRING ); | ||
$is_amp_submit = filter_input( INPUT_GET, '__amp_source_origin', FILTER_VALIDATE_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.
Let's opt to use $_SERVER
and $_GET
to facilitate unit testing.
|
||
$args = array_slice( func_get_args(), 4 ); | ||
|
||
$output = '<amp-live-list layout="container" data-poll-interval="15000" data-max-items-per-page="20" id="amp-live-comments-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.
The id
should probably be unique. It's possible that more than one comment loop could be displayed on a page. So there should perhaps be a new static
member variable that increments as the method is called.
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! will address 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.
Actually, probably should use the post ID in the id
here, as otherwise there could be problems with pagination.
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.
Was thinking the same thing. Will experiment and on it.
* @return string XHTML of the specified page of elements. | ||
*/ | ||
public function paged_walk( $elements, $max_depth, $page_num, $per_page ) { | ||
if ( empty( $elements ) || $max_depth < - 1 ) { |
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.
Trivial: Remove space between -
and 1
includes/class-amp-theme-support.php
Outdated
$amp_walker = new AMP_Comment_Walker(); | ||
$args['walker'] = $amp_walker; | ||
// @todo Make threaded work by setting 'data-update-time' of the parent first level parent with the last timestamp. | ||
$args['max_depth'] = 1; |
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.
Yeah, we need to be able to remove this constraint.
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.
Ye, this is temporary, I figured out how to do it. will experiment and make it work!
amp.php
Outdated
/** | ||
* Hook into a comment submission if an AMP xhr post request. | ||
*/ | ||
function amp_hook_comments_maybe() { |
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.
Rename this to amp_handle_comment_post
.
amp.php
Outdated
function amp_hook_comments_maybe() { | ||
|
||
$method = filter_input( INPUT_SERVER, 'REQUEST_METHOD', FILTER_SANITIZE_STRING ); | ||
$is_amp_submit = filter_input( INPUT_GET, '__amp_source_origin', FILTER_VALIDATE_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.
The variable name here implies it is a boolean. Let's change it to $amp_source_origin
@westonruter Thanks for the thorough review. Good suggestions made. Will work on these and update promptly. Thanks! |
assets/js/amp-admin-comments.js
Outdated
} | ||
} ); | ||
|
||
})( jQuery ); |
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.
@westonruter I think this could easily have been a simple inline script alongside the notice, but I made it a asset file for now, just in case.
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.
Thanks. I've decided to go ahead and inline it. See 310a74a
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.
Perfect. thought that would be the case. thanks for sorting it for me.
@westonruter You can review this again now I think I have addressed all issues as well as made changes necessary for xwp/ampnews#52 |
9e7e6ea
to
8f1b37c
Compare
includes/class-amp-theme-support.php
Outdated
* @param string $text Cancel comment reply link text. | ||
* @return string Cancel reply link. | ||
*/ | ||
public function filter_cancel_comment_reply_link( $formatted_link, $link, $text ) { |
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.
@westonruter should be a static function.
Also fix php notices regarding undefined pagenow var and pass var by ref
Remove unused amp_comments_order_disable_scripts() function.
div
container instead ofol
. Ideal isol
.form
after submission.update
does not force a request to update. In short term, just show message saying it will be available soon.amp-live-list
to start with.Fixes #862.
Fixes #797.