From 907f39db4ab00de43016646660d9d1ca9c73d1f9 Mon Sep 17 00:00:00 2001 From: Jonas Kümmerlin Date: Sat, 27 Jan 2024 13:05:41 +0100 Subject: initial commit --- communi-events.php | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 communi-events.php (limited to 'communi-events.php') diff --git a/communi-events.php b/communi-events.php new file mode 100644 index 0000000..36aac54 --- /dev/null +++ b/communi-events.php @@ -0,0 +1,95 @@ +prefix . "communievents_events"; + + $charset_collate = $wpdb->get_charset_collate(); + + $sql = "CREATE TABLE $table_name ( + id INT(1) NOT NULL, + `group` INT(1) NOT NULL, + title TEXT NOT NULL, + location TEXT NOT NULL, + description TEXT NOT NULL, + start CHAR(19) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, + end CHAR(19) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, + allday BOOLEAN NOT NULL, + official BOOLEAN NOT NULL, + url TEXT NOT NULL, + lastsync BIGINT(1) NOT NULL, + PRIMARY KEY (id), + KEY start_idx (start), + KEY end_idx (end) + ) $charset_collate;"; + + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); + dbDelta($sql); + + communievents_setup_ical_feed(); // need to call it here for the rewrite flush + flush_rewrite_rules(); + + if (!wp_next_scheduled('communievents_cron_hook')) { + wp_schedule_event(time(), 'hourly', 'communievents_cron_hook'); + } +} + +register_activation_hook(__FILE__, 'communievents_install'); + +function communievents_uninstall() { + global $wpdb; + + $table_name = $wpdb->prefix . "communievents_events"; + + $wpdb->query("DROP TABLE IF EXISTS $table_name"); + + flush_rewrite_rules(); + + $timestamp = wp_next_scheduled('communievents_cron_hook'); + if ($timestamp) { + wp_unschedule_event($timestamp, 'communievents_cron_hook'); + } +} + +register_deactivation_hook(__FILE__, 'communievents_uninstall'); + + +/* INIT - register stuff + * + */ +function communievents_init() { + communievents_setup_ical_feed(); + communievents_setup_event_list(); + communievents_setup_event_calendar(); + communievents_setup_cron_hook(); + communievents_setup_healthcheck(); + communievents_setup_admin_page(); +} + +add_action('init', 'communievents_init'); + + -- cgit v1.2.3