Most of the time, options for your theme or plugin will be set via the options panel. But what if you have a need to update an option someplace else? Perhaps an option would need to be changed behind the scenes, based on certain conditions, can it be done?

You better believe it!

SETting it all up

The Redux core includes a function titled set, which allows one to change any option on the fly. But to access this function we need to make one small change to your config file (sample-config.php by default, and what we’ll use in this example).

In the sample-config.php file, toward the bottom is the line new Redux_Framework_sample_config();. This is where the sample-config creates an object itself. We’ll need to assign this object to a global variable.

Replace this line:

new Redux_Framework_sample_config();

with these lines:

global $sampleReduxFramework;

$sampleReduxFramework = new Redux_Framework_sample_config();

Ready, SET, Go!

With the change made to the sample-config to hold an instance of itself in a global variable, we can now call set anywhere in the project, specifically to update a previously set/saved option. The set function takes two parameters. The first is $opt_name, which accepts a string value representing the option name, set via the id argument of the options field array. The second parameter accepts the new value in mixed format (string, int, bool, etc). Before using the set function, the global variable representing the config class must be declared. In the above example, it would be $sampleReduxFramework. Then, use the ReduxFramework object to call set, as shown below:

global $sampleReduxFramework

$sampleReduxFramework->ReduxFramework->set('my_option', 'its_value');

That’s all there is to it.