admin管理员组文章数量:1429658
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 ); ?>>
本文标签: Wordpress check box unchecked on null value ternary operator plugin development
版权声明:本文标题:Wordpress check box unchecked on null value ternary operator [plugin development] 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745472898a2659831.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
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