Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!




UPDATE: WordPress 5...
 
Share:
Notifications
Clear all

[Solved] UPDATE: WordPress 5.x - Reply Comment button fix (addComment.moveForm)

6 Posts
2 Users
0 Likes
5,500 Views
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2659
Topic starter  

Unfortunately, after the update to WP 5.1, the Reply to comment button no longer moved the comment field below the comment you'd like to reply to.
This has been fixed. For those with a similar problem in WordPress 5.x;

It seems that the get_comment_reply_link no longer works properly, or maybe I should say "screwed up" the way addComment.moveForm works.
I fixed this by adding a string replacement in the comment_callback($comment, $args, $depth) function, simply adding the old function incase the new function appeared.

Effectively replacing:

data-belowelement="comment-form-here-212086" data-respondelement="respond"

with the onclick inserted:

data-belowelement="comment-form-here-212086" onclick="comment-form-here-212086" onclick="return addComment.moveForm( 'comment-form-here-212086', '212086', 'respond', '178' )" data-respondelement="respond"

PHP Code in functions.php, for the comment call-back:

$replyButton = str_replace( 'data-belowelement', 'onclick="return addComment.moveForm( \'comment-form-here-'.get_comment_ID().'\', \''.get_comment_ID().'\', \'respond\', \''.get_the_ID().'\' )" data-belowelement', $replyButton);
echo $replyButton;

This way the change will only happen when the new method seems to be there, and the new method (if it would ever work in my theme) would still be there as well.


   
ReplyQuote
(@manux23)
New Member
Joined: 5 years ago
Posts: 3
 

I have the same problem with Wordpress 5.2.2 but after applying that fix, the "addComment.moveForm" command does not work ...


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2659
Topic starter  

Hi Manux23,

I'm still using this in WordPress 5.2.2 with success. Maybe my explanation wasn't clear. 
Note: did this work properly in WordPress 5.1 on your website?)

So in my case, I have created my own theme from scratch.
In the theme code (in functions.php), I call the function "get_comment_reply_link()" to get the proper link for posting a reply when building the reply form.
Note that not every theme will do this, some will actually use the built in function instead (in that case, this trick will not work - and you may have to contact the person or company that created the theme you're using, asking for an update).

My original form code looked something like this, and the code for your theme may be different;

$replyButton = get_comment_reply_link(array_merge( $args, array('add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'])));
// potentially some more code here
echo $replyButton; 

As of WordPress 5.1 this no longer seems to produce the correct link.  It would produce something like this (in the HTML of your page):

data-belowelement="comment-form-here-212086" data-respondelement="respond"

There used to be (if I recall correctly) an "onclick" JavaScript event, something like this:

data-belowelement="comment-form-here-212086" onclick="comment-form-here-212086" onclick="return addComment.moveForm( 'comment-form-here-212086', '212086', 'respond', '178' )" data-respondelement="respond"

(the bold part of the code is missing).

I'm sure there are better ways to fix this, but I was looking for a quick fix (getting a little tired of making fixes for functionality changes I didn't ask for - and frankly a little disappointed that the WP team is not really paying attention to backwards compatibility).

Anyhoo, I used "str_replace()" to "add" the missing code, which resulted in:

$replyButton = get_comment_reply_link(array_merge( $args, array('add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'])));
// potentially some more code here
// WP5.1 fix - missing:
$replyButton = str_replace( 'data-belowelement', 'onclick="return addComment.moveForm( \'comment-form-here-'.get_comment_ID().'\', \''.get_comment_ID().'\', \'respond\', \''.get_the_ID().'\' )" data-belowelement', $replyButton);
echo $replyButton; 

If unsure, you could try to see if you can retrieve what the reply button link HTML code looked like before updating to 5.2.2, and then compare it to what it has become after the 5.2.2 update.

But I understand this can be tricky, since WordPress never offers an easy way to revert back to a previous version of WordPress. In my case I got lucky, since I had upgraded WordPress first on a copy on my computer running for testing and development. This is where I can into this issue and could still retrieve the missing info from my real website.

What you could do, if you do not have access to the previous version, or are nervous about move back to a previous version (I would), then you could open the affected page in Google Chrome or FireFox and open the developer tools, so can see and edit the code. Now you can modify the code of one of the reply buttons and change it to the full code with the onClick event code added, to see if it works - even before modifying the functions.php code.


   
ReplyQuote
(@manux23)
New Member
Joined: 5 years ago
Posts: 3
 

Hi, thanks for answering.

Yes, I have checked that the HTML code of the button is the same as before, but apparently the problem is in the script, the page is reloaded by pressing the "Reply" button.

On this page the same thing happens to me, the "reply" button of the comments reloads the page, with the URL: 

 https://www.tweaking4all.com/forums/topic/update-wordpress-5-x-reply-comment-button-fix-addcomment-moveform /?bbp_reply_to=12229&_wpnonce=7e6f860512#new-post

I've tried it with the latest versions of the Mozilla Firefox and Google Chrome browsers.


   
ReplyQuote
(@manux23)
New Member
Joined: 5 years ago
Posts: 3
 

I have managed to identify and solve the problem (not in the best way, but it works). The problem, in my case, is that the "DOMContentLoaded" event was triggered before the "comment-reply.js" script was executed (it seems to me that it is caused by CloudFlare).


   
ReplyQuote


 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2659
Topic starter  

Thanks Manux23!

Good find, I better take a look and see what the deal is.
Thanks again 


   
ReplyQuote

Like what you see and you'd like to help out? 

The best way to help is of course by assisting others with their questions here in the forum, but you can also help us out in other ways:

- Do your shopping at Amazon, it will not cost you anything extra but may generate a small commission for us,
- send a cup of coffee through PayPal ($5, $10, $20, or custom amount),
- become a Patreon,
- donate BitCoin (BTC), or BitCoinCash (BCH).

Share: