WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 3 weeks ago

#24528 new defect (bug)

Customizer checkbox with refresh option gives inconsistent values

Reported by: nathanrowe82 Owned by:
Milestone: Awaiting Review 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 (3)

comment:1 @SergeyBiryukov2 years ago

  • Component changed from General to Appearance

Might be related to #20712.

comment:2 follow-up: @danielmilner4 weeks ago

I'm experiencing this same issue in Wordpress 4.2.4. It's driving me crazy because the checkbox value is not consistent.

comment:3 in reply to: ↑ 2 @steven_gardner3 weeks 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

Last edited 3 weeks ago by steven_gardner (previous) (diff)
Note: See TracTickets for help on using tickets.