Note that there are some explanatory texts on larger screens.

plurals
  1. PODefault state (Add options) overrides my update options?
    primarykey
    data
    text
    <p>I have a check box inside my admin page and the code looks like this <i>(this code works and i can toggle my check box off and on and able to save changes)</i></p> <pre><code>add_settings_field( 'my_checkbox_default', 'Checkbox:', 'my_default_checkbox_settings_function', 'override_theme_display_options', 'override_theme_display_options' ); function my_default_checkbox_settings_function(){ $options = get_option('override_theme_display_options'); if(isset($options['my_checkbox_default'])) { $checked = 'checked'; } else { $checked = ''; } update_option('my_checkbox_default', $checked); echo "&lt;input type='checkbox' name='override_theme_display_options[my_checkbox_default']' ".$checked." id='my_checkbox_default' /&gt;"; } </code></pre> <p>Now I want to add default state <b>"checked"</b> to my check box.</p> <p>So my check box setting function looks like this:</p> <pre><code>function my_default_checkbox_settings_function(){ $options = get_option('override_theme_display_options'); //Added default state "checked" to my check box add_option('my_checkbox_default',$checked = 'checked'); if(isset($options['my_checkbox_default'])) { $checked = 'checked'; } else { $checked = ''; } update_option('my_checkbox_default', $checked); echo "&lt;input type='checkbox' name='override_theme_display_options[my_checkbox_default']' ".$checked." id='my_checkbox_default' /&gt;"; } </code></pre> <p>My check box now has <b>"checked"</b> state as default , but now I <b>can't toggle</b> my check box <b>off</b> and <b>on</b> anymore (it stays "checked" all the time no matter what I do), if I comment out my <code>add_option()</code> obliviously my default "checked" state will not be set but I will be able to toggle and save my check box states again. </p> <p>How can I add "checked" state by default <i>and still be able to toggle and save options for my check box</i>? <br/><b><i>I will be more than happy to add 50 bounty for solving this. THX!</i></b> </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload