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

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