class-qdr-tss-activator.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * Fired during plugin activation.
  4. *
  5. * This class defines all code necessary to run during the plugin's activation.
  6. *
  7. * @package QDR_Temporary_Shared_Storage
  8. * @since 1.0.0
  9. */
  10. class QDR_TSS_Activator {
  11. /**
  12. * Activate the plugin.
  13. *
  14. * Creates necessary database tables, directories, and default settings.
  15. *
  16. * @since 1.0.0
  17. */
  18. public static function activate() {
  19. // Create database table
  20. require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-qdr-tss-db-manager.php';
  21. $db_manager = QDR_TSS_DB_Manager::instance();
  22. $db_manager->create_table();
  23. // Initialize file system
  24. require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-qdr-tss-file-manager.php';
  25. $file_manager = QDR_TSS_File_Manager::instance();
  26. $file_manager->init_file_system();
  27. // Set default settings
  28. require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-qdr-tss-settings.php';
  29. $settings = QDR_TSS_Settings::instance();
  30. // Only set default settings if they don't exist
  31. if (!get_option('qdr_tss_settings')) {
  32. $default_settings = array(
  33. 'api_key' => $settings->generate_api_key(),
  34. 'media_category' => 'shared-storage',
  35. 'max_upload_size' => 1073741824, // 1GB default
  36. );
  37. $settings->update_settings($default_settings);
  38. }
  39. // Create download page if it doesn't exist
  40. $download_page = get_page_by_path('shared-file-download');
  41. if (!$download_page) {
  42. wp_insert_post(array(
  43. 'post_title' => __('Shared File Download', 'qdr-temporary-shared-storage'),
  44. 'post_content' => '[qdr_tss_download]',
  45. 'post_status' => 'publish',
  46. 'post_type' => 'page',
  47. 'post_name' => 'shared-file-download'
  48. ));
  49. }
  50. // Schedule cron job
  51. if (!wp_next_scheduled('qdr_tss_purge_expired_files')) {
  52. wp_schedule_event(time(), 'hourly', 'qdr_tss_purge_expired_files');
  53. }
  54. // Set version number in database
  55. update_option('qdr_tss_version', QDR_TSS_VERSION);
  56. // Add rewrite rules
  57. add_rewrite_rule(
  58. '^shared-file-download/([a-zA-Z0-9]+)/?$',
  59. 'index.php?pagename=shared-file-download&qdr_file_id=$matches[1]',
  60. 'top'
  61. );
  62. // Clear permalinks
  63. flush_rewrite_rules();
  64. }
  65. }