Last active
February 26, 2016 10:37
-
-
Save champsupertramp/7014789411aa19898e5c to your computer and use it in GitHub Desktop.
Ultimate Member: shortcode to show content for specific role
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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