• Resolved Oleg Komarovskyi

    (@komarovski)


    Hello, I need help with understanding how to make gutenberg block work with ESI.

    Here’s an example of code in my functions.php.

    I have ESI function that I use in different places of the website template (and it’s working fine), but I also want to use it in custom gutenberg block.

    I have registered gutenberg block with “acf_register_block” function, and used a callback, but nothing’s working in that gutenberg block.

    /*ESI COUNTRY NAME*/
    function esi_country_name(){
    	do_action('litespeed_control_set_nocache');
    	$country_detect = do_shortcode('[useriploc type="country"]'); //Get user country name by ip
    	if($country_detect){
    		$country_name = 'Your country is '.$country_detect.'.';
    	}else{
    		$country_name = 'Your country not detected.';
    	}
    	echo $country_name;
    }
    add_action('litespeed_esi_load-esi_block_country_name', 'esi_country_name');
    
    /*REGISTER GUTENBERG BLOCK WITH ACF*/
    function acf_gutenberg_blocks_init(){
    	if(function_exists('acf_register_block')){
    		acf_register_block(array(
    			'name'=>'user_location',
    			'title'=>'User Location',
    			'description'=>'Get user location by ip.',
    			'render_callback'=>'user_location_acf_block_render_callback',
    			'category'=>'formatting',
    			'icon'=>'menu',
    			'mode'=>'edit',
    			'keywords'=>array('user location'),
    		));
    	}
    }
    add_action('acf/init', 'acf_gutenberg_blocks_init');
    
    /*USER LOCATION CALLBACK*/
    function user_location_acf_block_render_callback($block){
    	echo '<p>'.apply_filters('litespeed_esi_url', 'esi_block_country_name', 'Country Name').'</p>';
    }
Viewing 1 replies (of 1 total)
  • Plugin Support usabe

    (@usabe)

    Hi @komarovski

    Sorry we have missed this topic in the past.

    Due to inactivity of this topic, I will mark this topic as “resolved”. If you still have such issues, please feel free to open a ticket with further information by emailing to [email protected]. Remember to reference this topic and?ask to assign your ticket to?Abe.?I will check into this further from there.

Viewing 1 replies (of 1 total)
  • The topic ‘Gutenberg blocks and ESI doesn’t work’ is closed to new replies.