PluginProbe
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce / 1.2.3
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce v1.2.3
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 / class-hurrytimer.php

class-hurrytimer.php in HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce 1.2.3, at includes/class-hurrytimer.php

316 lines 10.3 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 file that defines the core plugin class
6 *
7 * A class definition that includes attributes and functions used across both the
8 * public-facing side of the site and the admin area.
9 *
10 * @link http://nabillemsieh.com
11 * @since 1.0.0
12 *
13 * @package Hurrytimer
14 * @subpackage Hurrytimer/includes
15 */
16
17 /**
18 * The core plugin class.
19 *
20 * This is used to define internationalization, admin-specific hooks, and
21 * public-facing site hooks.
22 *
23 * Also maintains the unique identifier of this plugin as well as the current
24 * version of the plugin.
25 *
26 * @since 1.0.0
27 * @package Hurrytimer
28 * @subpackage Hurrytimer/includes
29 * @author Nabil Lemsieh <contact@nabillemsieh.com>
30 */
31 class Hurrytimer
32 {
33
34 /**
35 * The loader that's responsible for maintaining and registering all hooks that power
36 * the plugin.
37 *
38 * @since 1.0.0
39 * @access protected
40 * @var Hurrytimer_Loader $loader Maintains and registers all hooks for the plugin.
41 */
42 protected $loader;
43
44 /**
45 * The unique identifier of this plugin.
46 *
47 * @since 1.0.0
48 * @access protected
49 * @var string $plugin_name The string used to uniquely identify this plugin.
50 */
51 protected $plugin_name;
52
53 /**
54 * The current version of the plugin.
55 *
56 * @since 1.0.0
57 * @access protected
58 * @var string $version The current version of the plugin.
59 */
60 protected $version;
61
62 /**
63 * Define the core functionality of the plugin.
64 *
65 * Set the plugin name and the plugin version that can be used throughout the plugin.
66 * Load the dependencies, define the locale, and set the hooks for the admin area and
67 * the public-facing side of the site.
68 *
69 * @since 1.0.0
70 */
71 public function __construct()
72 {
73 $this->version = HURRYTIMER_PLUGIN_VERSION;
74 $this->plugin_name = 'hurrytimer';
75 $this->load_dependencies();
76 $this->set_locale();
77 $this->on_upgrade();
78 $this->register_post_type();
79 $this->define_admin_hooks();
80 $this->define_public_hooks();
81
82 }
83
84 /**
85 * Load the required dependencies for this plugin.
86 *
87 * Include the following files that make up the plugin:
88 *
89 * - Hurrytimer_Loader. Orchestrates the hooks of the plugin.
90 * - Hurrytimer_i18n. Defines internationalization functionality.
91 * - Hurrytimer_Admin. Defines all hooks for the admin area.
92 * - Hurrytimer_Public. Defines all hooks for the public side of the site.
93 *
94 * Create an instance of the loader which will be used to register the hooks
95 * with WordPress.
96 *
97 * @since 1.0.0
98 * @access private
99 */
100 private function load_dependencies()
101 {
102
103 require_once HURRYTIMER_PLUGIN_DIR . '/includes/utils/class-hurrytimer-constants.php';
104 require_once HURRYTIMER_PLUGIN_DIR . '/includes/utils/class-hurrytimer-helper.php';
105 require_once HURRYTIMER_PLUGIN_DIR . '/includes/utils/class-sql-builder.php';
106 require_once HURRYTIMER_PLUGIN_DIR . '/includes/class-ip-detection.php';
107 require_once HURRYTIMER_PLUGIN_DIR . '/includes/class-cookie-detection.php';
108
109 require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-hurrytimer-countdown.php';
110 /**
111 * The class responsible for orchestrating the actions and filters of the
112 * core plugin.
113 */
114 require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-hurrytimer-loader.php';
115
116 /**
117 * The class responsible for defining internationalization functionality
118 * of the plugin.
119 */
120 require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-hurrytimer-i18n.php';
121
122 /**
123 * The class responsible for defining all actions that occur in the admin area.
124 */
125 require_once plugin_dir_path(dirname(__FILE__)) . 'admin/class-hurrytimer-admin.php';
126
127 /**
128 * The class responsible for defining all actions that occur in the public-facing
129 * side of the site.
130 */
131 require_once HURRYTIMER_PLUGIN_DIR . '/includes/class-hurrytimer-public.php';
132
133 $this->loader = new Hurrytimer_Loader();
134
135 }
136
137 /**
138 * Define the locale for this plugin for internationalization.
139 *
140 * Uses the Hurrytimer_i18n class in order to set the domain and to register the hook
141 * with WordPress.
142 *
143 * @since 1.0.0
144 * @access private
145 */
146 private function set_locale()
147 {
148
149 $plugin_i18n = new Hurrytimer_i18n();
150
151 $this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain');
152
153 }
154
155 private function on_upgrade()
156 {
157
158 add_action('plugins_loaded', function () {
159 $installed_ver = get_option('hurrytimer_db_version');
160 if(!$installed_ver || $installed_ver != HURRYTIMER_DB_VERSION){
161 $sql_builder = new SQL_Builder('hurrytimer_evergreen');
162 $sql_builder
163 ->create()
164 ->bigint('id', 20, true, false, true)
165 ->bigint('countdown_id', 20, true)
166 ->string('client_ip_address', 50, false)
167 ->boolean('expired')
168 ->bigint('client_expires_at', 20, true)
169 ->timestamp('destroy_at', true)
170 ->primary_key('id')
171 ->run();
172 update_option('hurrytimer_db_version', HURRYTIMER_DB_VERSION);
173 }
174
175 $current_version = get_option('hurrytimer_version');
176 if (version_compare($current_version, '1.1.3', '<=')) {
177 @delete_option('_htmr_reset_cookie');
178 }
179 if (version_compare($current_version, '1.0.1', '<=')) {
180 $result = get_posts(['post_type' => 'hurrytimer_countdown']);
181 foreach ($result as $item) {
182 $countdown = new Hurrytimer_Countdown($item->ID);
183 $headline_status = get_post_meta($item->ID, 'headline_status', true);
184 if (intval($headline_status) === Headline_Status::HIDE) {
185 $countdown->set_display_headline(false);
186 $countdown->set_headline_position(Headline_Position::ABOVE_TIMER);
187 } else {
188 $countdown->set_display_headline(true);
189 $countdown->set_headline_position($headline_status);
190 }
191 delete_post_meta($item->ID, 'headline_status');
192 }
193 }
194 update_option('hurrytimer_version', HURRYTIMER_PLUGIN_VERSION);
195
196 });
197 }
198
199 /**
200 * Register all of the hooks related to the admin area functionality
201 * of the plugin.
202 *
203 * @since 1.0.0
204 * @access private
205 */
206 private function define_admin_hooks()
207 {
208 $plugin_admin = new Hurrytimer_Admin($this->get_plugin_name(), $this->get_version());
209 $this->loader->add_action('admin_menu', $plugin_admin, 'menu');
210 $this->loader->add_action('admin_init', $plugin_admin, 'meta_boxes');
211 $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles');
212 $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts');
213 }
214
215 /**
216 * Register all of the hooks related to the public-facing functionality
217 * of the plugin.
218 *
219 * @since 1.0.0
220 * @access private
221 */
222 private function define_public_hooks()
223 {
224
225 $plugin_public = new Hurrytimer_Public($this->get_plugin_name(), $this->get_version());
226
227 $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles');
228 $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts');
229
230 }
231
232 /**
233 * Run the loader to execute all of the hooks with WordPress.
234 *
235 * @since 1.0.0
236 */
237 public function run()
238 {
239 $this->loader->run();
240 }
241
242 /**
243 * The name of the plugin used to uniquely identify it within the context of
244 * WordPress and to define internationalization functionality.
245 *
246 * @since 1.0.0
247 * @return string The name of the plugin.
248 */
249 public function get_plugin_name()
250 {
251 return $this->plugin_name;
252 }
253
254 /**
255 * The reference to the class that orchestrates the hooks with the plugin.
256 *
257 * @since 1.0.0
258 * @return Hurrytimer_Loader Orchestrates the hooks of the plugin.
259 */
260 public function get_loader()
261 {
262 return $this->loader;
263 }
264
265 /**
266 * Retrieve the version number of the plugin.
267 *
268 * @since 1.0.0
269 * @return string The version number of the plugin.
270 */
271 public function get_version()
272 {
273 return $this->version;
274 }
275
276 public function register_post_type()
277 {
278 $args = array(
279 'label' => __('All', DOMAIN),
280 'labels' => array(
281 'name' => __('Countdown Timer', DOMAIN),
282 'singular_name' => __('Countdown Timer', DOMAIN),
283 'add_new' => __('Add Timer', DOMAIN),
284 'add_new_item' => __('Add New Timer', DOMAIN),
285 'edit' => __('Edit', DOMAIN),
286 'edit_item' => __('Edit Countdown Timer', DOMAIN),
287 'new_item' => __('New Countdown Timer', DOMAIN),
288 'view' => __('View Countdown Timer', DOMAIN),
289 'view_item' => __('View Countdown Timer', DOMAIN),
290 'search_items' => __('Search Countdown Timer', DOMAIN),
291 'not_found' => __('No Countdown Timer', DOMAIN),
292 'not_found_in_trash' => __('No Countdown Timer found in trash', DOMAIN),
293 'parent' => __('Parent Campaign', DOMAIN),
294 'menu_name' => __('All Timers', DOMAIN),
295 ),
296 'public' => false,
297 'show_ui' => true,
298 'publicly_queryable' => false,
299 'exclude_from_search' => true,
300 'show_in_menu' => 'hurrytimer',
301 'hierarchical' => false,
302 'show_in_nav_menus' => false,
303 'rewrite' => false,
304 'query_var' => false,
305 'supports' => array('title'),
306 'has_archive' => false,
307 'menu_positon' => 65,
308
309 );
310 register_post_type(
311 HURRYTIMER_COUNTDOWN_PT,
312 $args
313 );
314 }
315 }
316