justintadlock / butterbean

A neat little post meta framework.
GNU General Public License v2.0
204 stars 31 forks source link

Serialized data storage #23

Open marke123 opened 7 years ago

marke123 commented 7 years ago

I didn't see anything in the docs/demos/explanations so please ignore this if it's already possible:

It'd be great to have a way ( maybe a register_manager flag ) that tells the plugin to serialize all the form data into one post_meta database record as an array.

justintadlock commented 7 years ago

I would consider a custom setting class for this. Use that class for any setting you want saved in the array.

Not sure if it should be core ButterBean material, but it's worth taking a look at if anyone wants to take a crack at it.

tfirdaus commented 7 years ago

Hi @marke123

In case you still need this functionality, I've made a custom setting called serialize to do so, and wrapped it up at: https://github.com/tfirdaus/butterbean-extend

Usage:

<?php
$manager->register_setting(
    'setting_1',
    array(
        'type' => 'serialize',
        'default' => 1,
        'sanitize_callback' => 'butterbean_validate_boolean'
    )
);
$manager->register_setting(
    'setting_2',
    array(
        'type' => 'serialize',
        'default' => 1,
        'sanitize_callback' => 'butterbean_validate_boolean'
    )
);

If @justintadlock would like to in include the serialize setting into ButterBean core, I'd be happy to prepare a pull request.

justintadlock commented 7 years ago

That looks like a pretty solid class from what I can see.