WordPress blog comment visible implementation method

Source: Internet
Author: User
Tags wordpress blog

Previously, I helped others test the comments visibility function and tried it in the previous article "add wordcount statistics for WordPress". It still seems to be a good practical function, which can increase the comments enthusiasm of visitors, A lot of useless spam messages may also be added. Common functions on forums may be annoying when many messages are used. However, many children's shoes are very interested in this, so I will post the implementation method.

First, we recommend a plug-in to implement this function: easy2hide.

Usage: After the plug-in is enabled, add the following content when editing the article:

  1. <! -- Easy2hide start {reply_to_this = true} --> some hidden content <! -- Easy2hide end -->

Let's talk about the implementation method without plug-ins. The original code of this method should be from: Messy.

The original code has a disadvantage that even the blogger or Webmaster can see the hidden content only after commenting, so someone has improved the code. The specific source of the Code is unknown. Please let us know if someone claims it.

Add the following code to the topic functions. php file:

  1. Function reply_to_read ($ atts, $ content = null ){
  2. Extract (export code_atts (array ("notice" => '<p class = "reply-to-read"> tips: the content here can be viewed only after <a href = "# respond" title = "comment on this article"> comment on this article </a>. </p> '), $ atts ));
  3. $ Email = null;
  4. $ User_ID = (int) wp_get_current_user ()-> ID;
  5. If ($ user_ID> 0 ){
  6. $ Email = get_userdata ($ user_ID)-> user_email;
  7. // Directly display the content of the blogger
  8. $ Admin_email = "xxx@aaa.com"; // blogger Email
  9. If ($ email = $ admin_email ){
  10. Return $ content;
  11. }
  12. } Else if (isset ($ _ COOKIE ['comment _ author_email _ '. COOKIEHASH]) {
  13. $ Email = str_replace ('% 40',' @ ', $ _ COOKIE ['comment _ author_email _'. COOKIEHASH]);
  14. } Else {
  15. Return $ notice;
  16. }
  17. If (empty ($ email )){
  18. Return $ notice;
  19. }
  20. Global $ wpdb;
  21. $ Post_id = get_the_ID ();
  22. $ Query = "SELECT 'comment _ id' FROM {$ wpdb-> comments} WHERE 'comment _ post_ID '= {$ post_id} and 'comment _ apache' = '1' and 'comment _ author_email '=' {$ email} 'LIMIT 1 ";
  23. If ($ wpdb-> get_results ($ query )){
  24. Return do_response code ($ content );
  25. } Else {
  26. Return $ notice;
  27. }
  28. }
  29.  
  30. Add_response code ('reply', 'reply _ to_read ');

Modify the Email address of the blogger.

Usage: add the following when editing an article:

  1. [@ Reply] comments visible content [@/reply]

Or

  1. [@ Reply notice = "Custom prompt information"] comments visible content [@/reply]

Tip: remove @

Demo: add article count statistics for WordPress

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.