Akismet Class
MeNeedz's robust Akismet Class supports the following features:
- Check comments for spam using the Akismet API
- Report false positives to the Akismet API
- Report false negatives to the Akismet API
Checking for spam
Checking a comment for spam is pretty easy.
Here is a basic example demonstrating how you can check a comment for spam.
Controller
Setting Akismet Preferences
There are 2 ways to set the preferences need to run the Akismet library:
Set the preferences by passing a config array to the init function
$config['api_key'] = 'abc';
$config['application_name'] = 'My application name';
$this->akismet->init($config);
Note: All preferences have default values that will be used if you do not set them.
Setting Akismet Preferences in a Config File
If you prefer not to set preferences using the above method, you can instead put them into a config file. Simply create a new file called the akismet.php, add the $config array in that file. Then save the file at config/akismet.php and it will be used automatically. You will NOT need to use the $this->akismet->init() function if you save your preferences in a config file.
Akismet Preferences
The following is a list of all the preferences that can be set when using Akismet spam protection.
| Preference | Default Value | Options | Description |
|---|---|---|---|
| api_key | NULL | String value | The API-Key you must obtain from http://en.wordpress.com/api-keys/. |
| akismet_server | rest.akismet.com | String value | The Akismet server used to for the requests |
| akismet_version | 1.1 | String value | The version of the Akismet API |
| application_name | My CI Application | String value | The name of your application |
| akismet_version | 1.1 | String value | The version of the Akismet API |
Akismet Function Reference
$this->akismet->comment_is_spam()
Checks a comment for spam:
$akismet = array(
'comment_type' => 'comment',
'comment_author' => 'viagra-test-123',
'comment_author_email' => 'buy_viagra@spam.org',
'comment_author_url' => 'http://www.spam.org',
'comment_content' => 'viagra and other spam stuff',
'permalink' => 'http://www.my_blog.org/perm-link-to-blog-entry-the-comment-was-submitted-to'
);
$this->akismet->comment_is_spam($akismet);
Returns TRUE if it's spam, FALSE if it's not.
$this->akismet->submit_spam()
Let's you submit the given comment as spam to the Akismet API
$akismet = array(
'comment_type' => 'comment',
'comment_author' => 'viagra-test-123',
'comment_author_email' => 'buy_viagra@spam.org',
'comment_author_url' => 'http://www.spam.org',
'comment_content' => 'viagra and other spam stuff',
'permalink' => 'http://www.my_blog.org/perm-link-to-blog-entry-the-comment-was-submitted-to'
);
$this->akismet->submit_spam($akismet);
$this->akismet->submit_ham()
Let's you submit the given comment as no spam to the Akismet API
$akismet = array(
'comment_type' => 'comment',
'comment_author' => 'viagra-test-123',
'comment_author_email' => 'buy_viagra@spam.org',
'comment_author_url' => 'http://www.spam.org',
'comment_content' => 'viagra and other spam stuff',
'permalink' => 'http://www.my_blog.org/perm-link-to-blog-entry-the-comment-was-submitted-to'
);
$this->akismet->submit_ham($akismet);