: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* The Akismet integration module
* @link https://akismet.com/development/api/
wpcf7_include_module_file( 'akismet/service.php' );
'wpcf7_akismet_register_service',
* Registers the Akismet service.
function wpcf7_akismet_register_service() {
$integration = WPCF7_Integration::get_instance();
$integration->add_service( 'akismet',
WPCF7_Akismet::get_instance()
add_filter( 'wpcf7_spam', 'wpcf7_akismet', 10, 2 );
function wpcf7_akismet( $spam, $submission ) {
if ( ! wpcf7_akismet_is_available() ) {
if ( ! $params = wpcf7_akismet_submitted_params() ) {
'comment_type' => 'contact-form',
'comment_author' => $params['author'],
'comment_author_email' => $params['author_email'],
'comment_author_url' => $params['author_url'],
'comment_content' => $params['content'],
'blog_lang' => get_locale(),
'blog_charset' => get_option( 'blog_charset' ),
'user_ip' => $submission->get_meta( 'remote_ip' ),
'user_agent' => $submission->get_meta( 'user_agent' ),
'referrer' => $_SERVER['HTTP_REFERER'] ?? '',
$datetime = date_create_immutable(
'@' . $submission->get_meta( 'timestamp' )
$comment['comment_date_gmt'] = $datetime->format( DATE_ATOM );
if ( $permalink = get_permalink() ) {
$comment['permalink'] = $permalink;
$server_vars = array_diff_key(
array_flip( array( 'HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW' ) )
$comment = array_merge( $comment, $server_vars );
$comment = apply_filters( 'wpcf7_akismet_parameters', $comment );
if ( wpcf7_akismet_comment_check( $comment ) ) {
$submission->add_spam_log( array(
'reason' => __( "Akismet returns a spam response.", 'contact-form-7' ),
* Returns true if Akismet is active and has a valid API key.
function wpcf7_akismet_is_available() {
if ( is_callable( array( 'Akismet', 'get_api_key' ) ) ) {
return (bool) Akismet::get_api_key();
* Returns an array of parameters based on the current form submission.
* Returns false if Akismet is not active on the contact form.
function wpcf7_akismet_submitted_params() {
$akismet_tags = array_filter(
static function ( $tag ) {
$akismet_option = $tag->get_option( 'akismet',
'(author|author_email|author_url)',
return (bool) $akismet_option;
if ( ! $akismet_tags ) { // Akismet is not active on this contact form.
foreach ( (array) $_POST as $key => $val ) {
if ( '_wpcf7' == substr( $key, 0, 6 )
or '_wpnonce' == $key ) {
wpcf7_array_flatten( $val ),
static function ( $val ) {
return '' !== trim( $val );
if ( $tags = wpcf7_scan_form_tags( array( 'name' => $key ) ) ) {
$akismet_option = $tag->get_option( 'akismet',
'(author|author_email|author_url)',
if ( 'author' === $akismet_option ) {
$params['author'] = sprintf(
if ( 'author_email' === $akismet_option
and '' === $params['author_email'] ) {
$params['author_email'] = $vals[0];
if ( 'author_url' === $akismet_option
and '' === $params['author_url'] ) {
$params['author_url'] = $vals[0];
static function ( $val ) use ( $tag ) {
if ( wpcf7_form_tag_supports( $tag->type, 'selectable-values' )
and in_array( $val, $tag->labels ) ) {
$params['content'] .= "\n\n" . implode( ', ', $vals );
$params = array_map( 'trim', $params );
* @param array $comment Submission and environment data.
* @return bool True if Akismet called it spam, or false otherwise.
function wpcf7_akismet_comment_check( $comment ) {
$query_string = wpcf7_build_query( $comment );
if ( is_callable( array( 'Akismet', 'http_post' ) ) ) {
$response = Akismet::http_post( $query_string, 'comment-check' );
if ( 'true' == $response[1] ) {
if ( $submission = WPCF7_Submission::get_instance() ) {
$submission->push( 'akismet', array(
return apply_filters( 'wpcf7_akismet_comment_check', $spam, $comment );
add_filter( 'wpcf7_posted_data', 'wpcf7_akismet_posted_data', 10, 1 );
* Removes Akismet-related properties from the posted data.
* This does not affect the $_POST variable itself.
* @link https://plugins.trac.wordpress.org/browser/akismet/tags/5.0/_inc/akismet-frontend.js
function wpcf7_akismet_posted_data( $posted_data ) {
if ( wpcf7_akismet_is_available() ) {
$posted_data = array_diff_key(
'wpcf7_default_template',
'wpcf7_akismet_default_template',
function wpcf7_akismet_default_template( $template, $prop ) {
if ( ! wpcf7_akismet_is_available() ) {
if ( 'form' === $prop ) {
'[text* your-name akismet:author ',
'[email* your-email akismet:author_email ',
$privacy_notice = sprintf( '%s %s',
__( "This form uses Akismet to reduce spam.", 'contact-form-7' ),
'https://akismet.com/privacy/',
__( "Learn how your data is processed.", 'contact-form-7' ),
'rel' => 'nofollow noopener',
$template .= "\n\n" . $privacy_notice;