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

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"]');
}

我正在尝试显示特定用户角色的短代码。 用户角色为客户 strong>。 p>

  global $ current_user;  
get_currentuserinfo();  
if(user_can($ current_user,“customer”)){
 echo do_shortcode('[gravityform id =“2”]'); 
} 
  code>  pre> 
  div>

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"]');
}