[wp-hackers] Deleting a lot of posts/terms on plugin deactivation

Nikola Nikolov nikolov.tmw at gmail.com
Fri Jun 28 08:28:36 UTC 2013

Hello everyone,

I'm currently working on a (yet-another)multilingual plugin for WordPress.
I'm willing to add an uninstall functionality that would allow the user to
remove all data created by the plugin(so any options, custom meta, posts,
terms, etc). The plugin works by creating a duplicate post/term in a custom
post type/taxonomy for each enabled language.

I've noticed that when I have for instance 7 enabled languages and I want
to delete a bunch of posts, my WAMP installation would time-out at 60
seconds if I try to delete more than probably 10 posts, since I hook to the
delete_post hook and use wp_delete_post to remove the corresponding
translation posts - which means, that wp_delete_post is actually called for
up to 80 posts.

I realize that wp_delete_post is generally a heavy function, since deletes
all post meta, comments(?), etc.

What I'm wondering is whether I should use wp_delete_post or if there would
be a different approach to deleting multiple files with less load on the
server. Obviously if I stick to wp_delete_post(), I would use ajax-driven
uninstall process which would only delete a handful of posts at a time.

I assume one way to beat the timeout would be to try to use
set_time_limit() whenever I delete translation posts, but obviously I can't
use this solution for plugin uninstallation, since there could be a lot of
data(let's say a thousands-of-posts situation).


Nikola Nikolov

More information about the wp-hackers mailing list