590 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $125,000+ on Envato Market
  • Made it to the Authors' Hall of Fame
  • Sells items exclusively on Envato Market
+5 more
CodeSwift says

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

590 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $125,000+ on Envato Market
  • Made it to the Authors' Hall of Fame
  • Sells items exclusively on Envato Market
+5 more
CodeSwift 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' 
        )
    ),
),
176 posts Amazing WordPress Themes
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $75,000+ on Envato Market and is now an Elite Author
  • Has referred 50+ members
  • Has collected 100+ items on Envato Market
+5 more
Code125 says

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

590 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $125,000+ on Envato Market
  • Made it to the Authors' Hall of Fame
  • Sells items exclusively on Envato Market
+5 more
CodeSwift 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.

498 posts
  • Has referred 10+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 more
wopethemes says
$responsive_checked = ''; //unchecked
$responsive_checked = 'checked="checked" '; //checked

<input type="checkbox" name="something" value="" <?php echo $responsive_checked;?> >
709 posts
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+2 more
ChillThemes says

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

590 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $125,000+ on Envato Market
  • Made it to the Authors' Hall of Fame
  • Sells items exclusively on Envato Market
+5 more
CodeSwift 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.

474 posts
  • Has sold $10,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Has referred 1000+ members
  • Helped several times protecting Envato Market against copyright violations
+4 more
readactor says

Hello WPScientist,

i used your code tip to can use the “std” to add the defaults values to the checkboxes but the problem now is that you cannot save different values, it keep the “std” value from theme-opion.php file. did that happen and to you?

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by