class-qdr-tss-public.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * The public-facing functionality of the plugin.
  4. *
  5. * @package QDR_Temporary_Shared_Storage
  6. * @since 1.0.0
  7. */
  8. class QDR_TSS_Public {
  9. /**
  10. * The ID of this plugin.
  11. *
  12. * @since 1.0.0
  13. * @access private
  14. * @var string $plugin_name The ID of this plugin.
  15. */
  16. private $plugin_name;
  17. /**
  18. * The version of this plugin.
  19. *
  20. * @since 1.0.0
  21. * @access private
  22. * @var string $version The current version of this plugin.
  23. */
  24. private $version;
  25. /**
  26. * Initialize the class and set its properties.
  27. *
  28. * @since 1.0.0
  29. * @param string $plugin_name The name of this plugin.
  30. * @param string $version The version of this plugin.
  31. */
  32. public function __construct($plugin_name, $version) {
  33. $this->plugin_name = $plugin_name;
  34. $this->version = $version;
  35. }
  36. /**
  37. * Register the stylesheets for the public-facing side of the site.
  38. *
  39. * @since 1.0.0
  40. */
  41. public function enqueue_styles() {
  42. // Only load on download page
  43. if (!is_page('shared-file-download')) {
  44. return;
  45. }
  46. wp_enqueue_style(
  47. $this->plugin_name . '-public',
  48. plugin_dir_url(dirname(__FILE__)) . 'public/css/public.css',
  49. array(),
  50. $this->version,
  51. 'all'
  52. );
  53. }
  54. /**
  55. * Register the JavaScript for the public-facing side of the site.
  56. *
  57. * @since 1.0.0
  58. */
  59. public function enqueue_scripts() {
  60. // Only load on download page
  61. if (!is_page('shared-file-download')) {
  62. return;
  63. }
  64. wp_enqueue_script(
  65. $this->plugin_name . '-public',
  66. plugin_dir_url(dirname(__FILE__)) . 'public/js/public.js',
  67. array('jquery'),
  68. $this->version,
  69. true
  70. );
  71. }
  72. /**
  73. * Create download page if it doesn't exist.
  74. *
  75. * @since 1.0.0
  76. */
  77. public function create_download_page() {
  78. $download_page = get_page_by_path('shared-file-download');
  79. if (!$download_page) {
  80. wp_insert_post(array(
  81. 'post_title' => __('Shared File Download', 'qdr-temporary-shared-storage'),
  82. 'post_content' => '[qdr_tss_download]',
  83. 'post_status' => 'publish',
  84. 'post_type' => 'page',
  85. 'post_name' => 'shared-file-download'
  86. ));
  87. }
  88. }
  89. }