Add QapTcha slider verification to wordpress

Source: Internet
Author: User

Over the past few days, the spam of blogs are everywhere... His lady's hammer. I am given a bunch of spam comments every day... It's annoying ..
There are many ways to prevent spam comments... WP, there are also many plug-ins, such as wp-seccod or something ..
Here I will write another method to prevent spam comments.

The traditional verification code requires you to identify (or calculate) and then press the keyboard to enter the result. To use QapTcha, you only need to move the mouse to improve the user experience. The principle is that when the slider slides to a specified position, a request is initiated by the background, which adds some content to the session, we only need to determine whether there is any such content in the session during the submission.

1. download the latest compressed package from the official website and decompress it.
Because QapTcha depends on jquery, the package contains jquery js files, which are renamed and uploaded.
The path to my qaptcha folder is Http: // x73.cc/wp-shortdes/qaptcha.
2. Find QapTcha. jquery. js in around 11 rows.

View sourceprint? 01 jQuery. QapTcha = {

02 build: function (options)

03 {

04 var defaults = {

05 txtLock: Locked: form can be submited, // prompt before unlocking, can be freely modified

06 txtUnlock: Unlocked: form can be submited, // The prompt is displayed after unlocking and can be freely modified.

07 disabledSubmit: true,

08 autoRevert: false,

09 PHPfile: php/Qaptcha. jquery. php // change the address to/wp-nodes des/qaptcha/php/Qaptcha. jquery. php.

10 };

3.If you want to modify the example, modify qaptcha.jquery.css by comparing the example topic.

4. Modify functions. php In the topic and add

View sourceprint? 01 function my_wp_head () {// The content in this function can also be directly written to header. php.

02 if (is_singular ()&&! Is_user_logged_in ()){

03 echo '<script type = "text/javascript" src = "'. get_bloginfo ("wpurl "). '/wp-includes/qaptcha/jquery/jquery-ui.js "> </script> '. "";

04 echo '<script type = "text/javascript" src = "'. get_bloginfo ("wpurl "). '/wp-includes/qaptcha/jquery. ui. touch. js "> </script> '. "";

05 echo '<script type = "text/javascript" src = "'. get_bloginfo ("wpurl "). '/wp-includes/qaptcha/jquery/QapTcha. jquery. js "> </script> '. "";

06 echo '<link rel = "stylesheet" href = "'. get_bloginfo ("wpurl "). '/wp-includes/qaptcha/jquery/QapTcha.jquery.css "type =" text/css "/> '. "";

07 echo '<script type = "text/javascript">

08 $ (document). ready (function (){

09 $ ("# QapTcha"). QapTcha ({disabledSubmit: true });

10 });

11 </script> '."";

12}

13}

14 add_action ('wp _ head', 'My _ wp_head ', 100 );

15 function my_preprocess_comment ($ comment ){

16 if (! Is_user_logged_in ()){

17 if (! Session_id () session_start ();

18 if (isset ($ _ POST ['iqaptcha ']) & empty ($ _ POST ['iqaptcha']) & isset ($ _ SESSION ['iqaptcha ']) & $ _ SESSION ['iqaptcha ']) {

19 unset ($ _ SESSION ['iqaptcha ']);

20 return ($ comment );

21} else wp_die ("sorry, you did not pass the verification. "); // Modify the prompt

22} else

23 return ($ comment );

24}

25 add_action ('preprocess _ comment', 'My _ preprocess_comment ');

5. Modify the comments. php (comment template) file of the topic, find the position where you want the scroll bar to appear, and add

View sourceprint? 1 <div id = "QapTcha"> </div>

6. Upload the file to your server, check the effect, and then modify the style until you are satisfied.

Original article, reprinted Please note: Reprinted from Ps7isys Blog

 

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.