0
votes

I'm working on a Wordpress plugin that uses the Wordpress Options.php functionality. I have a settings_field registered and access those options with this:

$xoptions = get_option('xsettings');

So that on my page I can reference $xoptions["first_name"] to pull given settings, and have them saved and updated automatically via Wordpress' Options.php. The problem is, I can't read or set values in the $xoptions associative array manually without having to use the "xsettings[first_name]" syntax that gets buried in the HTML and submitted with a form. I need to update these values without sending a form.

What I'm trying to do, basically, is set the value of one of those values manually like this:

$xoptions['first_name'] = "Derek Walters";

but that doesn't work as it would with a normal associative array. I'm wondering if there's a way to manually read and write names/values from Worpress Options.

I've tried setting it manually with

update_option('first_name',$_POST['name']);

Any help would be fantastic. Thanks in advance! I've been Googling for hours and trying different slabs of code and haven't figured out if it's even possible.

1
Have you tried update_option("xsettings", $xoptions) after $xoptions['first_name'] = "Derek Walters"; - imtheman
That worked. I swear my mind gets dumb the longer I stare at things. Thank you so much! - RalphTheWonderLlama
I know exactly how you feel. I'll post it as answer then. - imtheman
Why don't you use the Settings API instead? - Ron van der Heijden

1 Answers

1
votes

In order to update Wordpress options that are in an array you need to do like so:

$xoptions = get_option('xsettings');
$xoptions['first_name'] = "Derek Walters";
update_option("xsettings", $xoptions);