How to Password Protect Content built by ProPhoto Theme

ProPhoto is one of the best WordPress themes for photographers and creatives. With a simple drag and drop interface, ProPhoto gives you the ability to create a perfect custom responsive website for your business.

When it comes to password protection, only the content of the post/page will be protected by default. The ProPhoto layout (or template) applied to that post/page will still be visible. Fortunately, it’s possible to protect the whole ProPhoto’s layout/template with the Password Protect WordPress plugin.

In order to block all of the ProPhoto modules with a password form, you need to add the following code snippet into the ProPhoto (child) theme’s functions.php file.

add_action('pp_render_content', 'ppw_check_password_protection', -100 );
add_action('wp', 'ppw_prevent_caching' );

// Prevent password form from being cached with ProPhoto built-in function
function ppw_prevent_caching() { 
	global $post;

	if ( ! $post ) {
		return;
	}

	if ( ! class_exists( 'PPW_Password_Services' ) ) {
		return;
	}

	$ppwp_password_services = new PPW_Password_Services();

	if ( ! $ppwp_password_services->is_protected_content( $post->ID ) ) {
		return;
	}

	defined( 'DONOTCACHEPAGE' ) || define( 'DONOTCACHEPAGE', true );

	if ( ! headers_sent() ) {
		header( 'Cache-Control: private' );
	}
}

function ppw_check_password_protection() {
	if ( ! post_password_required() ) {
		return;
	}

	$form = get_the_password_form();
	echo $form;
	do_action( 'get_footer' );
	exit();
}

Please note that ProPhoto theme comes with a built-in page caching function which helps to improve the speed and performance of your website. As a result, once protected, you need to manually purge cache for the password form to be shown.

Lasted updated on November 2, 2020