

















For twenty years, Akismet has kept spam out of WordPress. But spammers don’t care what your site runs on and neither do we.
Last month we launched the official Akismet Drupal module. Today we’re introducing the engine that powers it: the official Akismet PHP SDK, a first-party client that brings Akismet to any PHP application.
The Akismet PHP SDK is a first-party PHP client for the Akismet API. It’s built for the platforms the WordPress plugin doesn’t reach: custom apps, SaaS backends, and PHP frameworks like Laravel and Symfony. (The official plugins are still the way to go for WordPress and Drupal.)
Under the hood it’s built to feel at home in a modern PHP codebase:
Install it with Composer:
composer require automattic/akismet-sdk
Then check a submission:
use Automattic\Akismet\Akismet;
use Automattic\Akismet\DTO\Content;
use Automattic\Akismet\Enum\ContentType;
$akismet = Akismet::create(
apiKey: 'your-api-key',
site: 'https://your-site.com',
);
$content = new Content(
userIp: $_SERVER['REMOTE_ADDR'],
userAgent: $_SERVER['HTTP_USER_AGENT'],
body: $formData['message'],
authorEmail: $formData['email'],
type: ContentType::ContactForm,
);
$result = $akismet->check($content);
if ($result->isSpam()) {
// Reject it, flag it, or queue it for review.
// $result->shouldDiscard() marks the blatant spam you can drop outright.
}
That’s the loop: build a Content object, call check(), act on the result.
The official Akismet Drupal module is built on this SDK. The SDK handles the API contract and type safety, while the module handles Drupal’s service wiring, queues, and moderation UI. That’s the pattern for Laravel, Symfony, and anything else you build: the SDK owns the Akismet integration and your framework owns the glue.
We have just released v1.5.0, which is about giving Akismet more to work with, and giving you more back:
Content now carries the site’s language and character set, plus the surrounding conversation context, so every check has more to go on.CheckResult now surfaces the error and classification Akismet returns, so you can log and act on why something was flagged, not just whether it was.The SDK is open source and live on Packagist today.
composer require automattic/akismet-sdkYou’ll need an Akismet API key to make calls. Akismet’s Personal plan is pay-what-you-can and free for personal, non-commercial sites. If you’re running something commercial, pick a paid plan that matches your traffic. Either way your code stays identical, since the plan lives with your API key, not in the SDK.
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。