• Resolved Andry

    (@blackstar1991)


    Hi. I find. that method comment_reply_link() Work incorect if in admin panel you unchecked checkbox Users must be registered and logged in to comment

    I needed to disable this function because my site uses two versions of the comment form, standard form for posts and a custom form.

    <?php
     comment_reply_link(array(
      'reply_text' => __('Reply', 'am'),
      'depth'      => $depth,
      'max_depth'  => $args['max_depth'],
      'login_text' => __('Log in to Reply', 'am'),
      'before' => '',
    ));
    ?>

    I wrote this connection for a button to reply to a comment, expecting to receive a link to log in to leave a comment, but instead Reply continues to be displayed to me

Viewing 4 replies - 1 through 4 (of 4 total)
  • A login button will only appear if you tick the box you mentioned. But if I understand correctly, you want to require login for one comment form but not for the other? That is a special case that is not provided for in the function. Or have I understood it wrong?

    Thread Starter Andry

    (@blackstar1991)

    You understand correctly. I have 2 different contact forms on the site and they should have different behavior regardless of what function is selected in the admin panel

    The comment_reply_link() function, or actually get_comment_reply_link(), works just fine. It is your requirement that is not supported by the function. Within the function, it is queried as a condition whether the tick is set – no matter how and where it is included. There is obviously no hook or property to influence this. And simply changing the label of the button does not change its link target.

    From my point of view, there is only one possibility. You would have to change the value for “comment_registration” before the output where you want the login button. Example:

    add_filter( 'option_comment_registration', 'custom_enable_registration' );
    
    function custom_enable_registration() { return true; }
    
    comment_reply_link(array(
      'reply_text' => __('Reply', 'am'),
      'depth'      => $depth,
      'max_depth'  => $args['max_depth'],
      'login_text' => __('Log in to Reply', 'am'),
      'before' => '',
    ));
    remove_filter( 'option_comment_registration', 'custom_enable_registration' );

    The trick here is that only for the execution of your custom link, the return of the setting is changed to force the output of the login link. Afterwards, this is undone so that it does not apply to the rest of the page.

    Thread Starter Andry

    (@blackstar1991)

    Thanks. That’s what i need.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘comment_reply_link() work wrong’ is closed to new replies.