Add multiple checkbox into general settings - mdhemalakhand1999/WordPressPluginDevelopment GitHub Wiki
To add multiple checkbox into general settings you can use this code:
/**
* Create multiple select checkbox
*/
function ptc_multiple_select_checkbox() {
add_settings_field('multiple_select_country', 'Select Your Country', 'multiple_select_country_callback', 'general');
register_setting( 'general', 'multiple_select_country' );
}
add_action('admin_init', 'ptc_multiple_select_checkbox');
function multiple_select_country_callback() {
$options = get_option('multiple_select_country');
$countries = array(
'Bangladesh',
'Africa',
'Malaysia',
'Maldives',
'New York',
'Netherland',
'Australia'
);
foreach($countries as $country) {
$country_checked = '';
if(is_array($options) && in_array($country, $options)) {
$country_checked = 'checked';
}
printf("<input type='checkbox' name='multiple_select_country[]' value='%s' %s /> %s<br/>", $country, $country_checked, $country);
}
}