Page 1 of 1

UPDATE: WordPress 5.x – Reply Comment button fix (addComment.moveForm)

UPDATE: WordPress 5.x – Reply Comment button fix (addComment.moveForm)

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.
Examples: "MacOS X - Your question", "MS Word - Your Tip or Trick".

Please note that switching to another language when reading a post will not work!
Posts will not have a translated counterpart.




RSS Feed

Home Forums Website Updates UPDATE: WordPress 5.x – Reply Comment button fix (addComment.moveForm)

This topic contains 5 replies, has 2 voices, and was last updated by  hans 1 week, 1 day ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • 11613

    hans
    Keymaster

    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.

    12229

    manux23
    Participant

    I have the same problem with WordPress 5.2.2 but after applying that fix, the “addComment.moveForm” command does not work …

    12231

    hans
    Keymaster

    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.

    12233

    manux23
    Participant

    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.

    12235

    manux23
    Participant

    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).

    12237

    hans
    Keymaster

    Thanks Manux23!

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

Viewing 6 posts - 1 through 6 (of 6 total)



You must be logged in to reply to this topic.