Open alekseyn1 opened 5 years ago
Here is a working solution. Replace the entire case: entry with this
case 'checkbox':
$checked = '';
global $wpdb;
$empty_option = false;
$row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option_name));
if (is_object($row)) {
$empty_option = true;
}
if( ($option) || ( $empty_option == false && $field['default'] ) ){
$checked = 'checked="checked"';
}
$html .= '<input id="' . esc_attr( $field['id'] ) . '" type="' . $field['type'] . '" name="' . esc_attr( $option_name ) . '" ' . $checked . '/>' . "\n";
break;
Hey @alekseyn1 thanks for this.
Are you able to open a pull request with these changes. I can't guarantee I will be able to merge it very soon, but if it's open I can at least try and prioritise it.
Hello, checkbox default 'on' not working
when settings screen gets loaded the first time after plugin activation, the checkbox is unchecked.
I am on the latest WP (5.0.3) and PHP 7.2
Any help would be greatly appreciated