Method 1: Add an arithmetic verification code to the comment
Add the following code to functions. php in the topic directory:
The code is as follows: |
Copy code |
// Arithmetic verification code by vfhky Function spam_provent_math (){ $ A = rand (5, 15 ); $ B = rand (5, 15 ); Echo "<input type = 'text' name = 'sum' id = 'sum' size = '22' tabindex = '3' value = 'hands-on and brains, oh, too! 'Onfocus = 'if (this. value! = "") {This. value = "";} 'onblur = 'if (this. value = "") {this. value = "start and brainstorm, oh, too! ";} '/>=$ A + $ B (<font color =' # 0088DD '> prevents bot comments </font> )". "<input type = 'did' name = 'a' value = '$ a'/> ". "<input type = 'ddn' name = 'B' value = '$ B'/> "; } Function spam_provent_pre ($ spam_result ){ $ Sum = $ _ POST ['sum']; Switch ($ sum ){ Case $ _ POST ['A'] + $ _ POST ['B']: break; Case null: wp_die ('kiss, calculate the result Zs'); break; Default: wp_die ('is wrong? ⊙ B Khan '); } Return $ spam_result; } // The registered user or administrator does not need verification If (! Is_user_logged_in () & $ comment_data ['Comment _ type'] = ''){ Add_filter ('preprocess _ comment', 'spam _ provent_pre '); } |
(2) The above code is called in comments. php under the topic directory (different topics may have different comments, and some topics may be in functions. php:
The code is as follows: |
Copy code |
// Determine whether to display the verification code based on whether it is an administrator. <? Php if (! Isset ($ _ COOKIE ['Comment _ author_email _ '. COOKIEHASH]) spam_provent_math ();?> |
Method 2: Use Programs for key filtering
Add the following code to functions. php under your topic:
View spam comments in the background
The code is as follows: |
Copy code |
// Disable the full English comment code for separate use Function scp_comment_post ($ incoming_comment ){ $ Pattern = '/[1-?] /U'; // verify whether it is Chinese If (! Preg_match ($ pattern, $ incoming_comment ['Comment _ content']) { Wp_die ("You shocould type some Chinese word (like" Hello ") in your comment to pass the spam-check, thanks for your patience! Your comment must contain Chinese characters! "); } Return ($ incoming_comment ); } Add_filter ('preprocess _ comment', 'scp _ comment_post '); // Comprehensive use <small ???> Anti-Spam v1.84 by Willin Kan. Class anti_spam { Function anti_spam (){ If (! Current_user_can ('read ')){ Add_action ('Template _ redirect ', array ($ this, 'W _ TB'), 1 ); Add_action ('init ', array ($ this, 'gate'), 1 ); Add_action ('preprocess _ comment', array ($ this, 'sink'), 1 ); } } //?? Why? Br/> function w_tb (){ If (is_singular ()){ // Non-Chinese? System If (stripos ($ _ SERVER ['http _ ACCEPT_LANGUAGE '], 'zh') = false ){ Add_filter ('comments _ open', create_function (''," return false ;"));//???? } Else { Ob_start (create_function ('$ input', 'Return preg_replace ("# textarea (.*?) Name = (["']) comment (["']) (. +)/textarea> #", "Textarea $1 name = $2 w $3 $4/textarea> <textarea name =" comment "cols =" 100% "rows =" 4 "style =" display: none ">/textarea>", $ input );')); } } } //? Z query Function gate (){ $ W = 'w '; If (! Empty ($ _ POST [$ w]) & empty ($ _ POST ['comment']) { $ _ POST ['comment'] =_ _ POST [$ w]; } Else { $ Request = $ _ SERVER ['request _ URI ']; $ Referer = isset ($ _ SERVER ['http _ referer'])? $ _ SERVER ['http _ referer']: '? '; $ IP = isset ($ _ SERVER ["HTTP_X_FORWARDED_FOR"])? $ _ SERVER ["HTTP_X_FORWARDED_FOR"]. '(transparent? Proxy) ': $ _ SERVER ["REMOTE_ADDR"]; $ Way = isset ($ _ POST [$ w])? 'Hand? Hard copy? ':' Wei ??? Table '; $ Spamcom = isset ($ _ POST ['comment'])? $ _ POST ['comment']: ''; $ _ POST ['spam _ confirmed '] = "? Request: ". $ request." n? ? ". $ Referer." nIP: ". $ IP." n mode: ". $ way." n? Hot? ". $ Spamcom." n --?? Success --"; } } //? Management Function sink ($ comment ){ // Regardless of Trackbacks/Pingbacks If (in_array ($ comment ['Comment _ type'], array ('pingback', 'trackback') return $ comment; // Already? OK? Spam If (! Empty ($ _ POST ['spam _ confirmed ']) { // Method 1: direct? Why? ? Die (); front? Shang Ben ?? Divide h. // Die (); // Method 2 :? Why ?? Spam, stay? Expected ?? Z check? Sentence. Add_filter ('pre _ comment_approved ', create_function ('', 'Return" spam ";')); $ Comment ['Comment _ content'] = "[small ?? Sentence? Consumer @ is Spam! ] N ". $ _ POST ['spam _ confirmed ']; $ This-> add_black ($ comment ); } Else { //? Z query? Image $ F = md5 (strtolower ($ comment ['Comment _ author_email ']); $ G = sprintf ("http: // % d.gravatar.com", (hexdec ($ f {0}) % 2). '/avatar/'. $ f .'? D = 404 '; $ Headers = @ get_headers ($ g ); If (! Preg_match ("| 200 |", $ headers [0]) { //?]? Is the image included ?? (That is, when the first message is sent, it must be reviewed) Add_filter ('pre _ comment_approved ', create_function ('', 'Return" 0 ";')); // $ This-> add_black ($ comment ); } } Return $ comment; } // Enter the black name ?? Br/> function add_black ($ comment ){ If (! ($ Comment_author_url = $ comment ['Comment _ author_url ']) return; If ($ pos = strpos ($ comment_author_url, '//') $ comment_author_url = substr ($ comment_author_url, $ pos + 2 ); If ($ pos = strpos ($ comment_author_url, '/') $ comment_author_url = substr ($ comment_author_url, 0, $ pos ); $ Comment_author_url = strtr ($ comment_author_url, array ('www. '=> '')); If (! Wp_blacklist_check ('','', $ comment_author_url, '') update_option ('Blacklist _ keys ', $ comment_author_url. "n ". get_option ('Blacklist _ keys ')); } } $ Anti_spam = new anti_spam (); // -- END ----------------------------------------
|
Remember to change the w and $ w = 'w' in the middle of the code $2 w $3 $4 to other English letters (but the two must be consistent ), for example, $ 2wc $3 and $ w = 'WC 'Do not let spam discover the amount ^