Advertisement
developerjustin

Untitled

Dec 19th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.51 KB | None | 0 0
  1. include 'akismet.class.php';
  2.  
  3. // Load array with comment data.
  4. $comment = array(
  5.                 'author' => 'viagra-test-123',
  6.                 'email' => 'test@example.com',
  7.                 'website' => 'http://www.example.com/',
  8.                 'body' => 'This is a test comment',
  9.                 'permalink' => 'http://your-domain.com/path-to-your-comment-page',
  10.                 'user_ip' => 'an-ip-address', // Optional, if not in array defaults to $_SERVER['REMOTE_ADDR'].
  11.                 'user_agent' => 'user-agent-string', // Optional, if not in array defaults to $_SERVER['HTTP_USER_AGENT'].
  12.         );
  13.        
  14. // Instantiate an instance of the class.
  15. $akismet = new Akismet('http://www.yourdomain.com/', 'YOUR_WORDPRESS_API_KEY', $comment);
  16.  
  17. // Test for errors.
  18. if($akismet->errorsExist()) { // Returns true if any errors exist.
  19.         if($akismet->isError('AKISMET_INVALID_KEY')) {
  20.                 // Do something.
  21.         } elseif($akismet->isError('AKISMET_RESPONSE_FAILED')) {
  22.                 // Do something.
  23.         } elseif($akismet->isError('AKISMET_SERVER_NOT_FOUND')) {
  24.                 // Do something.
  25.         }
  26. } else {
  27.         // No errors, check for spam.
  28.         if ($akismet->isSpam()) { // Returns true if Akismet thinks the comment is spam.
  29.                 // Do something with the spam comment.
  30.         } else {
  31.                 // Do something with the non-spam comment.
  32.         }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement