| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- /**
- * The public-facing functionality of the plugin.
- *
- * @package QDR_Temporary_Shared_Storage
- * @since 1.0.0
- */
- class QDR_TSS_Public {
- /**
- * The ID of this plugin.
- *
- * @since 1.0.0
- * @access private
- * @var string $plugin_name The ID of this plugin.
- */
- private $plugin_name;
- /**
- * The version of this plugin.
- *
- * @since 1.0.0
- * @access private
- * @var string $version The current version of this plugin.
- */
- private $version;
- /**
- * Initialize the class and set its properties.
- *
- * @since 1.0.0
- * @param string $plugin_name The name of this plugin.
- * @param string $version The version of this plugin.
- */
- public function __construct($plugin_name, $version) {
- $this->plugin_name = $plugin_name;
- $this->version = $version;
- }
- /**
- * Register the stylesheets for the public-facing side of the site.
- *
- * @since 1.0.0
- */
- public function enqueue_styles() {
- // Only load on download page
- if (!is_page('shared-file-download')) {
- return;
- }
-
- wp_enqueue_style(
- $this->plugin_name . '-public',
- plugin_dir_url(dirname(__FILE__)) . 'public/css/public.css',
- array(),
- $this->version,
- 'all'
- );
- }
- /**
- * Register the JavaScript for the public-facing side of the site.
- *
- * @since 1.0.0
- */
- public function enqueue_scripts() {
- // Only load on download page
- if (!is_page('shared-file-download')) {
- return;
- }
-
- wp_enqueue_script(
- $this->plugin_name . '-public',
- plugin_dir_url(dirname(__FILE__)) . 'public/js/public.js',
- array('jquery'),
- $this->version,
- true
- );
- }
- /**
- * Create download page if it doesn't exist.
- *
- * @since 1.0.0
- */
- public function create_download_page() {
- $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'
- ));
- }
- }
- /**
- * Add rewrite rules for pretty download URLs
- *
- * @since 1.0.0
- */
- public function 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'
- );
- }
- /**
- * Add query vars
- *
- * @since 1.0.0
- * @param array $vars The array of query vars.
- * @return array The modified array of query vars.
- */
- public function add_query_vars($vars) {
- $vars[] = 'qdr_file_id';
- return $vars;
- }
- }
|