mb_settings_page_load on save only not working

Support MB Settings Page mb_settings_page_load on save only not workingResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #27533
    wgstjfwgstjf
    Participant

    Hi guys,

    Hopefully a quick one for you.

    We're trying to update an option only on save of a MB settings page. Following the documentation we've got it setup as follows:

    
    add_action( 'mb_settings_page_load', function ( $args ) {
      if ( $args['id'] === 'json-settings' ) {
          $set_output_settings_updated_timestamp = update_option('settings_last_updated', current_time( 'mysql' ));
      }
    }, 20 );
    

    Whatever priority we set (tried up to 9999) the value still updates on load rather than on save. Can you help? What could be causing the default behaviour to not work as it should?

    Metaboxes being initiated using the following:

    
    add_filter( 'rwmb_meta_boxes', 'indigo_options_meta_boxes',999 );
    

    Cheers,

    Will

    #27555
    Long NguyenLong Nguyen
    Moderator

    Hi Will,

    There are two ways to do something after saving Settings page.

    • Hook a function to 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 function will be fired.

    Refer https://support.metabox.io/topic/settings-page-switch-field-hopefully-quick-question/
    https://support.metabox.io/topic/do-action-hook-mb_settings_page_load-execution-only-when-saved-updated/

    • Check the field value when clicking submits button.
    add_action( 'mb_settings_page_load', function ( $args ) {
        if ( $_POST['submit'] ) {
            // Do something
        }
    }, 20 );
    #27561
    wgstjfwgstjf
    Participant

    Wonderful thanks. For some reason the first option didn't work but the second did so problem solved!

    Cheers,

    Will

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