esc_attr() - WordPress 函数参考中文文档

返回介绍

esc_attr()

发布于 2017-09-10 字数22577 浏览 958 评论 0

esc_attr( string $text )

Escaping for HTML attributes.


描述


参数

$text

(string)
(Required)


返回值

(string)


源代码

File: wp-includes/formatting.php

function esc_attr( $text ) {
	$safe_text = wp_check_invalid_utf8( $text );
	$safe_text = _wp_specialchars( $safe_text, ENT_QUOTES );
	/**
	 * Filters a string cleaned and escaped for output in an HTML attribute.
	 *
	 * Text passed to esc_attr() is stripped of invalid or special characters
	 * before output.
	 *
	 * @since 2.0.6
	 *
	 * @param string $safe_text The text after it has been escaped.
 	 * @param string $text      The text prior to being escaped.
	 */
	return apply_filters( 'attribute_escape', $safe_text, $text );
}

更新日志

Version 描述
2.8.0 Introduced.

More Information

Encodes the <, >, &, ” and ‘ (less than, greater than, ampersand, double quote and single quote) characters. Will never double encode entities.

Always use when escaping HTML attributes (especially form values) such as alt, value, title, etc. To escape the value of a translation use esc_attr__() instead; to escape, translate and echo, use esc_attr_e().


相关函数

Uses

  • wp-includes/formatting.php:
    attribute_escape
  • wp-includes/formatting.php:
    wp_check_invalid_utf8()
  • wp-includes/formatting.php:
    _wp_specialchars()
  • wp-includes/plugin.php:
    apply_filters()

