Rest-Easy
Rest-Easy copied to clipboard
Add filter to opt-out of auto serializing of some data
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');
Great idea! Assigning to myself.
Pushed in b1ce02d and adding to the Vuepress dev backend next!
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 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');
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?