Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions includes/class-comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,31 +246,36 @@ public static function register_comment_types() {
}

/**
* replace the template for all URLs with a "replytocom" query-param
* Replace the template for all URLs with a "c" query-param.
*
* @param string $template the template url
* Uses "c" instead of "replytocom" to avoid conflicting with
* WordPress core's threaded/nested comment reply functionality.
*
* @see https://github.com/pfefferle/wordpress-webmention/issues/487
*
* @param string $template The template url.
*
* @return string
*/
public static function comment_template_include( $template ) {
global $wp_query;

// replace template
if ( isset( $wp_query->query['replytocom'] ) ) {
if ( isset( $wp_query->query['c'] ) || isset( $wp_query->query['replytocom'] ) ) {
return apply_filters( 'webmention_comment_template', WEBMENTION_PLUGIN_DIR . 'templates/comment.php' );
}

return $template;
}

/**
* adds some query vars
* Adds some query vars.
*
* @param array $vars
* @param array $vars The query vars.
*
* @return array
*/
public static function query_var( $vars ) {
$vars[] = 'c';
$vars[] = 'replytocom';
return $vars;
}
Expand Down
5 changes: 4 additions & 1 deletion includes/class-receiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,10 @@ public static function post( $request ) {
if ( $query_string ) {
$query_array = array();
parse_str( $query_string, $query_array );
if ( isset( $query_array['replytocom'] ) && get_comment( $query_array['replytocom'] ) ) {
if ( isset( $query_array['c'] ) && get_comment( $query_array['c'] ) ) {
$commentdata['comment_parent'] = $query_array['c'];
} elseif ( isset( $query_array['replytocom'] ) && get_comment( $query_array['replytocom'] ) ) {
// Backward compatibility with older webmentions using "replytocom".
$commentdata['comment_parent'] = $query_array['replytocom'];
}
}
Expand Down
2 changes: 1 addition & 1 deletion includes/class-sender.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static function comment_post( $id ) {
$target = get_url_from_webmention( $parent );

if ( $target ) {
$source = add_query_arg( 'replytocom', $comment->comment_ID, get_permalink( $comment->comment_post_ID ) );
$source = add_query_arg( 'c', $comment->comment_ID, get_permalink( $comment->comment_post_ID ) );

do_action( 'send_webmention', $source, $target );
}
Expand Down
11 changes: 8 additions & 3 deletions templates/comment.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<?php
global $wp_query, $post;
$comment_id = esc_attr( $wp_query->query['replytocom'] );
$comment = get_comment( $comment_id ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
// Support both the new "c" and legacy "replytocom" query vars.
if ( isset( $wp_query->query['c'] ) ) {
$comment_id = esc_attr( $wp_query->query['c'] );
} else {
$comment_id = esc_attr( $wp_query->query['replytocom'] );
}
$comment = get_comment( $comment_id ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited

// load 404 if replytocom is not valid
// Load 404 if comment ID is not valid.
if ( ! $comment ) {
status_header( 404 );
nocache_headers();
Expand Down