• Resolved Andrew Killen

    (@andrewkillen)


    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)
  • Plugin Support SergeM

    (@serge00)

    Hello.

    Thank you for your request.

    I have transferred your suggestions to our development team.

    We will inform you if we make any changes based on them.

    Your CleanTalk Control Panel: [ https://cleantalk.org/my/ ].

    Best regards.

    Hello,

    You’re correct again. Unfortunately we can not use it =(
    Users modify ctPublic via shortcodes and add forms to it.
    The code you edited was “overcoded” for the future in case we make setting field in plugin settings.

    This will patch will fix this problem correctly:

    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'])){
    		
    		wp_enqueue_script('ct_public',      APBCT_URL_PATH.'/js/apbct-public.js',       array(''), APBCT_VERSION, 'in_footer');
    		
    		if(shortcode_exists( 'cleantalk_gdpr_form')){
    			
    			wp_enqueue_script('ct_public_gdpr', APBCT_URL_PATH.'/js/apbct-public--gdpr.js', array(''), APBCT_VERSION);
    		
    			wp_localize_script('ct_public_gdpr', 'ctPublic', array(
    				'gdpr_forms'   => isset($ct_options['gdpr_forms_id']) ? explode(', ', $ct_options['gdpr_forms_id']) : 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'),
    			));
    		}
    		
    	}

    We’ll include it in the next release. Thank you once again!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘prevent pointless loading of code’ is closed to new replies.