Warning: Trying to access array offset on false in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 216
is_admin() - 当前请求是否用于管理界面页面 - WordPress函数 - WordPress动力
当前浏览:首页 / WordPress函数 / is_admin()

is_admin()

当前请求是否用于管理界面页面


Warning: Undefined array key -1 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 185

Warning: Undefined array key 2 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 186

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "b960e73ab949eb548887348a22fd2a03" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "c36259426466be41cc8d1020291d7414" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

adminmore...

is 条件判断more...


描述

不检查用户是否为管理员,可使用current_user_can()检查角色和能力。

更多类似的主题函数信息,请查看主题开发手册中的条件标签文章。


返回

(bool) 如果在WordPress管理界面内,则为True,否则为false。



源码

查看源码 官方文档


更新日志

版本描述
1.5.1开始引入

使用示例

  • 示例1

    请注意,“is_admin()”在主题定制器(外观>自定义)视图中时将返回“false”,尽管它基本上位于管理仪表板中。要测试定制器,请使用“is_customize_preview()”。

  • 示例2

    示例:

    if ( ! is_admin() ) {
        // Runs only if this PHP code is in a file that displays outside the admin panels, like the theme template.
        echo '<div style="text-align: center">Welcome to our website.</div>';
    } else {
        // Runs only if this code is in a file that displays inside the admin panels, like a plugin file.
        echo '<div style="text-align: center">Welcome to your Admin Panels.</div>';
    }
    
  • 示例3

    请注意,使用区块编辑器时,is_admin()将返回false。

  • 示例4

    从Codex迁移:

    if ( ! is_admin() ) {
        echo "You are viewing the theme";
    } else {
        echo "You are viewing the WordPress Administration Panels";
    }
    
  • 示例5

    is_admin()对于Ajax请求返回true,因为wp-admin/admin-ajax.php将WP_ADMIN常量定义为true。