Custom Fields
Re-Envisioned
Support MB Settings Page Do action hook 'mb_settings_page_load' execution only when saved/updated

This topic contains 1 reply, has 2 voices, and was last updated by  Anh Tran 1 month ago.

  • Creator
    Topic
  • #16039
    Resolved
    badabingbreda
    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?

Viewing 1 replies (of 1 total)
  • Author
    Replies
  • #16052

    Anh 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 1 replies (of 1 total)

You must be logged in to reply to this topic.