dsgsdg206050 2018-12-10 16:29
浏览 66

wordpress passowrd插件 - 前端的get_option“密码错误信息”

I'm using a wordpress plugin to protect the whole page with a password. The plugin shows a message if the user is using a wrong password. The code is located in main php file, but i want to place this into the front end php file to choose the specific place, where message will be shown.

That is the code part inside the main php file:

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>';
        }
    }
}

That is the front end code:

<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 } ?>

So i'm looking for a way like a hook, which puts the message to the front end below the logo file, if the user uses a wrong password.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看