• Resolved drahija

    (@drahija)


    I have a plugin I developed previously without using CMB2 and am in the process of converting it to use CMB2 for custom meta fields on post types, as well as the plugin options pages. However, I’m running into a situation with the later as a result of how the options were originally saved.

    Previously I added the Option Page using the add_menu_page() method and added settings using the add_settings_section() methods. This has resulted in the plugin saving settings as individual rows in the wp_options table.

    However, as I’m converting over to CMB2 it’s wanting to save each of my options in a single record in the wp_options table and serialize them in the option_value column. If I were just starting out developing my plugin I’d be fine with this, however, since the plugin is already built, I’m struggling with being able to maintain backward compatibility.

    If all of the settings were only called from within the plugin, it wouldn’t be a big deal to convert them over when the plugin is updated, but unfortunately there are a handful of settings that get used directly inside of the theme.

    Is it possible to get CMB2 to store each field as it’s own record in the wp_options table?

Viewing 1 replies (of 1 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Still asking around a bit, but I’m not personally finding any great way to handle this. I hope I’m wrong in the long term.

    Closest I can think of is some hooks I know of that allowed me to hotwire/bypass some default actions and save a post metabox value to an option, and populate the metabox based on that option. It was pretty much preventing saving as post meta and serving from the options value instead.

    That wouldn’t help so much when it comes to say your theme frontend though.

    That said, i know we have a lot of snippets handy that have a function like this: https://github.com/CMB2/CMB2-Snippet-Library/blob/master/options-and-settings-pages/add-cmb2-settings-to-other-settings-pages.php#L203

    It allows you to specify the key to fetch from the saved options. I don’t know the theme code at all, but one can hope that it’d be pretty minimal and straightforward refactoring, if it comes to that.

Viewing 1 replies (of 1 total)
  • The topic ‘Save Individual Options Instead of Single’ is closed to new replies.