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

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