I’m developing my first plugin for WordPress and I’m getting a grasp of the whole hook system. I’m now stuck on a (probably) small issue, that I could possibly circumvent, but I’m afraid of coming out with a “hack”, more than a real solution.
What I’m trying to do is putting two submit buttons on my Options page:
- Save
- Draft
Both of them would have to do something common (i.e. Saving the content of the form), but then they should take different action with such content. So far, I managed to ouput the two buttons using the following code:
echo '<form id="my_plugin_settings_form" method="post" action="options.php">';
settings_fields('my_plugin_settings');
do_settings_sections('my_plugin_settings');
submit_button(__('Save', 'MyPlugin'), 'Save');
submit_button(__('Draft', 'MyPlugin'), 'secondary','Draft');
echo '</form>';
I also implemented a validate method, which correctly receives the posted fields:
public function validate_settings($settings) {
var_dump($settings); // Here I can see all posted fields
}
The above works well, with all the data being saved correctly in WordPress Options table. However, I would like to “intercept” the data being saved to manipulate it. I was thinking of manipulating the data within the validate_settings()
method, but the button that was clicked is not included in the settings passed as an argument.
I could simply parse the $_POST
array to get it, but I’m having the doubt that the approach is a bit of a hack and, that, perhaps, I should implement a proper hook, somewhere else.
My question, therefore, is: where should I put my code to process the data posted from an Options page? Is there a specific hook I should use?
Thanks in advance for the answers.