wordpress隐藏内容回复后可见代码

将下面的代码复制到你使用的主题的functions.php最后,并把代码里面的“博主Email”改成你的,实现博主直接查看。

//wordpress隐藏内容回复后可见代码
function reply_to_read($atts,$content=null){
extract(shortcode_atts(array("notice" => '

温馨提示: 隐藏内容需要 回复评论 后才能查看, 评论后请  刷新 !.

'), $atts));
$email=null;
$user_ID=(int)wp_get_current_user()->ID;
if($user_ID>0)
{
$email = get_userdata($user_ID)->user_email;
//对博主直接显示内容
$admin_email = "service@77nn.net"; //把左面的邮箱换成博主Email
if ($email == $admin_email) {
return $content;
}
$email = get_userdata($user_ID)->user_email; //如果用户已登录,从登录信息中获取email
}else if(isset($_COOKIE['comment_author_email_'.COOKIEHASH])){
$email=str_replace('%40','@',$_COOKIE['comment_author_email_'.COOKIEHASH]);
//如果用户未登录但电脑上有本站的Cookie信息,从Cookie里读取email
}else{
return $notice; //无法获取email,直接返回提示信息
}
if(empty($email)){
return $notice;
}
global $wpdb;
$post_id=get_the_ID(); //文章的ID
$query="SELECT `comment_ID`
FROM {$wpdb->comments} WHERE `comment_post_ID`={$post_id}
and `comment_approved`='1' and `comment_author_email`='{$email}' LIMIT 1";
if($wpdb->get_results($query)){
return $content; //查询到对应的已经审核通过的评论则返回内容
}else{
return $notice; //否则返回提示信息
}
}
add_shortcode('reply', 'reply_to_read');

添加了上面的代码就算完工了,发表文章时只需要添加
【reply]【/reply]
就可以使用了,下面是演示

© 版权声明
THE END
喜欢就支持一下吧
点赞0赞赏 分享
评论 共3条

请登录后发表评论

    暂无评论内容