how wordpress a post add comment only for logged users?
-
How a post in wordpress add comment only for logged users?
visitors must answer their own add in comments. but i need a post, leave a comment (only for logged users) and users must register to site beforce add comment to post
can use functions file to do it ?
i found that 2 code but not work and do not know how to use it:
in facing link find this: https://codex.www.ads-software.com/Function_Reference/wp_get_current_user
Code:
<?php $current_user = wp_get_current_user(); if ( 0 == $current_user->ID ) { // Not logged in. } else { // Logged in. } ?>
and in facing link find this: https://codex.www.ads-software.com/Function_Reference/comment_form
code:
'<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( ) ) ) ) . '</p>'
and from the combination of these two together, I built below function!
<?php $current_user = wp_get_current_user(); if ( 0 == $current_user->ID ) { // Not logged in. '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( ) ) ) ) . '</p>' } else { // Logged in. } ?>
and add this to my post with Insert PHP Code Snippet plugin for use only (a) post
please help me to do this. thank you all
- The topic ‘how wordpress a post add comment only for logged users?’ is closed to new replies.