Skip to content

Commit a735fcf

Browse files
committed
Add filter to change honeypot styles
This filter can be used to change the styles of the honeypot field. It can also use an empty value, and then load the styles from an external file, if a strict CSP is used for the site.
1 parent 5dbd8f1 commit a735fcf

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

antispam_bee.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -1305,11 +1305,25 @@ public static function replace_comment_field_callback( $matches ) {
13051305
}
13061306
}
13071307

1308+
/**
1309+
* Filter to change the inline styles of the honeypot field.
1310+
*
1311+
* This filter can also be used to use an empty value and load the styles from an external file, if a strict
1312+
* CSP is used for the site.
1313+
*
1314+
* @see: https://wordpress.org/support/topic/honeypot-textarea-visible-with-strict-csp-header/
1315+
*
1316+
* @param string $honeypot_styles The inline styles for the honeypot.
1317+
*
1318+
* @return string The inline styles for the honeypot.
1319+
*/
1320+
$honeypot_styles = apply_filters( 'antispam_bee_honeypot_styles', 'padding:0 !important;clip:rect(1px, 1px, 1px, 1px) !important;position:absolute !important;white-space:nowrap !important;height:1px !important;width:1px !important;overflow:hidden !important;' );
1321+
13081322
$output .= ' name="' . esc_attr( self::get_secret_name_for_post( self::$_current_post_id ) ) . '" ';
13091323
$output .= $matches['between1'] . $matches['between2'] . $matches['between3'];
13101324
$output .= $matches['after'] . '>';
13111325
$output .= $matches['content'];
1312-
$output .= '</textarea><textarea id="comment" aria-label="hp-comment" aria-hidden="true" name="comment" autocomplete="new-password" style="padding:0 !important;clip:rect(1px, 1px, 1px, 1px) !important;position:absolute !important;white-space:nowrap !important;height:1px !important;width:1px !important;overflow:hidden !important;" tabindex="-1"></textarea>';
1326+
$output .= '</textarea><textarea id="comment" aria-label="hp-comment" aria-hidden="true" name="comment" autocomplete="new-password" style="' . esc_attr( $honeypot_styles ) . '" tabindex="-1"></textarea>';
13131327

13141328
$output .= $id_script;
13151329
$output .= $init_time_field;

0 commit comments

Comments
 (0)