临时-前台登录表单

时间:2016-04-14 作者:valentine

我的网站前端有几个页面,我的用户在其中编写内容。创建此内容可能需要很多小时。不幸的是,我的网站有4小时的会话限制,当我的用户提交他们的内容(通过web表单)时,他们已经注销,他们被重定向到登录页面,并且他们的内容丢失。

在管理面板中,特别是在“页面”页面上,有一个lightbox登录表单(临时登录),其中显示著名的“会话已过期。请重新登录。您将不会离开此页面。”消息一旦达到会话限制,就会显示该消息。如何在网站的所有前端页面上使用此内置功能?

1 个回复
SO网友:valentine

下面是一个简短的插件,它在每个前端页面上添加临时登录灯箱:

<?php

/*
Plugin Name: Interim Login Everywhere
Version: 1.0.1
Plugin URI: http://nowhere.com
Description: Provide interim login screens on all pages.
Author: S Valentine

*/

function ile_enqueue_scripts() {
    // we only care to add scripts and styles if the user is logged in.
    if ( is_user_logged_in() ) {

        // add javascript file
        wp_register_script( \'wp_auth_check\', \'/wp-includes/js/wp-auth-check.js\' , array(\'heartbeat\'), false, 1);
        wp_localize_script( \'wp_auth_check\', \'authcheckL10n\', array(
            \'beforeunload\' => __(\'Your session has expired. You can log in again from this page or go to the login page.\'),
            \'interval\' => apply_filters( \'wp_auth_check_interval\', 3 * MINUTE_IN_SECONDS ), // default interval is 3 minutes
        ) );
        wp_enqueue_script (\'wp_auth_check\');

        // add css file
        wp_enqueue_style( \'wp_auth_check\',\'/wp-includes/css/wp-auth-check.css\', array( \'dashicons\' ), NULL, \'all\' );

        // add the login html to the page
        add_action( \'wp_print_footer_scripts\', \'wp_auth_check_html\', 5 );
    }
}
add_action( \'wp_enqueue_scripts\', \'ile_enqueue_scripts\' );

// make sure the stylesheet appears on the lightboxed login iframe
function ile_enqueue_login_scripts() {
    wp_enqueue_style( \'wp_auth_check\',\'/wp-includes/css/wp-auth-check.css\', array( \'dashicons\' ), NULL, \'all\' );
}
add_action( \'login_enqueue_scripts\', \'ile_enqueue_login_scripts\' );

?>

相关推荐

尝试在WordPress中实现AJAX注释,遇到WP错误

我试图在WordPress中为我的评论实现Ajax,使用this tutorial. 但我在将教程中的代码集成到自己的预构建主题时遇到了问题。问题是,我要么得到一个WP错误“检测到重复注释;看来你已经说过了!”或标准500错误。以下是我得到的:下面是我对ajax的评论。js文件如下所示: * Let\'s begin with validation functions */ jQuery.extend(jQuery.fn, { /* * check i