PluginProbe
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce / 2.1.8
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce v2.1.8
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 / Admin.php

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

427 lines 15.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Hurrytimer;
4
5 use \Hurrytimer\Utils\Helpers;
6
7 class Admin
8 {
9 /**
10 * The ID of this plugin.
11 *
12 * @since 1.0.0
13 * @access private
14 * @var string $pluginName The ID of this plugin.
15 */
16 private $pluginName;
17
18 /**
19 * The version of this plugin.
20 *
21 * @since 1.0.0
22 * @access private
23 * @var string $version The current version of this plugin.
24 */
25 private $version;
26
27 /**
28 * Initialize the class and set its properties.
29 *
30 * @param string $pluginName The name of this plugin.
31 * @param string $version The version of this plugin.
32 *
33 * @since 1.0.0
34 *
35 */
36 public function __construct($pluginName, $version)
37 {
38
39 $this->pluginName = $pluginName;
40 $this->version = $version;
41 add_action('wp_ajax_wcSearchProducts', [$this, 'ajaxWcSearchProducts']);
42 add_action('admin_init', [$this, 'activateCampaign']);
43 add_action('admin_init', [$this, 'deactivateCampaign']);
44 add_filter('post_row_actions', [$this, 'campaignsListRowActions']);
45 add_action('admin_menu', [$this, 'menu']);
46 add_filter('bulk_actions-edit-' . HURRYT_POST_TYPE,
47 [$this, 'campaignsListBulkActions']);
48
49 add_filter('manage_' . HURRYT_POST_TYPE . '_posts_columns',
50 [$this, 'campaignsListColumns']);
51
52 add_action('manage_' . HURRYT_POST_TYPE . '_posts_custom_column',
53 [$this, 'countdownListColumnsContent'], 10, 2);
54
55
56 add_filter(
57 'bulk_post_updated_messages',
58 [$this, 'customBulkPostUpdatedMessages'], 10, 2);
59
60 add_action('admin_menu', [$this, 'helpTabs']);
61 add_action('admin_notices', [$this, 'countdown_activation_notice']);
62 add_filter('admin_footer_text', [$this, 'admin_footer_text']);
63 //removeIf(pro)
64 add_filter('plugin_action_links_' . HURRYT_BASENAME, [$this, 'pluginLinks']);
65 //endRemoveIf(pro)
66 }
67
68
69 public function admin_footer_text()
70 {
71 $screen = get_current_screen();
72 if ($screen->post_type === HURRYT_POST_TYPE) {
73 include HURRYT_DIR . 'admin/templates/footer-rate-plugin.php';
74 }
75 }
76
77 //removeIf(pro)
78 function pluginLinks($links)
79 {
80 $links[] = '<a href="https://hurrytimer.com/pricing" target="_blank">PREMIUM</a>';
81
82 return $links;
83 }
84
85 //endRemoveIf(pro)
86
87 public function countdown_activation_notice()
88 {
89 $post_id = filter_input(INPUT_GET, 'post', FILTER_VALIDATE_INT);
90 $status = filter_input(INPUT_GET, 'hurrytimer_action');
91
92 if ( ! $post_id || ! $status || ! ($post = get_post($post_id))) {
93 return;
94 }
95 if (
96 $status === "ctivate-compaign"
97 &&
98 ! Utils\Helpers::isPostActive($post_id)
99 ) { ?>
100 <div class="notice notice-success is-dismissible">
101 <p><?php _e(
102 'Countdown timer deactivated.',
103 "hurrytimer"
104 ); ?></p>
105 </div>
106 <?php } else { ?>
107 <div class="notice notice-success is-dismissible">
108 <p><?php _e('Countdown timer activated.', "hurrytimer"); ?></p>
109 </div>
110 <?php }
111 }
112
113 public function helpTabs()
114 {
115 add_action('load-edit.php', [$this, 'editHelpTabs']);
116 add_action('load-post-new.php', [$this, 'editHelpTabs']);
117 add_action('load-post.php', [$this, 'editHelpTabs']);
118 }
119
120 public function editHelpTabs()
121 {
122 $screen = get_current_screen();
123 if (strpos($screen->id, 'hurrytimer_countdown') === false) {
124 return;
125 }
126 $screen->remove_help_tabs();
127 }
128
129 public function customBulkPostUpdatedMessages(
130 $bulk_messages,
131 $bulk_counts
132 ) {
133 $bulk_messages[HURRYT_POST_TYPE] = [
134 'updated' => _n(
135 '%s countdown timer updated.',
136 '%s countdown timers updated.',
137 $bulk_counts['updated']
138 ),
139 'locked' => _n(
140 '%s countdown timer not updated, somebody is editing it.',
141 '%s countdown timers not updated, somebody is editing them.',
142 $bulk_counts['locked']
143 ),
144 'deleted' => _n(
145 '%s countdown timer permanently deleted.',
146 '%s countdown timers permanently deleted.',
147 $bulk_counts['deleted']
148 ),
149 'trashed' => _n(
150 '%s countdown timer deleted.',
151 '%s countdown timers deleted.',
152 $bulk_counts['trashed']
153 ),
154 'untrashed' => _n(
155 '%s countdown timer restored from the Trash.',
156 '%s countdown timers restored from the Trash.',
157 $bulk_counts['untrashed']
158 ),
159 ];
160
161 return $bulk_messages;
162 }
163
164
165
166 public function countdownListColumnsContent($column, $post_id)
167 {
168 $campaign = new Campaign($post_id);
169 switch ($column) {
170 case 'status':
171 echo $campaign->isPublished()
172 ? __('Active', "hurrytimer")
173 : __('Inactive', "hurrytimer");
174 break;
175 case 'mode':
176 echo $campaign->isEvergreen()
177 ? __('Evergreen', "hurrytimer")
178 : __('Regular', "hurrytimer");
179 break;
180 case 'CampaignShortcode':
181 echo '<pre class="htmr-list-shortcode">[hurrytimer id="' .
182 $post_id .
183 '"]</pre>';
184 break;
185 }
186 }
187
188 public function campaignsListBulkActions($actions)
189 {
190 unset($actions['edit']);
191
192 return $actions;
193 }
194
195 public function campaignsListColumns($columns)
196 {
197 $allowed_columns = [];
198 foreach ($columns as $column_name => $value) {
199 if (in_array($column_name, ['cb', 'title', 'date'])) {
200 $allowed_columns[$column_name] = $value;
201 }
202 }
203
204 $columns = $allowed_columns;
205 $date = $columns['date'];
206 unset($columns['date']);
207 $columns = array_merge($columns, [
208 'status' => __('Status', "hurrytimer"),
209 'mode' => __('Mode', "hurrytimer"),
210 'CampaignShortcode' => __('CampaignShortcode', "hurrytimer"),
211 ]);
212 $columns['date'] = $date;
213
214 return $columns;
215 }
216
217 /**
218 * Register the stylesheets for the admin area.
219 *
220 * @since 1.0.0
221 */
222 public function enqueueStyles()
223 {
224 $version = defined('WP_DEBUG') && WP_DEBUG ? time() : $this->version;
225 wp_enqueue_style('wp-color-picker');
226 wp_enqueue_style('iris');
227 wp_dequeue_style('select2');
228
229 wp_enqueue_style("codemirror",
230 HURRYT_URL . 'assets/css/codemirror.css', [], "5.42.2",
231 'all');
232 wp_enqueue_style(
233 'hurryt-select2',
234 HURRYT_URL . 'assets/css/select2.css', array(),
235 '4.0.5', 'all'
236 );
237
238 wp_enqueue_style(
239 'hurryt-base-css',
240 HURRYT_URL . 'assets/css/base.css', array(),
241 $version, 'all'
242 );
243
244 wp_enqueue_style($this->pluginName,
245 HURRYT_URL . 'assets/css/admin.css', ['hurryt-base-css', 'hurryt-select2'],
246 $version, 'all');
247 }
248
249 public function campaignsListRowActions($actions)
250 {
251 global $post;
252 if ($post->post_type === HURRYT_POST_TYPE) {
253 unset($actions['inline hide-if-no-js']);
254 }
255 return $actions;
256 }
257
258 /**
259 * Register the JavaScript for the admin area.
260 *
261 * @since 1.0.0
262 */
263 public function enqueueScripts()
264 {
265 wp_enqueue_script('jquery-ui-core');
266 wp_enqueue_script('jquery-ui-tooltip');
267 wp_enqueue_script('wp-color-picker');
268 wp_enqueue_script('iris');
269 wp_enqueue_script('jquery-ui-slider');
270 wp_dequeue_script('select2');
271 //removeIf(pro)
272 wp_enqueue_script(
273 "jq-modal",
274 HURRYT_URL . 'assets/js/jquery.modal.min.js',
275 ['jquery'],
276 "0.9.1",
277 true);
278 //endRemoveIf(pro)
279
280 wp_enqueue_script(
281 'jq-date-picker-addon',
282 HURRYT_URL . 'assets/js/timepicker-addon.js',
283 ['jquery-ui-datepicker'],
284 '1.6.3',
285 true);
286
287 wp_enqueue_script(
288 'hurryt-select2',
289 HURRYT_URL . 'assets/js/select2.min.js',
290 ['jquery'],
291 '4.0.5',
292 true);
293
294 $deps = ['jq-date-picker-addon', 'hurryt-select2'];
295
296 wp_enqueue_script(
297 $this->pluginName,
298 HURRYT_URL . 'assets/js/admin.js',
299 $deps,
300 $this->version,
301 true);
302
303 wp_localize_script($this->pluginName, 'hurrytimer_ajax_object',
304 array(
305 'ajax_url' => admin_url('admin-ajax.php'),
306 'headline_pos' => [
307 'above_timer' => C::HEADLINE_POSITION_ABOVE_TIMER,
308 'below_timer' => C::HEADLINE_POSITION_BELOW_TIMER,
309 ],
310 'mode' => [
311 'evergreen' => C::MODE_EVERGREEN,
312 'regular' => C::MODE_REGULAR,
313 ],
314 ));
315 }
316
317 public function menu()
318 {
319 add_menu_page('HurryTimer', 'HurryTimer', 'manage_options', 'hurrytimer', null,
320 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2aWV3Qm94PSIwIDAgNjkuNTYgNzAuNjIiPiAgPGRlZnM+ICAgIDxsaW5lYXJHcmFkaWVudCBpZD0iYzNiZGI3MTYtYmI3Ny00MzUxLTllOGYtYTUwY2Y3ODEzNDNlIiB5MT0iMzUuMzEiIHgyPSI2NS4wNyIgeTI9IjM1LjMxIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSI+ICAgICAgPHN0b3Agb2Zmc2V0PSIwIiBzdG9wLWNvbG9yPSIjZjg1MzdmIi8+ICAgICAgPHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSIjNjNjIi8+ICAgIDwvbGluZWFyR3JhZGllbnQ+ICAgIDxsaW5lYXJHcmFkaWVudCBpZD0iYzk5ODViMWMtYjg3Zi00M2Y1LWFiMzItNWE4ZWZiMzQ1ZDA1IiB4MT0iMTUuODgiIHkxPSIyOS4zIiB4Mj0iNjkuNTYiIHkyPSIyOS4zIiB4bGluazpocmVmPSIjYzNiZGI3MTYtYmI3Ny00MzUxLTllOGYtYTUwY2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QxLDAsMCwwLDI2LDIuNDFWNi4yaDBhMzIuMzcsMzIuMzcsMCwwLDAtMTEuNjQsNC45Yy0uMzUuMjQtLjY5LjQ5LTEsLjc0TDExLjQ4LDEwYTIuNDEsMi40MSwwLDAsMC0zLjQxLDBMNC44MiwxMy4yNWEyLjQxLDIuNDEsMCwwLDAsMCwzLjQxTDYuNiwxOC40NGMtLjM2LjQ3LS43MSwxLTEsMS40NWEzMi41MywzMi41MywwLDEsMCw1OCw4LjQ0WiIgc3R5bGU9ImZpbGw6IHVybCgjYzNiZGI3MTYtYmI3Ny00MzUxLTllOGYtYTUwY2Y3ODEzNDNlKSIvPiAgICAgICAgPHBhdGggZD0iTTU3LjY3LDEyLjk1bDEsMEwzOS45NCwzNC4yOSwzNSwzMC40YTIuNDEsMi40MSwwLDAsMC0zLjI0LjI0TDE2LjU0LDQ2LjcyYTIuNDEsMi40MSwwLDAsMCwuMDksMy40MWgwQTIuNDEsMi40MSwwLDAsMCwyMCw1MGwxMy43LTE0LjQ5LDUsMy45NGEyLjQxLDIuNDEsMCwwLDAsMy4zLS4zMUw2OS41Niw3LjgxbC0xMiwuMzJhMi40MSwyLjQxLDAsMCwwLC4xMyw0LjgyWiIgc3R5bGU9ImZpbGw6IHVybCgjYzk5ODViMWMtYjg3Zi00M2Y1LWFiMzItNWE4ZWZiMzQ1ZDA1KSIvPiAgICAgIDwvZz4gICAgPC9nPiAgPC9nPjwvc3ZnPg==',
321 55);
322 add_submenu_page(
323 'hurrytimer',
324 __('Add Campaign', 'hurrytimer'),
325 __('Add Campaign', 'hurrytimer'),
326 'manage_options',
327 'post-new.php?post_type=hurrytimer_countdown'
328 );
329 }
330
331 public function activateCampaign()
332 {
333 if (
334 isset($_GET['hurrytimer_action']) && $_GET['hurrytimer_action'] === "activate-compaign"
335 && isset($_GET['_wpnonce'])
336 && wp_verify_nonce($_GET['_wpnonce'], 'activate-compaign')
337 ) {
338 $postId = intval($_GET['post']);
339 wp_update_post(['ID' => $postId, 'post_status' => 'publish']);
340 }
341 }
342
343 public function deactivateCampaign()
344 {
345 if (
346 isset($_GET['hurrytimer_action'])
347 && $_GET['hurrytimer_action'] === "deactivate-compaign"
348 && isset($_GET['_wpnonce'])
349 && wp_verify_nonce($_GET['_wpnonce'], 'deactivate-compaign')
350 ) {
351 $postId = intval($_GET['post']);
352 wp_update_post(['ID' => $postId, 'post_status' => 'draft']);
353 }
354 }
355
356 public function settingsBox()
357 {
358 require plugin_dir_path(dirname(__FILE__)) . 'admin/CampaignSettings.php';
359 new CampaignSettings();
360 }
361
362 //removeIf(pro)
363 public function upgradeBanner()
364 {
365 add_meta_box(
366 'hurrytimer-upgrade-banner',
367 __('Get the Most of HurryTimer', 'hurrytimer'),
368 function () {
369 include HURRYT_DIR . 'admin/templates/upgrade-banner.php';
370 },
371 HURRYT_POST_TYPE,
372 'side',
373 'low'
374 );
375 }
376 //endRemoveIf(pro)
377
378
379 /**
380 * Search products
381 *
382 * @return void
383 */
384 public function ajaxWcSearchProducts()
385 {
386 $search = sanitize_text_field($_GET['search']);
387 $selection = sanitize_text_field($_GET['productsSelection']);
388 $exclude = array_map('intval', $_GET['exclude']);
389
390 if (
391 in_array($selection, [
392 C::WC_PS_TYPE_INCLUDE_CATEGORIES,
393 C::WC_PS_TYPE_EXCLUDE_CATEGORIES,
394 ])
395 ) {
396 $args = [
397 "hide_empty" => false,
398 "taxonomy" => "product_cat",
399 "name__like" => $search,
400 'exclude' => $exclude,
401 ];
402
403 $items = get_terms($args);
404 $results = array_map(function ($item) {
405 return [
406 "id" => $item->term_id,
407 "text" => $item->name,
408 ];
409 }, $items);
410 } else {
411 $args = [
412 's' => $search,
413 'post_type' => 'product',
414 'post__not_in' => $exclude,
415 ];
416 $items = get_posts($args);
417 $results = array_map(function ($item) {
418 return [
419 "id" => $item->ID,
420 "text" => $item->post_title,
421 ];
422 }, $items);
423 }
424 exit(json_encode(["results" => $results, "pagination" => true]));
425 }
426 }
427