Akismet PHP 7 class
, (*1)
A PHP-7 class to communicate with Akismet service to determine if a submitted comment to your website should be considered spam or not., (*2)
Installation
Requirements
Steps to install
Run : composer require romano83/akismet
or in your composer.json file, (*3)
"require": {
"romano83/akismet" : "^1.0"
}
How to use it
Before to use it, you need an Akismet API key.
Once you have one, in order to check if a comment is a spam:, (*4)
<?php
use Romano83\Akismet;
$website = 'https://your-website.com'; // must be a full URI including http:// or https://
$apikey = 'YOUR_API_KEY';
$akismet = new Akismet($website, $apikey);
$akismet->setCommentAuthor($author)
->setCommentAuthorEmail($email)
->setCommentContent($comment);
if ($akismet->isCommentSpam()) {
// store the comment and mark it as a spam
} else {
// store the comment normally
}
It's that simple!, (*5)
If Akismet filter wrongly tags messages, you can use this following methods :, (*6)
$akismet->submitSpam();
or, (*7)
$akismet->submitHam();
to submit mis-diagnosed spam and ham, which improves the system for everybody., (*8)
Others methods
This class provides you a set of methods in order to add parameters for comment check or submitted spam and ham.
This methods are :
* setUserIp (required)
* setUserAgent (required)
* setReferrer (note spelling)
* setPermalink
* setCommentType
* setCommentAuthor
* setCommentAuthorEmail
* setCommentAuthorUrl
* setCommentContent
* setCommentDateGmt
* setCommentPostModifiedGmt
* setBlogLang
* setBlogCharset
* setUserRole
* setIsTest, (*9)
All methods return self in order to have a fluent interface., (*10)
If you want more details for each method, look at the internal documentation or follow this link., (*11)
How to contribute
- create a ticket in Github if you have found a bug.
- create a new branch if you want to do a PR.
- you must add testcases