Odd issue with if/else statement
-
Hello all –
I have a custom widget I’ve written, and it’s worked for quite a while now. But since 3.1, it’s no longer functioning. The part that isn’t working is a checkbox option to show or hide the title of the widget – and simple if/else statement to see if the box is checked.
<p><input id="<?php echo $this->get_field_id('hide'); ?>" name="<?php echo $this->get_field_name('hide'); ?>" type="checkbox" <?php checked(isset($instance['hide']) ? $instance['hide'] : 0); ?> /> <label for="<?php echo $this->get_field_id('hide'); ?>"><?php _e('Hide?'); ?></label></p>
the
<?php checked(isset($instance['hide']) ? $instance['hide'] : 0); ?>
is what determines if the box is checked or not, and I lifted this spot of code directly from the default-widgets.php file back when I first wrote it (I think it might have been version 2.7 or something.) However, now, it doesn’t work. If I check the box, no matter what I do, it remains unchecked.I’ve also changed it to this:
<?php checked(isset($instance['hide']) ? true : false); ?>
and this<?php checked(isset($instance['hide'])); ?>
and this<?php checked($instance['hide']) ?>
and the latter two are the only ones that allow the checkbox to remain checked or unchecked based on what you do – it seems to retain what your decision is just fine BUT it returns nothing. Checked or not, a var_dump ($hide) gives you NULL every time, which is odd to me.Did something change in 3.1 for this? Does anyone know why it no longer works, and perhaps how to fix it?
Thanks ??
- The topic ‘Odd issue with if/else statement’ is closed to new replies.