_init(); } return self::$_instance; } /** * Object init, sets up hooks. Not done in the constructor so that the * _init() method may be extended without breaking the singleton. */ protected function _init() { if ( is_admin() ) { add_action( 'admin_footer', array( $this, 'enqueue_scripts' ) ); add_action( 'admin_print_footer_scripts', array( $this, 'footer_js' ) ); } elseif ( is_user_logged_in() ) { add_action( 'wp_footer', array( $this, 'enqueue_scripts' ) ); add_action( 'wp_print_footer_scripts', array( $this, 'footer_js' ) ); } add_filter( 'heartbeat_received', array( $this, 'login' ), 10, 2 ); add_filter( 'heartbeat_nopriv_received', array( $this, 'nopriv_login' ), 10, 2 ); } /** * Checks if the user is still logged in */ public function login( $response, $data ) { if ( array_key_exists('wp-auth-check', $data) && ( ! isset( $_COOKIE[LOGGED_IN_COOKIE] ) || ! wp_validate_auth_cookie() || ! empty( $GLOBALS['login_grace_period'] ) ) ) $response['wp-auth-check-html'] = $this->notice(); return $response; } /** * Runs when a user is expected to be logged in * but has logged out or cannot be validated */ public function nopriv_login( $response, $data ) { if ( array_key_exists('wp-auth-check', $data) ) $response['wp-auth-check-html'] = $this->notice(); return $response; } public function footer_js() { ?>
'; } }