Caching Plugins & Cache Servers Integration

Caching plugins or server-side caching could cause potential conflicts with our Password Protect WordPress (PPWP) plugins. In this article, we will show you how to make the top caching plugins and servers work properly with our PPWP plugins – both Free and Pro version.

Cache Servers

If you are using caching servers such as Cloudflare, LiteSpeed, or Sucuri, you might come across the issue where you have to enter passwords twice to unlock the content. In this case, you can exclude our cookies or protected page URLs from your caching servers.

If you are to password protect your entire site, you should “Purge all your site cache” first or simply deactivate these caching plugins for our site-wide protection feature to work properly. You shouldn’t cache a protected site in the first place, should you?

Simply add the following cookies to the Exclude Cache option in your hosting server’s account.

For PPWP Free version:

pda_protect_password
wp-postpass-role_*
ppw_cat-*

For PPWP Pro version:

pda_protect_password
wp-goldpass-pagepost_*
ppw_cat-*

Exclude password protected page URLs

Since our cookie exists on every page of your site, excluding cookies from caching servers will prevent your entire site from being cached. In case you just protect some pages in your site, the better solution is excluding your password protected page URLs only.

Sucuri Firewall

PPWP Pro works well with Sucuri Security Firewall. However, when enabling its caching, users may need to enter the password twice in order to access the protected content.

Here’s how you can fix it with 2 simple steps:

  1. Under Sucuri Firewall dashboard, click on Performance – Advanced Settings.
  2. Under Non-Cache URLs, exclude your password protected pages from the Firewall cache as follows:

That’s all you have to do. Now your password protected pages should work properly without you having to enter your password twice.

GoDaddy

In order for the sitewide protection feature to work properly with Godaddy server cache, add the code snippet below to your (child) theme’s functions.php file.

For PPWP Free 1.7.5 or greater:

function ppwp_generate_param_redirect( $bypass ) {
    if ( ! empty( $_POST ) ) {
        return $bypass;
    }

    $ip_hash   = substr( md5( microtime() . rand() ), 0, 12 );
    $query_key = 'vp';
    if ( ! isset( $_GET[ $query_key ] ) ) {
        global $wp;
        $redirect_url = trailingslashit( home_url( $wp->request ) );
        if ( ! empty( $_SERVER['QUERY_STRING'] ) ) {
            $redirect_url = add_query_arg( wp_unslash( $_SERVER['QUERY_STRING'] ), '', $redirect_url );
        }
        if ( ! get_option( 'permalink_structure' ) ) {
            $redirect_url = add_query_arg( $wp->query_string, '', $redirect_url );
        }
        $redirect_url = add_query_arg( $query_key, $ip_hash, remove_query_arg( $query_key, $redirect_url ) );
        wp_safe_redirect( $redirect_url );
        exit;
    }

    return $bypass;
}

add_action( 'ppw_sitewide_before_validate_password', 'ppwp_generate_param_redirect' );

For PPWP Pro version:

function ppwp_generate_param_redirect( $bypass ) {
	if ( ! empty( $_POST ) ) {
		return $bypass;
	}

	$ip_hash   = substr( md5( microtime() . rand() ), 0, 12 );
	$query_key = 'vp';
	if ( ! isset( $_GET[ $query_key ] ) ) {
		global $wp;
		$redirect_url = trailingslashit( home_url( $wp->request ) );
		if ( ! empty( $_SERVER['QUERY_STRING'] ) ) {
			$redirect_url = add_query_arg( wp_unslash( $_SERVER['QUERY_STRING'] ), '', $redirect_url );
		}
		if ( ! get_option( 'permalink_structure' ) ) {
			$redirect_url = add_query_arg( $wp->query_string, '', $redirect_url );
		}
		$redirect_url = add_query_arg( $query_key, $ip_hash, remove_query_arg( $query_key, $redirect_url ) );
		wp_safe_redirect( $redirect_url );
		exit;
	}

	return $bypass;
}

add_filter( 'ppwp_sitewide_handle_before_valid_password', 'ppwp_generate_param_redirect' );

Limitation: Might not work properly on Apple devices.

Cloudways

While our default password function works well with the Cloudways server cache, the quick access links (QALs) might not allow users to bypass protection as usual.

If that’s the case, simply exclude the QALs from both Cloudways Varnish cache and Breeze WordPress Cache plugin.

DreamHost

Unfortunately, DreamHost provides no way to exclude pages from the server cache. The only way to make our password protection work on DreamHost server is to enable Debug Mode.

To do so, simply add define( 'VHP_DEVMODE', true ); to your wp-config.php file.

Pair

In order for the sitewide protection feature to work properly with Pair server cache, add the code snippet below to your (child) theme’s functions.php file.

For PPWP Free version:

add_filter(
	'ppw_is_valid_password',
	function ($is_valid, $post_id, $password) {
		if (!method_exists('PPW_Password_Services', 'set_password_to_cookie')) {
			return $is_valid;
		}
		$password_services = new PPW_Password_Services();
		$password_services->set_password_to_cookie($password, 'wordpress_');

		return $is_valid;
	},
	10,
	3
);

For PPWP Pro version:

add_action( 'ppwp_pro_after_set_post_cookie',
	function ( $post_id, $password ) {
		if ( ! method_exists( 'PPW_Pro_Password_Services', 'set_password_to_cookie' ) ) {
			return;
		}
		$password_service = new PPW_Pro_Password_Services();
		$password_service->set_password_to_cookie( $password, 'wordpress_' );
	},
	10,
	2
);

Ezoic

If you’re using Ezoic, you might see the password form again after entering the right password. To resolve this issue, simply exclude your protected content from the Ezoic’s cache.

WP Engine

If you enable WP Engine caching, you’d experience the following issues:

  • Your content is still public after protection
  • You can unlock the private content/sitewide protection. But when reloading the page, the password form reappears

In these cased, simply “Clear all caches” after setting your passwords.

Caching Plugins

Our PPWP Free and Pro plugins work perfectly with the top WordPress caching plugins automatically without any extra configurations.

  • W3 Total Cache
  • WP Super Cache
  • WP Fastest Cace
Lasted updated on October 10, 2021