我是WordPress的新手,正在开发一个可以进行登录,注销和注册的WP插件。到目前为止,这个插件可以登录,但我无法注销。我尝试了unset($_SESSION['user_id']);
和session_destroy();
功能,但它们无效。
以下是我可以登录的代码,任何人都可以帮我注销功能吗?
<?php
/*this block of code is preventing user from submitting empty email or password*/
if(isset($_POST['email']) && isset($_POST['password'])){
$email = $_POST['email'];
$password = $_POST['password'];
$pass_hash = md5($password);
if( !empty($email) && !empty($password) ){
$query="SELECT `ID` FROM `vrm_users` WHERE `user_email`='$email' AND `user_pass`='$pass_hash'";
if($query_run= mysql_query($query)){
$query_num_rows= mysql_num_rows($query_run);
if($query_num_rows==0){
echo'Invalid Login';
}else if($query_num_rows==1) {
$user_id=mysql_result($query_run, 0, 'ID');
$_SESSION['user_id'] = $user_id;
//header('Location: test_form.php');
}//if($query_num_rows==0) ends here
}//if($query_run= mysql_query($query)) ends here
}else{
echo'Please Enter Email & Password';
}//if( !empty($email) && !empty($password) ends here!
}//if(isset($_POST['email']) && isset($_POST['password']) ends here
/*
Shortcode: [loginform]
Description: Craetes A form that takes inputs
*/
/* Login Form */
function form_shortcode(){
return '<div class="loginform">
<h2>Custom VRM LOGIN FORM</h2>
<form action="" method="POST">
<input type="email" name="email">Email<br>
<input type="password" name="password">Password<br>
<input type="submit" name="submit" value="Login"><br>
</form>
</div>';
}//form_shortcode()
add_shortcode('loginform', 'form_shortcode');
?>
答案 0 :(得分:1)
您可以使用wp_logout_url()模板标记在插件文件中生成退出链接。
<a href="<?php echo wp_logout_url( home_url( '/redirect_page' ) ); ?>" title="Logout">Logout</a>
答案 1 :(得分:0)
查看wp_logout_url()