has_cap( apply_filters( 'admon_access_capability', 'manage_options' ) ); // Administrators are exempt unless explicitly included. if ( $is_admin && ! $apply_to_admins ) { return $expiration; } // Start with the general timeout, then use a valid administrator override if set. if ( 'custom' === ( $settings['session_timeout'] ?? '' ) ) { $timeout_hours = absint( $settings['custom_timeout_hours'] ?? 0 ); } else { $timeout_hours = absint( $settings['session_timeout'] ?? 0 ); } $admin_hours = $settings['admin_timeout_hours'] ?? ''; if ( $is_admin && is_scalar( $admin_hours ) && ctype_digit( (string) $admin_hours ) && (int) $admin_hours >= 1 && (int) $admin_hours <= 168 ) { $timeout_hours = (int) $admin_hours; } // Validate timeout hours (1 hour minimum, 168 hours/1 week maximum). if ( $timeout_hours < 1 || $timeout_hours > 168 ) { return $expiration; // Fall back to default if invalid. } // Check if we should respect "Remember Me" checkbox. $override_remember_me = ! empty( $settings['override_remember_me'] ); if ( ! $override_remember_me && $remember ) { // If "Remember Me" is checked and we're not overriding it, // let WordPress handle the extended session (typically 2 weeks). return $expiration; } $timeout_seconds = $timeout_hours * HOUR_IN_SECONDS; // Return the custom timeout. return $timeout_seconds; } add_filter( 'auth_cookie_expiration', 'admon_set_session_expiration', 10, 3 );