我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

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

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

近期文章

  • 感谢登录用户进行文件上传
  • 如何访问由findAll生成的数组中的元素
  • 如何在symfony API请求中正确处理异常
  • Slug输入字段检查功能无法正常工作
  • 在本机中发送和获取JSON数据[JSON解析错误]
  • 从SQL Server过程创建的Http post请求未获得授权
  • WordPress中的SVG Sprites:实现SVG精灵的最佳方法是什么?
  • Nextcloud - 用户登录失败 - Doctrine \\ DBAL \\ DBALException - 错误42601
  • 表格内容分为下一页
  • 为谷歌地图煽动创建XML文件
  • PHP合并和分组数组并总结它们
  • 如何阻止blur()事件函数触发两次?
  • 如何在基于select列的mysql where子句中给出case?
  • 使用laravel excel映射具有多个标题的查询结果
  • 可以使用此代码来验证$ _GET变量吗?
  • 尝试将db中的选定行插入到新表中
  • 如何在php中使用kso​​rt对重音字母进行排序?
  • 将当前日期时间插入自定义wordpress日期时间列
  • Buddypress重定向到会员页面
  • Web项目:多个实例与单个实例

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华