How to Password Protect Power BI content in WordPress

Power BI Embedded for WordPress gives you an easy way to embed reports, dashboards, or titles into WordPress content. However, this plugin doesn’t support protecting these valuable data by default.

Fortunately, thanks to the PPWP Pro plugin, you can achieve that with a few simple steps as below.

Requirements:

Step 1: Navigate to Password Protect WordPress >> General tab and select “Power BI Items” from Post Type Protection dropdown

Step 2: Password protect a Power BI Item

Step 3: Add the following code snippet into your (child) theme functions.php

add_filter( 'the_content', 'ppwp_integrate_powerbi', 999999 );
function ppwp_integrate_powerbi($content) {
	if ( is_singular( 'powerbi' ) ) {
		if ( post_password_required() ) {
			echo get_the_password_form(); // WPCS: XSS ok.
			return;
		} else {
			return $content;
		}
	} 
	return $content;
}
Lasted updated on September 29, 2020