在funcation.php中加入以下代码
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 = “自己修改哦”; //站长Email
if ($email == $admin_email) {
return $content;
}
} else if (isset($_COOKIE[‘comment_author_email_’ . COOKIEHASH])) {
$email = str_replace(‘%40’, ‘@’, $_COOKIE[‘comment_author_email_’ . COOKIEHASH]);
} else {
return $notice;
}
if (empty($email)) {
return $notice;
}
global $wpdb;
$post_id = get_the_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 do_shortcode($content);
} else {
return $notice;
}
}
add_shortcode(‘reply’, ‘reply_to_read’);
自己修改一下站长Email哦????
接下来是怎么去文章中使用,任意选择一种简码使用,可以在文章中的区块转换为html,然后在前后加上简码即可,reply前面要去掉一个空格
//简码1 任选一种使用
[ reply]评论可见的内容[/reply]
//简码2 任选一种使用
[ reply notice=”自定义的提示信息”]评论可见的内容[/reply]
原创文章,转载请注明:转自于122&&113
本文链接地址:WordPress设置某些内容评论可见
标签:
WordPress