I want to make a php class that gets an option from the wp database (which is an array of options) and be able to call this class with the name of the option and the class to return the options value.
Does anyone know how would I go about doing this?
EDIT: I have tried the following code
class N_Options {
function __construct($name) {
if(isset($name)):
$options = get_option(THEME_SPACE . '_options');
$option = $options[$name];
echo $option;
endif;
}
}
And I have tried to call the option using
new N_Options('option');
This retrieves the option from the database just fine now. However, I think this may be accessing the database too many times as I will be accessing this class over and over for all my options.
Is there a way to store these options inside the class as an array variable and keep calling the class to look inside the variable without calling a new class for each option?