ThemeForest

OptionTree + Checkbox + Default state

589 posts
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Has been a member for 2-3 years
  • Europe
  • Exclusive Author
  • Referred between 10 and 49 users
  • Bought between 100 and 499 items
WPScientist says

I’m probably missing something obvious. Is there a way to set a default state for the checkbox (checked or not)?

589 posts
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Has been a member for 2-3 years
  • Europe
  • Exclusive Author
  • Referred between 10 and 49 users
  • Bought between 100 and 499 items
WPScientist says

Ok, it appeared to be impossible so i jumped in the code.

File: includes/ot-settings.api.php

Line: 475

This…

$options[$id] = trim( $std );

...to this…

if ( is_array($std) )
    $options[$id] = $std;
else
    $options[$id] = trim( $std );

So now you can use the “std” to add the defaults like…

array(
    'id'      => 'multiple_checkbox_example',
    'label'   => 'Multiple Checkbox,
    'desc'    => 'Blah blah blah.',
    'std'     => array(
            0 => 'first',
            2 => 'third'
        ),
    'type'    => 'checkbox',
    'section' => 'section',
    'choices' => array(
        array( 
            'value' => 'first',
            'label' => 'First'
        ),
        array( 
            'value' => 'second',
            'label' => 'Second' 
        ),
        array( 
            'value' => 'third',
            'label' => 'Third' 
        )
    ),
),
105 posts
  • Most Wanted Bounty Winner
  • Has been a member for 2-3 years
  • Sold between 50 000 and 100 000 dollars
  • Egypt
  • Author had a Free File of the Month
  • Referred between 10 and 49 users
  • Bought between 50 and 99 items
  • Exclusive Author
Code125 says

For me I use Drop Down Menu for Yes and No to be able to set the default value

589 posts
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Has been a member for 2-3 years
  • Europe
  • Exclusive Author
  • Referred between 10 and 49 users
  • Bought between 100 and 499 items
WPScientist says

For me I use Drop Down Menu for Yes and No to be able to set the default value

Yeah but having multiple checkboxes for something that should be grouped is way more organized then having multiple select inputs each as separate option.

373 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 2-3 years
  • Referred between 1 and 9 users
  • Sold between 5 000 and 10 000 dollars
  • Vietnam
rongcon says
$responsive_checked = ''; //unchecked
$responsive_checked = 'checked="checked" '; //checked

<input type="checkbox" name="something" value="" <?php echo $responsive_checked;?> >
656 posts
  • Sold between 5 000 and 10 000 dollars
  • Referred between 10 and 49 users
  • Bought between 10 and 49 items
  • Has been a member for 4-5 years
  • Exclusive Author
  • Microlancer Beta Tester
ChillThemes says

Does OptionTree use the checked() function? http://codex.wordpress.org/Function_Reference/checked

589 posts
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Has been a member for 2-3 years
  • Europe
  • Exclusive Author
  • Referred between 10 and 49 users
  • Bought between 100 and 499 items
WPScientist says

@rongcon – Yeah, i know, that’s the HTML basics :) The issue here is handling checkbox default state in OptionsTree theme options framework for WordPress.


Does OptionTree use the checked() function? http://codex.wordpress.org/Function_Reference/checked

I think not (from what i remember when i was looking at the code earlier today). But it doesn’t matter. The issue with the default state can be fixed with the code i posted above. But maybe there’s a reason why checkbox default state isn’t supported, hope to hear from the OptionTree author.

by
by
by
by
by