Filters

This page is part of the plugin documentation for the WP Template Viewer plugin.

Filters can be used to change (override) the default settings or behavior of the plugin. For example, show the menu and file content to specific or all users instead of admins and super admins. Filters are code snippets that go in your (child) theme’s functions.php file.

Filter: wp_template_viewer_user_id

This filter allows specific users, besides (super) admins, to see the toolbar menu and file content. For example, let’s grant access to a user with a user id 6.

add_filter( 'wp_template_viewer_user_id', 'wp_tv_allow_access_user_id' );

function wp_tv_allow_access_user_id( $user_id ) {
	//return user id;
	return 6;
}

For more control over who can access the menu and file content see the next filter.

Filter: wp_template_viewer_user_is_varified

This filter allows you to control who can access the menu and file content.

Example
Only allow access to a logged in user with a user id 6.

add_filter( 'wp_template_viewer_user_is_varified', 'wp_tv_current_user', 10, 2 );

function wp_tv_current_user( $verified, $logged_in_user_id ) {

	// $verified          = user already approved or not (boolean)
	// $logged_in_user_id = user ID of logged in user.

	// allow user with id 6
	if ( 6 === $logged_in_user_id ) {
		return true;
	}
	
	// return false for all other users
	return false;
}

Example
Allow access to all users (logged in and out).
Notice: The menu and content will be shown in the footer of your site to users that are not logged in.

add_filter( 'wp_template_viewer_user_is_varified', 'wp_tv_current_user', 10, 2 );

function wp_tv_current_user( $verified, $logged_in_user_id ) {

	// $verified          = user already approved or not (boolean) (true or false)
	// $logged_in_user_id = user ID of logged in user.

	// WARNING: all users are allowed access to menu and file content
	return true;
}

This can also be done with this one-liner:

// WARNING: all users are allowed access to menu and file content
add_filter( 'wp_template_viewer_user_is_varified', '__return_true' );

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s