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