网站优化

网站优化

Products

当前位置:首页 > 网站优化 >

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

GG网络技术分享 2025-03-18 16:12 3


问题描述:

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

}

图片转代码服务由CSDN问答提供

感谢您的意见,我们尽快改进~

功能建议

我正在尝试显示特定用户角色的短代码。 用户角色为客户</ 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\\\"]\');

}

标签:

提交需求或反馈

Demand feedback