我正在使用wordpress插件通过密码保护整个页面。 如果用户使用了错误的密码,该插件将显示一条消息。 该代码位于主php文件中,但我想将此放置到前端php文件中以选择特定的位置,该位置将显示消息。
这是主要php文件中的代码部分:
function VSPFW_auth_frontend_user() {
$nonce=$_REQUEST['vspfw_user_entered_password_wpnonce'];
if (VSPFW_should_ask_password() && wp_verify_nonce($nonce, 'vspfw_user_entered_password_wpnonce')) {
if (isset($_POST['vspfw_password']) && !empty($_POST['vspfw_password'])) {
$ip_address = filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP);
if (VSPFW_prevent_brute_force_check($ip_address)) {
$pw = sanitize_text_field($_POST['vspfw_password']);
if ($pw == get_option('vspfw_password')) {
// Generate unique md5 to store as cookie
$unique_key = md5(current_time(timestamp)+(rand(0,100)));
if (!VSPFW_add_md5_cookie_do_database($unique_key, $ip_address)) {
error_log('Warning from Very Simple Password for Wordpress: There was an error inserting the unique id to the database. You should review the plugin code or disable it.', 1, get_bloginfo('admin_email'));
wp_die("Very Simple Password for Wordpress couldn't insert the UniqueID to the database. Please contact website owner.");
exit;
}
// Set the cookie with the unique id for the period specified by the admin
setcookie('vspfw_password_entered', esc_html($unique_key), strtotime( '+'.get_option('vspfw_days').' days'), '/', esc_html(get_option('vspfw_debug_domain')));
$_COOKIE['vspfw_password_entered'] = esc_html($unique_key);
// Refresh after setting cookie, because $_COOKIE is set on page load - http://stackoverflow.com/questions/3230133/accessing-cookie-immediately-after-setcookie
//echo '<script type="text/javascript">window.location.reload(true);</script>';
//header('Refresh:0');
} else {
// Add this failed login to database to prevent anti-brute force attacks
VSPFW_prevent_brute_force_add_try($ip_address);
// Display wrong password
echo '<div class="error">'.get_option('vspfw_wrong_password').'</div>';
}
} else {
// Display brute force protection
echo '<div style="text-align:center;color: #a94442;background-color: #f2dede;border-color: #ebccd1; padding:15px;margin:20px;">'.get_option('vspfw_brute_force_protection_message').'</div>';
}
}
}
那是前端代码:
<div id="vspfw">
<div id="vspfw-logo">
<?php
// Sets logo
if (get_option('vspfw_logo_url') != "") {
echo '<img src="'.esc_url(get_option('vspfw_logo_url')).'" style="margin:20px 0 30px 0;"><br>';
}
?>
</div>
<div id="vspfw-enter-password-string"><?php echo esc_attr(get_option('vspfw_enter_password_string')); ?></div>
<form method="POST">
<?php wp_nonce_field('vspfw_user_entered_password_wpnonce', 'vspfw_user_entered_password_wpnonce') ?>
<input type="password" autofocus name="vspfw_password" placeholder="passwort"><br><br>
<input type="submit" value="<?php echo esc_attr(get_option('vspfw_submit')); ?>">
</form>
<?php if (get_option('vspfw_show_contact_info') == 'true') { ?>
<div id="vspfw-request-password">
<?php echo esc_html(get_option('vspfw_need_the_password_string'));?><br>
<?php echo esc_attr(get_option('vspfw_contact_email'));?>
</div>
<?php } ?>
因此,我正在寻找一种类似钩子的方法,如果用户使用了错误的密码,该消息会将消息放置在徽标文件下方的前端。