• Creator
    Topic
  • #24178
    Resolved elindydotcom
    Participant

    Hi:

    Is there an action hook that I can tap into AFTER the settings have been saved?

    Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Author
    Replies
  • #24179
    elindydotcom
    Participant

    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!

    #24191
    Long Nguyen
    Moderator

    Hi,

    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.

    See more in the documentation https://docs.metabox.io/extensions/mb-settings-page/#hooks.

    #24196
    elindydotcom
    Participant

    Hi:

    ’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?

    Thanks.

    #24197
    Long Nguyen
    Moderator

    Hi,

    There isn't a hook like that. I'm going to create a feature request for the developer team to support a hook only after saving settings.

    Thank you.

    #24247
    Long Nguyen
    Moderator

    Hi,

    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 );
    

    Hope that helps.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.