Quantcast
Channel: Toolset » All Posts
Viewing all articles
Browse latest Browse all 20145

Reply To: Access restrictions

$
0
0

Hi Pat,

please try modify the php codes as this:

add_shortcode('access', 'my_access_shortcode');
function my_access_shortcode($atts, $content = '') {
	$atts = shortcode_atts( array(
		'role' => '',
		'condition' => 1
	), $atts );
	$in_roles = 0;
	if(!empty($atts['role']))
	{
		$roles_arr = explode(',', $atts['role']);
		foreach($roles_arr as $r){
			if(current_user_can($r))
			{
				$in_roles = 1;
				break;
			}
		}
	}
	$res = '';
	if(($in_roles == 1 && $atts['condition'] == 1) ||  ($in_roles == 0 && $atts['condition'] == 0))
	{
		$res = do_shortcode($content);
	}
	return $res;
}

1) Limit to anybody who is not subscriber.
[access role="subscriber" condition=0]anybody who is not subscriber[/access]

2) limit to subscriber and administrator
[access role="subscriber,administrator"]anybody who is subscriber or administrator[/access]


Viewing all articles
Browse latest Browse all 20145

Trending Articles