I'm trying to use wordpress plugin development, without a checked checkbox getting an error.
<?php global $options; ?>
<input name="settings[enable]" type="checkbox" id=""
value="1" <?php checked( $options['enable'], 1 ); ?> />
I'm trying to use wordpress plugin development, without a checked checkbox getting an error.
<?php global $options; ?>
<input name="settings[enable]" type="checkbox" id=""
value="1" <?php checked( $options['enable'], 1 ); ?> />
Share
Improve this question
edited May 22, 2019 at 7:29
nmr
4,5672 gold badges17 silver badges25 bronze badges
asked May 22, 2019 at 7:20
ApsaraArunaApsaraAruna
156 bronze badges
1
|
1 Answer
Reset to default 0checked()
only checks if the passed first and second parameters match. It doesn't do any array key checking, so you need to do it yourself before using the function to avoid errors.
<?php
global $options;
$enabled = ( isset( $options['enable'] ) ) ? $options['enable']: '';
?>
<input name="settings['enable']" type="checkbox" id="" value="1" <?php checked( $enabled, 1 ); ?>>
print_r($options)
give you anything? Depending on the context this may or may not be the way you need to refer to the options. Also, your input name needs to besettings['enable']
with quotes. – WebElaine Commented May 22, 2019 at 14:00