为 wordpress 站点添加评论后可见短代码 | 周良博客
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | <?php /** * 短代码之评论可见 * @xiaowu 周良博客(http://www.aips.me) */ 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 = "xxx@aaa.com"; //博主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'); ?> |