[suggestion] the ot_get_option() function
-
First of all greetings and many thanks for this useful plugin.
I used to base my option pages on a self-made very basic class but as i always like to include user friendly tools in the themes I produce, I decided to give your plugin a try.
Calling options is made with the ‘ot_get_option()’ function, each time it’s used it makes a database query calling the ‘get_option()’ function and retrieves the same ‘option_tree’ entry.
As this entry is an array, wouldn’t it be more ressource efficient to query the db once and store its value in a variable globally available?
I replaced the native function with this one:
function ot_get_option( $option_id, $default = '' ) { /* get the saved options */ global $option_tree_value; if (!isset($option_tree_value)) { $option_tree_value = get_option( 'option_tree' ); } $options = $option_tree_value; /* look for the saved value */ if ( isset( $options[$option_id] ) && '' != $options[$option_id] ) { return $options[$option_id]; } return $default; }
The database is then queried only once each time a page loads.
Adam
- The topic ‘[suggestion] the ot_get_option() function’ is closed to new replies.