I have a custom options page. I have several sections of settings and some of them are even more closely related to each other so I decided to store them in arrays, seems more logical to me. It surely, minimizes the code a bit too. First question: Is this a good practice?
Example:
get_option('header')['header_logo']['image'];
get_option('header')['header_logo']['width'];
get_option('header')['header_logo']['height'];
get_option('header')['header_color'];
This results to an array which includes nested arrays at different levels.
If we use get_option('header');
normally and supposedly store a string, we can use get_option('header', 'default value');
to echo a default value if the option is not set. How can I do this for a value within an array ex. get_option('header')['header_logo'];
and similarly for get_option('header')['header_logo']['image'];
? Also how can this be done for all items in the whole array at once?
Second question: Which is the best practice when it comes to setting default option values? Should I use the update_option
function in the after_theme_setup
function to set the defaults? Is there any better way?
Thanks in advance.