From e81981a83098f85aebf88c508ebdb794a6e33bf9 Mon Sep 17 00:00:00 2001 From: champsupertramp Date: Fri, 26 Feb 2016 18:35:09 +0800 Subject: [PATCH] Add shortcode: show custom content to specific role Usage: [um_show_content roles='member'] [/um_show_content] You can add multiple target roles, just use ',' e.g. [um_show_content roles='member,candidates,pets'] [/um_show_content] --- core/um-shortcodes.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/core/um-shortcodes.php b/core/um-shortcodes.php index 8a17cf1a..64e8f19a 100644 --- a/core/um-shortcodes.php +++ b/core/um-shortcodes.php @@ -12,6 +12,8 @@ class UM_Shortcodes { add_shortcode('um_loggedin', array(&$this, 'um_loggedin')); add_shortcode('um_loggedout', array(&$this, 'um_loggedout')); + add_shortcode('um_show_content', array(&$this, 'um_shortcode_show_content_for_role') ); + add_filter('body_class', array(&$this, 'body_class'), 0); @@ -510,4 +512,33 @@ class UM_Shortcodes { return $str; } + /** + * Shortcode: Show custom content to specific role + * + * [um_show_content roles='member'] [/um_show_content] + * You can add multiple target roles, just use ',' e.g. [um_show_content roles='member,candidates,pets'] + * + * @param array $atts + * @param string $content + * @return string + */ + 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 ''; + } + }