Opened 11 years ago
Closed 8 years ago
#24528 closed defect (bug) (invalid)
Customizer checkbox with refresh option gives inconsistent values
Reported by: | nathanrowe82 | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.5 |
Component: | Customize | Keywords: | |
Focuses: | Cc: |
Description
When adding a checkbox control to the customizer feature with type = refresh, the value returned is sometimes a string and sometimes a boolean, when the checkbox is changed.
I've tested this in 3.5, and 3.6-beta3-24407.
How to reproduce in 3.5:
Load the "Twenty Twelve" theme. In the functions file add a test checkbox setting & control:
$wp_customize->add_setting('test', array( 'type' => 'option', 'default' => true, 'priority' => 10, 'transport' => 'refresh' )); $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'test', array( 'label' => __( 'Test' ), 'section' => 'title_tagline', 'settings' => 'test', 'type' => 'checkbox' )));
Dump the value into the index.php of the theme:
<?php var_dump(get_option('test')); ?>
This is where things get odd:
Load up the customizer,
- Theme should output: bool(true)
Toggle the checkbox, allowing for the iframe to refresh each time:
All results should be boolean values.
Toggle to checkbox to ON, hit save, and refresh the browser window.
- Theme should output: string(1) "1"
Toggle the checkbox to OFF, allowing for the iframe to refresh:
Value does not update
Toggle the checkbox some more, allowing for the iframe to refresh each time:
Results will toggle between string(1) "1" and boolean(true)
ONE LAST TEST:
Toggle to checkbox to OFF, hit save, and refresh the browser window.
- Theme should output: string(0) ""
Toggle the checkbox some more, allowing for the iframe to refresh each time:
Results will toggle between string(0) "" and boolean(true)
Thanks
Change History (4)
#2
follow-up:
↓ 3
@
9 years ago
I'm experiencing this same issue in Wordpress 4.2.4. It's driving me crazy because the checkbox value is not consistent.
#3
in reply to:
↑ 2
@
9 years ago
Replying to danielmilner:
I'm experiencing this same issue in Wordpress 4.2.4. It's driving me crazy because the checkbox value is not consistent.
Yeah me too. My checkbox returns true whether its checked or not.
I'm trying to hide some text if checkbox is checked but not matter if its checked or not its returning true so hiding the text.
SORRY FIXED!!
I was sanatizing it as an integer instead of a boolean
Might be related to #20712.