PPWP Pro Hooks, REST APIs, & Public Functions

Since version 1.3, Password Protect WordPress Pro provides RESTful APIs and public functions to achieve the following:

PPWP public action & filter hook

CategoryHookTypeAvailable on
Individual Protection
ppwp_qal_single_allowed_pagefilterPro
ppwp_single_page_robots_contentfilterPro
Partial Protection
ppwp_qal_pcp_allowed_pagefilterPro
Sitewide Protection
ppw_custom_header_form_entire_siteactionFree
ppw_custom_footer_form_entire_siteactionFree
ppwp_sitewide_headactionPro
ppwp_sitewide_footeractionPro
ppwp_before_show_sidewide_formactionPro
ppwp_sitewide_error_messagefilterPro
ppwp_sidewide_robots_contentfilterPro

Where are sitewide passwords stored?

PPWP Free and Pro store sitewide passwords under wp_options table:

  • PPWP Free’s option name is wp_protect_password_set_password_options
  • PPWP Pro’s option name is ppw_entire_site_options

With PPWP Suite extension, we migrate sitewide passwords to our own wp_pda_passwords table for extended features management.

Change Shortcode Passwords Conditionally

Use the following hook to filter passwords shortcode attributes when protecting partial content.

add_filter( 'ppw_shortcode_passwords', 'ppw_filter_shortcode_passwords' );
/**
 * Filter PPWP Passwords.
 * 
 * @param array $passwords Array shortcode passwords.
 * 
 * @return array
 */
function ppw_filter_shortcode_passwords( $passwords ) {
	// Filter array passwords.
	return $passwords;
}

Check if content is protected

Use the following code snippet to check if your content is password protected by our plugins. You can get the ID number by hovering over the desired post title.

By PPWP Pro

if ( class_exists( 'PPW_Pro_Password_Services' ) ) {
 $post_id = 15503;
 $password_service = new PPW_Pro_Password_Services();
 $is_protected_content = $password_service->is_protected_content( $post_id );
}

By PPWP Groups

if ( class_exists( 'PPWP_Group_Password_Service' ) ) {
//1153 is your post ID.
   $group_ids = PPWP_Group_Password_Service::get_instance()->get_group_ids_by_post( 1153 );
   if ( ! empty( $group_ids ) ) {
     // This post is protected by PPWP Group
   }
}

Remove ?ppwp=1 query string

Once users enter the right password, our plugin will add the ?ppwp=1 query string to the page URL for tracking purposes. This doesn’t affect your site whatsoever.

However, if you want to remove the query string for some reason, simply add the following codes to your (child) theme’s functions.php file.

add_filter('ppwp_ppf_redirect_url_before_return_content', function ($url) {
    $url = add_query_arg('ppwp', null);
    return $url;
});

Use multiple QAL parameters

Each type of our quick access links comes with a different access token and you can’t use them all at the same time.

If you want users to be able to access multiple protection layers at once, simply add the following code snippet to your (child) theme’s functions.php file.

add_filter( 'ppwp_shortcode_url', function ( $url ) {
	if ( ! class_exists( 'PPW_Pro_Constants' ) ) {
		return $url;
	}

	$bypass_key = PPW_Pro_Constants::BYPASS_PARAM;
	if ( ! isset( $_GET[ $bypass_key ] ) ) {
		return $url;
	}

	// Do not truncate the ppwp_ac params.
	$query = wp_parse_url( $url, PHP_URL_QUERY );

	$by_pass_val  = $_GET[ PPW_Pro_Constants::BYPASS_PARAM ];
	$bypass_param = "$bypass_key=$by_pass_val";
	if ( $query ) {
		$url .= "&$bypass_param";
	} else {
		$url .= "?$bypass_param";
	}

	return $url;
} );

Show passwords by default

By default, users need to click on the “Show password” checkbox to see what they’re typing. In order for the passwords to always display, simply add the following code snippet to your (child) theme’s functions.php file.

For Single Password Form

add_filter( 'ppwp_customize_password_form', function( $content ) {
  return str_replace( 'type="password"', 'type="text"', $content );
});

For Sitewide Form – Pro version

add_filter( 'ppw_custom_entire_site_login_form', function( $content ) {
  return str_replace( 'type="password"', 'type="text"', $content );
});

Hide the “Password Protection” column

There are 3 ways to hide our “Password Protection” column in the Pages or Posts dashboard.

Option 1: Uncheck that column in the Screen Options.

Option 2: Use the Admin Columns plugin.

Option 3: Add the following custom codes to your (child) theme’s functions.php file.

For PPWP Free version

$post_types = array( 
			'posts', 
			'pages', ); 
		foreach ( $post_types as $post_type ) { 
			add_filter( "manage_${post_type}_posts_columns", function ( $columns ) { 
				unset( $columns['ppw_password_protection'] ); 
				return $columns; }, 99 ); }

For PPWP Pro version

$post_types = array( 
			'posts', 
			'pages', 
			'your-custom-post-type' ); 
		foreach ( $post_types as $post_type ) { 
			add_filter( "manage_${post_type}_columns", function ( $columns ) { 
				unset( $columns['pda_password_protection'] ); 
				return $columns; }, 99 ); }

Grant access to PPWP settings page

Requirements:

By default, only admin users can access PPWP settings page and create master passwords.

To grant access to other users, you need to modify their capabilities by adding  ppwp_manage_options.

Lasted updated on June 21, 2021