WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 4 months 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)

#1 @SergeyBiryukov
3 years ago

  • Component changed from General to Appearance

Might be related to #20712.

#2 follow-up: @danielmilner
16 months 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 @steven_gardner
16 months 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 16 months ago by steven_gardner (previous) (diff)

#4 @westonruter
4 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

It seems the answer is sanitizing as a boolean. Otherwise, closing this due to inactivity. It can be re-opened if there is still a bug here.

Note: See TracTickets for help on using tickets.