• Resolved Messaone

    (@messaone)


    Hey there.

    I want to use page caching. But i can’t. I have a php script that check if user has allowed to set marketing cookies. So after that it allows to load the content. But i set the request in php.

    I got this in my code.

    $cookie = $_COOKIE[$cookie_name];
    
    if(!empty($cookie)) {
    	// SHOW CONTENT - After User allow over cookie 
    }

    So my problem is if i use page cache it always shows nothing but the cookie is set.
    Thats because i go a cache page with no cookies set – so i need something like cache if cookies XYZ is not set and make a second version if cookie XYZ is set or have value.

    Best Regards

Viewing 4 replies - 1 through 4 (of 4 total)
  • This line:
    hummingbird-performance/core/modules/class-page-cache.php:622

    if ( preg_match( '/^wp-postpass_|^comment_author_|^wordpress_logged_in_/', $key ) ) {

    If you add your cookie name here, Hummingbird will save different cache files for different cookie values.

    @wpmudev Please add an apply_filters to this line.

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @messaone & @tivnetinc

    I hope you are doing well.

    We forward this thread to our developers to take a closer look and check what is the best option to avoid it, maybe a filter as @tivnetinc suggested.

    We will update once hearing back from the team.

    Best Regards
    Patrick Freitas

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @messaone

    Could you please try to add this code on a mu-plugin?

    <?php
    
    add_action( 'after_setup_theme', function(){
    	if( ! empty( $_SERVER['REQUEST_URI'] ) ){
    		add_filter( 'wphb_shold_cache_request_pre', function( $state ){
    			$_SERVER['REQUEST_URI'] = str_replace( '#without-cookie', '', $_SERVER['REQUEST_URI'] );
    			return $state;
    		} );
    	}
    } );

    https://premium.wpmudev.org/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

    On the wp-config, before of /** That’s all.. **/

    $cookie_name = 'your-cookie-name';
    if( empty( $_COOKIE[ $cookie_name ] ) ){
    	$_SERVER['REQUEST_URI'] .= '#without-cookie';
    }

    Let us know the result you got.
    Best Regards
    Patrick Freitas

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @messaone

    I hope you are doing well.

    We haven’t heard from you in a while, I’ll go and mark this thread as resolved.

    However, feel free to let us know if you have any additional question or problem.

    Best Regards
    Patrick Freitas

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

The topic ‘Cookie – Page cache – Different Layouts’ is closed to new replies.