Created
March 29, 2023 18:29
-
-
Save dantetesta/62fc39fc4662149dde062d686b6325de to your computer and use it in GitHub Desktop.
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
<?php | |
function delete_user_and_posts() { | |
$user_id = get_current_user_id(); | |
$cpts_with_author = array('cpt_slug1,cpt_slug2'); | |
remove_user_and_posts($user_id, $cpts_with_author); | |
// Redireciona para a home e desloga o usuário | |
wp_logout(); | |
wp_redirect(home_url()); | |
exit; | |
} | |
add_action('wp_ajax_delete_user_and_posts', 'delete_user_and_posts'); | |
/* | |
CRIE UM BOTÃO COM ID = #deleteuser | |
E coloque esse script na mesma pagina do botão | |
*/ | |
jQuery(document).ready(function($) { | |
$('#deleteuser').on('click', function(e) { | |
e.preventDefault(); | |
if (confirm('Tem certeza de que deseja excluir sua conta? Esta ação não pode ser desfeita.')) { | |
$.ajax({ | |
url: '/wp-admin/admin-ajax.php', | |
type: 'POST', | |
data: { | |
action: 'delete_user_and_posts' | |
}, | |
success: function() { | |
window.location.replace('/'); | |
} | |
}); | |
} | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment