试了一段代码,之间500错误,重新找了一段,代码如下:
- //文章内容回复可见
- add_shortcode('reply', 'reply_to_read');
- function reply_to_read($atts, $content=null) {
- extract(shortcode_atts(array("notice" => '<p>温馨提示:此处内容需要<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 = "550005887@qq.com"; //<span style="color: #0000ff;">博主Email</span>
- 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 (emptyempty($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;
- }
- }
代码中邮箱换成博主邮箱。
调用方法是:
- [reply]评论可见的内容[/reply]
或者;
- [reply notice="自定义的提示信息"]评论可见的内容[/reply]
照例给后台文本编辑器增加按钮:
- // 后台文本编辑器增加按钮
- function download($atts, $content = null) {
- return '<i class="icon-download"></i><a class="download" href="'.$content.'" rel="external" target="_blank" title="下载地址">下载地址</a>';}
- add_shortcode("download", "download");
- add_action('after_wp_tiny_mce', 'bolo_after_wp_tiny_mce');
- function bolo_after_wp_tiny_mce($mce_settings) {
- ?>
- <script type="text/javascript">
- QTags.addButton( 'download', '下载按钮', "[download]下载地址[/download]" );
- QTags.addButton('hr', '横线', "<hr />\n");//添加横线
- QTags.addButton('h3', 'H3标签', "<h3>", "</h3>\n"); //添加标题3
- QTags.addButton('h4', 'H4标签', "<h4>", "</h4>\n"); //添加标题4
- QTags.addButton('sb', '上标', "<sup>", "</sup>");
- QTags.addButton('xb', '下标', "<sub>", "</sub>");
- QTags.addButton('shsj', '首行缩进', " ");
- QTags.addButton('hc', '回车', "<br />");
- QTags.addButton('jz', '居中', "<center>", "</center>");
- QTags.addButton('mark', '黄字', "<mark>", "</mark>");
- QTags.addButton('xhx', '下划线', "<u>", "</u>");
- QTags.addButton('pre', '代码pre', "<pre>", "</pre>\n"); //添加代码
- QTags.addButton( 'reply1', '评论可见', '[reply]','[/reply]' );
- QTags.addButton( 'reply2', '回复可见', '[reply notice="自定义提醒回复内容"]','[/reply]' );
- QTags.addButton( 'mimakejian', '密码可见', '[secret key="输入密码"]', '[/secret]' );
- QTags.addButton('embed', '文章引用', "[mimelove_insert_post ids=文章id]");
- function bolo_QTnextpage_arg1() {
- }
- </script>
- <?php
- }
请登录以参与评论
现在登录