Custom Fields
Re-Envisioned
Support General action rwmb_after_{$meta_box_id} or action for settings page

This topic contains 4 replies, has 2 voices, and was last updated by  Anh Tran 1 year, 3 months ago.

  • Creator
    Topic
  • #10250

    I have a settings page with 9 meta boxes and I need to fire some code after the settings page is saved.

    It looks like as of right now the only hook I can use is rwmb_after_{$meta_box_id}. Do I need to do an add_action 9 times or do you have a hook that will fire when a settings page is saved, like the WordPress action wp_insert_post?

    If you don’t, it would be nice and more efficient to trigger one action when all meta boxes in a page is saved.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Author
    Replies
  • #10251

    Sorry I meant rwmb_{$meta_box_id}_after_save_post . . . instead of a meta box ID, a $settings_pages[id] as opposed to the meta_boxes[id].

    fyi, there is a space in the action of “rwmb_{$meta_box_id}_ after_save_post.”

    #10277

    Anh Tran
    Keymaster

    Yes, you can do that with the hook mb_settings_page_load. It’s the internal hook used to save the fields’ values after the settings page is loaded. The process uses priority 10, so if you want to do something after that, you should use a higher priority, such as 20.

    Here is an example:

    add_action( 'mb_settings_page_load', function ( $args ) {
        if ( $args['id'] === 'YOUR SETTINGS PAGE ID' ) {
            // Do something
        }
    }, 20 );
    #10284

    Perfect, tks!.

    Is that listed hook listed in the docs?

    #10288

    Anh Tran
    Keymaster

    No, it’s created for internal use. I’ll add it to the docs right now.

Viewing 4 replies - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.