返回介绍

is_admin()

发布于 2017-09-11 01:09:53 字数 6567 浏览 1029 评论 0 收藏 0

is_admin()

Whether the current request is for an administrative interface page.


description

Does not check if the user is an administrator; current_user_can() for checking roles and capabilities.


返回值

(bool) True if inside WordPress administration interface, false otherwise.


源代码

File: wp-includes/load.php

function is_admin() {
	if ( isset( $GLOBALS['current_screen'] ) )
		return $GLOBALS['current_screen']->in_admin();
	elseif ( defined( 'WP_ADMIN' ) )
		return WP_ADMIN;

	return false;
}

更新日志

Versiondescription
1.5.1Introduced.

相关函数

Used By

  • wp-includes/class-wp-editor.php: _WP_Editors::enqueue_default_editor()
  • wp-includes/l10n.php: _get_path_to_translation_from_lang_dir()
  • wp-includes/class-wp-locale-switcher.php: WP_Locale_Switcher::switch_to_locale()
  • wp-includes/class-wp-locale-switcher.php: WP_Locale_Switcher::__construct()
  • wp-includes/class-wp-taxonomy.php: WP_Taxonomy::set_props()
  • wp-includes/class-wp-taxonomy.php: WP_Taxonomy::add_rewrite_rules()
  • wp-includes/class-wp-post-type.php: WP_Post_Type::add_rewrite_rules()
  • wp-includes/class-wp-post-type.php: WP_Post_Type::set_props()
  • wp-includes/rest-api.php: get_rest_url()
  • wp-includes/admin-bar.php: wp_admin_bar_customize_menu()
  • wp-includes/customize/class-wp-customize-nav-menu-item-setting.php: WP_Customize_Nav_Menu_Item_Setting::sort_wp_get_nav_menu_items()
  • wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::wp_loaded()
  • wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::wp_redirect_status()
  • wp-includes/theme.php: add_editor_style()
  • wp-includes/theme.php: remove_editor_styles()
  • wp-includes/theme.php: _custom_header_background_just_in_time()
  • wp-includes/theme.php: _wp_customize_include()
  • wp-includes/theme.php: switch_theme()
  • wp-includes/theme.php: get_theme_mods()
  • wp-includes/l10n.php: load_default_textdomain()
  • wp-includes/l10n.php: load_plugin_textdomain()
  • wp-includes/l10n.php: load_muplugin_textdomain()
  • wp-includes/l10n.php: load_theme_textdomain()
  • wp-includes/general-template.php: wp_heartbeat_settings()
  • wp-includes/deprecated.php: wp_admin_bar_dashboard_view_site_menu()
  • wp-includes/class-wp-theme.php: WP_Theme::get_allowed_on_site()
  • wp-includes/class-wp.php: WP::handle_404()
  • wp-includes/class-wp.php: WP::parse_request()
  • wp-includes/class-wp-query.php: WP_Query::parse_query()
  • wp-includes/functions.wp-scripts.php: wp_deregister_script()
  • wp-includes/functions.php: wp_auth_check_load()
  • wp-includes/widgets.php: wp_widget_rss_output()
  • wp-includes/link-template.php: network_home_url()
  • wp-includes/link-template.php: get_home_url()
  • wp-includes/link-template.php: get_pagenum_link()
  • wp-includes/class-wp-admin-bar.php: WP_Admin_Bar::_render()
  • wp-includes/admin-bar.php: wp_admin_bar_sidebar_toggle()
  • wp-includes/admin-bar.php: wp_admin_bar_site_menu()
  • wp-includes/admin-bar.php: wp_admin_bar_edit_menu()
  • wp-includes/admin-bar.php: wp_admin_bar_search_menu()
  • wp-includes/admin-bar.php: is_admin_bar_showing()
  • wp-includes/option.php: wp_user_settings()
  • wp-includes/post-template.php: get_post_class()
  • wp-includes/post-template.php: get_the_title()
  • wp-includes/media.php: wp_enqueue_media()
  • wp-includes/media.php: wp_video_shortcode()
  • wp-includes/media.php: image_constrain_size_for_editor()
  • wp-includes/post.php: wp_get_attachment_url()
  • wp-includes/canonical.php: redirect_canonical()
  • wp-includes/ms-load.php: ms_not_installed()
  • wp-includes/post-formats.php: _post_format_request()
  • wp-includes/nav-menu.php: wp_get_nav_menu_items()
  • wp-includes/widgets.php: wp_get_sidebars_widgets()
  • wp-includes/widgets.php: wp_convert_widget_settings()
  • wp-includes/class-wp-customize-widgets.php: WP_Customize_Widgets::schedule_customize_register()
  • wp-includes/script-loader.php: script_concat_settings()
  • wp-includes/script-loader.php: wp_default_scripts()
  • wp-includes/class-wp-editor.php: _WP_Editors::editor_settings()
  • wp-includes/class-wp-editor.php: _WP_Editors::editor_js()
  • Show 54 more used by Hide more used by

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 4You must log in to vote on the helpfulness of this note Contributed by Ken Dirschl

    Be aware that ‘is_admin()’ will return ‘false’ while in the theme customizer view, despite essentially being in the admin dashboard. To test for the customizer, use ‘is_customize_preview()’.

  2. Example:

    
    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>';
    }
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文