plugin_file = $plugin_file; // Initialize logger and rate limiter. $this->logger = new Logger(); $this->rate_limiter = new Rate_Limiter( $this->logger ); // Initialize configuration and factory. $this->config = new Config( $this->logger ); $this->client_factory = new S3_Client_Factory( $this->config ); // Initialize components with dependency injection. $this->admin_page = new Admin_Page( $this->config, $this->client_factory, $this->logger, $this->rate_limiter, $plugin_file ); $this->media_uploader = new Media_Uploader( $this->config, $this->client_factory, $this->logger ); $this->url_rewriter = new URL_Rewriter( $this->config ); $this->subsize_filter = new Subsize_Filter( $this->config ); $this->manager_dependency = new Manager_Dependency(); } /** * Get the singleton instance. * * @since 0.3.0 * * @param string $plugin_file Path to the main plugin file. * @return Plugin The singleton instance. */ public static function get_instance( string $plugin_file ): Plugin { if ( null === self::$instance ) { self::$instance = new self( $plugin_file ); } return self::$instance; } /** * Initialize the plugin by registering all hooks. * * @since 0.3.0 * * @return void */ public function init(): void { // Load text domain for translations. add_action( 'plugins_loaded', array( $this, 'load_textdomain' ), 20 ); // Add custom cron interval. add_filter( 'cron_schedules', array( $this, 'add_cron_intervals' ) ); // phpcs:ignore WordPress.WP.CronInterval.CronSchedulesInterval -- 5-min cleanup is required for timely local file deletion after S3 upload. // Register component hooks. $this->admin_page->register(); $this->media_uploader->register(); $this->url_rewriter->register(); $this->subsize_filter->register(); $this->manager_dependency->register(); } /** * Add custom cron intervals. * * @since 1.0.1 * * @param array> $schedules Existing schedules. * @return array> Modified schedules. */ public function add_cron_intervals( array $schedules ): array { $schedules['every_five_minutes'] = array( 'interval' => 300, 'display' => __( 'Every 5 Minutes', 'idrivee2-media-upload' ), ); return $schedules; } /** * Load the plugin text domain for translations. * * Registers the plugin's text domain so that translation files in the * /languages directory are loaded on the front end and in the admin. * * @since 0.3.0 * * @return void */ public function load_textdomain(): void { load_plugin_textdomain( 'idrivee2-media-upload', false, dirname( plugin_basename( $this->plugin_file ) ) . '/languages' ); } }