illegal offset in option add

The array is ‘hidden’ inside the form elements. Their respective name/ID is like MY_option_name[some_other_name]. That is the array structure. // Edit (to elaborate a little on that) Suppose you have the following form: <form action=”options.php” method=”post”> Font:<br /> <input type=”text” name=”MY_options[font]” id=”MY_options[font]” /> Color:<br /> <input type=”text” name=”MY_options[color]” id=”MY_options[color]” /> <?php submit_button(); ?> </form> If … Read more

Custom button and html with [settings api plugin]

You can modify the plugin to add a “Save & Execute” button, but not sure what will you do with that. As the PHP class doesn’t do anything for saving the options, WordPress handles it by default. So it’s tricky that how you’ll implement the execution. You can add a html type field for documentation. … Read more

Adding Form Fields with Settings API

You’re using same callback function for both setting fields. Use different ones with it’s own inputs. Here’s updated code: <?php /* Plugin Name: Settings API Demo Description: Learning Setting Field and Settings Section Author: Teno */ add_action(‘admin_init’, ‘settingsapi_init’); function settingsapi_init(){ register_setting( ‘settingsapi_optiongroupname’, ‘settingsapi_optionname’); add_settings_section(‘plugin_main’, ‘Section 1’, ‘settingsapi_sectiondescription’, ‘settingsapi_pageslug’); add_settings_field(‘plugin_text_string_a’, ‘Option A’, ‘settingsapi_setting_string_a’, ‘settingsapi_pageslug’, ‘plugin_main’); add_settings_field(‘plugin_text_string_b’, … Read more

Option doesn’t save

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