您有许多问题需要纠正才能正常工作。
短代码应返回内容,而不是将其回显/打印到屏幕上
在使用之前,您应该清理检索到的$\\u POST值无法在db中查询纯文本密码。密码被哈希化请勿在函数之外执行表单处理。为它设置一个函数,并将该函数挂接到init.您的“错误”消息
$errMessage 在快捷码函数外部定义,因此除非声明为全局值,否则其值在函数内部不可用
不要使用结束PHP分隔符(“?>”)关闭文件。如果在它后面出现意外的空格,可能会导致问题不要简单地检查$_POST[\'submit\'] 已设置。还要检查其值。否则,您将运行任何提交按钮的检查以下是您针对上述各项的代码:
/**
* Plugin Name: LD Login Form
* Plugin URI: https://testsite.co.za
* Description: Empire Investment Login Form
* Version: 1.0
* Author: Luthando
* Author URI: https://testsite.co.za
*/
// Hooks, etc.
add_action( \'init\', \'luecustom_form_process\' );
add_shortcode(\'luthandoLog\', \'luecustom_form\');
function luecustom_form( $atts, $content, $tag ) {
// Make sure you pick up the global $errMessage
global $errMessage;
// Don\'t echo/print your HTML in a shortcode.
// Instead put your HTML into $content to return at the end.
$content = \'<form action="\' . $_SERVER[\'REQUEST_URI\'] . \'" method="post" style="color: #fff">
<div class="form-group">
<label for="email">Email address:</label>
<input name="email" type="email" class="form-control" id="email">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input name="pass" type="password" class="form-control" id="pwd">
</div>
<div class="form-group form-check">
<label class="form-check-label">
<a style="color: #08a873" href="#"> Forgot Password? </a> </label>
</div>
<input style="background: #08a873; margin-top: 5px; width: 100%" type="submit" class="btn btn-primary btn-lg active" role="button" aria-pressed="true" value="Login" />
<div class="alert alert-danger" role="alert">\' . $errMessage . \'</div>
</form>\';
return $content;
}
function luecustom_form_process() {
/*
* You don\'t need $wpdb because you don\'t need to query the db directly
* You DO need to globalize $errMessage so it can be used in your shortcode.
* Do this before the "if" so that you have a defined variable
* regardless of whether post is submitted or not. Otherwise
* you may get an undefined variable notice in the shortcode result.
*/
global $errMessage;
$errMessage = "";
if(isset($_POST[\'submit\']) && \'Login\' == $_POST[\'submit\'] ) {
// Sanitize email
$email = sanitize_email( $_POST[\'email\'] );
// Don\'t sanitize password because it may contain characters that would be removed.
// It\'s going to be hashed for comparison anyway.
$pass = $_POST[\'pass\'];
// Get the user by their email address
$user = get_user_by( \'email\', $email );
// Check if the posted password is the same as the user\'s hashed password.
$validate_pass = wp_check_password( $pass, $user->user_pass );
// If the user validates (wp_check_password() returns true), then...
if( $validate_pass ){
header("Location: https://dhetcodesigns.000webhostapp.com/?page_id=5");
exit;
}else{
$errMessage = "Incorrect username/password";
}
}
}