rwmb_{$meta_box_id}_after_save_post

Support General rwmb_{$meta_box_id}_after_save_postResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #33822
    dom@viewtolearn.co.uk[email protected]
    Participant

    Hi

    I have a settings page in a plugin comprised of several tabs each with groups of fields on them. When the settings are saved I need to trigger an update to an element in another plugin and for that I used rwmb_after_save_post. This actually worked rather well, but as I added more groups of fields to the settings page i realised that this was getting fired continuously and came to the conclusion that each group of fields on a settings page must be being treated as a separate post which would explain why the element in the other plugin was being continually updated.

    Consulting the documentation I realised that using rwmb_{$meta_box_id}_after_save_post might actually be the answer. I went ahead and implemented that but now the element I need to update is not being updated. I suspect that I may have got the signature wrong but I'm not sure.

    The meta box I need to trigger the update on saving is defined thus.

    add_filter(
    'rwmb_meta_boxes',
    function ($meta_boxes) {
    $prefix = 'vtl_';

    $meta_boxes[] = array(
    'title' => __('Settings'),
    'id' => 'settings',
    'settings_pages' => 'vtl_site_options',
    'tab' => 'site_colours',
    'fields' => array( /* etc

    From this I assume that the id I need is 'settings'

    In the main constructor of my plugin I have this;

    add_action('rwmb_{$settings}_after_save_post', array($this, 'vtl_save_settings'), 20);

    and then finally the function itself

    public function vtl_save_settings($vtl_site_options)
    { /code here/}

    The function that contains the code is not being called so I assume my add action statement is wrong but it looks correct to me.

    Could you tell me if there is an obvious error here that I've overlooked , or if not is there another way I can trigger something to happen when just this one particular set of fields is saved from the settings page.

    PS. What is the correct format to add code snippets to the forum, I never seem to get it right?

    Many thanks

    #33842
    Long NguyenLong Nguyen
    Moderator

    Hi Dom,

    You need to replace the variable {$meta_box_id} with your real meta box ID (include the prefix)

    add_action('rwmb_vtl_settings_after_save_post', array($this, 'vtl_save_settings'), 20);
    
    #33848
    dom@viewtolearn.co.uk[email protected]
    Participant

    Thank you

    That turned out to ne just what was needed.

    The additional functionality that MetaBox can bring to custom plugins is fantastic, I'm really enjoying getting to grips with it.

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