To be clear, I'm not looking for a hook when the settings page is load but immediately after the settings have been saved. This is because we need to clear a cache when settings are saved. But we don't want to clear the cache every time the settings page loads!
After the settings on the settings page saved, the page also reloads so you can use the action hook mb_settings_page_load to add some actions after settings have been saved.
’m not looking for a hook when the settings page is loading but immediately after the settings have been saved. This is because we need to clear a cache when settings are saved. With the mb_settings_page_load we'll end up clearing the cache every time the settings page loads - which is not what we want to do. I'm looking for something that fires only once upon saving. Hopefully there's something like that?
There are two ways to fire an action after saving the settings page.
Use the action rwmb_{$meta_box_id}_after_save_post with the latest meta box register on the settings page. After saving the value of this meta box, the custom action will be fired.
Still use the action mb_settings_page_load but we need to check if the $_POST variable has value.
add_action( 'mb_settings_page_load', function ( $args ) {
if( !empty( $_POST['submit'] ) ) {
// do your stuff
}
}, 20 );