跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • wordpress 评论后可见 有人能做吗?
未分類
8 2 月 2020

wordpress 评论后可见 有人能做吗?

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
详细点

老哥你这个貌似没报错,网上有个和你相近的代码运行起会报错,明天我再测试一下,先谢谢老哥你了

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具