Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save champsupertramp/7014789411aa19898e5c to your computer and use it in GitHub Desktop.
Save champsupertramp/7014789411aa19898e5c to your computer and use it in GitHub Desktop.
Ultimate Member: shortcode to show content for specific role
/**
* Usage:
* [um_show_content roles='member'] <!-- insert content here --> [/um_show_content]
* You can add multiple target roles, just use ',' e.g. [um_show_content roles='member,candidates,pets']
**/
if( ! function_exists("um_shortcode_show_content_for_role") ){
function um_shortcode_show_content_for_role( $atts = array() , $content = '' ) {
$a = shortcode_atts( array(
'roles' => 'member',
), $atts );
$roles = explode(",", $a['roles'] );
// For multiple target roles
if(is_array( $roles ) && in_array( um_user('role'), $roles ) ){
return $content;
}
// Single target role
if( $atts['roles'] == um_user('role') ){
return $content;
}
return '';
}
add_shortcode( 'um_show_content', 'um_shortcode_show_content_for_role' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment