| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- <?php
- /**
- * The core plugin class.
- *
- * This is used to define internationalization, admin-specific hooks, and
- * public-facing site hooks.
- *
- * @since 1.0.0
- * @package QDR_Temporary_Shared_Storage
- */
- class QDR_TSS {
- /**
- * The loader that's responsible for maintaining and registering all hooks that power
- * the plugin.
- *
- * @since 1.0.0
- * @access protected
- * @var QDR_TSS_Loader $loader Maintains and registers all hooks for the plugin.
- */
- protected $loader;
- /**
- * The unique identifier of this plugin.
- *
- * @since 1.0.0
- * @access protected
- * @var string $plugin_name The string used to uniquely identify this plugin.
- */
- protected $plugin_name;
- /**
- * The current version of the plugin.
- *
- * @since 1.0.0
- * @access protected
- * @var string $version The current version of the plugin.
- */
- protected $version;
- /**
- * Define the core functionality of the plugin.
- *
- * Set the plugin name and the plugin version that can be used throughout the plugin.
- * Load the dependencies, define the locale, and set the hooks for the admin area and
- * the public-facing side of the site.
- *
- * @since 1.0.0
- */
- public function __construct() {
- $this->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_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');
- // 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;
- }
- }
|