From 8d2d6010b06802bffe6e5101a6ec765e597e79b8 Mon Sep 17 00:00:00 2001 From: Timi Wahalahti Date: Tue, 10 Oct 2023 23:43:11 +0300 Subject: [PATCH] CampTix: Automatically disable Attendance UI after 2 weeks (#1055) --- .../camptix-attendance/addons/attendance.php | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 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 9e5c29eb07..be6c2a7050 100644 --- a/public_html/wp-content/plugins/camptix-attendance/addons/attendance.php +++ b/public_html/wp-content/plugins/camptix-attendance/addons/attendance.php @@ -3,8 +3,10 @@ * Allows event organizers to track which attendees showed up to the event. */ class CampTix_Attendance extends CampTix_Addon { - public $secret = ''; - public $questions = array(); + 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,15 @@ 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'] = ''; + $camptix_options['attendance-secret-generated'] = ''; + 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 +333,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 +354,13 @@ public function field_secret() { +

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