I have several inputboxes and no textareas in my custom content type. Can I use Akismet that comes with WP for that? If I can, how to do that?
E.g. If I have 5 inputboxes like: name, address, city, telephone, email in my form that is saved from the front page and is used for further processing.
How to use Akismet on that? Is it possible?
if the names of the inputbosex are: name, address, city, telephone and emai, how would you set up the Akismet plugin. What should be done so no spams are saved in my db? (I need to filter the data before being saved to data using akismet in my function in functions.php. So if I get the values like e.g.
$name = $_POST['name'];
$name = $_POST['address'];
$name = $_POST['city'];
$name = $_POST['telephone'];
$name = $_POST['email'];
// here I need if condition to use akismet database to redirect back to the post without executing the rest of my code in my function.
How to do such condition using the Akismet plugin that comes with WordPress?
Akismet – libraries:
First I want to mention that there are many Akismet libraries out there:
http://akismet.com/development/
and here are the API documents:
http://akismet.com/development/api/
Akismet – WordPress plugin:
But as I understand it, you want to use the Akismet WordPress plugin as your library.
The following code snippet is a simple proof of concept, based on the Akismet plugin:
// We assume that Akismet is installed with the corresponding API key
if( function_exists( 'akismet_http_post' ) )
{
global $akismet_api_host, $akismet_api_port;
// data package to be delivered to Akismet (Modify this to your needs)
$data = array(
'comment_author' => 'Mr. Spam',
'comment_author_email' => 'mr.spam@ispamalot.com',
'comment_author_url' => 'spamalot.com',
'comment_content' => 'Hello Spam World!',
'user_ip' => '123.123.123.123',
'user_agent' => '',
'referrer' => '',
'blog' => 'http://example.com',
'blog_lang' => 'en_US',
'blog_charset' => 'UTF-8',
'permalink' => 'http://example.com/hello-world',
'is_test' => TRUE,
);
// construct the query string
$query_string = http_build_query( $data );
// post it to Akismet
$response = akismet_http_post( $query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port );
// check the results
$result = ( is_array( $response ) && isset( $response[1] ) ) ? $response[1] : 'false';
// display the result (it can be 'true', 'false' or some error message )
printf( 'Is it spam? Akismet says: %s', $result );
}
where I use the akismet_http_post
function to post the data to the Akismet servers.
According to the API docs, the following parameters are required:
blog, user_ip, user_agent
and one should be careful regarding the spelling of the referrer
parameter 😉
Other useful Akismet functions are for example:
- akismet_get_key()
- akismet_check_key_status()
- akismet_verify_key()
The response I got when testing a real spam comment, was like this:
Array
(
[0] => Array
(
[server] => nginx
2025 => Wed, 23 Oct 2013 12:44:37 GMT
[content-type] => text/plain; charset=utf-8
[content-length] => 4
[connection] => close
[x-akismet-server] => 192.0.80.244
[x-akismet-guid] => 07d0136b53cda37432ff5a7b6d86c843
)
[1] => true
)
with the positive (true) spam result.
The next step would be to modify this into a usable function or a class.
Since you’re using some custom form fields, I think you could map them like this:
name --> comment_author
email --> comment_author_email
address + city + telephone --> comment_content