prevent pointless loading of code
-
From the file /inc/cleantalk-public.php, changed the code layout to prevent loading pointless code. clearly documented. will also post a new apbct-public–gdpr.js without jQuery dependency. just that one file adds nearly 40k to my site
function ct_enqueue_scripts_public($hook){ global $current_user, $ct_data, $ct_options; $ct_options = ct_get_options(); $ct_data = ct_get_data(); if(!empty($ct_options['registrations_test']) || !empty($ct_options['comments_test']) || !empty($ct_options['contact_forms_test']) || !empty($ct_options['general_contact_forms_test']) || !empty($ct_options['wc_checkout_test']) || !empty($ct_options['check_external']) || !empty($ct_options['check_internal']) || !empty($ct_options['bp_private_messages']) || !empty($ct_options['general_postdata_test'])){ /* Andrew Killen: Create Forms array earlier */ $forms_array = isset($ct_options['gdpr_forms_id']) ? explode(', ', $ct_options['gdpr_forms_id']) : array(); /* Andrew Killen: if forms array is empty, don't enqueue the script */ if(!empty($forms_array)){ wp_enqueue_script('ct_public_gdpr', APBCT_URL_PATH.'/js/apbct-public--gdpr.js', array('jquery'), APBCT_VERSION); } /* Andrew Killen: removed dependency on jQuery as apbct-public.js does not have any jQuery in it */ wp_enqueue_script('ct_public', APBCT_URL_PATH.'/js/apbct-public.js', [], APBCT_VERSION, 'in_footer'); /* Andrew Killen: if forms array is empty, the handle will not exist and this will not get added to the html on the page */ wp_localize_script('ct_public_gdpr', 'ctPublic', array( 'gdpr_forms' => $forms_array, 'gdpr_text' => isset($ct_options['gdpr_text']) ? $ct_options['gdpr_text'] : __('By using this form you agree with the storage and processing of your data by using the Privacy Policy on this website.', 'cleantalk'), )); }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘prevent pointless loading of code’ is closed to new replies.