version = QDR_TSS_VERSION; $this->plugin_name = 'qdr-temporary-shared-storage'; $this->define_constants(); $this->load_dependencies(); $this->set_locale(); $this->define_admin_hooks(); $this->define_public_hooks(); $this->define_rest_api_hooks(); $this->define_cron_hooks(); } /** * Define constants used by the plugin. * * @since 1.0.0 * @access private */ private function define_constants() { define('QDR_TSS_PLUGIN_DIR', plugin_dir_path(dirname(__FILE__))); define('QDR_TSS_PLUGIN_URL', plugin_dir_url(dirname(__FILE__))); define('QDR_TSS_PLUGIN_BASENAME', plugin_basename(dirname(__FILE__))); define('QDR_TSS_UPLOADS_DIR', wp_upload_dir()['basedir'] . '/qdr-shared-storage/'); define('QDR_TSS_UPLOADS_URL', wp_upload_dir()['baseurl'] . '/qdr-shared-storage/'); define('QDR_TSS_PLUGIN_TABLE', 'qdr_temporary_shared_storage'); } /** * Load the required dependencies for this plugin. * * Include the following files that make up the plugin: * * - QDR_TSS_Loader. Orchestrates the hooks of the plugin. * - QDR_TSS_i18n. Defines internationalization functionality. * - QDR_TSS_Admin. Defines all hooks for the admin area. * - QDR_TSS_Public. Defines all hooks for the public side of the site. * - QDR_TSS_REST_Controller. Defines all hooks for the REST API. * - QDR_TSS_DB_Manager. Handles database operations. * - QDR_TSS_File_Manager. Handles file operations. * - QDR_TSS_Settings. Handles plugin settings. * - QDR_TSS_Cron_Manager. Handles scheduled tasks. * * @since 1.0.0 * @access private */ private function load_dependencies() { /** * The class responsible for orchestrating the actions and filters of the * core plugin. */ require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-qdr-tss-loader.php'; /** * The class responsible for defining internationalization functionality * of the plugin. */ require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-qdr-tss-i18n.php'; /** * The class responsible for defining all database operations. */ require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-qdr-tss-db-manager.php'; /** * The class responsible for defining all file operations. */ require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-qdr-tss-file-manager.php'; /** * The class responsible for handling plugin settings. */ require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-qdr-tss-settings.php'; /** * The class responsible for handling scheduled tasks. */ require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-qdr-tss-cron-manager.php'; /** * Helper functions. */ require_once plugin_dir_path(dirname(__FILE__)) . 'includes/functions.php'; /** * The class responsible for defining all actions that occur in the admin area. */ require_once plugin_dir_path(dirname(__FILE__)) . 'admin/class-qdr-tss-admin.php'; require_once plugin_dir_path(dirname(__FILE__)) . 'admin/class-qdr-tss-media-page.php'; require_once plugin_dir_path(dirname(__FILE__)) . 'admin/class-qdr-tss-settings-page.php'; /** * The class responsible for defining all actions that occur in the public-facing * side of the site. */ require_once plugin_dir_path(dirname(__FILE__)) . 'public/class-qdr-tss-public.php'; require_once plugin_dir_path(dirname(__FILE__)) . 'public/class-qdr-tss-shortcode.php'; require_once plugin_dir_path(dirname(__FILE__)) . 'public/class-qdr-tss-download.php'; /** * The class responsible for defining all REST API functionality. */ require_once plugin_dir_path(dirname(__FILE__)) . 'rest-api/class-qdr-tss-rest-controller.php'; require_once plugin_dir_path(dirname(__FILE__)) . 'rest-api/class-qdr-tss-media-controller.php'; require_once plugin_dir_path(dirname(__FILE__)) . 'rest-api/class-qdr-tss-upload-controller.php'; $this->loader = new QDR_TSS_Loader(); } /** * Define the locale for this plugin for internationalization. * * Uses the QDR_TSS_i18n class in order to set the domain and to register the hook * with WordPress. * * @since 1.0.0 * @access private */ private function set_locale() { $plugin_i18n = new QDR_TSS_i18n(); $this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain'); } /** * Register all of the hooks related to the admin area functionality * of the plugin. * * @since 1.0.0 * @access private */ private function define_admin_hooks() { $plugin_admin = new QDR_TSS_Admin($this->get_plugin_name(), $this->get_version()); $media_page = new QDR_TSS_Media_Page($this->get_plugin_name(), $this->get_version()); $settings_page = new QDR_TSS_Settings_Page($this->get_plugin_name(), $this->get_version()); // Admin hooks $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles'); $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts'); $this->loader->add_action('admin_menu', $plugin_admin, 'add_admin_menu'); // AJAX handlers $this->loader->add_action('wp_ajax_qdr_tss_get_items', $media_page, 'ajax_get_items'); $this->loader->add_action('wp_ajax_qdr_tss_edit_item', $media_page, 'ajax_edit_item'); $this->loader->add_action('wp_ajax_qdr_tss_delete_item', $media_page, 'ajax_delete_item'); $this->loader->add_action('wp_ajax_qdr_tss_get_item_details', $media_page, 'ajax_get_item_details'); $this->loader->add_action('wp_ajax_qdr_tss_force_activate_item', $media_page, 'ajax_force_activate_item'); // NEW $this->loader->add_action('wp_ajax_qdr_tss_save_settings', $settings_page, 'ajax_save_settings'); $this->loader->add_action('wp_ajax_qdr_tss_purge_expired', $settings_page, 'ajax_purge_expired'); } /** * Register all of the hooks related to the public-facing functionality * of the plugin. * * @since 1.0.0 * @access private */ private function define_public_hooks() { $plugin_public = new QDR_TSS_Public($this->get_plugin_name(), $this->get_version()); $plugin_shortcode = new QDR_TSS_Shortcode($this->get_plugin_name(), $this->get_version()); $plugin_download = new QDR_TSS_Download($this->get_plugin_name(), $this->get_version()); // Public hooks $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles'); $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts'); $this->loader->add_action('init', $plugin_public, 'create_download_page'); // Add rewrite rules $this->loader->add_action('init', $plugin_public, 'add_rewrite_rules'); $this->loader->add_filter('query_vars', $plugin_public, 'add_query_vars'); // Shortcode registration $this->loader->add_action('init', $plugin_shortcode, 'register_shortcodes'); } /** * Register all of the hooks related to the REST API functionality * of the plugin. * * @since 1.0.0 * @access private */ private function define_rest_api_hooks() { $rest_controller = new QDR_TSS_REST_Controller($this->get_plugin_name(), $this->get_version()); $media_controller = new QDR_TSS_Media_Controller($this->get_plugin_name(), $this->get_version()); $upload_controller = new QDR_TSS_Upload_Controller($this->get_plugin_name(), $this->get_version()); // REST API hooks $this->loader->add_action('rest_api_init', $rest_controller, 'register_routes'); $this->loader->add_filter('rest_authentication_errors', $rest_controller, 'check_api_key'); } /** * Register all of the hooks related to the cron functionality * of the plugin. * * @since 1.0.0 * @access private */ private function define_cron_hooks() { $cron_manager = new QDR_TSS_Cron_Manager($this->get_plugin_name(), $this->get_version()); // Cron hooks $this->loader->add_action('qdr_tss_purge_expired_files', $cron_manager, 'purge_expired_files'); } /** * Run the loader to execute all of the hooks with WordPress. * * @since 1.0.0 */ public function run() { $this->loader->run(); } /** * The name of the plugin used to uniquely identify it within the context of * WordPress and to define internationalization functionality. * * @since 1.0.0 * @return string The name of the plugin. */ public function get_plugin_name() { return $this->plugin_name; } /** * The reference to the class that orchestrates the hooks with the plugin. * * @since 1.0.0 * @return QDR_TSS_Loader Orchestrates the hooks of the plugin. */ public function get_loader() { return $this->loader; } /** * Retrieve the version number of the plugin. * * @since 1.0.0 * @return string The version number of the plugin. */ public function get_version() { return $this->version; } }