How to Block Spam Words in WPForms Without Premium Version ??
MUHAMMAD HAMZA
Beyond Transactions: Building Lasting E-Commerce Relationships and Revenue! ???? #ECommerceExpert #Onlinestore
Spam submissions cluttering your WPForms? Fret not! With a simple tweak, you can effectively block spam words without the need for the premium version. Are you tired of sifting through form submissions cluttered with spammy offers and promotions? In today's digital landscape, every cent counts, and every interaction matters.
But fear not! There's a cost-effective solution to combat spam and maintain the integrity of your form submissions without breaking the bank Follow these steps to reclaim control over your form submissions:
Important: Before proceeding with any code modifications, make sure to back up your website to prevent data loss in case of any unexpected issues.
Step 1: Access Your WordPress Dashboard
Step 2: Navigate to the WPForms Plugin
Step 3: Find the Form ID
Step 4: Update the Code with the Form ID
领英推荐
Step 5: Integrate Form ID into Code
function custom_wpforms_validate( $fields, $entry, $form_data ) {
if ( ! defined( 'WP_DEBUG' ) ) {
define( 'WP_DEBUG', true );
}
if ( ! defined( 'WP_DEBUG_LOG' ) ) {
define( 'WP_DEBUG_LOG', true );
}
// Log the form ID being processed
error_log( 'Validating form ID: ' . $form_data['id'] );
// List of form IDs to apply the validation to
$form_ids_to_validate = array( 5846, 5526, 5447 );
if ( in_array( $form_data['id'], $form_ids_to_validate ) ) {
$blocked_words = array(
'job', 'offer', 'seo', 'service', 'promotion', 'free', 'money', 'cash',
'earn', 'income', 'investment', 'loan', 'credit', 'mortgage', 'insurance',
'discount', 'deal', 'bargain', 'cheap', 'save', 'winner', 'winning',
'prize', 'bonus', 'gift', 'click', 'buy', 'purchase', 'order', 'subscribe',
'signup', 'sign up', 'sale', 'special', 'urgent', 'limited', 'hurry',
'act now', 'exclusive', 'trial', 'risk-free', 'guarantee', 'offer expires'
);
foreach ( $fields as $field_id => $field ) {
foreach ( $blocked_words as $word ) {
if ( stripos( $field['value'], $word ) !== false ) {
error_log( 'Blocked word found: ' . $word );
wpforms()->process->errors[$form_data['id']][$field_id] = 'This field contains forbidden words.';
break;
}
}
}
}
}
add_action( 'wpforms_process', 'custom_wpforms_validate', 10, 3 );
?
Step 6: Test Your Forms
Step 7: Monitor Form Submissions
?
Conclusion
We hope this code and guide will work for you and help you keep your WPForms submissions clean from spam words. By following these steps, you can save time and maintain the quality of your data without incurring additional costs. However, if you still face any issues or need further assistance, we are here to help you. Feel free to reach out with any questions or concerns, and we’ll be happy to assist you!
?