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
*/
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() ) {
$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' ) );
@@ -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 );
include al_ext_config::AL_EXT_TEMPLATE_DIR . 'success.php';
}
$opt = get_option( '_al_ext' );
$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 );
$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', '' );
$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';
}
@@ -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;
}
}
}
}
}