如何WordPress的帖子添加评论只为登录用户? [英] how wordpress a post add comment only for logged users?

查看:131
本文介绍了如何WordPress的帖子添加评论只为登录用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

wordpress中的帖子如何仅为登录用户添加评论?



访问者必须回答自己的添加评论。但是我需要一个帖子,留下评论(仅适用于登录用户),用户必须注册到站点,然后强制添加评论才能发布



可以使用功能文件来做到这一点? / p>

我发现有2个代码,但没有用,也不知道如何使用它:



面对链接这:
https://codex.wordpress.org/Function_Reference/wp_get_current_user



代码:

  <?php 
$ current_user = wp_get_current_user();
if(0 == $ current_user-> ID){
//未登录。
} else {
//已登录。
}
?>

,并在面对链接中找到:
https://codex.wordpress.org/Function_Reference/comment_form



代码:

 '< p class =必须登录>'。 sprintf(__(’您必须先< a href =%s>登录< / a>才能发表评论。 '< / p>'

,从这两者的组合中,我构建了以下功能!

 <?php 
$ current_user = wp_get_current_user();
if(0 == $ current_user-> ID){
//未登录。
’< p class =必须登录>’。 sprintf(__(’您必须先< a href =%s>登录< / a>才能发表评论。 ’< / p>’
} else {
//登录。
}
?>

并使用插入PHP代码段插件仅用于(a)发布



请帮助我要这样做。谢谢大家

解决方案

在菜单导航下查看

 设置>>>讨论
选中用户必须注册并登录后才能发表评论复选框


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.wordpress.org/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.wordpress.org/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

解决方案

Review below menu navigation

Settings >>> Discussion 
Checked the "Users must be registered and logged in to comment " checkbox

这篇关于如何WordPress的帖子添加评论只为登录用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