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 / Admin.php

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

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