add honeypot to wp-admin login form
-
This code if form my plugin wp-comment-toolbox as make a honeypot the acts like a one time code
https://github.com/WP-Developer-Hub/wp-comment-toolboxpublic function add_wp_nonce_and_huonoy_pot_field() {
if (get_option('wpct_enable_spam_protect', 0)) {
$textarea_name = str_shuffle(base64_encode(wp_generate_uuid4() . uniqid('', true)));
wp_nonce_field('comment_nonce', 'wpct_comment_nonce');
// Start the session if it's not already started
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
// Store the textarea name in the session variable
$_SESSION['wpct_comment_honeypot_name'] = $textarea_name;
$textarea_section_name = sanitize_text_field($_SESSION['wpct_comment_honeypot_name']);
// Output the hidden textarea field
echo '<p style="display:none">';
echo '<textarea name="' . esc_attr($textarea_section_name) . '" cols="100" rows="10"></textarea>';
echo '<label>' . esc_html__('If you are a human, do not fill in this field.', 'wpct') . '</label>';
echo '</p>';
}
}
- You must be logged in to reply to this topic.