fathimasmat
Forum Replies Created
-
Forum: Plugins
In reply to: [Footnotes Made Easy] Plugin issues: updateHi David,
I think the better way to approach the options save would be using WordPress settings API instead of a custom form submission method for POST. That way you can also safely ensure that your plugin settings are updated only when the ‘submit’ button from your plugin options page is pressed but not when other options are saved or updated.
Here is a guide to WP settings API and there are useful functions to automatically render the options in your relevant form fields (settings_fields, do_settings_fields() and automatically update the options when the form is submitted (register_setting).
So, in your options form, you can add these two lines immediately after the form tag:
<form ... settings_fields('footnotes-made-easy-settings-group'); do_settings_sections('footnotes-made-easy-settings-group'); ....and before closing the form you can add the submit button using the function:
... submit_button(); </form>To register your custom settings group so WP knows that they are valid options to be automatically processed, you can use the
register_settingfunction in an admin hook.add_action('admin_init', 'register_footnotes_settings'); function register_footnotes_settings() { register_setting('footnotes-made-easy-settings-group', 'your_option_name'); register_setting('footnotes-made-easy-settings-group', 'your_option_name'); }I would advise to use your
option_nameas an array for all your fields so as to store the options in a serialised array rather than each single option. Otherwise, you will have to register each option field separately using theregister_settingmethod as shown above.I hope it helps.
Best,
Fathima