zzz123 大佬有话说 :
wordpress 评论后可见 有人能做吗?
本帖最后由 zzz123 于 2020-2-8 01:08 编辑
帮人做一个站,需要一个 评论后可见的功能,网上好多现成的代码都不支持php7.0,请问有人能做吗?
需求:评论后刷新文章可以查看隐藏内容
环境:
linux、apache2.4、php7.0redis+opcache
主题:justnews
价格:
私聊pm
30826 大佬有话说 :
其实找个现成的插件,找个会改代码的直接改下就能兼容。
nutterchen 大佬有话说 :
function reply_to_read($atts, $content=null) {
extract(shortcode_atts(array("notice" => ‘<div class="post-restrict-area border border-light border-2 rounded text-center has-very-light-gray-background-color py-4 py-md-5 mb-3">
<div class="restrict-text text-sm text-secondary">此处内容已隐藏,评论后刷新可见</div>
<div class="restrict-action mt-3 "><a href="#comments" class="btn btn-primary">立即评论,阅读全文</a></div>
</div>’), $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 protected]"; //博主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’);
zzz123 大佬有话说 :
nutterchen 大佬有话说 : 2020-2-8 01:14
function reply_to_read($atts, $content=null) {
extract(shortcode_atts(array("notice" =>…
这个试过了
} else if (isset($_COOKIE[‘comment_author_email_’ . COOKIEHASH])) {
报错
yjlml 大佬有话说 :
现成的插件很多
zzz123 大佬有话说 :
yjlml 大佬有话说 : 2020-2-8 01:16
现成的插件很多
都不兼容php7.0
nutterchen 大佬有话说 :
zzz123 大佬有话说 : 2020-2-7 20:16
这个试过了
} else if (isset($_COOKIE[‘comment_author_email_’ . COOKIEHASH])) {
报错
详细点
zzz123 大佬有话说 :
nutterchen 大佬有话说 : 2020-2-8 01:17
详细点
老哥你这个貌似没报错,网上有个和你相近的代码运行起会报错,明天我再测试一下,先谢谢老哥你了