Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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