Akismet class
Possible Methods
__construct
Default constructor
Creates an instance of the Akismet Class.
Parameters
- apiKey string
- The API key being verified for use with the API.
- url string
- The front page or home URL of the instance making the request. For a blog or wiki this would be the front page. Note: Must be a full URI, including http://.
Return
void
Example
<?php
// require class
require_once 'akismet.php';
// create instance
$akismet = new Akismet('<your-api-key>', '<your-url>');
?>
setTimeOut
Set the timeout
After this time the request will stop. You should handle any errors triggered by this.
Parameters
- seconds int
- The timeout in seconds.
Return
void
setUserAgent
Set the user-agent for you application
It will be appended to ours, the result will look like: "PHP Akismet/<version> <your-user-agent>"
Parameters
- userAgent string
- Your user-agent, it should look like <app-name>/<app-version>.
Return
void
verifyKey
Verifies the key
Return
bool If the key is valid it will return true, otherwise false will be returned.
Example
<?php
// require class
require_once 'akismet.php';
// create instance
$akismet = new Akismet('<your-api-key>', '<your-url>');
echo $akismet->verifyKey();
?>
isSpam
Check if the comment is spam or not
This is basically the core of everything. This call takes a number of arguments and characteristics about the submitted content and then returns a thumbs up or thumbs down.
Almost everything is optional, but performance can drop dramatically if you exclude certain elements.
REMARK: If you are having trouble triggering you can send "viagra-test-123" as the author and it will trigger a true response, always.
Parameters
- content string (optional)
- The content that was submitted.
- author string (optional)
- Commenters name.
- email string (optional)
- Commenters email address.
- url string (optional)
- Commenters URL.
- permalink string (optional)
- The permanent location of the entry the comment was submitted to.
- type string (optional)
- May be blank, comment, trackback, pingback, or a made up value like "registration".
Return
bool If the comment is spam true will be returned, otherwise false.
Example
<?php
// require class
require_once 'akismet.php';
// create instance
$akismet = new Akismet('<your-api-key>', '<your-url>');
echo $akismet->isSpam('Hello, this is just a comment.', 'Tijs Verkoyen',
'email@domain.com', 'http://classes.verkoyen.eu',
'http://classes.verkoyen.eu/akismet', 'comment');
?>
submitHam
Submit ham to Akismet
This call is intended for the marking of false positives, things that were incorrectly marked as spam.
Parameters
- userIp string
- IP address of the comment submitter.
- userAgent string
- User agent information.
- content string (optional)
- The content that was submitted.
- author string (optional)
- Submitted name with the comment.
- email string (optional)
- Submitted email address.
- url string (optional)
- Commenter URL.
- permalink string (optional)
- The permanent location of the entry the comment was submitted to.
- type string (optional)
- May be blank, comment, trackback, pingback, or a made up value like "registration".
- referrer string (optional)
- The content of the HTTP_REFERER header should be sent here.
- others array (optional)
- Other data (the variables from $_SERVER).
Return
bool If everything went fine true will be returned, otherwise an exception will be triggered.
submitSpam
Submit spam to Akismet
This call is for submitting comments that weren't marked as spam but should have been.
Parameters
- userIp string
- IP address of the comment submitter.
- userAgent string
- User agent information.
- content string (optional)
- The content that was submitted.
- author string (optional)
- Submitted name with the comment.
- email string (optional)
- Submitted email address.
- url string (optional)
- Commenter URL.
- permalink string (optional)
- The permanent location of the entry the comment was submitted to.
- type string (optional)
- May be blank, comment, trackback, pingback, or a made up value like "registration".
- referrer string (optional)
- The content of the HTTP_REFERER header should be sent here.
- others array (optional)
- Other data (the variables from $_SERVER).
Return
bool If everything went fine true will be returned, otherwise an exception will be triggered.