• Resolved Damian

    (@timersys)


    Hi! I have a client with this plugin which needs some functions to run at init hook or a hook near init.
    On WP Supercache or W3 total cache there are option to run in PHP legacy mode or after init hook.
    There is something similar on Litespeed cache plugin that will let me run those functions before the page cache is generated?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author LiteSpeed Technologies

    (@litespeedtech)

    Hi Damian,

    Do you have any specific requirements for the hook? E.g. only when the user is logged in, only when user is visiting admin page, etc.

    For all visitors and pages, we have an action litespeed_cache_detect_thirdparty.

    If it is an ajax request, it will run at the after_setup_theme hook.
    Else if it is an admin page, it will run at the admin_init hook.
    For all other requests, this will run at the wp hook.

    Will this suffice?

    Cheers,
    Kevin

    Thread Starter Damian

    (@timersys)

    Nothing special. I need to run some checks with the Geotargeting plugin that runs at init hook and then perform redirection of the user . I just tried and works perfectly

    Thanks!

    Plugin Author LiteSpeed Technologies

    (@litespeedtech)

    Glad to hear it!

    We do plan to make some changes to the thirdparty integration, but I will make a note to confer with you if we change this hook in any way.

    Cheers,
    Kevin

    Thread Starter Damian

    (@timersys)

    I spoke to soon. I made more tests and it seems that is not working fine. It seems that the hook is not fired on every page load.

    For example I use one browser with VPN and visit a page and If I use another browser without the vpn the user is not being redirected as if they both were from same country.

    IF you want to better understand what Im doing please take a look to the following:

    add_action( 'litespeed_cache_detect_thirdparty', 'geot_custom_redirects');
     
     function geot_custom_redirects() {
        global $geot;
    	
       
        $whitelist = array(
           
            #'24.232.111.111',
    	); 
    
        // if main plugin is not enabled return
        if( ! function_exists( 'geot_target' ) )
            return;
            
        // if search engine exit    
        if( $geot->functions->isSearchEngine() )
            return;
           
        // if is admin  return    
        if( current_user_can('administrator') && ! isset( $_GET['debug_geot'] ) )
        	return;
    
        // if is admin page return
        if( is_admin() )
            return;
        
    	// If user IP is whitelisted return
    	$ip = $geot->functions->getUserIP();
    	
    	if( in_array( $ip, $whitelist ) )
    		return;
    	
    	if( isset( $_GET['timersys_debug_geot'] )) {
    		echo '<pre>';
            var_dump(geot_country_name());
    		var_dump(geot_target( '', 'AU_COUNTRIES'));
    		echo '</pre>';
    		die();
    	}		    
        if( ! geot_target( '', 'AU_COUNTRIES') ) {
        	$url =  "{$_SERVER['REQUEST_URI']}";
    		$escaped_url = 'https://xxxxxxxx.com' . htmlspecialchars( $url, ENT_QUOTES, 'UTF-8' );	
          	wp_redirect( $escaped_url );
          	die();
        }
     }   

    Browser A with Australia vpn generates the page cache.
    Browser B visitst the site and can browse around.
    Once all cache is purged browser B gets redirected normally again.

    Any clue?

    Plugin Author LiteSpeed Technologies

    (@litespeedtech)

    Hi Damian,

    As it looks like you are using geo-ip related functionality, you may need to do something with the rewrite rules.

    RewriteEngine on
    RewriteRule .* – [E=Cache-Control:vary=%{ENV:GEO_COUNTRY}]

    This will add a vary for each country that visits using geoip databases (essentially, marking each country as a different type of user).

    If my answer is incorrect, I think I misunderstood what you mean, so further clarification could be useful.

    Cheers,
    Kevin

    Thread Starter Damian

    (@timersys)

    Im using a plugin to calculate the country, Not the server so that’s not going to work.
    I just need the code on my previous message to run on every page load on litespeed_cache_detect_thirdparty

    Regards

    Plugin Author LiteSpeed Technologies

    (@litespeedtech)

    Hi Damian,

    The cache operates by storing the php output as a static file. The server will not enter php if the page is in the cache, so no hooks will run on those pages.

    As the rewrite rules operate at the server level (before checking the cache), the rules can check the countries without needing to enter php.

    I recommend you try to use a server level Geo IP system because it can improve your server’s performance if you have many requests that need to be redirected. By using the plugin, each of those requests are forced to enter php at least once, then again when redirected.

    I hope this is helpful, let me know if my understanding is still incorrect, or if you are still confused 🙂

    Cheers,
    Kevin

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Setup for late init hook ?’ is closed to new replies.