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

672 lines 23.2 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 Carbon\Carbon;
6 use Hurrytimer\Utils\Helpers;
7
8 class Admin
9 {
10 /**
11 * The ID of this plugin.
12 *
13 * @since 1.0.0
14 * @access private
15 * @var string $pluginName The ID of this plugin.
16 */
17 private $pluginName;
18
19 /**
20 * The version of this plugin.
21 *
22 * @since 1.0.0
23 * @access private
24 * @var string $version The current version of this plugin.
25 */
26 private $version;
27
28 /**
29 * Initialize the class and set its properties.
30 *
31 * @param string $pluginName The name of this plugin.
32 * @param string $version The version of this plugin.
33 *
34 * @since 1.0.0
35 *
36 */
37 public function __construct( $pluginName, $version )
38 {
39 $this->pluginName = $pluginName;
40 $this->version = $version;
41 add_action( 'wp_ajax_wcSearchProducts', [ $this, 'ajaxWcSearchProducts' ] );
42 add_action( 'wp_ajax_add_wc_condition_group', [ $this, 'ajaxAddWcConditionGroup' ] );
43 add_action( 'wp_ajax_add_wc_condition', [ $this, 'ajaxAddWcCondition' ] );
44 add_action( 'wp_ajax_load_wc_condition', [ $this, 'ajaxLoadWcCondition' ] );
45 add_action( 'admin_init', [ $this, 'activateCampaign' ] );
46 add_action( 'admin_init', [ $this, 'deactivateCampaign' ] );
47 add_action( 'admin_init', [ $this, 'resetEvergreenCampaign' ] );
48 add_action( 'admin_init', [ $this, 'resetAllEvergreenCampaigns' ] );
49 add_action( 'admin_init', [ $this, 'pluginSettings' ] );
50 add_filter( 'post_row_actions', [ $this, 'campaignsListRowActions' ] );
51 add_action( 'admin_menu', [ $this, 'menu' ] );
52 add_filter( 'bulk_actions-edit-' . HURRYT_POST_TYPE, [
53 $this,
54 'campaignsListBulkActions',
55 ] );
56
57 add_filter( 'manage_' . HURRYT_POST_TYPE . '_posts_columns', [
58 $this,
59 'campaignsListColumns',
60 ] );
61
62 add_action(
63 'manage_' . HURRYT_POST_TYPE . '_posts_custom_column',
64 [ $this, 'countdownListColumnsContent' ],
65 10,
66 2
67 );
68
69 add_filter(
70 'bulk_post_updated_messages',
71 [ $this, 'customBulkPostUpdatedMessages' ],
72 10,
73 2
74 );
75
76 add_action( 'admin_menu', [ $this, 'helpTabs' ] );
77 add_action( 'admin_notices', [ $this, 'resetEvergreenCampaignNotice' ] );
78 add_action( 'admin_notices', [ $this, 'resetAllEvergreenCampaignNotice' ] );
79
80 add_action( 'admin_notices', [ $this, 'countdown_activation_notice' ] );
81 add_filter( 'admin_footer_text', [ $this, 'admin_footer_text' ] );
82 //removeIf(pro)
83 add_filter( 'plugin_action_links_' . HURRYT_BASENAME, [
84 $this,
85 'pluginLinks',
86 ] );
87 //endRemoveIf(pro)
88 }
89
90 public function admin_footer_text()
91 {
92 $screen = get_current_screen();
93 if ( $screen->post_type === HURRYT_POST_TYPE ) {
94 include HURRYT_DIR . 'admin/templates/footer-rate-plugin.php';
95 }
96 }
97
98 //removeIf(pro)
99 public function pluginLinks( $links )
100 {
101 $links[]
102 = '<a href="https://hurrytimer.com/?utm_source=plugin&utm_medium=installed_plugins&utm_campaign=go_pro" target="_blank" class="hurryt-text-green-500 hurryt-font-bold">Go Pro</a>';
103
104 return $links;
105 }
106
107 //endRemoveIf(pro)
108
109 public function countdown_activation_notice()
110 {
111 $post_id = filter_input( INPUT_GET, 'post', FILTER_VALIDATE_INT );
112 $status = filter_input( INPUT_GET, 'hurrytimer_action' );
113
114 if ( ! $post_id || ! $status || ! ( $post = get_post( $post_id ) ) ) {
115 return;
116 }
117 if (
118 $status === "activate-compaign"
119 &&
120 ! Utils\Helpers::isPostActive( $post_id )
121 ) { ?>
122 <div class="notice notice-success is-dismissible">
123 <p><?php _e(
124 'Countdown timer deactivated.',
125 "hurrytimer"
126 ); ?></p>
127 </div>
128 <?php } else { ?>
129 <div class="notice notice-success is-dismissible">
130 <p><?php _e( 'Countdown timer activated.', "hurrytimer" ); ?></p>
131 </div>
132 <?php }
133 }
134
135 public function helpTabs()
136 {
137 add_action( 'load-edit.php', [ $this, 'editHelpTabs' ] );
138 add_action( 'load-post-new.php', [ $this, 'editHelpTabs' ] );
139 add_action( 'load-post.php', [ $this, 'editHelpTabs' ] );
140 }
141
142 public function editHelpTabs()
143 {
144 $screen = get_current_screen();
145 if ( strpos( $screen->id, 'hurrytimer_countdown' ) === false ) {
146 return;
147 }
148 $screen->remove_help_tabs();
149 }
150
151 public function customBulkPostUpdatedMessages( $bulk_messages, $bulk_counts )
152 {
153 $bulk_messages[ HURRYT_POST_TYPE ] = [
154 'updated' => _n(
155 '%s countdown timer updated.',
156 '%s countdown timers updated.',
157 $bulk_counts[ 'updated' ]
158 ),
159 'locked' => _n(
160 '%s countdown timer not updated, somebody is editing it.',
161 '%s countdown timers not updated, somebody is editing them.',
162 $bulk_counts[ 'locked' ]
163 ),
164 'deleted' => _n(
165 '%s countdown timer permanently deleted.',
166 '%s countdown timers permanently deleted.',
167 $bulk_counts[ 'deleted' ]
168 ),
169 'trashed' => _n(
170 '%s countdown timer deleted.',
171 '%s countdown timers deleted.',
172 $bulk_counts[ 'trashed' ]
173 ),
174 'untrashed' => _n(
175 '%s countdown timer restored from the Trash.',
176 '%s countdown timers restored from the Trash.',
177 $bulk_counts[ 'untrashed' ]
178 ),
179 ];
180
181 return $bulk_messages;
182 }
183
184 public function countdownListColumnsContent( $column, $post_id )
185 {
186 $campaign = new Campaign( $post_id );
187 switch ( $column ) {
188 case 'status':
189 echo $campaign->isPublished()
190 ? __( 'Active', "hurrytimer" )
191 : __( 'Inactive', "hurrytimer" );
192 break;
193 case 'mode':
194 if ( $campaign->isEvergreen() ) {
195 echo __( 'Evergreen', "hurrytimer" );
196 }
197 if ( $campaign->isRegular() ) {
198 echo __( 'One-Time', "hurrytimer" );
199 }
200 if ( $campaign->isRecurring() ) {
201 echo __( 'Recurring', "hurrytimer" );
202 }
203 break;
204 case 'CampaignShortcode':
205 echo '<pre class="htmr-list-shortcode">[hurrytimer id="' .
206 $post_id .
207 '"]</pre>';
208 break;
209 }
210 }
211
212 public function campaignsListBulkActions( $actions )
213 {
214 unset( $actions[ 'edit' ] );
215
216 return $actions;
217 }
218
219 public function campaignsListColumns( $columns )
220 {
221 $allowed_columns = [];
222 foreach ( $columns as $column_name => $value ) {
223 if ( in_array( $column_name, [ 'cb', 'title', 'date' ] ) ) {
224 $allowed_columns[ $column_name ] = $value;
225 }
226 }
227
228 $columns = $allowed_columns;
229 $date = $columns[ 'date' ];
230 unset( $columns[ 'date' ] );
231 $columns = array_merge( $columns, [
232 'status' => __( 'Status', "hurrytimer" ),
233 'mode' => __( 'Mode', "hurrytimer" ),
234 'CampaignShortcode' => __( 'CampaignShortcode', "hurrytimer" ),
235 ] );
236 $columns[ 'date' ] = $date;
237
238 return $columns;
239 }
240
241 /**
242 * Register the stylesheets for the admin area.
243 *
244 * @since 1.0.0
245 */
246 public function enqueueStyles()
247 {
248 $version = defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : $this->version;
249 wp_enqueue_style( 'wp-color-picker' );
250 wp_enqueue_style( 'iris' );
251 wp_dequeue_style( 'select2' );
252
253 wp_enqueue_style(
254 "codemirror",
255 HURRYT_URL . 'assets/css/codemirror.css',
256 [],
257 "5.42.2",
258 'all'
259 );
260 wp_enqueue_style(
261 'hurryt-select2',
262 HURRYT_URL . 'assets/css/select2.css',
263 array(),
264 '4.0.5',
265 'all'
266 );
267
268 wp_enqueue_style(
269 'hurryt-base-css',
270 HURRYT_URL . 'assets/css/base.css',
271 array(),
272 $version,
273 'all'
274 );
275
276 wp_enqueue_style(
277 $this->pluginName,
278 HURRYT_URL . 'assets/css/admin.css',
279 [ 'hurryt-base-css', 'hurryt-select2' ],
280 $version,
281 'all'
282 );
283 }
284
285 public function campaignsListRowActions( $actions )
286 {
287 global $post;
288 if ( $post->post_type === HURRYT_POST_TYPE ) {
289 unset( $actions[ 'inline hide-if-no-js' ] );
290 }
291
292 return $actions;
293 }
294
295 /**
296 * Register the JavaScript for the admin area.
297 *
298 * @since 1.0.0
299 */
300 public function enqueueScripts()
301 {
302 wp_enqueue_script( 'jquery-ui-core' );
303 wp_enqueue_script( 'jquery-ui-tooltip' );
304 wp_enqueue_script( 'wp-color-picker' );
305 wp_enqueue_script( 'iris' );
306 wp_enqueue_script( 'jquery-ui-slider' );
307 wp_dequeue_script( 'select2' );
308
309 wp_enqueue_script(
310 'hurryt-cookie',
311 HURRYT_URL . 'assets/js/cookie.min.js',
312 [],
313 '2.2.0',
314 true
315 );
316
317 //removeIf(pro)
318 wp_enqueue_script(
319 "jq-modal",
320 HURRYT_URL . 'assets/js/jquery.modal.min.js',
321 [ 'jquery' ],
322 "0.9.1",
323 true
324 );
325 //endRemoveIf(pro)
326
327 wp_enqueue_script(
328 'jq-date-picker-addon',
329 HURRYT_URL . 'assets/js/timepicker-addon.js',
330 [ 'jquery-ui-datepicker' ],
331 '1.6.3',
332 true
333 );
334
335 wp_enqueue_script(
336 'hurryt-select2',
337 HURRYT_URL . 'assets/js/select2.min.js',
338 [ 'jquery' ],
339 '4.0.5',
340 true
341 );
342
343 $deps = [ 'hurryt-cookie', 'jq-date-picker-addon', 'hurryt-select2' ];
344
345 wp_enqueue_script(
346 $this->pluginName,
347 HURRYT_URL . 'assets/js/admin.js',
348 $deps,
349 $this->version,
350 true
351 );
352
353 wp_localize_script( $this->pluginName, 'hurrytimer_ajax_object', array(
354 'ajax_nonce' => wp_create_nonce( 'hurryt-admin' ),
355 'ajax_url' => admin_url( 'admin-ajax.php' ),
356 'headline_pos' => [
357 'above_timer' => C::HEADLINE_POSITION_ABOVE_TIMER,
358 'below_timer' => C::HEADLINE_POSITION_BELOW_TIMER,
359 ],
360 'mode' => [
361 'evergreen' => C::MODE_EVERGREEN,
362 'regular' => C::MODE_REGULAR,
363 'recurring' => C::MODE_RECURRING,
364 ],
365 'browser_tz_offset' => Carbon::now( hurryt_tz() )->getOffset() / 60,
366 ) );
367
368 }
369
370 public function menu()
371 {
372 add_menu_page(
373 'HurryTimer',
374 'HurryTimer',
375 'manage_options',
376 'hurrytimer',
377 null,
378 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2aWV3Qm94PSIwIDAgNjkuNTYgNzAuNjIiPiAgPGRlZnM+ICAgIDxsaW5lYXJHcmFkaWVudCBpZD0iYzNiZGI3MTYtYmI3Ny00MzUxLTllOGYtYTUwY2Y3ODEzNDNlIiB5MT0iMzUuMzEiIHgyPSI2NS4wNyIgeTI9IjM1LjMxIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSI+ICAgICAgPHN0b3Agb2Zmc2V0PSIwIiBzdG9wLWNvbG9yPSIjZjg1MzdmIi8+ICAgICAgPHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSIjNjNjIi8+ICAgIDwvbGluZWFyR3JhZGllbnQ+ICAgIDxsaW5lYXJHcmFkaWVudCBpZD0iYzk5ODViMWMtYjg3Zi00M2Y1LWFiMzItNWE4ZWZiMzQ1ZDA1IiB4MT0iMTUuODgiIHkxPSIyOS4zIiB4Mj0iNjkuNTYiIHkyPSIyOS4zIiB4bGluazpocmVmPSIjYzNiZGI3MTYtYmI3Ny00MzUxLTllOGYtYTUwY2Y3ODEzNDNlIi8+ICA8L2RlZnM+ICA8dGl0bGU+QXNzZXQgMzwvdGl0bGU+ICA8ZyBpZD0iMGIwNjBiYzEtNGVlNS00YjUwLTkxMjctYTFjZWRmNGYxZDljIiBkYXRhLW5hbWU9IkxheWVyIDIiPiAgICA8ZyBpZD0iNmRiZGQyZWItOWY5My00YWMwLWE3YTQtYjE0ODY1MDQyYzNiIiBkYXRhLW5hbWU9IkxheWVyIDEiPiAgICAgIDxnPiAgICAgICAgPHBhdGggZD0iTTYzLjU5LDI4LjMzYTIuODUsMi44NSwwLDAsMC0zLjg0LTEuNzRsLS4wNSwwYTIuODgsMi44OCwwLDAsMC0xLjYsMy41M2MuMjYuODQuNDgsMS42OS42NSwyLjU1YTI3LDI3LDAsMCwxLDAsMTAuNzksMjYuNTksMjYuNTksMCwwLDEtNCw5LjU2LDI2Ljg0LDI2Ljg0LDAsMCwxLTExLjc3LDkuNywyNi42LDI2LjYsMCwwLDEtNSwxLjU2LDI3LjE3LDI3LjE3LDAsMCwxLTEwLjc5LDAsMjYuNTksMjYuNTksMCwwLDEtOS41Ni00LDI2Ljg0LDI2Ljg0LDAsMCwxLTkuNy0xMS43NywyNi42LDI2LjYsMCwwLDEtMS41Ni01LDI3LDI3LDAsMCwxLDAtMTAuNzksMjYuNTksMjYuNTksMCwwLDEsNC05LjU2LDI2Ljg0LDI2Ljg0LDAsMCwxLDExLjc3LTkuNywyNi42LDI2LjYsMCwwLDEsNS0xLjU2LDI3LjE3LDI3LjE3LDAsMCwxLDEwLjc5LDAsMjYuNiwyNi42LDAsMCwxLDUsMS41NnExLjE5LjUsMi4zMywxLjEyQTIuODMsMi44MywwLDAsMCw0OSwxMy42OGwuMDYtLjA5YTIuODUsMi44NSwwLDAsMC0xLTQuMVE0Ni42OCw4LjczLDQ1LjIsOC4xYTMyLjM5LDMyLjM5LDAsMCwwLTQuNjktMS41N1YyLjQxQTIuNDEsMi40MSwwLDAsMCwzOC4xLDBIMjguNDJBMi40MSwyLjQxLDAsMCwwLDI2LDIuNDFWNi4yaDBhMzIuMzcsMzIuMzcsMCwwLDAtMTEuNjQsNC45Yy0uMzUuMjQtLjY5LjQ5LTEsLjc0TDExLjQ4LDEwYTIuNDEsMi40MSwwLDAsMC0zLjQxLDBMNC44MiwxMy4yNWEyLjQxLDIuNDEsMCwwLDAsMCwzLjQxTDYuNiwxOC40NGMtLjM2LjQ3LS43MSwxLTEsMS40NWEzMi41MywzMi41MywwLDEsMCw1OCw4LjQ0WiIgc3R5bGU9ImZpbGw6IHVybCgjYzNiZGI3MTYtYmI3Ny00MzUxLTllOGYtYTUwY2Y3ODEzNDNlKSIvPiAgICAgICAgPHBhdGggZD0iTTU3LjY3LDEyLjk1bDEsMEwzOS45NCwzNC4yOSwzNSwzMC40YTIuNDEsMi40MSwwLDAsMC0zLjI0LjI0TDE2LjU0LDQ2LjcyYTIuNDEsMi40MSwwLDAsMCwuMDksMy40MWgwQTIuNDEsMi40MSwwLDAsMCwyMCw1MGwxMy43LTE0LjQ5LDUsMy45NGEyLjQxLDIuNDEsMCwwLDAsMy4zLS4zMUw2OS41Niw3LjgxbC0xMiwuMzJhMi40MSwyLjQxLDAsMCwwLC4xMyw0LjgyWiIgc3R5bGU9ImZpbGw6IHVybCgjYzk5ODViMWMtYjg3Zi00M2Y1LWFiMzItNWE4ZWZiMzQ1ZDA1KSIvPiAgICAgIDwvZz4gICAgPC9nPiAgPC9nPjwvc3ZnPg==',
379 $this->get_menu_position( 55, 0.3 )
380 );
381 add_submenu_page(
382 'hurrytimer',
383 __( 'Add Campaign', 'hurrytimer' ),
384 __( 'Add Campaign', 'hurrytimer' ),
385 'manage_options',
386 'post-new.php?post_type=hurrytimer_countdown'
387 );
388
389 add_submenu_page(
390 'hurrytimer',
391 __( 'Settings', 'hurrytimer' ),
392 __( 'Settings', 'hurrytimer' ),
393 'manage_options',
394 'hurrytimer_settings',
395 [ $this, 'settings' ]
396 );
397 }
398
399 private function get_menu_position( $start, $increment = 0.3 )
400 {
401 $menus_positions = [];
402 foreach ( $GLOBALS[ 'menu' ] as $key => $menu ) {
403 $menus_positions[] = $key;
404 }
405 if ( ! in_array( $start, $menus_positions ) ) {
406 return $start;
407 }
408
409 /* the position is already reserved find the closet one */
410 while ( in_array( $start, $menus_positions ) ) {
411 $start += $increment;
412 }
413
414 return $start;
415 }
416
417 public function settings()
418 {
419 include_once HURRYT_DIR . 'admin/templates/settings.php';
420 }
421
422 public function activateCampaign()
423 {
424 if (
425 isset( $_GET[ 'hurrytimer_action' ] )
426 && $_GET[ 'hurrytimer_action' ] === "activate-compaign"
427 && isset( $_GET[ '_wpnonce' ] )
428 && wp_verify_nonce( $_GET[ '_wpnonce' ], 'activate-compaign' )
429 ) {
430 $postId = intval( $_GET[ 'post' ] );
431 wp_update_post( [ 'ID' => $postId, 'post_status' => 'publish' ] );
432 }
433 }
434
435 function resetEvergreenCampaignNotice()
436 {
437 if (
438 isset( $_GET[ 'hurryt-action' ] )
439 && isset( $_GET[ 'hurryt-scope' ] )
440 && isset( $_GET[ 'post' ] )
441 && $_GET[ 'hurryt-action' ] === "reset-evergreen-compaign"
442 && isset( $_GET[ '_wpnonce' ] )
443 && wp_verify_nonce( $_GET[ '_wpnonce' ], 'reset-evergreen-compaign' )
444 ) {
445 $scopeText
446 = $_GET[ 'hurryt-scope' ] === 'admin'
447 ? ' you '
448 : ' all visitors '; ?>
449 <div class="notice notice-success is-dismissible">
450 <p><?php _e(
451 "Campaign has been reset for $scopeText successfully.",
452 'hurrytimer'
453 ); ?></p>
454 </div>
455 <?php
456 }
457 }
458
459 function resetAllEvergreenCampaignNotice()
460 {
461 if (
462 isset( $_GET[ 'hurryt-page' ] )
463 && isset( $_GET[ 'hurryt-scope' ] )
464 && isset( $_GET[ 'hurryt-action' ] )
465 && $_GET[ 'hurryt-page' ] === "hurrytimer_settings"
466 && $_GET[ 'hurryt-action' ] === "reset-all-evergreen-compaigns"
467 && isset( $_GET[ '_wpnonce' ] )
468 && wp_verify_nonce( $_GET[ '_wpnonce' ], 'reset-all-evergreen-compaigns' )
469 ) {
470 $scopeText
471 = $_GET[ 'hurryt-scope' ] === 'admin'
472 ? ' you '
473 : ' all visitors '; ?>
474 <div class="notice notice-success is-dismissible">
475 <p><?php _e(
476 "All evergreen campaigns have been reset for $scopeText successfully.",
477 'hurrytimer'
478 ); ?></p>
479 </div>
480 <?php
481 }
482 }
483
484 public function resetEvergreenCampaign()
485 {
486 if (
487 isset( $_GET[ 'hurryt-action' ] )
488 && isset( $_GET[ 'hurryt-scope' ] )
489 && isset( $_GET[ 'post' ] )
490 && $_GET[ 'hurryt-action' ] === "reset-evergreen-compaign"
491 && isset( $_GET[ '_wpnonce' ] )
492 && wp_verify_nonce( $_GET[ '_wpnonce' ], 'reset-evergreen-compaign' )
493 ) {
494 $postId = intval( $_GET[ 'post' ] );
495 $IPDetection = new IPDetection();
496 $cookieDetection = new CookieDetection();
497 $campaign = new EvergreenCampaign(
498 $postId,
499 $cookieDetection,
500 $IPDetection
501 );
502 $campaign->reset( sanitize_text_field( $_GET[ 'hurryt-scope' ] ) );
503 }
504 }
505
506 public function resetAllEvergreenCampaigns()
507 {
508 if (
509 isset( $_GET[ 'hurryt-page' ] )
510 && isset( $_GET[ 'hurryt-scope' ] )
511 && isset( $_GET[ 'hurryt-action' ] )
512 && $_GET[ 'hurryt-page' ] === "hurrytimer_settings"
513 && $_GET[ 'hurryt-action' ] === "reset-all-evergreen-compaigns"
514 && isset( $_GET[ '_wpnonce' ] )
515 && wp_verify_nonce( $_GET[ '_wpnonce' ], 'reset-all-evergreen-compaigns' )
516 ) {
517 $evergreenCampaign = new EvergreenCampaign( null, new CookieDetection(),
518 new IPDetection() );
519 $evergreenCampaign->resetAll( sanitize_text_field( $_GET[ 'hurryt-scope' ] ) );
520 }
521 }
522
523 public function deactivateCampaign()
524 {
525 if (
526 isset( $_GET[ 'hurrytimer_action' ] )
527 && $_GET[ 'hurrytimer_action' ] === "deactivate-compaign"
528 && isset( $_GET[ '_wpnonce' ] )
529 && wp_verify_nonce( $_GET[ '_wpnonce' ], 'deactivate-compaign' )
530 ) {
531 $postId = intval( $_GET[ 'post' ] );
532 wp_update_post( [ 'ID' => $postId, 'post_status' => 'draft' ] );
533 }
534 }
535
536 public function settingsBox()
537 {
538 require plugin_dir_path( dirname( __FILE__ ) ) .
539 'admin/CampaignSettings.php';
540 new CampaignSettings();
541 }
542
543 //removeIf(pro)
544 public function upgradeBanner()
545 {
546 add_meta_box(
547 'hurrytimer-upgrade-banner',
548 __( 'Get the Most of HurryTimer', 'hurrytimer' ),
549 function () {
550 include HURRYT_DIR . 'admin/templates/upgrade-banner.php';
551 },
552 HURRYT_POST_TYPE,
553 'side',
554 'low'
555 );
556 }
557 //endRemoveIf(pro)
558
559 /**
560 * Search products
561 *
562 * @return void
563 */
564 public function ajaxWcSearchProducts()
565 {
566 $search = sanitize_text_field( $_GET[ 'search' ] );
567 $selection = sanitize_text_field( $_GET[ 'productsSelection' ] );
568 $exclude = array_map( 'intval', $_GET[ 'exclude' ] );
569
570 if (
571 in_array( $selection, [
572 C::WC_PS_TYPE_INCLUDE_CATEGORIES,
573 C::WC_PS_TYPE_EXCLUDE_CATEGORIES,
574 ] )
575 ) {
576 $args = [
577 "hide_empty" => false,
578 "taxonomy" => "product_cat",
579 "name__like" => $search,
580 'exclude' => $exclude,
581 ];
582
583 $items = get_terms( $args );
584 $results = array_map( function ( $item ) {
585 return [
586 "id" => $item->term_id,
587 "text" => $item->name,
588 ];
589 }, $items );
590 } else {
591 $args = [
592 's' => $search,
593 'post_type' => 'product',
594 'post__not_in' => $exclude,
595 'posts_per_page' => -1,
596 ];
597 $items = get_posts( $args );
598 $results = array_map( function ( $item ) {
599 return [
600 "id" => $item->ID,
601 "text" => $item->post_title,
602 ];
603 }, $items );
604 }
605 exit( json_encode( [ "results" => $results, "pagination" => true ] ) );
606 }
607
608 public function pluginSettings()
609 {
610 register_setting( 'hurrytimer_settings', 'hurryt_settings' );
611 add_settings_section(
612 'hurryt_settings_general',
613 __( 'General', 'hurrytimer' ),
614 null,
615 'hurrytimer_settings'
616 );
617 add_settings_field(
618 'hurryt_disable_actions_edit_mode',
619 'Disable actions in the admin area',
620 function ( $args ) {
621 $options = get_option( 'hurryt_settings' ); ?>
622 <label for="">
623 <input type="checkbox"
624 name="hurryt_settings[disable_actions]" <?php checked(
625 isset( $options[ 'disable_actions' ] )
626 && $options[ 'disable_actions' ],
627 1
628 ); ?> id="hurryt-disable-actions" value="1"/>
629 </label>
630 <p class="description">
631 Don't run actions when editing or previewing a page in the admin area.
632 </p>
633 <?php
634 },
635 'hurrytimer_settings',
636 'hurryt_settings_general'
637 );
638 }
639
640 function ajaxAddWcConditionGroup()
641 {
642 check_ajax_referer( 'hurryt-admin', 'nonce' );
643
644 ob_start();
645 include HURRYT_DIR . 'admin/templates/wc-condition-group.php';
646 echo ob_get_clean();
647 wp_die();
648 }
649
650 function ajaxAddWcCondition()
651 {
652 check_ajax_referer( 'hurryt-admin', 'nonce' );
653
654 ob_start();
655 $groupId = sanitize_key( $_GET[ 'group_id' ] );
656 include HURRYT_DIR . 'admin/templates/wc-condition.php';
657 echo ob_get_clean();
658 wp_die();
659 }
660
661 function ajaxLoadWcCondition()
662 {
663 check_ajax_referer( 'hurryt-admin', 'nonce' );
664 ob_start();
665 $groupId = sanitize_key( $_GET[ 'group_id' ] );
666 $selected = hurryt_wc_conditions()[ sanitize_key( $_GET[ 'condition_key' ] ) ];
667 include HURRYT_DIR . 'admin/templates/wc-condition.php';
668 echo ob_get_clean();
669 wp_die();
670 }
671 }
672