This shortcode below can be used to restrict content from specific users by providing their user id.
// Add Shortcode function restrict_user( $atts , $content = null ) { // Attributes $atts = shortcode_atts( array( 'user_id' => '', ), $atts ); $current_user = get_current_user_id(); $restricted_ids=explode(",",$atts['user_id']); if(in_array($current_user,$restricted_ids)){ $content = ""; } return "<p>".$content."</p>"; } add_shortcode( 'restrict_users', 'restrict_user' );
Example usage [restrict_users user_id=”32,4″]My Content to Restrict[/restrict_users]
Let us know if this snippet is not working for you:
This snippet doesn’t work