The
Akismet API documentation describes the low level interface. Its intended audience is authors of code such as the Akismet PHP 5 class used in R3-born. As such, it contains some information you don't need to know or be concerned with, but it may help you understand what the Akismet class is doing.
Using the Class
The Akismet class takes care of all the connection and communications with the Akismet server and gives you a simpler high level interface.
Example 1, submitting a comment to be checked:
Код: |
include 'class_akismet5.php';
// instantiate an instance of the class
$akismet = new Akismet('http://www.yourdomain.com/', 'YOUR_WORDPRESS_API_KEY');
$akismet->setCommentAuthor('viagra-test-123');
$akismet->setCommentAuthorEmail('test@example.com');
$akismet->setCommentAuthorURL('http://www.example.com/');
$akismet->setCommentContent('This is a test comment');
$akismet->setPermalink(''http://your-domain.com/path-to-your-comment-page');
$akismet->setCommentType(comment);// type: comment,pingback or trackback
$akismet->setUserIP('an-ip-address');// optional, if not in array defaults to $_SERVER['REMOTE_ADDR']
// test for error
// Was the server down?
if ($akismet_return === 'conn_error')
{
// Assume it's not spam. We log an error to the error log later
$error = $lang['Akismet_response_failed'];
//The comment can't be tagged as Spam is there was an Akismet error, therefore approve the comment by log the error.
// do something
}
// Is this... SPAM?!?!?!
elseif ($akismet_return === true)
{
// Oh, the horror! Someone posted spam to your forum!
// do something with the spam comment
//$lang['Akismet_spam'];
}
else
{
//$spam = false;
// do something with the non-spam comment
//$lang['Akismet_ham'];
}
|
Example 2, submitting a mis-diagnosed comment:
You should incorporate the submitSpam() and submitHam() calls in your applications. Doing so helps Akisment improve its spam checking algorithms.
Код: |
// load array with comment data
// instantiate an instance of the class
$akismet = new Akismet('http://www.yourdomain.com/', 'YOUR_WORDPRESS_API_KEY');
$akismet->setCommentAuthor('viagra-test-123');
$akismet->setCommentAuthorEmail('test@example.com');
$akismet->setCommentAuthorURL('http://www.example.com/');
$akismet->setCommentContent('This is a test comment');
$akismet->setPermalink(''http://your-domain.com/path-to-your-comment-page');
$akismet->setCommentType(comment);// type: comment,pingback or trackback
$akismet->setUserIP('an-ip-address');// optional, if not in array defaults to $_SERVER['REMOTE_ADDR']
// submit the ham or spam comment
$akismet->submitHam(); // or submitSpam()
|
References