Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theRealRizeo/56116fcbf78eb5622116e6dcbb1d40ff to your computer and use it in GitHub Desktop.
Save theRealRizeo/56116fcbf78eb5622116e6dcbb1d40ff to your computer and use it in GitHub Desktop.
<?php
/**
* Delete old Defender logs from all sites
* Clean up custom post meta that is no longer used
* call the function defender_delete_old_posts()
*
* @param bool $echo - echo the tables
*/
function defender_delete_old_posts( $echo = false ) {
global $wpdb;
//main site first
$post_meta_table = $wpdb->prefix . 'postmeta';
$posts_table = $wpdb->prefix . 'posts';
$wpdb->query( "DELETE from $post_meta_table where post_id in(SELECT ID from $posts_table WHERE post_type = 'wd_iplockout_log')" );
$wpdb->query( "DELETE from $posts_table WHERE post_type = 'wd_iplockout_log'" );
if ( is_multisite() ) {
$sites = get_sites();
foreach( $sites as $site ) {
$subsite_id = $site->blog_id;
$post_meta_table = $wpdb->prefix . $subsite_id . '_postmeta';
$posts_table = $wpdb->prefix . $subsite_id . '_posts';
if ( $echo ) {
echo "Deleting from : $post_meta_table and $posts_table <br/>";
}
$wpdb->query( "DELETE from $post_meta_table where post_id in(SELECT ID from $posts_table WHERE post_type = 'wd_iplockout_log')" );
$wpdb->query( "DELETE from $posts_table WHERE post_type = 'wd_iplockout_log'" );
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment