| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- /**
- * Fired during plugin activation.
- *
- * This class defines all code necessary to run during the plugin's activation.
- *
- * @package QDR_Temporary_Shared_Storage
- * @since 1.0.0
- */
- class QDR_TSS_Activator {
- /**
- * Activate the plugin.
- *
- * Creates necessary database tables, directories, and default settings.
- *
- * @since 1.0.0
- */
- public static function activate() {
- // Create database table
- require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-qdr-tss-db-manager.php';
- $db_manager = QDR_TSS_DB_Manager::instance();
- $db_manager->create_table();
-
- // Initialize file system
- require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-qdr-tss-file-manager.php';
- $file_manager = QDR_TSS_File_Manager::instance();
- $file_manager->init_file_system();
-
- // Set default settings
- require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-qdr-tss-settings.php';
- $settings = QDR_TSS_Settings::instance();
-
- // Only set default settings if they don't exist
- if (!get_option('qdr_tss_settings')) {
- $default_settings = array(
- 'api_key' => $settings->generate_api_key(),
- 'media_category' => 'shared-storage',
- 'max_upload_size' => 1073741824, // 1GB default
- );
- $settings->update_settings($default_settings);
- }
-
- // Create download page if it doesn't exist
- $download_page = get_page_by_path('shared-file-download');
- if (!$download_page) {
- wp_insert_post(array(
- 'post_title' => __('Shared File Download', 'qdr-temporary-shared-storage'),
- 'post_content' => '[qdr_tss_download]',
- 'post_status' => 'publish',
- 'post_type' => 'page',
- 'post_name' => 'shared-file-download'
- ));
- }
-
- // Schedule cron job
- if (!wp_next_scheduled('qdr_tss_purge_expired_files')) {
- wp_schedule_event(time(), 'hourly', 'qdr_tss_purge_expired_files');
- }
-
- // Set version number in database
- update_option('qdr_tss_version', QDR_TSS_VERSION);
-
- // Add rewrite rules
- add_rewrite_rule(
- '^shared-file-download/([a-zA-Z0-9]+)/?$',
- 'index.php?pagename=shared-file-download&qdr_file_id=$matches[1]',
- 'top'
- );
-
- // Clear permalinks
- flush_rewrite_rules();
- }
- }
|