Do action hook 'mb_settings_page_load' execution only when saved/updated

Support MB Settings Page Do action hook 'mb_settings_page_load' execution only when saved/updatedResolved

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #16039
    badabingbredabadabingbreda
    Participant

    Hi, I'm exploring a mechanism in which the settings page(s) are used to write global CSS-styles. I need to clear cache plugin after an update to the settings has been performed.

    I can't seem to find a way to easily determine if an update has been performed. I can hook the callback with a priority 20 or higher, which makes it run after the save, but don't want to run it all the time. I know I can hook into mb_settings_page_load to do some actions after save, but the $args don't tell me there has been an update or initial save action. Maybe I'm missing something, can you point me in the right direction?

    #16052
    Anh TranAnh Tran
    Keymaster

    Hi,

    I think you need to track the 'initial save' or 'update' with a custom option, like this:

    add_action( 'mb_settings_page_load', function() {
        $is_updated = get_option( 'your_custom_option' );
        if ( ! $is_updated ) {
            do_your_work();
            update_option( 'your_custom_option', 1 );
        }
    }, 20 );
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.