forked from LiveCarta/LiveCartaWP
131 lines
5.5 KiB
JavaScript
131 lines
5.5 KiB
JavaScript
var wpa_field_name, wpa_unique_id, wpa_add_test, wpa_hidden_field;
|
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
wpa_field_name = wpa_field_info.wpa_field_name;
|
|
wpa_unique_id = wpa_field_info.wpa_field_value;
|
|
wpa_add_test = wpa_field_info.wpa_add_test;
|
|
|
|
wpa_hidden_field = "<div id='altEmail_container' class='altEmail_container'><label for='alt_s'>Alternative:</label><input type='text' id='alt_s' name='alt_s' ></div><span class='wpa_hidden_field' style='display:none;height:0;width:0;'><label>WPA <input type='text' name='"+wpa_field_name+"' value='"+wpa_unique_id+"' /></label></span>";
|
|
|
|
wpa_add_honeypot_field();
|
|
|
|
if (typeof wpae_add_honeypot_field === 'function') { // IF EXTENDED version exists.
|
|
wpae_add_honeypot_field();
|
|
}
|
|
|
|
if (wpa_add_test === 'yes') {
|
|
wpa_add_test_block();
|
|
}
|
|
});
|
|
|
|
function wpa_act_as_spam() {
|
|
const wpaButton = document.querySelector('span.wpa-button');
|
|
const actiontype = wpaButton.dataset.actiontype;
|
|
|
|
if (actiontype === 'remove') {
|
|
wpa_remove_honeypot_field();
|
|
wpaButton.dataset.actiontype = 'add';
|
|
wpaButton.textContent = 'Acting as Spam Bot';
|
|
} else {
|
|
wpa_add_honeypot_field();
|
|
wpaButton.dataset.actiontype = 'remove';
|
|
wpaButton.textContent = 'Act as Spam Bot';
|
|
}
|
|
}
|
|
|
|
function wpa_add_honeypot_field() {
|
|
// Combined form selectors
|
|
const allFormSelectors = [
|
|
// Main forms
|
|
'form.wpcf7-form, .wpcf7 form', // CONTACT FORM 7
|
|
'form.wpforms-form', // WPForms
|
|
'.gform_wrapper form', // Gravity Forms
|
|
'.frm_forms form', // Formidable Forms
|
|
'.caldera-grid form', // Caldera Forms
|
|
'.wp-block-toolset-cred-form form', // Toolset Forms
|
|
'form.cred-user-form', // Toolset Forms
|
|
'form.cred-form', // Toolset Forms
|
|
'form.et_pb_contact_form', // Divi Form
|
|
'form.fb_form', // Divi Form Builder - Divi Engine
|
|
'form.elementor-form', // Elementor
|
|
'form.form-contribution', // WooCommerce Reviews Pro
|
|
'form.cart', // WooCommerce Cart
|
|
'form#learn-press-checkout-form', // LearnPress Checkout Form
|
|
|
|
'form.wpa_form', // Generic Class
|
|
'.wpa_form form', // Generic Class
|
|
|
|
'.um-form form', // Ulimate Membership Form
|
|
|
|
// Login forms
|
|
'form.spectra-pro-login-form', // SPECTRA LOGIN FORM
|
|
'form#loginform', // Default Login Form
|
|
'form#edd_login_form', // EDD LOGIN FORM
|
|
'form.uwp-login-form', // USER WP LOGIN FORM
|
|
'.et_pb_login_form form', // For Elementor login form
|
|
'form.eael-login-form', // essential-addons login form
|
|
'form.user-registration-form-login', // User Registration & Membership for WordPress
|
|
|
|
'form#lostpasswordform', // Lost Password Form
|
|
'form.lost_reset_password', // Tutor Password Form
|
|
'form.ur_lost_reset_password', // User Registration & Membership for WordPress
|
|
|
|
//Registration Forms
|
|
'form.register', // User Registration & Membership for WordPress
|
|
|
|
// Comment forms
|
|
'form#commentform', // WP Comment with ID
|
|
'form.ast-commentform', // Astra Comment Form with class
|
|
'form#fl-comment-form', // Beaver Builder Theme Form with ID
|
|
'form.comment-form', // WP Comment with class
|
|
'.review-form form', // LearnPress Review
|
|
'form#edd-reviews-form', // EDD Reviews with ID
|
|
'form.wpr-comment-form',
|
|
|
|
// BBPress forms
|
|
'.bbp-topic-form form', // BBPress Topic Form
|
|
'.bbp-reply-form form' // BBPress Reply Form
|
|
];
|
|
|
|
const forms = document.querySelectorAll(allFormSelectors.join(', '));
|
|
forms.forEach(form => {
|
|
form.insertAdjacentHTML('beforeend', wpa_hidden_field);
|
|
});
|
|
|
|
// FOR FLUENT FORMS
|
|
const fluentForms = document.querySelectorAll('form.frm-fluent-form, .ff_conv_app');
|
|
fluentForms.forEach(form => {
|
|
form.insertAdjacentHTML('beforeend', wpa_hidden_field);
|
|
});
|
|
|
|
if (typeof fluent_forms_global_var_1 !== 'undefined') { // QUICK HACK FOR FLUENT FORMS CONVERSIONAL
|
|
fluent_forms_global_var_1.extra_inputs[wpa_field_name] = wpa_unique_id;
|
|
fluent_forms_global_var_1.extra_inputs['alt_s'] = '';
|
|
}
|
|
// EOF FLUENT FORMS
|
|
|
|
const wpaInitiators = document.querySelectorAll('input.wpa_initiator');
|
|
wpaInitiators.forEach(initiator => {
|
|
const form = initiator.closest('form');
|
|
if (form && !form.querySelector('.wpa_hidden_field')) {
|
|
initiator.insertAdjacentHTML('afterend', wpa_hidden_field);
|
|
}
|
|
});
|
|
}
|
|
|
|
function wpa_add_test_block() {
|
|
const checkingTest = '<div class="wpa-test-msg"><strong>WP Armour ( Only visible to site administrators. Not visible to other users. )</strong><br />This form has a honeypot trap enabled. If you want to act as spam bot for testing purposes, please click the button below.<br/><span class="wpa-button" onclick="wpa_act_as_spam()" data-actiontype="remove">Act as Spam Bot</span></div>';
|
|
document.querySelectorAll('.wpa-test-msg').forEach(el => el.remove());
|
|
document.querySelectorAll('span.wpa_hidden_field').forEach(span => {
|
|
span.insertAdjacentHTML('afterend', checkingTest);
|
|
});
|
|
}
|
|
|
|
function wpa_remove_honeypot_field() {
|
|
document.querySelectorAll('.wpa_hidden_field, #altEmail_container, .altEmail_container').forEach(el => el.remove());
|
|
|
|
if (typeof fluent_forms_global_var_1 !== 'undefined') {
|
|
delete fluent_forms_global_var_1.extra_inputs[wpa_field_name];
|
|
delete fluent_forms_global_var_1.extra_inputs['alt_s'];
|
|
}
|
|
} |