WP-Mix

A fresh mix of code snippets and tutorials

WordPress clean up do_pings

When your WordPress site is configured to enable pings, the database can fill up with many do_pings WP Cron entries. This post provides a couple of quick ways to clean them up, by either disabling the functionality or deleting the do_pings entries from the database.

Disable do_pings

First, understand that the do_pings entries are added only when Pings are enabled in the WordPress General settings (visit Settings > Discussion > “Attempt to notify any blogs linked to from the article”). So you can disable future occurrences from there.

Understand that disabling this setting means that your site will not ping any linked resources. No big deal really, but be advised.

Delete do_pings

To remove all existing instances of do_pings from the database, you can add the following line of code to your theme’s functions.php file:

wp_clear_scheduled_hook('do_pings');

Then reload any page on your site to execute that line of code. That will remove all instances of do_pings. So you can leave that in place or remove it, it’s up to you. If you leave it in place, a little extra processing will be used on each request to delete the do_pings entries from your database. Or if you remove the line, the do_pings entries eventually will return.

Disable & delete

Here is an alternate technique for disabling and deleting the whole do_pings thing entirely. Add the following to your theme’s functions file:

if (isset($_GET['doing_wp_cron'])) {
	remove_action('do_pings', 'do_all_pings');
	wp_clear_scheduled_hook('do_pings');
}

That code snippet disables do_pings whenever WordPress is “doing” cron, and it also deletes any existing do_pings entries in the database. Your mileage may vary, so test this technique well before going live.

Notes

Some notes that may apply when working in the ping/cron arena:

  • Pings only happen during the cron process.
  • Pings may be slow due to the sites you are pinging.
  • The wp_update_post() function always schedules the do_pings action.

¡salud!

Learn more

WordPress Themes In Depth