Javascript 用户会话到期时的AJAX覆盖Wordpress前端
如果用户会话在wp admin中过期,则用户已注销,且页面仍处于打开状态,WordPress将覆盖模式登录 如何注册从其他位置过期/注销的用户会话,并从前端启动覆盖 目前,我们正在通过Javascript打开“点击”按钮的登录表单,。。。登录和注销的操作在functions.php中处理 以及后端过期会话的示例Javascript 用户会话到期时的AJAX覆盖Wordpress前端,javascript,php,ajax,wordpress,Javascript,Php,Ajax,Wordpress,如果用户会话在wp admin中过期,则用户已注销,且页面仍处于打开状态,WordPress将覆盖模式登录 如何注册从其他位置过期/注销的用户会话,并从前端启动覆盖 目前,我们正在通过Javascript打开“点击”按钮的登录表单,。。。登录和注销的操作在functions.php中处理 以及后端过期会话的示例 请注意:我不想使用插件来实现这一点。我在这里找到了解决方案 $('a#show_login').on('click', function(e){ $('body').prepen
请注意:我不想使用插件来实现这一点。我在这里找到了解决方案
$('a#show_login').on('click', function(e){
$('body').prepend('<div class="login_overlay"></div>');
$('form#login').fadeIn(500);
$('div.login_overlay, form#login a.close').on('click', function(){
$('div.login_overlay').remove();
$('form#login').hide();
});
e.preventDefault();
});
function ajax_login_init(){
wp_register_script('ajax-login-script', get_template_directory_uri() . '/assets/js/ajax-login-script.js', array('jquery') );
wp_enqueue_script('ajax-login-script');
wp_localize_script( 'ajax-login-script', 'ajax_login_object', array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'redirecturl' => home_url(),
'loadingmessage' => __('Sending user info, please wait...')
));
// Enable the user with no privileges to run ajax_login() in AJAX
add_action( 'wp_ajax_nopriv_ajaxlogin', 'ajax_login' );
}
// Execute the action only if the user isn't logged in
if (!is_user_logged_in()) {
add_action('init', 'ajax_login_init');
}
function login_session_expired() {
// 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', 1 * 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', 'login_session_expired' );
// make sure the stylesheet appears on the lightboxed login iframe
function login_session_expired_styles() {
wp_enqueue_style( 'wp_auth_check','/wp-includes/css/wp-auth-check.css', array( 'dashicons' ), NULL, 'all' );
}
add_action( 'login_enqueue_scripts', 'login_session_expired_styles' );