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

返回介绍

checked()

发布于 2017-09-10 字数5354 浏览 914 评论 0

checked( mixed $checked,  mixed $current = true,  bool $echo = true )

Outputs the html checked attribute.


描述

Compares the first two arguments and if identical marks as checked


参数

$checked

(mixed)
(Required)
One of the values to compare

$current

(mixed)
(Optional)
(true) The other value to compare if not just true

Default value: true

$echo

(bool)
(Optional)
Whether to echo or just return the string

Default value: true


返回值

(string) html attribute or empty string


源代码

File: wp-includes/general-template.php

function checked( $checked, $current = true, $echo = true ) {
	return __checked_selected_helper( $checked, $current, $echo, 'checked' );
}

更新日志

Version 描述
1.0.0 Introduced.

相关函数

Uses

  • wp-includes/general-template.php:
    __checked_selected_helper()

Used By

  • wp-admin/includes/class-wp-screen.php:
    WP_Screen::render_meta_boxes_preferences()
  • wp-admin/includes/class-wp-screen.php:
    WP_Screen::render_list_table_columns_preferences()
  • wp-admin/includes/class-wp-screen.php:
    WP_Screen::render_view_mode()
  • wp-admin/includes/class-wp-press-this.php:
    WP_Press_This::post_formats_html()
  • wp-signup.php:
    signup_user()
  • wp-admin/includes/network.php:
    network_step1()
  • wp-admin/install.php:
    display_setup_form()
  • wp-admin/includes/user.php:
    use_ssl_preference()
  • wp-admin/includes/class-wp-screen.php:
    WP_Screen::show_screen_options()
  • wp-admin/includes/class-wp-screen.php:
    WP_Screen::render_screen_layout()
  • wp-admin/includes/screen.php:
    meta_box_prefs()
  • wp-admin/includes/misc.php:
    admin_color_scheme_picker()
  • wp-admin/includes/class-walker-category-checklist.php:
    Walker_Category_Checklist::start_el()
  • wp-admin/includes/media.php:
    wp_media_insert_url_form()
  • wp-admin/includes/meta-boxes.php:
    post_comment_status_meta_box()
  • wp-admin/includes/meta-boxes.php:
    link_submit_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/class-walker-nav-menu-edit.php:
    Walker_Nav_Menu_Edit::start_el()
  • wp-admin/includes/file.php:
    request_filesystem_credentials()
  • wp-admin/custom-header.php:
    Custom_Image_Header::step_1()
  • wp-admin/custom-header.php:
    Custom_Image_Header::show_header_selector()
  • wp-admin/custom-background.php:
    Custom_Background::admin_page()
  • 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-archives.php:
    WP_Widget_Archives::form()
  • wp-includes/widgets/class-wp-widget-links.php:
    WP_Widget_Links::form()
  • wp-includes/widgets.php:
    wp_widget_rss_form()
  • wp-includes/class-wp-customize-control.php:
    WP_Customize_Control::render_content()
  • Show 25 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

    
    <?php
    
    // Get an array of options from the database.
    $options = get_option( 'slug_option' );
    
    // Get the value of this option.
    $checked = $options['self-destruct'];
    
    // The value to compare with (the value of the checkbox below).
    $current = 1; 
    
    // True by default, just here to make things clear.
    $echo = true;
    
    ?>
    <input name="slug-option[self-destruct]" value="1"
    	<?php checked( $checked, $current, $echo ); ?>/>
    

    Testing the value with if():

    
    <input type='checkbox' name='options[postlink]' value='1'
    	<?php if ( 1 == $options['postlink'] ) echo 'checked="checked"'; ?> />
    

    Using checked() instead:

    
    <input type="checkbox" name="options[postlink]" value="1"
    	<?php checked( $options['postlink'], 1 ); ?> />
    

发布评论

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

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