From 47c8953ce0a1e09e36e8b9472a9f681e542daa36 Mon Sep 17 00:00:00 2001 From: Timi Wahalahti Date: Thu, 21 Sep 2023 14:56:20 +0300 Subject: [PATCH] turn camptix attendance UI automatically off after two weeks from generating the link --- .../camptix-attendance/addons/attendance.php | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/public_html/wp-content/plugins/camptix-attendance/addons/attendance.php b/public_html/wp-content/plugins/camptix-attendance/addons/attendance.php index 9e5c29eb0..b88c55747 100644 --- a/public_html/wp-content/plugins/camptix-attendance/addons/attendance.php +++ b/public_html/wp-content/plugins/camptix-attendance/addons/attendance.php @@ -5,6 +5,8 @@ class CampTix_Attendance extends CampTix_Addon { public $secret = ''; public $questions = array(); + public $secret_expiry = '2 weeks'; + /** * Runs during CampTix init. */ @@ -23,6 +25,7 @@ public function camptix_init() { return; $this->secret = $camptix_options['attendance-secret']; + $this->secret_generated = $camptix_options['attendance-secret-generated']; if ( isset( $camptix_options['attendance-questions'] ) ) { $this->questions = $camptix_options['attendance-questions']; @@ -31,6 +34,14 @@ public function camptix_init() { if ( empty( $camptix_options['attendance-enabled'] ) ) return; + // If secret has expired, trun the UI off, reset link and do not allow setup for UI use. + if ( strtotime( $this->secret_generated ) < strtotime( "-{$this->secret_expiry}" ) ) { + $camptix_options['attendance-enabled'] = 0; + $camptix_options['attendance-secret'] = ''; + update_option( 'camptix_options', $camptix_options ); + return; + } + add_filter( 'wp_ajax_camptix-attendance', array( $this, 'ajax_callback' ) ); add_filter( 'wp_ajax_nopriv_camptix-attendance', array( $this, 'ajax_callback' ) ); @@ -321,9 +332,7 @@ public function setup_controls( $section ) { add_settings_section( 'general', esc_html__( 'Attendance UI', 'wordcamporg' ), array( $this, 'setup_controls_section' ), 'camptix_options' ); // Fields - $camptix->add_settings_field_helper( 'attendance-enabled', esc_html__( 'Enabled', 'wordcamporg' ), 'field_yesno', 'general', - esc_html__( "Don't forget to disable the UI after the event is over.", 'wordcamporg' ) - ); + $camptix->add_settings_field_helper( 'attendance-enabled', esc_html__( 'Enabled', 'wordcamporg' ), 'field_yesno', 'general' ); add_settings_field( 'attendance-questions', esc_html__( 'Questions', 'wordcamporg' ), array( $this, 'field_questions' ), 'camptix_options', 'general', esc_html__( 'Show these additional ticket questions in the UI.', 'wordcamporg' ) ); @@ -344,6 +353,13 @@ public function field_secret() { +

+ secret_generated ) ) { + echo sprintf( esc_html__( "Link will expire automatically after two weeks from generating it.", 'wordcamporg' ), $this->secret_expiry ); + } else { + echo sprintf( esc_html__( "Link will expire automatically on %s.", 'wordcamporg' ), wp_date( 'Y-m-d H:i:s', strtotime( "+{$this->secret_expiry}", strtotime( $this->secret_generated ) ) ) ); + } ?> +