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

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