Used By

  • wp-includes/widgets/class-wp-widget-media.php:
    WP_Widget_Media::form()
  • wp-includes/widgets/class-wp-widget-media.php:
    WP_Widget_Media::render_control_template_scripts()
  • wp-includes/widgets/class-wp-widget-media-image.php:
    WP_Widget_Media_Image::render_media()
  • wp-includes/class-wp-customize-nav-menus.php:
    WP_Customize_Nav_Menus::print_post_type_container()
  • wp-includes/customize/class-wp-customize-background-position-control.php:
    WP_Customize_Background_Position_Control::content_template()
  • wp-includes/general-template.php:
    wp_re源代码_hints()
  • wp-admin/includes/ms.php:
    network_edit_site_nav()
  • wp-admin/includes/class-wp-plugins-list-table.php:
    WP_Plugins_List_Table::search_box()
  • wp-includes/class-wp-customize-widgets.php:
    WP_Customize_Widgets::filter_dynamic_sidebar_params()
  • wp-includes/embed.php:
    get_post_embed_html()
  • wp-includes/author-template.php:
    get_the_author_posts_link()
  • wp-includes/media.php:
    wp_image_add_srcset_and_sizes()
  • wp-admin/includes/class-wp-posts-list-table.php:
    WP_Posts_List_Table::get_edit_link()
  • wp-includes/customize/class-wp-customize-nav-menu-location-control.php:
    WP_Customize_Nav_Menu_Location_Control::render_content()
  • wp-includes/customize/class-wp-customize-nav-menu-control.php:
    WP_Customize_Nav_Menu_Control::content_template()
  • wp-includes/class-wp-customize-panel.php:
    WP_Customize_Panel::print_template()
  • wp-includes/class-wp-customize-nav-menus.php:
    WP_Customize_Nav_Menus::filter_wp_nav_menu()
  • wp-includes/customize/class-wp-customize-new-menu-section.php:
    WP_Customize_New_Menu_Section::render()
  • wp-admin/includes/class-wp-posts-list-table.php:
    WP_Posts_List_Table::handle_row_actions()
  • wp-admin/includes/class-wp-posts-list-table.php:
    WP_Posts_List_Table::column_title()
  • wp-admin/includes/class-wp-links-list-table.php:
    WP_Links_List_Table::column_cb()
  • wp-admin/includes/class-wp-links-list-table.php:
    WP_Links_List_Table::column_name()
  • wp-admin/includes/class-wp-ms-themes-list-table.php:
    WP_MS_Themes_List_Table::column_name()
  • wp-admin/includes/class-wp-ms-themes-list-table.php:
    WP_MS_Themes_List_Table::column_描述()
  • wp-admin/includes/class-wp-ms-themes-list-table.php:
    WP_MS_Themes_List_Table::column_cb()
  • wp-admin/includes/class-wp-ms-sites-list-table.php:
    WP_MS_Sites_List_Table::column_cb()
  • wp-admin/includes/class-wp-terms-list-table.php:
    WP_Terms_List_Table::handle_row_actions()
  • wp-admin/includes/class-wp-ms-users-list-table.php:
    WP_MS_Users_List_Table::column_cb()
  • wp-admin/includes/class-wp-media-list-table.php:
    WP_Media_List_Table::column_parent()
  • wp-admin/includes/class-wp-media-list-table.php:
    WP_Media_List_Table::column_title()
  • wp-includes/kses.php:
    wp_kses_one_attr()
  • wp-includes/customize/class-wp-customize-theme-control.php:
    WP_Customize_Theme_Control::content_template()
  • wp-includes/customize/class-wp-customize-themes-section.php:
    WP_Customize_Themes_Section::render()
  • wp-admin/includes/theme.php:
    customize_themes_print_templates()
  • wp-admin/includes/class-wp-press-this.php:
    WP_Press_This::html()
  • wp-admin/includes/class-wp-press-this.php:
    WP_Press_This::post_formats_html()
  • wp-admin/includes/class-wp-press-this.php:
    WP_Press_This::categories_html()
  • wp-includes/l10n.php:
    wp_dropdown_languages()
  • wp-includes/class-wp-customize-control.php:
    WP_Customize_Control::input_attrs()
  • wp-admin/includes/translation-install.php:
    wp_install_language_form()
  • wp-login.php:
    login_header()
  • wp-signup.php:
    show_user_form()
  • wp-signup.php:
    signup_blog()
  • wp-signup.php:
    show_blog_form()
  • wp-admin/includes/network.php:
    network_step1()
  • wp-admin/install.php:
    display_setup_form()
  • wp-admin/includes/class-wp-screen.php:
    WP_Screen::render_screen_layout()
  • wp-admin/includes/class-wp-screen.php:
    WP_Screen::render_per_page_options()
  • wp-admin/includes/theme.php:
    get_theme_update_available()
  • wp-admin/includes/class-wp-screen.php:
    WP_Screen::render_screen_meta()
  • wp-admin/includes/class-wp-plugins-list-table.php:
    WP_Plugins_List_Table::single_row()
  • wp-admin/includes/screen.php:
    meta_box_prefs()
  • wp-admin/includes/class-wp-links-list-table.php:
    WP_Links_List_Table::display_rows()
  • wp-admin/includes/theme-install.php:
    install_theme_search_form()
  • wp-admin/includes/theme-install.php:
    install_themes_dashboard()
  • wp-admin/includes/class-bulk-upgrader-skin.php:
    Bulk_Upgrader_Skin::before()
  • wp-admin/includes/class-bulk-upgrader-skin.php:
    Bulk_Upgrader_Skin::after()
  • wp-admin/includes/class-wp-list-table.php:
    WP_List_Table::view_switcher()
  • wp-admin/includes/class-wp-list-table.php:
    WP_List_Table::display_tablenav()
  • wp-admin/includes/class-wp-list-table.php:
    WP_List_Table::search_box()
  • wp-admin/includes/class-wp-list-table.php:
    WP_List_Table::bulk_actions()
  • wp-admin/includes/class-wp-list-table.php:
    WP_List_Table::months_dropdown()
  • wp-admin/includes/ms.php:
    mu_dropdown_languages()
  • wp-admin/includes/class-wp-ms-themes-list-table.php:
    WP_MS_Themes_List_Table::single_row()
  • wp-admin/includes/misc.php:
    admin_color_scheme_picker()
  • wp-admin/includes/class-wp-theme-install-list-table.php:
    WP_Theme_Install_List_Table::install_theme_info()
  • wp-admin/includes/taxonomy.php:
    get_terms_to_edit()
  • wp-admin/includes/class-wp-theme-install-list-table.php:
    WP_Theme_Install_List_Table::single_row()
  • wp-admin/includes/update.php:
    wp_plugin_update_row()
  • wp-admin/includes/update.php:
    wp_theme_update_row()
  • wp-admin/includes/plugin-install.php:
    install_search_form()
  • wp-admin/includes/plugin-install.php:
    install_plugins_favorites_form()
  • wp-admin/includes/plugin-install.php:
    install_plugin_information()
  • wp-admin/includes/dashboard.php:
    wp_dashboard_recent_posts()
  • wp-admin/includes/deprecated.php:
    wp_dashboard_plugins_output()
  • wp-admin/includes/dashboard.php:
    wp_dashboard_browser_nag()
  • wp-admin/includes/dashboard.php:
    wp_dashboard_recent_drafts()
  • wp-admin/includes/dashboard.php:
    _wp_dashboard_control_callback()
  • wp-admin/includes/plugin.php:
    settings_fields()
  • wp-admin/includes/class-wp-plugin-install-list-table.php:
    WP_Plugin_Install_List_Table::display_rows()
  • wp-admin/includes/template.php:
    get_submit_button()
  • wp-admin/includes/template.php:
    do_settings_fields()
  • wp-admin/includes/template.php:
    find_posts_div()
  • wp-admin/includes/template.php:
    the_post_password()
  • wp-admin/includes/template.php:
    _admin_search_query()
  • wp-admin/includes/template.php:
    wp_comment_reply()
  • wp-admin/includes/template.php:
    _list_meta_row()
  • wp-admin/includes/template.php:
    meta_form()
  • wp-admin/includes/template.php:
    wp_dropdown_roles()
  • wp-admin/includes/template.php:
    do_accordion_sections()
  • wp-admin/includes/class-wp-themes-list-table.php:
    WP_Themes_List_Table::display_rows()
  • wp-admin/includes/class-wp-themes-list-table.php:
    WP_Themes_List_Table::_js_vars()
  • wp-admin/includes/class-wp-users-list-table.php:
    WP_Users_List_Table::single_row()
  • wp-admin/includes/media.php:
    media_upload_gallery_form()
  • wp-admin/includes/media.php:
    media_upload_library_form()
  • wp-admin/includes/media.php:
    edit_form_image_editor()
  • wp-admin/includes/media.php:
    attachment_submitbox_metadata()
  • wp-admin/includes/media.php:
    get_attachment_fields_to_edit()
  • wp-admin/includes/media.php:
    get_media_item()
  • wp-admin/includes/media.php:
    get_compat_media_markup()
  • wp-admin/includes/media.php:
    media_upload_form_handler()
  • wp-admin/includes/media.php:
    wp_media_upload_handler()
  • wp-admin/includes/media.php:
    media_sideload_image()
  • wp-admin/includes/media.php:
    image_align_input_fields()
  • wp-admin/includes/media.php:
    image_link_input_fields()
  • wp-admin/includes/media.php:
    the_media_upload_tabs()
  • wp-admin/includes/media.php:
    get_image_send_to_editor()
  • wp-admin/includes/media.php:
    media_buttons()
  • wp-admin/includes/post.php:
    _wp_post_thumbnail_html()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_find_posts()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_add_link_category()
  • wp-admin/includes/meta-boxes.php:
    post_trackback_meta_box()
  • wp-admin/includes/meta-boxes.php:
    post_slug_meta_box()
  • wp-admin/includes/meta-boxes.php:
    page_attributes_meta_box()
  • wp-admin/includes/meta-boxes.php:
    link_xfn_meta_box()
  • wp-admin/includes/meta-boxes.php:
    link_advanced_meta_box()
  • wp-admin/includes/meta-boxes.php:
    attachment_id3_data_meta_box()
  • wp-admin/includes/meta-boxes.php:
    post_submit_meta_box()
  • wp-admin/includes/meta-boxes.php:
    post_format_meta_box()
  • wp-admin/includes/meta-boxes.php:
    post_tags_meta_box()
  • wp-admin/includes/meta-boxes.php:
    post_categories_meta_box()
  • wp-admin/includes/bookmark.php:
    get_default_link_to_edit()
  • wp-admin/includes/class-wp-media-list-table.php:
    WP_Media_List_Table::get_views()
  • wp-admin/includes/class-wp-media-list-table.php:
    WP_Media_List_Table::_get_row_actions()
  • wp-admin/includes/class-wp-comments-list-table.php:
    WP_Comments_List_Table::extra_tablenav()
  • wp-admin/includes/class-wp-comments-list-table.php:
    WP_Comments_List_Table::column_comment()
  • wp-admin/includes/class-wp-terms-list-table.php:
    WP_Terms_List_Table::column_name()
  • wp-admin/includes/class-wp-terms-list-table.php:
    WP_Terms_List_Table::inline_edit()
  • wp-admin/includes/class-walker-nav-menu-edit.php:
    Walker_Nav_Menu_Edit::start_el()
  • wp-admin/includes/class-walker-nav-menu-checklist.php:
    Walker_Nav_Menu_Checklist::start_el()
  • wp-admin/includes/nav-menu.php:
    wp_nav_menu_item_post_type_meta_box()
  • wp-admin/includes/nav-menu.php:
    wp_nav_menu_item_taxonomy_meta_box()
  • wp-admin/includes/file.php:
    request_filesystem_credentials()
  • wp-admin/includes/class-wp-posts-list-table.php:
    WP_Posts_List_Table::inline_edit()
  • wp-admin/includes/widgets.php:
    wp_list_widget_controls()
  • wp-admin/includes/widgets.php:
    wp_widget_control()
  • wp-admin/includes/options.php:
    options_reading_blog_charset()
  • wp-admin/custom-header.php:
    Custom_Image_Header::step_1()
  • wp-admin/custom-header.php:
    Custom_Image_Header::step_2()
  • wp-admin/custom-header.php:
    Custom_Image_Header::show_header_selector()
  • wp-admin/includes/ms.php:
    confirm_delete_users()
  • wp-admin/update-core.php:
    list_core_update()
  • wp-admin/update-core.php:
    list_plugin_updates()
  • wp-admin/update-core.php:
    list_theme_updates()
  • wp-admin/custom-background.php:
    Custom_Background::wp_set_background_image()
  • wp-admin/menu-header.php:
    _wp_menu_output()
  • wp-admin/custom-background.php:
    Custom_Background::admin_page()
  • wp-includes/class.wp-styles.php:
    WP_Styles::print_inline_style()
  • wp-includes/class.wp-styles.php:
    WP_Styles::do_item()
  • wp-includes/class-walker-category.php:
    Walker_Category::start_el()
  • wp-includes/class-walker-category-dropdown.php:
    Walker_CategoryDropdown::start_el()
  • wp-includes/category-template.php:
    wp_generate_tag_cloud()
  • wp-includes/category-template.php:
    wp_dropdown_categories()
  • wp-includes/category-template.php:
    wp_list_categories()
  • wp-includes/l10n.php:
    esc_attr__()
  • wp-includes/l10n.php:
    esc_attr_e()
  • wp-includes/l10n.php:
    esc_attr_x()
  • wp-includes/formatting.php:
    _links_add_target()
  • wp-includes/formatting.php:
    translate_smiley()
  • wp-includes/pluggable.php:
    get_avatar()
  • wp-includes/general-template.php:
    the_search_query()
  • wp-includes/general-template.php:
    feed_links()
  • wp-includes/general-template.php:
    feed_links_extra()
  • wp-includes/general-template.php:
    get_search_query()
  • wp-includes/general-template.php:
    get_archives_link()
  • wp-includes/general-template.php:
    get_calendar()
  • wp-includes/general-template.php:
    wp_login_form()
  • wp-includes/deprecated.php:
    get_boundary_post_rel_link()
  • wp-includes/deprecated.php:
    get_index_rel_link()
  • wp-includes/deprecated.php:
    get_parent_post_rel_link()
  • wp-includes/deprecated.php:
    get_the_attachment_link()
  • wp-includes/deprecated.php:
    get_attachment_icon()
  • wp-includes/deprecated.php:
    get_attachment_innerHTML()
  • wp-includes/deprecated.php:
    attribute_escape()
  • wp-includes/deprecated.php:
    get_links()
  • wp-includes/functions.php:
    wp_timezone_choice()
  • wp-includes/functions.php:
    wp_nonce_field()
  • wp-includes/functions.php:
    wp_referer_field()
  • wp-includes/functions.php:
    wp_original_referer_field()
  • wp-includes/widgets/class-wp-nav-menu-widget.php:
    WP_Nav_Menu_Widget::form()
  • wp-includes/widgets/class-wp-widget-recent-comments.php:
    WP_Widget_Recent_Comments::form()
  • wp-includes/widgets/class-wp-widget-rss.php:
    WP_Widget_RSS::widget()
  • wp-includes/widgets/class-wp-widget-tag-cloud.php:
    WP_Widget_Tag_Cloud::form()
  • wp-includes/widgets/class-wp-widget-categories.php:
    WP_Widget_Categories::form()
  • wp-includes/widgets/class-wp-widget-recent-posts.php:
    WP_Widget_Recent_Posts::form()
  • wp-includes/widgets/class-wp-widget-calendar.php:
    WP_Widget_Calendar::form()
  • wp-includes/widgets/class-wp-widget-text.php:
    WP_Widget_Text::form()
  • wp-includes/widgets/class-wp-widget-categories.php:
    WP_Widget_Categories::widget()
  • wp-includes/widgets/class-wp-widget-search.php:
    WP_Widget_Search::form()
  • wp-includes/widgets/class-wp-widget-archives.php:
    WP_Widget_Archives::widget()
  • wp-includes/widgets/class-wp-widget-archives.php:
    WP_Widget_Archives::form()
  • wp-includes/widgets/class-wp-widget-meta.php:
    WP_Widget_Meta::form()
  • wp-includes/widgets/class-wp-widget-pages.php:
    WP_Widget_Pages::form()
  • wp-includes/widgets.php:
    wp_widget_rss_output()
  • wp-includes/widgets.php:
    wp_widget_rss_form()
  • wp-includes/taxonomy.php:
    get_the_taxonomies()
  • wp-includes/taxonomy.php:
    sanitize_term_field()
  • wp-includes/link-template.php:
    get_adjacent_post_rel_link()
  • wp-includes/link-template.php:
    edit_post_link()
  • wp-includes/class-wp-admin-bar.php:
    WP_Admin_Bar::_render_container()
  • wp-includes/class-wp-admin-bar.php:
    WP_Admin_Bar::_render_group()
  • wp-includes/class-wp-admin-bar.php:
    WP_Admin_Bar::_render_item()
  • wp-includes/class-wp-admin-bar.php:
    WP_Admin_Bar::add_node()
  • wp-includes/update.php:
    wp_get_update_data()
  • wp-includes/class-oembed.php:
    WP_oEmbed::data2html()
  • wp-includes/admin-bar.php:
    wp_admin_bar_shortlink_menu()
  • wp-includes/feed.php:
    get_the_category_rss()
  • wp-includes/option.php:
    form_option()
  • wp-includes/user.php:
    wp_dropdown_users()
  • wp-includes/user.php:
    sanitize_user_field()
  • wp-includes/template.php:
    load_template()
  • wp-includes/bookmark-template.php:
    _walk_bookmarks()
  • wp-includes/class-walker-nav-menu.php:
    Walker_Nav_Menu::start_el()
  • wp-includes/class-walker-page-dropdown.php:
    Walker_PageDropdown::start_el()
  • wp-includes/nav-menu-template.php:
    wp_nav_menu()
  • wp-includes/class-walker-nav-menu.php:
    Walker_Nav_Menu::start_lvl()
  • wp-includes/class-walker-page.php:
    Walker_Page::start_el()
  • wp-includes/post-template.php:
    wp_dropdown_pages()
  • wp-includes/post-template.php:
    wp_page_menu()
  • wp-includes/post-template.php:
    the_title_attribute()
  • wp-includes/media.php:
    wp_video_shortcode()
  • wp-includes/media.php:
    wp_playlist_shortcode()
  • wp-includes/media.php:
    wp_audio_shortcode()
  • wp-includes/media.php:
    get_image_tag()
  • wp-includes/media.php:
    img_caption_shortcode()
  • wp-includes/post.php:
    sanitize_post_field()
  • wp-includes/class-wp-rewrite.php:
    WP_Rewrite::iis7_url_rewrite_rules()
  • wp-includes/bookmark.php:
    sanitize_bookmark_field()
  • wp-includes/author-template.php:
    get_the_author_link()
  • wp-includes/author-template.php:
    wp_list_authors()
  • wp-includes/rss.php:
    wp_rss()
  • wp-includes/customize/class-wp-widget-area-customize-control.php:
    WP_Widget_Area_Customize_Control::render_content()
  • wp-includes/class-wp-customize-control.php:
    WP_Customize_Control::render()
  • wp-includes/class-wp-customize-control.php:
    WP_Customize_Control::get_link()
  • wp-includes/class-wp-customize-control.php:
    WP_Customize_Control::render_content()
  • wp-includes/comment-template.php:
    comment_form()
  • wp-includes/comment-template.php:
    comments_popup_link()
  • wp-includes/comment-template.php:
    get_comment_reply_link()
  • wp-includes/class-wp-customize-widgets.php:
    WP_Customize_Widgets::output_widget_control_templates()
  • wp-includes/comment.php:
    sanitize_comment_cookies()
  • wp-includes/media-template.php:
    wp_print_media_templates()
  • wp-includes/class-wp-editor.php:
    _WP_Editors::editor()
  • Show 237 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: 0You must log in to vote on the helpfulness of this note

    Contributed by Codex

    Example of escaping $_POST data on output

    
    <?php $fname = ( isset( $_POST['fname'] ) ) ? $_POST['fname'] : ''; ?>
    <input type="text" name="fname" value="<?php echo esc_attr( $fname ); ?>">
    

上一篇:ent2ncr()

下一篇:esc_attr_e()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!