PPWP Pro – Generate Password Bypass URL

Add the following function into your (child) theme functions.php

if ( ! function_exists( 'ppwp_pro_generate_bypass_url' ) ) {
	function ppwp_pro_generate_bypass_url( $post_id, $parameters = array() ) {
		if ( ! function_exists( 'ppw_encrypt_decrypt' ) || ! method_exists( 'PPW_Pro_Repository', 'add_new_password' ) || ! function_exists( 'generate_pwd' ) || ! method_exists( 'PPW_Pro_Repository', 'add_new_password' ) || ! method_exists( 'PPW_Pro_Password_Services', 'get_expired_time_stamp' ) ) {
			return false;
		}
		if ( ! $post_id ) {
			return false;
		}
		$post_url = get_permalink( $post_id );
		if ( ! $post_url ) {
			return false;
		}
		$password = generate_pwd();
		$ppwp_repo = new PPW_Pro_Repository();
		$result    = $ppwp_repo->add_new_password(
			array(
				'password'          => $password,
				'created_time'      => time(),
				'campaign_app_type' => 'Auto',
				'usage_limit'       => isset( $parameters['usage_limit'] ) ? $parameters['usage_limit'] : null,
				'expired_date'      => isset( $parameters['expired_date'] ) ? ( new PPW_Pro_Password_Services() )->get_expired_time_stamp( $parameters['expired_date'] ) : null,
				'label'             => isset( $parameters['label'] ) ? $parameters['label'] : '',
				'post_id'           => $post_id,
			)
		);
		if ( ! $result ) {
			return false;
		}		$token = ppw_encrypt_decrypt( 'encrypt', array( 'password' => $password ) );
		if ( strpos( $post_url, '?' ) ) {
			$bypass_url = $post_url . '&' . PPW_Pro_Constants::BYPASS_PARAM . '=' . $token;
		} else {
			$bypass_url = $post_url . '?' . PPW_Pro_Constants::BYPASS_PARAM . '=' . $token;
		}		return $bypass_url;
	}
}

This is how you generate a bypass URL expiring in 1 day for post id 1963

ppwp_pro_generate_bypass_url( 1963, array('label' => 'test'; 'expired_date' => 1 ) )