douxi3233
douxi3233
2019-06-20 08:30

Wordpress - 显示用户特定用户角色的短代码

已采纳

I am trying to display a shortcode of a specific user role. The user role is customer.

global $current_user; 
get_currentuserinfo(); 
if ( user_can( $current_user, "customer" ) ){ 
    echo do_shortcode('[gravityform id="2"]');
}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dongmei9508 dongmei9508 2年前

    You can use the following code:

    $user = wp_get_current_user();
    if ( in_array( 'shop_manager', (array) $user->roles ) ) { // user role condition
        echo do_shortcode('[gravityform id="2"]');
    }
    
    点赞 评论 复制链接分享