下面是一个简短的插件,它在每个前端页面上添加临时登录灯箱:
<?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\' );
?>