Util_AttachToActions Trash Medias Conflict
-
Hello,
I was working on a custom plugin to clean medias of a website, and I use the trash media.
I noticed that I have a conflict with W3TC when I put a media into the trash, and I find what is the problem, maybe you could add code correction to fix it (I use a custom filter in my plugin for now to bypass the problem).
In “Util_AttachToActions.php” file, in “flush_posts_on_actions” function, you have this :
add_filter( ‘pre_trash_post’, array( $o, ‘on_post_change’ ), 0, 2 );
And in the ‘on_post_change’ function, I noticed this error :
On line 108, where there is this code, you configure $post_id as the parent page of the media, to clear cache of this post, but the problem is that there is some medias that don’t have parent page, so the $post_id value become 0, and so the wp_trash_post is not working because the returned id is null. Also, It configure the trash post_id as the parent page instead of the media, so It trash the page and not the media if the parent is not empty.
You should change the code to clear cache of the parent if it’s not empty, but keep the media initial id in $post_id, so maybe the code could be something like this :
if ( isset( $post->post_type ) && 'attachment' === $post->post_type ) {
$post_parent_id = $post->post_parent;
if($post_parent_id !== 0) {
// Clear cache parent only here
$cacheflush->flush_post( $post_parent_id );
}
}Like this the page parent cache is clear, but we keep the action on the media wich is trashed.
Hope you could change this part of the code and correct the error !
Thank you !
- You must be logged in to reply to this topic.