michaeluno / admin-page-framework

Facilitates WordPress plugin and theme development.
http://admin-page-framework.michaeluno.jp/
Other
337 stars 71 forks source link

Post type meta keys revisions #210

Closed vladkucherov closed 9 years ago

vladkucherov commented 9 years ago

Hi,

Looks like the meta keys are not stored in revisions (all the fields create are metas) I tried using: https://wordpress.org/plugins/wp-post-meta-revisions/

And added this:

add_filter('wp_post_revision_meta_keys', function ($keys) {
    return array_merge(array_keys($this->oForm->aFields), $keys);
});

To:

class Some_Metabox extends AdminPageFramework_MetaBox {

    public function __construct() {
        parent::__construct(null, __('Some Settings', 'topfive'), array('some'));
    }

    public function setUp() {
        $this->addSettingFields(
            //
        );

        add_filter('wp_post_revision_meta_keys', function ($keys) {
            return array_merge(array_keys($this->oForm->aFields), $keys);
        });
    }
}

But it doesn't seem to work as I am getting only the sections. but other fields are not part of sections. Maybe I am missing something?

Thanks, Vlad.

michaeluno commented 9 years ago

Hi,

You may need to modify the framework code. In the _replyToFilterSavingData() method of AdminPageFramework_MetaBox_Model class, there are lines that check whether the passed data should be saved or not (the linked lines). Currently when the post status is auto-draft and the DOING_AUTOSAVE constant is true, the check yields false thus the data will not be saved.

So you may modify that part and see if the data starts getting saved. If it works, let me know.

vladkucherov commented 9 years ago

Hi,

Looks like I forgot about this ticket, I managed to come up with a solution:

I put this into every meta box class in the setUp

add_filter('wp_post_revision_meta_keys', function ($keys) {
    return array_merge(array_keys($this->oForm->aFields['_default']), $keys);
});

Why there? because only there it seems like the fields are set. What changed? ['_default'] key :smiley:

Thanks.

michaeluno commented 9 years ago

Glad to hear you found a way!

(I'm not sure if you are asking a new question. If so, I need more details to understand it. If not, never mind.)