AUTO LOGOUT EXTENDED

自動ログアウト除外ユーザ設定を追加
This commit is contained in:
2021-07-02 18:54:27 +09:00
parent 6d4b4c813d
commit adc35d3e8a
8 changed files with 91 additions and 4 deletions
+17
View File
@@ -68,6 +68,9 @@ if ( ! class_exists( 'AL_EXT' ) ) {
* @throws Exception * @throws Exception
*/ */
public function can_logged_in_extend() { public function can_logged_in_extend() {
if ( $this->is_exclude_user() ) {
return;
}
if ( isset( $_COOKIE[ al_ext_config::AL_EXT_TMP_COOKIE ] ) && is_user_logged_in() ) { if ( isset( $_COOKIE[ al_ext_config::AL_EXT_TMP_COOKIE ] ) && is_user_logged_in() ) {
$prev_time = new DateTime( date( 'Y-m-d H:i:s', $_COOKIE[ al_ext_config::AL_EXT_TMP_COOKIE ] ) ); $prev_time = new DateTime( date( 'Y-m-d H:i:s', $_COOKIE[ al_ext_config::AL_EXT_TMP_COOKIE ] ) );
$current_time = new DateTime( date( 'Y-m-d H:i:s' ) ); $current_time = new DateTime( date( 'Y-m-d H:i:s' ) );
@@ -112,6 +115,20 @@ if ( ! class_exists( 'AL_EXT' ) ) {
} }
} }
//自動ログアウト除外ユーザ判定
private function is_exclude_user(): bool {
if ( ! is_user_logged_in() ) {
return false;
}
$excludes = get_option( '_al_ext' )['exclude_users'];
$current_user_role = wp_get_current_user()->roles[0];
if ( $excludes[ $current_user_role ] == '1' ) {
return true;
}
return false;
}
} }
} }
+23 -1
View File
@@ -33,13 +33,13 @@ if ( ! class_exists( 'AL_EXT_SETTING' ) ) {
update_option( '_al_ext', $update_option ); update_option( '_al_ext', $update_option );
include al_ext_config::AL_EXT_TEMPLATE_DIR . 'success.php'; include al_ext_config::AL_EXT_TEMPLATE_DIR . 'success.php';
} }
$opt = get_option( '_al_ext' ); $opt = get_option( '_al_ext' );
$al_ext_type = $this->set_al_ext_parameter( $opt, 'type', al_ext_config::AL_EXT_DEFAULT_LOGOUT_TYPE ); $al_ext_type = $this->set_al_ext_parameter( $opt, 'type', al_ext_config::AL_EXT_DEFAULT_LOGOUT_TYPE );
$expire_date = $this->set_al_ext_parameter( $opt, 'expire_date', al_ext_config::AL_EXT_DEFAULT_EXPIRE_DATE ); $expire_date = $this->set_al_ext_parameter( $opt, 'expire_date', al_ext_config::AL_EXT_DEFAULT_EXPIRE_DATE );
$force_logout = $this->set_al_ext_parameter( $opt, 'force_logout', al_ext_config::AL_EXT_DEFAULT_EXPIRE_TIME ); $force_logout = $this->set_al_ext_parameter( $opt, 'force_logout', al_ext_config::AL_EXT_DEFAULT_EXPIRE_TIME );
$force_logout_url = $this->set_al_ext_parameter( $opt, 'force_logout_url', '' ); $force_logout_url = $this->set_al_ext_parameter( $opt, 'force_logout_url', '' );
$default_logout_url = al_ext_config::get_default_logout_url(); $default_logout_url = al_ext_config::get_default_logout_url();
$exclude_users = $this->create_exclude_user_data();
include al_ext_config::AL_EXT_TEMPLATE_DIR . 'al_ext_form.php'; include al_ext_config::AL_EXT_TEMPLATE_DIR . 'al_ext_form.php';
} }
@@ -51,6 +51,28 @@ if ( ! class_exists( 'AL_EXT_SETTING' ) ) {
} }
} }
private function create_exclude_user_data(): array {
return array(
'administrator' => '管理者',
'editor' => '編集者',
'author' => '投稿者',
'contributor' => '寄稿者',
'subscriber' => '購読者',
);
}
private function check_exclude_user( $user_role ) {
$opt = get_option( '_al_ext' );
if ( ! isset( $opt['exclude_users'] ) ) {
return;
}
foreach ( $opt['exclude_users'] as $user => $role ) {
if ( $user_role == $user ) {
return $role;
}
}
}
} }
} }
+14
View File
@@ -32,3 +32,17 @@
.logout-redirect-url::placeholder { .logout-redirect-url::placeholder {
color: #999; color: #999;
} }
#logout-exclude-users {
margin-top: .5em;
}
.logout-exclude-user {
margin: .5em 0;
}
@media only screen and (max-width: 964px) {
.logout-redirect-url {
width: 100%;
}
}
+9 -1
View File
@@ -7,6 +7,7 @@ jQuery(function ($) {
let my_type = $('.logout-type_radio'); let my_type = $('.logout-type_radio');
let expire_date = $('.expire-date'); let expire_date = $('.expire-date');
let force_logout = $('.force-logout'); let force_logout = $('.force-logout');
let exclude_user = $('.select_exclude_checkbox')
my_type.each(function () { my_type.each(function () {
if ($(this).prop('checked') == true) { if ($(this).prop('checked') == true) {
@@ -15,6 +16,7 @@ jQuery(function ($) {
} }
if ($(this).val() == 1) { if ($(this).val() == 1) {
force_logout.prop('disabled', true); force_logout.prop('disabled', true);
exclude_user.prop('disabled', true);
} }
} }
}); });
@@ -22,14 +24,20 @@ jQuery(function ($) {
my_type.click(function () { my_type.click(function () {
if ($(this).val() == 1) { if ($(this).val() == 1) {
force_logout.prop('disabled', true); force_logout.prop('disabled', true);
exclude_user.prop('checked', false);
exclude_user.prop('disabled', true);
} else { } else {
force_logout.prop('disabled', false); force_logout.prop('disabled', false);
exclude_user.prop('disabled', false);
} }
if ($(this).val() == 2) { if ($(this).val() == 2) {
expire_date.prop('disabled', true); expire_date.prop('disabled', true);
} else { } else {
expire_date.prop('disabled', false); expire_date.prop('disabled', false);
} }
}) });
} }
}); });
+6 -2
View File
@@ -46,14 +46,18 @@
<th scope="row">ログイン状態の保存期間</th> <th scope="row">ログイン状態の保存期間</th>
<td> <td>
<input type="number" class="expire-date" name="_al_ext[expire_date]" <input type="number" class="expire-date" name="_al_ext[expire_date]"
value="<?php echo esc_attr( $expire_date ); ?>"> 日 value="<?php echo esc_attr( $expire_date ); ?>" min="1" max="500"> 日(1〜500日)
</td> </td>
</tr> </tr>
<tr valign="top"> <tr valign="top">
<th scope="row">自動ログアウト時間</th> <th scope="row">自動ログアウト時間</th>
<td> <td>
<input type="number" class="force-logout" name="_al_ext[force_logout]" <input type="number" class="force-logout" name="_al_ext[force_logout]"
value="<?php echo esc_attr( $force_logout ); ?>"> 分 value="<?php echo esc_attr( $force_logout ); ?>" min="1" max="120"> 分(1〜120分)
<div id="logout-exclude-users">
自動ログアウト除外ユーザ
<?php include_once al_ext_config::AL_EXT_TEMPLATE_DIR . 'al_ext_user.php'; ?>
</div>
</td> </td>
</tr> </tr>
<tr valign="top"> <tr valign="top">
+14
View File
@@ -0,0 +1,14 @@
<?php foreach ( $exclude_users as $role => $exclude_user ): ?>
<div class="logout-exclude-user">
<label>
<input type="hidden"
name="_al_ext[exclude_users][<?php echo esc_attr( $role ); ?>]"
value="0">
<input class="select_exclude_checkbox" type="checkbox"
name="_al_ext[exclude_users][<?php echo esc_attr( $role ); ?>]"
<?php checked( $this->check_exclude_user( $role ), 1 ); ?>
value="1">
<?php echo esc_html( $exclude_user ); ?>
</label>
</div>
<?php endforeach; ?>
+4
View File
@@ -15,6 +15,10 @@ if ( ! trait_exists( 'al_ext_force_trait' ) ) {
* 自動ログアウトの一時Cookie作成 * 自動ログアウトの一時Cookie作成
*/ */
public function set_force_al_ext_cookie() { public function set_force_al_ext_cookie() {
//自動ログアウト除外ユーザの判定
if($this->is_exclude_user()){
return;
}
//ログイン+一時Cookieが存在する場合、一時Cookieを更新する //ログイン+一時Cookieが存在する場合、一時Cookieを更新する
if ( isset( $_COOKIE[ al_ext_config::AL_EXT_TMP_COOKIE ] ) && is_user_logged_in() ) { if ( isset( $_COOKIE[ al_ext_config::AL_EXT_TMP_COOKIE ] ) && is_user_logged_in() ) {
$this->create_tmp_cookie(); $this->create_tmp_cookie();
+4
View File
@@ -13,6 +13,10 @@ if ( ! trait_exists( 'al_ext_trait' ) ) {
* 拡張ログアウトの一時Cookie作成 * 拡張ログアウトの一時Cookie作成
*/ */
public function set_al_ext_cookie() { public function set_al_ext_cookie() {
//自動ログアウト除外ユーザの判定
if ( $this->is_exclude_user() ) {
return;
}
if ( is_user_logged_in() ) { if ( is_user_logged_in() ) {
//rememberme cookieが存在する場合は一時Cookieを作成する //rememberme cookieが存在する場合は一時Cookieを作成する
if ( isset( $_COOKIE[ al_ext_config::AL_EXT_REMEMBER_COOKIE ] ) if ( isset( $_COOKIE[ al_ext_config::AL_EXT_REMEMBER_COOKIE ] )