PluginProbe
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce / 2.0.0
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce v2.0.0
2.15.0 trunk 1.0.0 1.0.1 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1.2 2.1.3 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 All 62 releases
hurrytimer / includes / Frontend.php

Frontend.php in HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce 2.0.0, at includes/Frontend.php

146 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Hurrytimer;
3
4 /**
5 * The public-facing functionality of the plugin.
6 *
7 * @link http://nabillemsieh.com
8 * @since 1.0.0
9 *
10 * @package Hurrytimer
11 * @subpackage Hurrytimer/public
12 */
13
14 /**
15 * The public-facing functionality of the plugin.
16 *
17 * Defines the plugin name, version, and two examples hooks for how to
18 * enqueue the public-facing stylesheet and JavaScript.
19 *
20 * @package Hurrytimer
21 * @subpackage Hurrytimer/public
22 * @author Nabil Lemsieh <contact@nabillemsieh.com>
23 */
24 class Frontend
25 {
26 /**
27 * The ID of this plugin.
28 *
29 * @since 1.0.0
30 * @access private
31 * @var string $plugin_name The ID of this plugin.
32 */
33 private $plugin_name;
34
35 /**
36 * The version of this plugin.
37 *
38 * @since 1.0.0
39 * @access private
40 * @var string $version The current version of this plugin.
41 */
42 private $version;
43
44 /**
45 * Initialize the class and set its properties.
46 *
47 * @since 1.0.0
48 *
49 * @param string $plugin_name The name of the plugin.
50 * @param string $version The version of this plugin.
51 */
52 public function __construct($plugin_name, $version)
53 {
54 $this->plugin_name = $plugin_name;
55 $this->version = $version;
56 $shortcode = new CampaignShortcode();
57 add_shortcode('hurrytimer', [$shortcode, 'content']);
58 add_action('wp', [$this, 'handleWCSingleProduct']);
59 add_action('wp_ajax_action_change_stock_status', [$this, 'ajaxChangeStockStatus']);
60 add_action('wp_ajax_nopriv_action_change_stock_status', [$this, 'ajaxChangeStockStatus']);
61 }
62
63 function changeStockStatus()
64 {
65 check_ajax_referer('hurryt', 'ajax_nonce');
66 if (isset($_POST['id']) || ! isset($_POST['stockStatus'])) {
67 die(-1);
68 }
69 $id = intval($_POST['id']);
70 $stockStatus = sanitize_key($_POST['stockStatus']);
71 $wcCampaign = new WCCampaign();
72 $campaign = new Campaign($id);
73
74 $wcCampaign->changeStockStatus($campaign, $stockStatus);
75 die();
76 }
77
78 public function handleWCSingleProduct()
79 {
80 global $post;
81
82 if ( Utils\Helpers::isWcActive() && is_product()) {
83 $wcCampaign = new WCCampaign();
84 $wcCampaign->run($post->ID);
85 }
86
87 }
88
89
90 /**
91 * Register the stylesheets for the public-facing side of the site.
92 *
93 * @since 1.0.0
94 */
95 public function enqueue_styles()
96 {
97
98 wp_enqueue_style(
99 $this->plugin_name,
100 HURRYT_URL . 'assets/css/hurrytimer.css', [], time()
101 );
102
103 }
104
105 /**
106 * Register the JavaScript for the public-facing side of the site.
107 *
108 * @since 1.0.0
109 */
110 public function enqueue_scripts()
111 {
112 wp_enqueue_script(
113 'jq-countdown',
114 HURRYT_URL. 'assets/js/jquery.countdown.min.js',
115 ['jquery'],
116 '2.2.0',
117 true
118 );
119
120 wp_enqueue_script(
121 $this->plugin_name,
122 HURRYT_URL. 'assets/js/hurrytimer.js',
123 ['jq-countdown'],
124 $this->version,
125 true
126 );
127 wp_localize_script($this->plugin_name, 'hurrytimer_ajax_object', [
128 'ajax_url' => admin_url('admin-ajax.php'),
129 'ajax_nonce' => wp_create_nonce('hurryt'),
130 'actionsOptions' => [
131 'none' => C::ACTION_NONE,
132 'hide' => C::ACTION_HIDE,
133 'redirect' => C::ACTION_REDIRECT,
134 'stockStatus' => C::ACTION_CHANGE_STOCK_STATUS,
135 'hideAddToCartButton' => C::ACTION_HIDE_ADD_TO_CART_BUTTON,
136 'displayMessage' => C::ACTION_DISPLAY_MESSAGE,
137 ],
138 'restartOptions' => [
139 'none' => C::RESTART_NONE,
140 'immediately' => C::RESTART_IMMEDIATELY,
141 'afterReload' => C::RESTART_AFTER_RELOAD,
142 ],
143 ]);
144 }
145 }
146