evertiro / historical-redux2

A simple, easily extendable options framework for WordPress based on NHP Theme Options Framework.
http://reduxframework.com
Other
105 stars 43 forks source link

Add hook before saving options #120

Closed mekshq closed 11 years ago

mekshq commented 11 years ago

It would be cool if we have a possibility to hook options array before saving. For example, if some option I use is connected with some API. Let's say I use Google Maps to retrieve coordinates for a given address. I would like to have a possibility to store the coordinates inside options as well, so when I use the options on the front-end I don't need to do HTTP request to Google API every time, I just use the cached options.

As I see in the code, all the options are always shown in options panel UI. So, perhaps we can make additional array of, let's say, UI inaccessible options which we can fill while saving the options for internal use, options which user can't modify directly, and we can use it for caching preferably.

What do you think?

evertiro commented 11 years ago

I think that's not a bad idea! I'd honestly never considered it, but I suppose I can see the use for it. What does everyone else think?

psaikali commented 11 years ago

I like it too, that should be quite useful in some cases like for caching things or querying APIs.

denis0706 commented 11 years ago

All we need to perform this task is to change action hook to filter hook here: #L517

 $plugin_options = apply_filters('redux-opts-options-validate-' . $this->args['opt_name'], $plugin_options, $this->options);```
dovy commented 11 years ago

@denis0706 @mekshq @psaikali I'll get around to better documentaiton, but take a look at a more recent post about this.

There are now options for a saving hook as well as a concept of a compiler hook. Check it out.

https://github.com/ghost1227/Redux-Framework/issues/152

All new in 3.0. ;)