WordPress 添加回覆可見小工具
6,320 1
有時候我們寫了一篇有價值的文章,為保護辛勤勞動或者不給伸手黨一絲機會,再或者是為了增加評論量,所以就想用到評論可見的功能,我參考了一下知更鳥的回覆可見,然後把他的代碼獨立出來,下面會分享給小夥伴們喔
代碼
PHP PHP
// 评论可见
function reply_to_read($atts, $content=null) {
extract(shortcode_atts(array("notice" => '<p class="reply-to-read">此处内容需要<a href="#respond" title="评论本文">评论</a>后才能查看.</p>'), $atts));
$email = null;
$user_ID = (int) wp_get_current_user()->ID;
if ($user_ID > 0) {
$email = get_userdata($user_ID)->user_email;
$admin_email = "xinyewl@qq.com";
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');
代碼中的 xinyewl@qq.com 請改為你的管理員郵箱,直接對該郵箱的用戶展示內容。
將以上的代碼放到主題目錄下的 functions.php 即可使用。
調用方法
在可視化或者編輯框下輸入短代碼 [reply]隱藏的內容[/reply],中間可以改為你要隱藏的內容。

評論
(1)没用啊,还是现实隐藏内容