I am creating a Wordpress theme from scratch and I would like to save a file with the theme option anytime the theme options change.
I was thinking about:
do_action('admin_init', 'my_custom_function');
function my_custom_function(){
save_file();
...
}
but in this case the file will be save anytime the admin area is loaded.
On the dashboard the theme creates forms to manage the theme options, like the following:
<form method="post" action="options.php">
<?php settings_fields( 'theme-settings-group' ); ?>
<?php do_settings_sections( 'theme-settings-group' ); ?>
// form in here
<?php submit_button(); ?>
</form>
This form send information to options.php which save the theme options on the database based on the setting group specified.
I would like to trigger an function any time something is saved in "options.php".
Can you guys suggest please? Thannks
I am creating a Wordpress theme from scratch and I would like to save a file with the theme option anytime the theme options change.
I was thinking about:
do_action('admin_init', 'my_custom_function');
function my_custom_function(){
save_file();
...
}
but in this case the file will be save anytime the admin area is loaded.
On the dashboard the theme creates forms to manage the theme options, like the following:
<form method="post" action="options.php">
<?php settings_fields( 'theme-settings-group' ); ?>
<?php do_settings_sections( 'theme-settings-group' ); ?>
// form in here
<?php submit_button(); ?>
</form>
This form send information to options.php which save the theme options on the database based on the setting group specified.
I would like to trigger an function any time something is saved in "options.php".
Can you guys suggest please? Thannks
Share Improve this question edited Jun 10, 2020 at 9:07 Marcello Perri asked Jun 10, 2020 at 9:01 Marcello PerriMarcello Perri 1117 bronze badges 1- Welcome to WordPress Development. WordPress has a special API for themes to store options which I do not currently understand well enough to explain but others do. Our site is different from most - if you have not done so yet, consider checking out the tour and help center to find out how things work. – Matthew Brown aka Lord Matt Commented Jun 10, 2020 at 9:14
1 Answer
Reset to default 0Here is the solution:
update_option_{option_name}: Runs after the option with name "option_name" has been updated. For example, for the option with name "foo":
add_action('update_option_foo', 'my_custom_function', 10, 2);
update_option: Runs before an option gets updated. Example:
add_action('update_option', 'my_custom_function', 10, 3);
updated_option: Runs after an an option has been updated. Example:
add_action('updated_option', 'my_custom_function', 10, 3);