Write forms, collect data from them, validate, then store. That’s the routine familiar to most plugin developers, and one that could always be easier. Why should you have to waste your time writing boring form handling functions when you could be working on one of the more interesting parts of your code?
With WordPress 2.8 comes the register_setting() function, which just might make things a bit easier.
Essentially the function lets WordPress handle the data collection and storage dirty work. After calling register_setting()
when the init
hook runs, you can just create the form and sanitize the data with a callback function.
add_action('admin_init', 'ozh_sampleoptions_init'); function ozh_sampleoptions_init() { register_setting('ozh_sampleoptions_options', 'ozh_sample'); }
Apparently this method works in 2.7 as well, but in 2.8 it is required if you’re using options.php for your settings.