Custom Fields
Re-Envisioned
Support MB Settings Page How to update MB Settings field programatically

  • Creator
    Topic
  • #20797
    Resolved wgstjf
    Participant

    Hi guys,

    We need to be able to update a MB settings value from within a function. I’ve previously reached out on Github (https://github.com/wpmetabox/meta-box/issues/1245) but am posting here to in the hope that someone can help asap. We have a client site experiencing issues as our solution (see github post) no longer works.

    This is what we were using:

    $next_member_number_incremented = $next_member_number + 1;
    $rwmb_setting_method = new RWMB_Setting_Storage; // Obviously requires MB Settings Page to work!
    $increment_next_member_number = $rwmb_setting_method->update('indigo_membership_settings','member_number_next',$next_member_number_incremented);
    

    But this now returns an error:

    Fatal error: Uncaught Error: Class 'RWMB_Setting_Storage' not found in....

    Any help gratefully appreciated.

    Thanks,

    Will

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #20804
    Long Nguyen
    Moderator

    Hi Will,

    You can find the new class name in the file wp-content/plugins/mb-settings-page/src/Storage.php.

    new \MBSP\Storage

    Because the settings page saves data in the table wp_options just like the theme options so you can just use the prebuilt function of WordPress update_option().

    For more information, please follow this documentation https://developer.wordpress.org/reference/functions/update_option/.

    #20807
    wgstjf
    Participant

    Long,

    Thanks for coming back to me. It is now working as desired using the following:

    $rwmb_storage_method     = new MBSP\Storage;
        $increment_next_member_number = $rwmb_storage_method->update('indigo_membership_settings','member_number_next',$next_member_number_incremented);

    Very much appreciated.

    Will

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