美文网首页
为WordPress添加一个隐藏内容,评论可见

为WordPress添加一个隐藏内容,评论可见

作者: 盾给网络 | 来源:发表于2019-08-28 14:08 被阅读0次

添加代码

将下面的代码添加到主题的 functions.php 文件:

//部分内容评论可见

function reply_to_read($atts, $content = null) {

extract(shortcode_atts(array("notice" => '<blockquote><center><p class="reply-to-read" style="color: blue;">注意:本段内容须成功“<a href="' . get_permalink() . '#respond" title="回复本文">回复本文</a>”后“<a href="javascript:window.location.reload();" title="刷新本页">刷新本页</a>”方可查看!</p></center></blockquote>') , $atts));

$email = null;

$user_ID = (int)wp_get_current_user()->ID;if ($user_ID > 0) {

$email = get_userdata($user_ID)->user_email;//对博主直接显示内容

$admin_email = get_bloginfo('admin_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');

调用方法

编辑文章时,使用下面的两种简码调用:

删除第一个reply的空格,把斜杠替换为/

注意:此方法对QQ快速登录的用户是无效的。

//简码1 任选一种使用

[ reply]评论可见的内容[斜杠reply]

//简码2 任选一种使用

[ reply notice="自定义的提示信息"]评论可见的内容[斜杠reply]

原文交流地址:http://www.dungei.com/2604.html

相关文章

网友评论

      本文标题:为WordPress添加一个隐藏内容,评论可见

      本文链接:https://www.haomeiwen.com/subject/hrwpectx.html