Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filter to opt-out of auto serializing of some data #35

Open
cyrusdean opened this issue Nov 13, 2018 · 5 comments
Open

Add filter to opt-out of auto serializing of some data #35

cyrusdean opened this issue Nov 13, 2018 · 5 comments
Assignees

Comments

@cyrusdean
Copy link
Contributor

On a new website I'm building, the client has attached 300+ images too many pages. These all get auto-serialized on each page (so when viewing a grid page, it is insanely slow).

We should have a filter that we can use to opt-out of things in the serializer. Perhaps like the way WordPress does it for opting out of the rich editor?

    function disabled_serialize_attachments($boo) {
        return false;
    }
    add_filter( 'vp_serialize_attachments', 'disabled_serialize_attachments');
@SaFrMo
Copy link
Contributor

SaFrMo commented Nov 14, 2018

Great idea! Assigning to myself.

@SaFrMo SaFrMo self-assigned this Nov 14, 2018
@SaFrMo
Copy link
Contributor

SaFrMo commented Nov 14, 2018

Pushed in b1ce02d and adding to the Vuepress dev backend next!

@SaFrMo
Copy link
Contributor

SaFrMo commented Nov 14, 2018

Pushed in Vuepress! Apply these changes and upgrade to the latest version of Rest-Easy to get a checkbox to deactivate automatic attachment serialization.

There's also a new utility function called set_attachment_serialization($target_post, $serialization = true) that lets you do this programmatically. It isn't a filter because I didn't want to mess around with the filter queue system - this way should be a bit more robust. Let me know if you have any thoughts or issues!

@SaFrMo SaFrMo closed this as completed Nov 14, 2018
@drewbaker
Copy link
Member

drewbaker commented Nov 23, 2018

@SaFrMo can you give me an example of how we are supposed to use set_attachment_serialization($target_post, $serialization = true)?

Like this?

    function disable_attachments($target_post){
        set_attachment_serialization($target_post, false);
    }
    add_filter('rez_serialize_post', 'disable_attachments');

@drewbaker drewbaker reopened this Nov 23, 2018
@drewbaker
Copy link
Member

drewbaker commented Nov 23, 2018

OK I looked into how set_attachment_serialization() is supposed to be used, and all it does is set a meta value.

This isn't going to solve my issue, because I'd need to set it on all pages on the site, and then on all pages going forward due to the way the client is using the site.

It would be way more helpful if I could turn off auto-attachment serializing for the entire site, always. Not turning it off per post. I'd rather opt-in to auto serializing than opt-out.

Now that we are using ACF for post galleys, I wonder if turning off auto-serializing of attachments by default, and having a rest easy filter commented out is a better way to go?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants