Settings API Multiple Checkbox in General Settings
Settings API Multiple Checkbox in General Settings
Settings API Multiple Checkbox in General Settings
Real-time updating is achieved with JavaScript. Is your .js code working? The Codex has great examples and I think Otto has a defacto post about it somewhere on Google. This has everything you need: https://codex.wordpress.org/Theme_Customization_API
An option is a meta information saved in the database as a string. An array is a memory specific variable that has its own characteristics. But to every problem there is a workaround: $myoption = json_encode($the_array(); add_option(‘myoption’, $myoption, ”, ‘yes’); Now to fetch it: $myoption = json_decode(get_option(‘myoption’)); Voila. When saving the option I converting to … Read more
Use http://codex.wordpress.org/Settings_API to add new setting to existed group “general”: add_action( ‘admin_init’, ‘register_my_setting’ ); function register_my_setting() { add_settings_field(‘foo’, ‘Foo settings’, ‘foo_function’, ‘general’, ‘default’, array(‘label_for’ => ‘foo’)); register_setting(‘general’, ‘foo’, ‘foo value’); } function foo_function() { echo ‘<input name=”foo” id=”foo” value=”” class=”regular-text ltr”>’; } You must modify function to validate input and to show saved value.
A quick and dirty way of doing this is by adding a .htaccess file to the wp-admin directory, with the following content. <FilesMatch “^options-(.*)\.php$”> Order Allow,Deny Deny from all </FilesMatch>
That’s because you need to print your settings fields in Kaipo_menu_callback, something like: <?php function Kaipo_menu_callback() { ?> <div class=”wrap”> <h2>Kaipo</h2> <form action=”options.php” method=”post”><?php do_settings_sections( ‘kaipo_menu_page’ ); settings_fields( ‘kaipo_menu_page’ ); submit_button(); ?></form> </div> <?php } I would strongly suggest reading the settings API in detail.
I found the answer. Problem was I was retrieving those setting option values outside the if statement if(isset($_POST[‘formvalue’])){ } and using them inside it. For that reason values were actually not pulled from database.
From the settings API, add_settings_field( ‘my_first_field-id’, ‘This is the setting title’, ‘myprefix_setting_callback_function’, ‘general’, ‘myprefix_settings-section-name’, array( ‘label_for’ => ‘my_first_field-id’ ) ); myprefix_setting_callback_function(){ echo ‘<input type=”text” name=”my_first_field” value=”‘.get_option(‘my_first_field’).'” />’; }
Add Logo Upload per Setting API
I’ve done some debugging, it came out that this line caused wrong behavior: $settings = wp_parse_args( $settings, $defaults ); I wondered why it’s after this line which supposedly does the same: $settings = get_option( ‘acau_settings’, $defaults ); These 2 lines one after another were part of code from a wiser man, so I thought that … Read more