What is the best way to go about setting up default values for a plugin? Should I just insert those values into the wp_options table?
AND…if that’s the best way to go about it, I have another question. My options are listed as a group which currently looks like:
a:4:{s:26:”nc_location_drop_down_zoom”;s:2:”14″;s:17:”nc_location_width”;s:3:”200″;s:29:”nc_location_drop_down_maptype”;s:7:”roadmap”;s:11:”text_string”;s:0:””;}
Is this a serialized array? How do I do an insert like this into the table? (I realized this is more of an sql question…)
Use the Settings API and save your data in a single option as an array, WordPress will serialize the data for you.
You should do defaults at the time of pulling the data out. Never insert default values into the database. Defaults are default. Options in the DB override defaults.
How to do defaults for a serialized options array:
In addition to the answer by Otto.
If you have the multidimensional options array and you still want it to merge with the array of defaults, use the following function in place of
wp_parse_args()
:For example,
The recursive function was found here.
Use add_option. If you use add_option existing options will not be updated and checks are performed to ensure that you arenât adding a protected WordPress option.
See add_option at developer.wordpress.org