Created
July 29, 2017 08:15
-
-
Save MrVibe/79597100d1861c5742718e1e247436c9 to your computer and use it in GitHub Desktop.
Delete users from WPLMS Site which logged in more than 3 months ago. Copy and past this code in Child theme - functions.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Screenshot of how this works : http://prntscr.com/g1qkzf | |
add_action('in_admin_footer',function(){ | |
if(isset($_POST['delete_3_month_users']) && wp_verify_nonce($_POST['delete_3_month'],'delete_3_month') && current_user_can('manage_options')){ | |
global $wpdb; | |
$results = $wpdb->get_results("SELECT user_id FROM {$wpdb->usermeta} WHERE `meta_key` = 'last_activity' and `meta_value` <= DATE_SUB(NOW(), INTERVAL 3 MONTH)"); // change interval to change duration. | |
if(is_array($results)){ | |
echo '<div style="padding:15px;background:#fff;border:1px solid #eee;margin:15px 0;"><ol>'; | |
if(count($results)){foreach($results as $result){ | |
echo '<li>User Deleted : ID '.$result->user_id.'</li>'; | |
//wp_delete_user($result->user_id); | |
}}else{ | |
echo '<li>No users found</li>'; | |
} | |
echo '</ol></div>'; | |
} | |
} | |
echo '<form method="post"> | |
<input type="submit" name="delete_3_month_users" class="button-primary" value="Delete users 3 months old"/> | |
'; | |
wp_nonce_field('delete_3_month','delete_3_month'); | |
echo '</form>'; | |
},1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment