• Resolved Preetinder Singh

    (@preetindersodhi)


    Please convert the javascript code to vanilla javascript.

    jQuery is very bloated and affects the performance of the website.

    Plain javascript version:

    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') {
    wpae_add_honeypot_field();
    }

    if (wpa_add_test === 'yes') {
    wpa_add_test_block();
    }
    });

    function wpa_act_as_spam() {
    var button = document.querySelector('span.wpa-button');
    var actiontype = button.getAttribute('data-actiontype');

    if (actiontype === 'remove') {
    wpa_remove_honeypot_field();
    button.setAttribute('data-actiontype', 'add');
    button.innerHTML = 'Acting as Spam Bot';
    } else {
    wpa_add_honeypot_field();
    button.setAttribute('data-actiontype', 'remove');
    button.innerHTML = 'Act as Spam Bot';
    }
    }

    function wpa_add_honeypot_field() {
    var selectors = [
    'form.wpcf7-form, .wpcf7 form',
    'form.wpforms-form',
    '.gform_wrapper form',
    '.frm_forms form',
    '.caldera-grid form',
    '.wp-block-toolset-cred-form form',
    'form.cred-user-form',
    'form.cred-form',
    'form.et_pb_contact_form',
    'form.fb_form',
    'form.elementor-form',
    'form.form-contribution',
    'form.cart',
    'form#learn-press-checkout-form',
    'form.wpa_form',
    '.wpa_form form',
    'form.spectra-pro-login-form',
    'form#loginform',
    'form#edd_login_form',
    'form.uwp-login-form',
    '.et_pb_login_form form',
    'form.eael-login-form',
    'form#commentform',
    'form.ast-commentform',
    'form#fl-comment-form',
    'form.comment-form',
    '.review-form form',
    'form#edd-reviews-form',
    '.bbp-topic-form form',
    '.bbp-reply-form form'
    ];

    document.querySelectorAll(selectors.join(', ')).forEach(function (form) {
    form.insertAdjacentHTML('beforeend', wpa_hidden_field);
    });

    document.querySelectorAll('form.frm-fluent-form, .ff_conv_app').forEach(function (form) {
    form.insertAdjacentHTML('beforeend', wpa_hidden_field);
    });

    if (typeof fluent_forms_global_var_1 !== 'undefined') {
    fluent_forms_global_var_1.extra_inputs[wpa_field_name] = wpa_unique_id;
    fluent_forms_global_var_1.extra_inputs['alt_s'] = '';
    }

    document.querySelectorAll('input.wpa_initiator').forEach(function (input) {
    var form = input.closest('form');
    if (form && form.querySelector('.wpa_hidden_field') === null) {
    input.insertAdjacentHTML('afterend', wpa_hidden_field);
    }
    });
    }

    function wpa_add_test_block() {
    var testBlock = "<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(function (el) { el.remove(); });
    document.querySelectorAll('span.wpa_hidden_field').forEach(function (el) {
    el.insertAdjacentHTML('afterend', testBlock);
    });
    }

    function wpa_remove_honeypot_field() {
    document.querySelectorAll('.wpa_hidden_field, #altEmail_container, .altEmail_container').forEach(function (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'];
    }
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Dnesscarkey

    (@dnesscarkey)

    Hi Preetinder,

    Thank you for your feedback! We understand your concern about jQuery and are planning to transition to JavaScript. However, since jQuery comes bundled with WordPress by default, we initially chose to go with it for compatibility reasons.

    With over 200K active installations, making major changes requires careful implementation to avoid breaking existing setups, especially with caching plugins in use. We want to ensure a smooth transition without disrupting functionality.

    That said, we truly appreciate your input and will keep it in mind as we work towards optimizing the plugin.

    Thanks

    Thread Starter Preetinder Singh

    (@preetindersodhi)

    Thank you. WordPress itself does not load jQuery on front-end by default unless it is added by theme or any plugin.

    I avoid plugins that add a lot of code, but I love your plugin. I’ve tried many different anti-spam plugins. I’m using it on around 50 sites and I want to add it to 200 more, but jQuery is a problem.

    Plain javascript won’t require anything else, there’s no reason why it would break the site.

    Caching could break site, if it unloads jQuery but still loads the old jQuery based code, but why would that happen in the first place? JS file will have a new version attached to it, so server would serve new code, not old.

    It’s difficult to achieve core web vitals if you have jQuery on your site. Please switch to plain javascript code. Thanks for creating such an awesome plugin!

    Plugin Author Dnesscarkey

    (@dnesscarkey)

    Hi Preetinder,

    Thank you for your detailed feedback and for supporting our plugin! We understand the concerns regarding jQuery and its impact on core web vitals. We will definitely look into the possibility of switching to plain JavaScript in future updates.

    Appreciate your support and insights!

    Best,

    Thread Starter Preetinder Singh

    (@preetindersodhi)

    Any update regarding this? It’s been over a month. Because of your plugin, I’m unable to pass the core web vitals test, as your plugin loads jQuery.

    Kindly convert the Javascript code so it does not require jQuery. Unnecessary bloat, awful for performance. Please make the plugin lightweight.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.