PluginProbe
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce / 2.1.7
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce v2.1.7
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.7, at includes/Admin.php

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