$interval, 'display' => esc_html__( 'Calendar fetch interval' ), ); return $schedules; } /** * Initializes the plugin and creates a table * * @since 0.1.0 * * - wolkal3000_category - name of the calendar, for later per-unit display * - wolkal3000_link - the public or private .ics link * - wolkal3000_veranstalter - ? * - wolkal3000_active - flag if a calendar is active or not. Default active. * * Since there is no install hook in WP, we will use the activation hook for both. */ function wolkal3000_activate() { global $wpdb; // CREATE geocoding caching table if it does not exist already. // the location field will be used only during development and debugging, and will be omitted in production. $table = $wpdb->prefix.WOLKAL3000_GEO_TABLE; $query = "CREATE TABLE IF NOT EXISTS $table ( id INT(9) NOT NULL AUTO_INCREMENT, wolkal3000_geo_location VARCHAR(128) NOT NULL, wolkal3000_geo_hash VARCHAR(40) NOT NULL, wolkal3000_geo_lat VARCHAR(20) NOT NULL, wolkal3000_geo_lon VARCHAR(20) NOT NULL, wolkal3000_geo_timestamp INT(16) NOT NULL, UNIQUE KEY id (id) );"; $wpdb->query($query); // and start the scheduler; if ( ! wp_next_scheduled( 'wolkal3000_worker_hook' ) ) { wp_schedule_event( time(), 'wolkal3000_interval', 'wolkal3000_worker_hook' ); } wolkal3000_error_log (INFO, "wolkal3000 activated"); // empty geocode cache if option is set. $options = get_option('wolkal3000_options'); if ( isset ( $options['wolkal3000_reset_cache'] ) && '1' == $options['wolkal3000_reset_cache'] ) { $wpdb->query("DELETE IGNORE FROM $table WHERE 1=1"); wolkal3000_error_log (INFO, "emptied geocoding cache"); } } register_activation_hook( __FILE__, 'wolkal3000_activate' ); /** * Deactivate unregisters the scheduling function. * * @since 0.1.0 * */ function wolkal3000_deactivate() { // clean up! Many plugins forget the housekeeping when deactivating. wp_clear_scheduled_hook('wolkal3000_worker_hook'); wolkal3000_error_log (INFO, "wolkal3000 deactivated"); } register_deactivation_hook( __FILE__, 'wolkal3000_deactivate' ); /** * Uninstall drops our DB table * * @since 0.1.0 * */ function wolkal3000_uninstall() { // clean up! Many plugins forget the housekeeping when uninstalling. wolkal3000_error_log (INFO, "uninstalling wolkal3000"); // can we uninstall without deactivating first? // wolkal3000_deactivate; global $wpdb; // drop the geocache table $table = $wpdb->prefix.WOLKAL3000_GEO_TABLE ; $wpdb->query( "DROP TABLE IF EXISTS $table" ); // and the options. delete_option ( 'wolkal3000_options' ); } register_uninstall_hook( __FILE__, 'wolkal3000_uninstall' ); /* * Debug logging if debugging is activated * * @since 0.3.0 */ function wolkal3000_error_log($level, $args) { $levels = array ( 'NONE', 'CRIT', 'WARN', 'INFO' ); $options = get_option('wolkal3000_options'); if ( isset ( $options['wolkal3000_debugging'] )) { if ( $level <= (int) $options['wolkal3000_debugging'] ) { error_log ( "WolKal3000 [" . $levels[$level] . "] " . $args ); } } }