Modify the checked property of the checkbox when using register_setting
![Modify the checked property of the checkbox when using register_setting Modify the checked property of the checkbox when using register_setting](http://up-free-imgs.azimiao.com/wp-content/uploads/2020/03/wordpress.jpg)
text
example
<? php function RegMenu(){ add_menu_page( "Page Title", # Page Title "Menu Title", # Menu Title "Administrator", # Who can see "My test setting", # Set page alias (url access) "Output_settingpage", # Output function "dashicons-heart" #icon url ); Add_submenu_page (# Add submenu "My test setting", # parent menu alias "Page Title", # Page Title "Sub menu title", # menu title "administrator", "My test setting1", # Page alias "Output_settingpage1" # Output function ); add_action('admin_init', 'reg_custom_settings'); } fcunction reg_custom_settings(){ register_setting('test_group','zm_test_isopen'); } function output_settingpage(){ ?> <form method="post" action="options.php"> <? php settings_fields('test_group'); ?> <input type="checkbox" name="zm_test_isopen" value="1" <? php checked( '1', get_option( 'zm_test_isopen' ), true ); ?>/>Test</label> <? php submit_button(); ?> </form> <? php } function output_settingpage1(){ } ?>
WordPress checked details
//Outputs the html checked attribute. checked( mixed $checked, # One of the values to compare mixed $current = true, # The other value to compare if not just true bool $echo = true # Whether to echo or just return the string )
<input type='checkbox' name='zm_test_isopen' value='1' <? php if ( 1 == $options['zm_test_isopen'] ) echo 'checked="checked"'; ?> />
<input type="checkbox" name="zm_test_isopen" value="1" <? php checked("1",$options['zm_test_isopen'], 1 ); ?> />