This is no updated_option_{$option}
filter.
You’d have to use update_option_{$option}
instead:
/**
* Fires after the value of a specific option has been successfully updated.
*
* The dynamic portion of the hook name, `$option`, refers to the option name.
*
* @since 2.0.1
* @since 4.4.0 The `$option` parameter was added.
*
* @param mixed $old_value The old option value.
* @param mixed $value The new option value.
* @param string $option Option name.
*/
do_action( "update_option_{$option}", $old_value, $value, $option );
Don’t forget to remove your filter before if you save the option again:
class MyClass {
public function __construct()
{
add_action('admin_init', [$this, 'theme_init']);
add_action('admin_menu', [$this, 'theme_menu']);
add_action('updated_option', [$this, 'save_options'], 10, 3);
add_action('update_option_my_update_option', [$this, 'save_my_update_option'], 10, 3);
}
public function theme_init()
{
register_setting('my_update_option', 'theme_options', 'lapocus_validate_options', 'checkOption');
}
public function theme_menu()
{
add_menu_page('Main Page', 'Main Page', 'my_update_option', 'menu-slug', [$this, 'main_page'], 'dashicons-admin-network', 2);
add_submenu_page('menu-slug', 'Sub Page', 'Sub Page','my_update_option', 'menu-slug' . '-subpage-online-form', [$this, 'subpage_online_form']);
}
public function save_my_update_option($oldvalue, $value, $option) {
// Begin prevent infinite loop
remove_action('update_option_my_update_option', [$this, 'save_my_update_option'], 10);
// do something
$value = $this->change_value($old_value, $value);
// save the option again
update_option('my_update_option', $value);
// End prevent infinite loop
add_action('update_option_my_update_option', [$this, 'save_my_update_option'], 10, 3);
}