我正在开发帐户页面。除删除用户帐户外,几乎完成。我希望用户在前端删除他们的帐户。
这是我删除帐号的代码。php。但它不起作用。我不知道为什么。
add_action( \'init\', \'rnm_remove_user_account\' );
也许,这是行不通的。你能帮帮我吗?
<?php
/* Recheck if user is logged in just to be sure, this should have been done already */
if( !is_user_logged_in() ) {
wp_redirect( home_url() );
exit;
}
//delete user. Maybe this part makes errors.
if ( is_user_logged_in() && $_GET[\'myaccount\'] == \'delete\' ) {
add_action( \'init\', \'rnm_remove_user_account\' );
}
function rnm_remove_user_account() {
// Verify that the user intended to take this action.
require_once(ABSPATH.\'wp-admin/includes/user.php\' );
$current_user = wp_get_current_user();
wp_delete_user( $current_user->ID );
wp_redirect( home_url() );
exit;
}
if( $_SERVER[\'REQUEST_METHOD\'] == \'POST\' && !empty( $_POST[\'action\'] ) && $_POST[\'action\'] == \'update-user\' ) {
$current_user = wp_get_current_user();
//탈퇴 내용 체크 확인
$pass1 = $_POST[\'deletecheck\'];
if( empty($_POST[\'deletecheck\']) ){
wp_redirect( get_permalink() . \'?validation=deletchecknone\' );
exit;
} else if( $_POST[\'deletecheck\'] == \'yes\' ) {
wp_redirect( get_permalink() . \'?myaccount=delete\' );
exit;
} else {
wp_redirect( get_permalink() . \'?validation=unknown\' );
exit;
}
/* We got here, assuming everything went OK */
wp_redirect( get_permalink() . \'?updated=true\' );
exit;
}
?>
<?php get_header(); ?>
<div class="rnm_page">
<?php while (have_posts()) : the_post(); ?>
<?php if( !empty( $_GET[\'validation\'] ) ): ?>
<?php if( $_GET[\'validation\'] == \'deletchecknone\' ): ?>
<div class="error"><?php _e(\'<p class="rnm_login_msg">!! Please check to delete your account.</p>\', \'mythmeme\'); ?></div>
<?php elseif( $_GET[\'validation\'] == \'unknown\' ): ?>
<div class="error"><?php _e(\'<p class="rnm_login_msg">!! Unknown Error!</p>\', \'mythmeme\'); ?></div>
<?php endif; ?>
<?php endif; ?>
<?php $current_user = wp_get_current_user(); ?>
<form method="post" id="rnm_account_form" action="<?php the_permalink(); ?>">
<p class="form-password">
<label for="deletecheck"><?php _e(\'Delete My Account\', \'mythmeme\'); ?> </label>
<input name="deletecheck" type="checkbox" id="deletecheck" class="checkbox" value="yes" />
</p>
<p class="form-submit">
<input name="updateuser" type="submit" id="rnm_wp_submit" class="submit button" value="<?php _e(\'Delete My Account\', \'mythmeme\'); ?>" />
<?php wp_nonce_field( \'update-user3\' ); ?>
<input name="honey-name" value="" type="text" style="display:none;"></input>
<input name="action" type="hidden" id="action" value="update-user" />
</p><!-- .form-submit -->
</form><!-- #rnm_account_form -->
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
</div>
<?php get_footer(); ?>