set_basename( false, __FILE__ ); } else { /** * DO NOT REMOVE THIS IF, IT IS ESSENTIAL FOR THE * `function_exists` CALL ABOVE TO PROPERLY WORK. */ if ( ! function_exists( 'webcal_fs' ) ) { // Load scoped vendor dependencies (built by bin/build-release.sh for distribution). if ( file_exists( WEBCALENDAR_WP_PATH . 'vendor-prefixed/autoload.php' ) ) { require_once WEBCALENDAR_WP_PATH . 'vendor-prefixed/autoload.php'; } // Autoload dependencies. if ( file_exists( WEBCALENDAR_WP_PATH . 'vendor/autoload.php' ) ) { require_once WEBCALENDAR_WP_PATH . 'vendor/autoload.php'; } // Load Freemius SDK (guarded so tests work without it). $webcal_freemius_init = WEBCALENDAR_WP_PATH . 'freemius-init.php'; if ( file_exists( WEBCALENDAR_WP_PATH . 'freemius/start.php' ) && file_exists( $webcal_freemius_init ) ) { require_once $webcal_freemius_init; } } /** * The code that runs during plugin activation. * This action is documented in src/Activator.php */ function webcal_activate_plugin(): void { require_once WEBCALENDAR_WP_PATH . 'src/Activator.php'; \WebCalendar\WP\Activator::activate(); } /** * The code that runs during plugin deactivation. * This action is documented in src/Deactivator.php */ function webcal_deactivate_plugin(): void { require_once WEBCALENDAR_WP_PATH . 'src/Deactivator.php'; \WebCalendar\WP\Deactivator::deactivate(); } register_activation_hook( __FILE__, 'webcal_activate_plugin' ); register_deactivation_hook( __FILE__, 'webcal_deactivate_plugin' ); /** * Cleanup data on uninstall (opt-in via Settings). * * Hooked to Freemius after_uninstall so Freemius can track the * uninstall event and collect user feedback before data is removed. */ function webcal_fs_uninstall_cleanup() { $delete_data = get_option( 'webcal_delete_data_on_uninstall' ); if ( 'yes' !== $delete_data ) { return; } global $wpdb; $tables = [ 'webcal_entry', 'webcal_entry_repeats', 'webcal_entry_repeats_not', 'webcal_entry_user', 'webcal_categories', 'webcal_entry_categories', 'webcal_user_pref', 'webcal_config', 'webcal_entry_log', 'webcal_reminders', 'webcal_site_extras', 'webcal_import', 'webcal_import_data', 'webcal_nonuser_cals', // Everything below was created by a release that did not extend // this list, so "delete all data" left it behind. DeactivatorTest // now reads the CREATE TABLE statements out of Schema.php and // fails if the two ever diverge again. 'webcal_user_layers', 'webcal_venue', 'webcal_organizer', 'webcal_attendee', 'webcal_ticket_type', 'webcal_ticket_order', 'webcal_rsvp_pending', ]; foreach ( $tables as $table ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.SchemaChange $wpdb->query( $wpdb->prepare( 'DROP TABLE IF EXISTS %i', $wpdb->prefix . $table ) ); } delete_option( 'webcalendar_wp_db_version' ); delete_option( 'webcal_license_tier' ); delete_option( 'webcal_license_key' ); delete_option( 'webcal_license_dev_override' ); delete_option( 'webcal_single_event_pages' ); delete_option( 'webcal_google_maps_api_key' ); delete_option( 'webcal_delete_data_on_uninstall' ); // Every option, transient and user meta key the plugin writes starts // with webcal_ or webcalendar_ (DeactivatorTest scans src/ to keep it // so). Deleting by prefix rather than by a list is what reaches the // feed tokens, which otherwise resolved again after a reinstall, and // the email queue, which holds guests' names and cancel links. $option_prefixes = [ 'webcal\_%', 'webcalendar\_%', '\_transient\_webcal\_%', '\_transient\_timeout\_webcal\_%' ]; foreach ( $option_prefixes as $prefix ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s", $prefix ) ); } // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE %s", 'webcal\_%' ) ); // Deleted behind the options API's back, so drop its cached copies. wp_cache_delete( 'alloptions', 'options' ); wp_cache_delete( 'notoptions', 'options' ); } // Hook uninstall cleanup to Freemius (runs after uninstall tracking). if ( function_exists( 'webcal_fs' ) ) { webcal_fs()->add_action( 'after_uninstall', 'webcal_fs_uninstall_cleanup' ); } require_once WEBCALENDAR_WP_PATH . 'src/functions.php'; require_once WEBCALENDAR_WP_PATH . 'src/Plugin.php'; $webcal_plugin = new \WebCalendar\WP\Plugin(); $webcal_plugin->run(); }