WP_PLUGIN 自動ログアウト拡張

初回コミット
This commit is contained in:
2021-06-29 15:49:09 +09:00
commit 6d4b4c813d
13 changed files with 535 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
} // Exit if accessed directly
if ( ! trait_exists( 'al_ext_force_trait' ) ) {
/**
* 自動ログアウト
* Trait al_ext_force_trait
*/
trait al_ext_force_trait {
/**
* 自動ログアウトの一時Cookie作成
*/
public function set_force_al_ext_cookie() {
//ログイン+一時Cookieが存在する場合、一時Cookieを更新する
if ( isset( $_COOKIE[ al_ext_config::AL_EXT_TMP_COOKIE ] ) && is_user_logged_in() ) {
$this->create_tmp_cookie();
}
}
/**
* 自動ログアウトのログイン:remembermeを元に一時Cookieを作成
*/
public function my_force_login() {
if ( isset( $_POST['rememberme'] ) ) {
//一時ログインCookieを生成
$this->create_tmp_cookie();
}
}
}
}
+53
View File
@@ -0,0 +1,53 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
} // Exit if accessed directly
if ( ! trait_exists( 'al_ext_trait' ) ) {
/**
* 拡張ログアウト
* Trait al_ext_trait
*/
trait al_ext_trait {
/**
* 拡張ログアウトの一時Cookie作成
*/
public function set_al_ext_cookie() {
if ( is_user_logged_in() ) {
//rememberme cookieが存在する場合は一時Cookieを作成する
if ( isset( $_COOKIE[ al_ext_config::AL_EXT_REMEMBER_COOKIE ] )
&& ! isset( $_COOKIE[ al_ext_config::AL_EXT_TMP_COOKIE ] ) ) {
$this->create_tmp_cookie();
}
}
}
/**
* 拡張ログアウト時のログイン:remembermeを元に一時Cookieを作成
*/
public function my_login() {
//ログイン継続のチェックがあれば、Cookieに保存する
if ( isset( $_POST['rememberme'] ) ) {
$this->create_remember_cookie();
//一時ログインCookieを生成
$this->create_tmp_cookie();
} else {
setcookie( al_ext_config::AL_EXT_REMEMBER_COOKIE, '', time() - 30 );
}
}
private function create_remember_cookie() {
$expire = $this->set_remember_cookie_expire_time();
setcookie( al_ext_config::AL_EXT_REMEMBER_COOKIE, 'al_ext_remember', $expire, '/' );
}
private function set_remember_cookie_expire_time() {
if ( isset( $this->options['expire_date'] ) ) {
return time() + 60 * 60 * 24 * $this->options['expire_date'];
}
return time() + 60 * 60 * 24 * al_ext_config::AL_EXT_DEFAULT_EXPIRE_DATE;
}
}
}