Wordpress check box unchecked on null value ternary operator [plugin development]

I'm trying to use wordpress plugin development, without a checked checkbox getting an error.<?php global $option

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
  • Does 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 be settings['enable'] with quotes. – WebElaine Commented May 22, 2019 at 14:00
Add a comment  | 

1 Answer 1

Reset to default 0

checked() 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 ); ?>>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745472898a4629215.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信