Title: Ping log clean up script
Last modified: September 3, 2021

---

# Ping log clean up script

 *  [Brian Brown, Ph.D.](https://wordpress.org/support/users/brianbrown/)
 * (@brianbrown)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/ping-log-clean-up-script/)
 * For [@fudgeminers](https://wordpress.org/support/users/fudgeminers/) and [@fabioperri](https://wordpress.org/support/users/fabioperri/)
   and all others who requested it. Here is code to delete the ping logs on a schedule.
   I put this in the mu-plugins folder, but you can put it in the regular plugins
   folder if you wish:
 *     ```
       <?php
       /*
       Plugin Name: Empty Ping Optimizer Logs every 72 Hours
       Plugin URI: 
       Description: Removes log entries older than 72 hours in the WordPress Ping Optimizer Plugin
       Author: Brian Brown, Ph.D.
       Version: 2020.12.16.15.18
       Author URI:
       */
       defined( 'ABSPATH'  ) or die( 'No script kiddies please!' );
       add_action('init','bjb_delete_ping_optimizer');
       add_action('bjb_ping_optimizer','bjb_ping_optimizer_func');
   
       function bjb_ping_optimizer_func() {
           global $wpdb;
           $sql = 'DELETE FROM '.$wpdb->prefix.'cbnetpo_ping_optimizer WHERE date_time < DATE_ADD( NOW(), INTERVAL -72 HOUR )';
           $wpdb->query( $sql );
   
       }
   
       function bjb_delete_ping_optimizer(){
         if(!wp_next_scheduled('bjb_ping_optimizer_trim_logs')) {
              wp_schedule_event (time(), 'daily', 'bjb_ping_optimizer_trim_logs');
           }
       }
       ```
   
 * I save it as `mt-ping-logs.php` but you can name it anything that you want.
    
   I should also add that this does NOT reset the ping count (stored in the options
   table), since that value is there whether it is zero or 10,000 or whatever, so
   it takes up nearly the same ‘space’ (bit count) for all practical purposes. Cheers!
   [@brianbrown](https://wordpress.org/support/users/brianbrown/)
    -  This topic was modified 4 years, 9 months ago by [Brian Brown, Ph.D.](https://wordpress.org/support/users/brianbrown/).
    -  This topic was modified 4 years, 9 months ago by [Brian Brown, Ph.D.](https://wordpress.org/support/users/brianbrown/).
    -  This topic was modified 4 years, 9 months ago by [Brian Brown, Ph.D.](https://wordpress.org/support/users/brianbrown/).
    -  This topic was modified 4 years, 9 months ago by [Brian Brown, Ph.D.](https://wordpress.org/support/users/brianbrown/).

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [fudgeminers](https://wordpress.org/support/users/fudgeminers/)
 * (@fudgeminers)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/ping-log-clean-up-script/#post-15049578)
 * thank you!!!!
 *  Thread Starter [Brian Brown, Ph.D.](https://wordpress.org/support/users/brianbrown/)
 * (@brianbrown)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/ping-log-clean-up-script/#post-15050637)
 * This does NOT delete the ping count, however.
    -Brian
 *  [fudgeminers](https://wordpress.org/support/users/fudgeminers/)
 * (@fudgeminers)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/ping-log-clean-up-script/#post-15087602)
 * the logs though.. right?
 *  Thread Starter [Brian Brown, Ph.D.](https://wordpress.org/support/users/brianbrown/)
 * (@brianbrown)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/ping-log-clean-up-script/#post-15088307)
 * Yes. The count will still show up on the admin page, but not the L-O-N-G list
   of pings and responses.
    -Brian
 *  [fudgeminers](https://wordpress.org/support/users/fudgeminers/)
 * (@fudgeminers)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/ping-log-clean-up-script/#post-15091753)
 * good stuff thanx and happy holidays

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Ping log clean up script’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/wordpress-ping-optimizer_ebeef0.svg)
 * [WordPress Ping Optimizer](https://wordpress.org/plugins/wordpress-ping-optimizer/)
 * [Support Threads](https://wordpress.org/support/plugin/wordpress-ping-optimizer/)
 * [Active Topics](https://wordpress.org/support/plugin/wordpress-ping-optimizer/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wordpress-ping-optimizer/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wordpress-ping-optimizer/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [fudgeminers](https://wordpress.org/support/users/fudgeminers/)
 * Last activity: [4 years, 6 months ago](https://wordpress.org/support/topic/ping-log-clean-up-script/#post-15091753)
 * Status: not resolved