• Resolved wpalsansan

    (@neoworlds)


    hi! I have the “Login to comment” link in my comments section and when i click it leads to the wp-login page. i want to show the modal popup form when clicking there. who could I do it?
    regards ??

Viewing 12 replies - 1 through 12 (of 12 total)
  • Hi,

    Add the class lrm-login to your link in comments.php

    Plugin Author Max K

    (@kaminskym)

    Hi,

    Try to add “.must-log-in>a” to the plugin Advanced tab, “Extra login selectors” field.

    Regards, Max

    Hello,

    Unfortunately, adding .must-log-in>a to the plugin Advanced tab in the extra login selector field does not work for me, nor does .must-log-in a:link

    As for adding the class lrm-login to the link in comments.php, I’m not sure where as I don’t see any link. The only link to login I can find is within WordPress itself, in its function get_comment_reply_link() (/wp-includes/comment-template.php).

    Is there a way to add a filter/action to this function?

    function get_comment_reply_link( $args = array(), $comment = null, $post = null ) {
    	$defaults = array(
    		'add_below'     => 'comment',
    		'respond_id'    => 'respond',
    		'reply_text'    => __( 'Reply' ),
    		'reply_to_text' => __( 'Reply to %s' ),
    		'login_text'    => __( 'Log in to Reply' ),
    		'max_depth'     => 0,
    		'depth'         => 0,
    		'before'        => '',
    		'after'         => ''
    	);
    
    	$args = wp_parse_args( $args, $defaults );
    
    	if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] ) {
    		return;
    	}
    
    	$comment = get_comment( $comment );
    
    	if ( empty( $post ) ) {
    		$post = $comment->comment_post_ID;
    	}
    
    	$post = get_post( $post );
    
    	if ( ! comments_open( $post->ID ) ) {
    		return false;
    	}
    
    	$args = apply_filters( 'comment_reply_link_args', $args, $comment, $post );
    
    	if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) {
    		$link = sprintf( '<a rel="nofollow" class="comment-reply-login" href="%s">%s</a>',
    			esc_url( wp_login_url( get_permalink() ) ),
    			$args['login_text']
    		);
    	} else {
    		$onclick = sprintf( 'return addComment.moveForm( "%1$s-%2$s", "%2$s", "%3$s", "%4$s" )',
    			$args['add_below'], $comment->comment_ID, $args['respond_id'], $post->ID
    		);
    
    		$link = sprintf( "<a rel='nofollow' class='comment-reply-link' href='%s' onclick='%s' aria-label='%s'>%s</a>",
    			esc_url( add_query_arg( 'replytocom', $comment->comment_ID, get_permalink( $post->ID ) ) ) . "#" . $args['respond_id'],
    			$onclick,
    			esc_attr( sprintf( $args['reply_to_text'], $comment->comment_author ) ),
    			$args['reply_text']
    		);
    	}
    
    	return apply_filters( 'comment_reply_link', $args['before'] . $link . $args['after'], $args, $comment, $post );
    }

    Thank you I used your solution and it works in comment sections, so could you tell me how can I use same in “Sabai Discuss” plugin? is a plugin for making a FAQ/Question-Answer/Forum in website, so in that plugin the Login link redirect person to default WordPress page and not your plugin (Ajax) working, how I can use your plugin even for that plugin login section?

    Put “.popup_login,.must-log-in>a” in “Extra selectors to handle log in modal?” field in Advance section, as developer said, I tried and works.

    Plugin Author Max K

    (@kaminskym)

    @alikit

    Look on this: https://monosnap.com/file/2Zb8kE0gz9UwqmHIf4pWosA54Kjcgl

    Use class .sabai-login in advanced selectors

    Plugin Author Max K

    (@kaminskym)

    Hi @golok,

    This to add this: .comment-reply-login (replace whole content with .popup_login with this class, as .popup_login just for example).

    Hi @kaminskym,

    Thanks a lot for your help.

    I must be stupid, but whatever I put in this field it just doesn’t work

    https://ibb.co/cj4gye

    The class does not even show up in the link to reply to a comment or in the link to comment:

    https://ibb.co/go88de

    https://ibb.co/fXPgye

    Any suggestion?

    Hi @kaminskym,

    I finally found the source of my problem: it is a conflict with Lazy Load for Comments plugin. If I deactivate it, everything works fine.

    Would you imagine any work around?

    In advance thanks for your precious help.

    Plugin Author Max K

    (@kaminskym)

    Hi,

    Then the problem is with the attaching event – when the page has loaded this element not yet exists, so event can’t be attached.

    Try to use this JS:

    jQuery(document).on('click', '.must-log-in>a', function (event) {
      event.preventDefault();
      $(document).trigger('lrm_show_login', [event]);
      return false;
    });

    Thank you so much @kaminskym for your quick reply. Very unfortunately it doesn’t seem to work.

    I created a load_modal.js file with your script:

    jQuery(document).on('click', '.must-log-in>a', function (event) {
      event.preventDefault();
      $(document).trigger('lrm_show_login', [event]);
      return false;
    });

    I then added the following in functions.php to enqueue this script:

    add_action( 'wp_enqueue_scripts', 'add_my_script' );
    function add_my_script() {
        wp_enqueue_script(
            'load_modal', // name your script so that you can attach other scripts and de-register, etc.
            get_template_directory_uri() . '/js/load_modal.js', // this is the location of your script file
            array('jquery') // this array lists the scripts upon which your script depends
        );
    }

    Isn’t it the correct way to add a .js script?

    Hi @kaminskym,

    I finally managed to access the JS, but the only result is that the link to which the event is linked doesn’t work anymore; one clicks and nothing happens. I deactivate the script and the link works (but send me to the default login page), I activate the script and the link is dead…

    Any suggestion?

    Once again thanks zillions for your help.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘comments login’ is closed to new replies.