The plugin admin panel works fine until I attempt to validate the settings;
register_setting('jo_plugin_options', 'jo_plugin_options', array($this, 'jo_validate_settings'));
add_settings_section('jo_main_section', 'Data Table Settings', array($this, 'jo_main_section_cb'), __FILE__); // id, title, section, callback, page
add_settings_field('jo_col_1_name', 'Column 1 Name: ', array($this, 'jo_col_1_name_setting'), __FILE__, 'jo_main_section');
add_settings_field('jo_col_2_name', 'Column 2 Name: ', array($this, 'jo_col_2_name_setting'), __FILE__, 'jo_main_section');
add_settings_field('jo_col_3_name', 'Column 3 Name: ', array($this, 'jo_col_3_name_setting'), __FILE__, 'jo_main_section');
add_settings_field('jo_file_upload', 'Upload File: ', array($this, 'jo_file_upload_setting'), __FILE__, 'jo_main_section');
So if I remove the // array($this, ‘jo_validate_settings’) // from the register_setting line my text boxes function fine. But when I add that validation code, it breaks them and returns this error;
*Warning: Illegal string offset ‘jo_col_1_name’ in /Applications/MAMP/htdocs/wp-content/plugins/plugin-rough.php on line 82*
The boxes are here:
public function jo_col_1_name_setting() {
echo "<input id='jo_col_1_name' name='jo_plugin_options[jo_col_1_name]' type='text' value='{$this->options['jo_col_1_name']}' />"; }
public function jo_col_2_name_setting() {
echo "<input name='jo_plugin_options[jo_col_2_name]' type='text' value='{$this->options['jo_col_2_name']}' />"; }
public function jo_col_3_name_setting() {
echo "<input name='jo_plugin_options[jo_col_3_name]' type='text' value='{$this->options['jo_col_3_name']}' />"; }
I did some reading online and found something semi relevant, someone saying that the keys were the same and I needed to change $this to &$this for it to function. I tried it and nothing happened, same errors.
Any ideas?
Additionally: Is it necessary to use add_settings_field for each additional field I want to add? Seems like I will be adding a very large amount of these.
var_dump shows me this:
string(31) "{$this->options[jo_col_1_name]}"
Try something like this:
Full working example (added inside “Settings” backend) :