wpcf7_akismet_submitted_params()
Returns an array of parameters based on the current form submission. Returns false if Akismet is not active on the contact form.
Хуков нет.
Возвращает
null. Ничего (null).
Использование
wpcf7_akismet_submitted_params();
Код wpcf7_akismet_submitted_params() wpcf7 akismet submitted params CF7 6.1.6
function wpcf7_akismet_submitted_params() {
$akismet_tags = array_filter(
wpcf7_scan_form_tags(),
static function ( $tag ) {
$akismet_option = $tag->get_option( 'akismet',
'(author|author_email|author_url)',
true
);
return (bool) $akismet_option;
}
);
if ( ! $akismet_tags ) { // Akismet is not active on this contact form.
return false;
}
$params = array(
'author' => '',
'author_email' => '',
'author_url' => '',
'content' => '',
);
foreach ( (array) $_POST as $key => $val ) {
if ( str_starts_with( $key, '_wpcf7' ) or '_wpnonce' === $key ) {
continue;
}
$vals = array_filter(
wpcf7_array_flatten( $val ),
static function ( $val ) {
return '' !== trim( $val );
}
);
if ( empty( $vals ) ) {
continue;
}
if ( $tags = wpcf7_scan_form_tags( array( 'name' => $key ) ) ) {
$tag = $tags[0];
$akismet_option = $tag->get_option( 'akismet',
'(author|author_email|author_url)',
true
);
if ( 'author' === $akismet_option ) {
$params['author'] = sprintf(
'%s %s',
$params['author'],
implode( ' ', $vals )
);
continue;
}
if (
'author_email' === $akismet_option and
'' === $params['author_email']
) {
$params['author_email'] = $vals[0];
continue;
}
if (
'author_url' === $akismet_option and
'' === $params['author_url']
) {
$params['author_url'] = $vals[0];
continue;
}
$vals = array_filter(
$vals,
static function ( $val ) use ( $tag ) {
if (
wpcf7_form_tag_supports( $tag->type, 'selectable-values' ) and
in_array( $val, $tag->labels, true )
) {
return false;
} else {
return true;
}
}
);
}
if ( $vals ) {
$params['content'] .= "\n\n" . implode( ', ', $vals );
}
}
$params = array_map( 'trim', $params );
return $params;
}