如果用户以管理员或任何特定角色登录,则不执行

时间:2016-07-06 作者:The Little Cousin

我怎么能不执行一些<script> </script> 用户是否是管理员或任何特定角色?

基本上我需要这样做:

    <?php if( !User( \'Administrator\', \'Editor\' ) ) {        
        <script> </script>        
    } ?>

1 个回复
SO网友:The Little Cousin

解决方案、使用和声明(&&;\'另一个特定角色。

正在关闭<?php if() : ?>, <?php else : ?> 使用列标记:能够在循环内发布脚本。

<?php
global $current_user; // Use global
get_currentuserinfo(); // Make sure global is set, if not set it.

if ( ! user_can( $current_user, "administrator") && ! user_can( $current_user, "specific_role" ) )  : ?> // Check user object has not got subscriber role
    <!-- Not Administrator -->
<?php else : ?>
    <!-- Administrator -->
<?php endif; ?>

相关推荐

显示作者姓名PHP(自制插件)

我有一个需要帮助的问题,因为我自己找不到解决办法。我接管了一个网站,之前有人在那里创建了一个自制插件。。使用默认插件“Contact Form 7”,用户可以在页面上创建帖子。()https://gyazo.com/c8b20adecacd90fb9bfe72ad2138a980 )关于自行创建的插件“Contact Form 7 extender”,帖子是通过PHP代码在后台生成的(https://gyazo.com/115a6c7c9afafd2970b66fd421ca76a3)其工作原理如下:如果