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 +388 -156 2.1.62.2.16 View file →
@@ -1,9 +1,10 @@
1 1 <?php
2 2
3 3 namespace Hurrytimer;
4 4
5 -use \Hurrytimer\Utils\Helpers;
5 +use Carbon\Carbon;
6 +use Hurrytimer\Utils\Helpers;
6 7
7 8 class Admin
8 9 {
9 10 /**
@@ -32,54 +33,74 @@
32 33 *
33 34 * @since 1.0.0
34 35 *
35 36 */
36 - public function __construct($pluginName, $version)
37 + public function __construct( $pluginName, $version )
37 38 {
38 -
39 39 $this->pluginName = $pluginName;
40 40 $this->version = $version;
41 - add_action('wp_ajax_wcSearchProducts', [$this, 'ajaxWcSearchProducts']);
42 - add_action('admin_init', [$this, 'activateCampaign']);
43 - add_action('admin_init', [$this, 'deactivateCampaign']);
44 - add_filter('post_row_actions', [$this, 'campaignsListRowActions']);
45 - add_action('admin_menu', [$this, 'menu']);
46 - add_filter('bulk_actions-edit-' . HURRYT_POST_TYPE,
47 - [$this, 'campaignsListBulkActions']);
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 + ] );
48 56
49 - add_filter('manage_' . HURRYT_POST_TYPE . '_posts_columns',
50 - [$this, 'campaignsListColumns']);
57 + add_filter( 'manage_' . HURRYT_POST_TYPE . '_posts_columns', [
58 + $this,
59 + 'campaignsListColumns',
60 + ] );
51 61
52 - add_action('manage_' . HURRYT_POST_TYPE . '_posts_custom_column',
53 - [$this, 'countdownListColumnsContent'], 10, 2);
62 + add_action(
63 + 'manage_' . HURRYT_POST_TYPE . '_posts_custom_column',
64 + [ $this, 'countdownListColumnsContent' ],
65 + 10,
66 + 2
67 + );
54 68
55 - add_action('views_edit-' . HURRYT_POST_TYPE,
56 - [$this, 'countdown_list_header_links'], 10);
57 69 add_filter(
58 70 'bulk_post_updated_messages',
59 - [$this, 'customBulkPostUpdatedMessages'], 10, 2);
71 + [ $this, 'customBulkPostUpdatedMessages' ],
72 + 10,
73 + 2
74 + );
60 75
61 - add_action('admin_menu', [$this, 'helpTabs']);
62 - add_action('admin_notices', [$this, 'countdown_activation_notice']);
63 - add_filter('admin_footer_text', [$this, 'admin_footer_text']);
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' ] );
64 82 //removeIf(pro)
65 - add_filter('plugin_action_links_' . HURRYT_BASENAME, [$this, 'pluginLinks']);
83 + add_filter( 'plugin_action_links_' . HURRYT_BASENAME, [
84 + $this,
85 + 'pluginLinks',
86 + ] );
66 87 //endRemoveIf(pro)
67 88 }
68 89
69 -
70 90 public function admin_footer_text()
71 91 {
72 92 $screen = get_current_screen();
73 - if ($screen->post_type === HURRYT_POST_TYPE) {
93 + if ( $screen->post_type === HURRYT_POST_TYPE ) {
74 94 include HURRYT_DIR . 'admin/templates/footer-rate-plugin.php';
75 95 }
76 96 }
77 97
78 98 //removeIf(pro)
79 - function pluginLinks($links)
99 + public function pluginLinks( $links )
80 100 {
81 - $links[] = '<a href="https://hurrytimer.com/pricing" target="_blank">PREMIUM</a>';
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>';
82 103
83 104 return $links;
84 105 }
85 106
@@ -86,18 +107,18 @@
86 107 //endRemoveIf(pro)
87 108
88 109 public function countdown_activation_notice()
89 110 {
90 - $post_id = filter_input(INPUT_GET, 'post', FILTER_VALIDATE_INT);
91 - $status = filter_input(INPUT_GET, 'hurrytimer_action');
111 + $post_id = filter_input( INPUT_GET, 'post', FILTER_VALIDATE_INT );
112 + $status = filter_input( INPUT_GET, 'hurrytimer_action' );
92 113
93 - if ( ! $post_id || ! $status || ! ($post = get_post($post_id))) {
114 + if ( ! $post_id || ! $status || ! ( $post = get_post( $post_id ) ) ) {
94 115 return;
95 116 }
96 117 if (
97 - $status === "ctivate-compaign"
118 + $status === "activate-compaign"
98 119 &&
99 - ! Utils\Helpers::isPostActive($post_id)
120 + ! Utils\Helpers::isPostActive( $post_id )
100 121 ) { ?>
101 122 <div class="notice notice-success is-dismissible">
102 123 <p><?php _e(
103 124 'Countdown timer deactivated.',
@@ -105,9 +126,9 @@
105 126 ); ?></p>
106 127 </div>
107 128 <?php } else { ?>
108 129 <div class="notice notice-success is-dismissible">
109 - <p><?php _e('Countdown timer activated.', "hurrytimer"); ?></p>
130 + <p><?php _e( 'Countdown timer activated.', "hurrytimer" ); ?></p>
110 131 </div>
111 132 <?php }
112 133 }
113 134
@@ -112,51 +133,49 @@
112 133 }
113 134
114 135 public function helpTabs()
115 136 {
116 - add_action('load-edit.php', [$this, 'editHelpTabs']);
117 - add_action('load-post-new.php', [$this, 'editHelpTabs']);
118 - add_action('load-post.php', [$this, 'editHelpTabs']);
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' ] );
119 140 }
120 141
121 142 public function editHelpTabs()
122 143 {
123 144 $screen = get_current_screen();
124 - if (strpos($screen->id, 'hurrytimer_countdown') === false) {
145 + if ( strpos( $screen->id, 'hurrytimer_countdown' ) === false ) {
125 146 return;
126 147 }
127 148 $screen->remove_help_tabs();
128 149 }
129 150
130 - public function customBulkPostUpdatedMessages(
131 - $bulk_messages,
132 - $bulk_counts
133 - ) {
134 - $bulk_messages[HURRYT_POST_TYPE] = [
151 + public function customBulkPostUpdatedMessages( $bulk_messages, $bulk_counts )
152 + {
153 + $bulk_messages[ HURRYT_POST_TYPE ] = [
135 154 'updated' => _n(
136 155 '%s countdown timer updated.',
137 156 '%s countdown timers updated.',
138 - $bulk_counts['updated']
157 + $bulk_counts[ 'updated' ]
139 158 ),
140 159 'locked' => _n(
141 160 '%s countdown timer not updated, somebody is editing it.',
142 161 '%s countdown timers not updated, somebody is editing them.',
143 - $bulk_counts['locked']
162 + $bulk_counts[ 'locked' ]
144 163 ),
145 164 'deleted' => _n(
146 165 '%s countdown timer permanently deleted.',
147 166 '%s countdown timers permanently deleted.',
148 - $bulk_counts['deleted']
167 + $bulk_counts[ 'deleted' ]
149 168 ),
150 169 'trashed' => _n(
151 170 '%s countdown timer deleted.',
152 171 '%s countdown timers deleted.',
153 - $bulk_counts['trashed']
172 + $bulk_counts[ 'trashed' ]
154 173 ),
155 174 'untrashed' => _n(
156 175 '%s countdown timer restored from the Trash.',
157 176 '%s countdown timers restored from the Trash.',
158 - $bulk_counts['untrashed']
177 + $bulk_counts[ 'untrashed' ]
159 178 ),
160 179 ];
161 180
162 181 return $bulk_messages;
@@ -161,28 +180,27 @@
161 180
162 181 return $bulk_messages;
163 182 }
164 183
165 - public function countdown_list_header_links($views)
184 + public function countdownListColumnsContent( $column, $post_id )
166 185 {
167 - unset($views['trash']);
168 -
169 - return $views;
170 - }
171 -
172 - public function countdownListColumnsContent($column, $post_id)
173 - {
174 - $campaign = new Campaign($post_id);
175 - switch ($column) {
186 + $campaign = new Campaign( $post_id );
187 + switch ( $column ) {
176 188 case 'status':
177 189 echo $campaign->isPublished()
178 - ? __('Active', "hurrytimer")
179 - : __('Inactive', "hurrytimer");
190 + ? __( 'Active', "hurrytimer" )
191 + : __( 'Inactive', "hurrytimer" );
180 192 break;
181 193 case 'mode':
182 - echo $campaign->isEvergreen()
183 - ? __('Evergreen', "hurrytimer")
184 - : __('Regular', "hurrytimer");
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 + }
185 203 break;
186 204 case 'CampaignShortcode':
187 205 echo '<pre class="htmr-list-shortcode">[hurrytimer id="' .
188 206 $post_id .
@@ -190,33 +208,33 @@
190 208 break;
191 209 }
192 210 }
193 211
194 - public function campaignsListBulkActions($actions)
212 + public function campaignsListBulkActions( $actions )
195 213 {
196 - unset($actions['edit']);
214 + unset( $actions[ 'edit' ] );
197 215
198 216 return $actions;
199 217 }
200 218
201 - public function campaignsListColumns($columns)
219 + public function campaignsListColumns( $columns )
202 220 {
203 221 $allowed_columns = [];
204 - foreach ($columns as $column_name => $value) {
205 - if (in_array($column_name, ['cb', 'title', 'date'])) {
206 - $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;
207 225 }
208 226 }
209 227
210 228 $columns = $allowed_columns;
211 - $date = $columns['date'];
212 - unset($columns['date']);
213 - $columns = array_merge($columns, [
214 - 'status' => __('Status', "hurrytimer"),
215 - 'mode' => __('Mode', "hurrytimer"),
216 - 'CampaignShortcode' => __('CampaignShortcode', "hurrytimer"),
217 - ]);
218 - $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;
219 237
220 238 return $columns;
221 239 }
222 240
@@ -226,45 +244,51 @@
226 244 * @since 1.0.0
227 245 */
228 246 public function enqueueStyles()
229 247 {
230 - $version = defined('WP_DEBUG') && WP_DEBUG ? time() : $this->version;
231 - wp_enqueue_style('wp-color-picker');
232 - wp_enqueue_style('iris');
233 - wp_dequeue_style('select2');
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' );
234 252
235 - wp_enqueue_style("codemirror",
236 - HURRYT_URL . 'assets/css/codemirror.css', [], "5.42.2",
237 - 'all');
238 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(
239 261 'hurryt-select2',
240 - HURRYT_URL . 'assets/css/select2.css', array(),
241 - '4.0.5', 'all'
262 + HURRYT_URL . 'assets/css/select2.css',
263 + array(),
264 + '4.0.5',
265 + 'all'
242 266 );
243 267
244 268 wp_enqueue_style(
245 269 'hurryt-base-css',
246 - HURRYT_URL . 'assets/css/base.css', array(),
247 - $version, 'all'
270 + HURRYT_URL . 'assets/css/base.css',
271 + array(),
272 + $version,
273 + 'all'
248 274 );
249 275
250 - wp_enqueue_style($this->pluginName,
251 - HURRYT_URL . 'assets/css/admin.css', ['hurryt-base-css', 'hurryt-select2'],
252 - $version, 'all');
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 + );
253 283 }
254 284
255 - public function campaignsListRowActions($actions)
285 + public function campaignsListRowActions( $actions )
256 286 {
257 287 global $post;
258 - if ($post->post_type === HURRYT_POST_TYPE) {
259 - unset($actions['inline hide-if-no-js']);
260 - unset($actions['trash']);
288 + if ( $post->post_type === HURRYT_POST_TYPE ) {
289 + unset( $actions[ 'inline hide-if-no-js' ] );
261 290 }
262 - $actions['delete'] = '<a href="' .
263 - get_delete_post_link($post->ID) .
264 - '">' .
265 - __('Delete', "hurrytimer") .
266 - '</a>';
267 291
268 292 return $actions;
269 293 }
270 294
@@ -274,38 +298,50 @@
274 298 * @since 1.0.0
275 299 */
276 300 public function enqueueScripts()
277 301 {
278 - wp_enqueue_script('jquery-ui-core');
279 - wp_enqueue_script('jquery-ui-tooltip');
280 - wp_enqueue_script('wp-color-picker');
281 - wp_enqueue_script('iris');
282 - wp_enqueue_script('jquery-ui-slider');
283 - wp_dequeue_script('select2');
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 +
284 317 //removeIf(pro)
285 318 wp_enqueue_script(
286 319 "jq-modal",
287 320 HURRYT_URL . 'assets/js/jquery.modal.min.js',
288 - ['jquery'],
321 + [ 'jquery' ],
289 322 "0.9.1",
290 - true);
323 + true
324 + );
291 325 //endRemoveIf(pro)
292 326
293 327 wp_enqueue_script(
294 328 'jq-date-picker-addon',
295 329 HURRYT_URL . 'assets/js/timepicker-addon.js',
296 - ['jquery-ui-datepicker'],
330 + [ 'jquery-ui-datepicker' ],
297 331 '1.6.3',
298 - true);
332 + true
333 + );
299 334
300 335 wp_enqueue_script(
301 336 'hurryt-select2',
302 337 HURRYT_URL . 'assets/js/select2.min.js',
303 - ['jquery'],
338 + [ 'jquery' ],
304 339 '4.0.5',
305 - true);
340 + true
341 + );
306 342
307 - $deps = ['jq-date-picker-addon', 'hurryt-select2'];
343 + $deps = [ 'hurryt-cookie', 'jq-date-picker-addon', 'hurryt-select2' ];
308 344
309 345 wp_enqueue_script(
310 346 $this->pluginName,
311 347 HURRYT_URL . 'assets/js/admin.js',
@@ -310,66 +346,198 @@
310 346 $this->pluginName,
311 347 HURRYT_URL . 'assets/js/admin.js',
312 348 $deps,
313 349 $this->version,
314 - true);
350 + true
351 + );
315 352
316 - wp_localize_script($this->pluginName, 'hurrytimer_ajax_object',
317 - array(
318 - 'ajax_url' => admin_url('admin-ajax.php'),
319 - 'headline_pos' => [
320 - 'above_timer' => C::HEADLINE_POSITION_ABOVE_TIMER,
321 - 'below_timer' => C::HEADLINE_POSITION_BELOW_TIMER,
322 - ],
323 - 'mode' => [
324 - 'evergreen' => C::MODE_EVERGREEN,
325 - 'regular' => C::MODE_REGULAR,
326 - ],
327 - ));
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 +
328 368 }
329 369
330 370 public function menu()
331 371 {
332 - add_menu_page('HurryTimer', 'HurryTimer', 'manage_options', 'hurrytimer', null,
372 + add_menu_page(
373 + 'HurryTimer',
374 + 'HurryTimer',
375 + 'manage_options',
376 + 'hurrytimer',
377 + null,
333 378 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2aWV3Qm94PSIwIDAgNjkuNTYgNzAuNjIiPiAgPGRlZnM+ICAgIDxsaW5lYXJHcmFkaWVudCBpZD0iYzNiZGI3MTYtYmI3Ny00MzUxLTllOGYtYTUwY2Y3ODEzNDNlIiB5MT0iMzUuMzEiIHgyPSI2NS4wNyIgeTI9IjM1LjMxIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSI+ICAgICAgPHN0b3Agb2Zmc2V0PSIwIiBzdG9wLWNvbG9yPSIjZjg1MzdmIi8+ICAgICAgPHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSIjNjNjIi8+ICAgIDwvbGluZWFyR3JhZGllbnQ+ICAgIDxsaW5lYXJHcmFkaWVudCBpZD0iYzk5ODViMWMtYjg3Zi00M2Y1LWFiMzItNWE4ZWZiMzQ1ZDA1IiB4MT0iMTUuODgiIHkxPSIyOS4zIiB4Mj0iNjkuNTYiIHkyPSIyOS4zIiB4bGluazpocmVmPSIjYzNiZGI3MTYtYmI3Ny00MzUxLTllOGYtYTUwY2Y3ODEzNDNlIi8+ICA8L2RlZnM+ICA8dGl0bGU+QXNzZXQgMzwvdGl0bGU+ICA8ZyBpZD0iMGIwNjBiYzEtNGVlNS00YjUwLTkxMjctYTFjZWRmNGYxZDljIiBkYXRhLW5hbWU9IkxheWVyIDIiPiAgICA8ZyBpZD0iNmRiZGQyZWItOWY5My00YWMwLWE3YTQtYjE0ODY1MDQyYzNiIiBkYXRhLW5hbWU9IkxheWVyIDEiPiAgICAgIDxnPiAgICAgICAgPHBhdGggZD0iTTYzLjU5LDI4LjMzYTIuODUsMi44NSwwLDAsMC0zLjg0LTEuNzRsLS4wNSwwYTIuODgsMi44OCwwLDAsMC0xLjYsMy41M2MuMjYuODQuNDgsMS42OS42NSwyLjU1YTI3LDI3LDAsMCwxLDAsMTAuNzksMjYuNTksMjYuNTksMCwwLDEtNCw5LjU2LDI2Ljg0LDI2Ljg0LDAsMCwxLTExLjc3LDkuNywyNi42LDI2LjYsMCwwLDEtNSwxLjU2LDI3LjE3LDI3LjE3LDAsMCwxLTEwLjc5LDAsMjYuNTksMjYuNTksMCwwLDEtOS41Ni00LDI2Ljg0LDI2Ljg0LDAsMCwxLTkuNy0xMS43NywyNi42LDI2LjYsMCwwLDEtMS41Ni01LDI3LDI3LDAsMCwxLDAtMTAuNzksMjYuNTksMjYuNTksMCwwLDEsNC05LjU2LDI2Ljg0LDI2Ljg0LDAsMCwxLDExLjc3LTkuNywyNi42LDI2LjYsMCwwLDEsNS0xLjU2LDI3LjE3LDI3LjE3LDAsMCwxLDEwLjc5LDAsMjYuNiwyNi42LDAsMCwxLDUsMS41NnExLjE5LjUsMi4zMywxLjEyQTIuODMsMi44MywwLDAsMCw0OSwxMy42OGwuMDYtLjA5YTIuODUsMi44NSwwLDAsMC0xLTQuMVE0Ni42OCw4LjczLDQ1LjIsOC4xYTMyLjM5LDMyLjM5LDAsMCwwLTQuNjktMS41N1YyLjQxQTIuNDEsMi40MSwwLDAsMCwzOC4xLDBIMjguNDJBMi40MSwyLjQxLDAsMCwwLDI2LDIuNDFWNi4yaDBhMzIuMzcsMzIuMzcsMCwwLDAtMTEuNjQsNC45Yy0uMzUuMjQtLjY5LjQ5LTEsLjc0TDExLjQ4LDEwYTIuNDEsMi40MSwwLDAsMC0zLjQxLDBMNC44MiwxMy4yNWEyLjQxLDIuNDEsMCwwLDAsMCwzLjQxTDYuNiwxOC40NGMtLjM2LjQ3LS43MSwxLTEsMS40NWEzMi41MywzMi41MywwLDEsMCw1OCw4LjQ0WiIgc3R5bGU9ImZpbGw6IHVybCgjYzNiZGI3MTYtYmI3Ny00MzUxLTllOGYtYTUwY2Y3ODEzNDNlKSIvPiAgICAgICAgPHBhdGggZD0iTTU3LjY3LDEyLjk1bDEsMEwzOS45NCwzNC4yOSwzNSwzMC40YTIuNDEsMi40MSwwLDAsMC0zLjI0LjI0TDE2LjU0LDQ2LjcyYTIuNDEsMi40MSwwLDAsMCwuMDksMy40MWgwQTIuNDEsMi40MSwwLDAsMCwyMCw1MGwxMy43LTE0LjQ5LDUsMy45NGEyLjQxLDIuNDEsMCwwLDAsMy4zLS4zMUw2OS41Niw3LjgxbC0xMiwuMzJhMi40MSwyLjQxLDAsMCwwLC4xMyw0LjgyWiIgc3R5bGU9ImZpbGw6IHVybCgjYzk5ODViMWMtYjg3Zi00M2Y1LWFiMzItNWE4ZWZiMzQ1ZDA1KSIvPiAgICAgIDwvZz4gICAgPC9nPiAgPC9nPjwvc3ZnPg==',
334 - 55);
379 + $this->get_menu_position( 55, 0.3 )
380 + );
335 381 add_submenu_page(
336 382 'hurrytimer',
337 - __('Add Campaign', 'hurrytimer'),
338 - __('Add Campaign', 'hurrytimer'),
383 + __( 'Add Campaign', 'hurrytimer' ),
384 + __( 'Add Campaign', 'hurrytimer' ),
339 385 'manage_options',
340 386 'post-new.php?post_type=hurrytimer_countdown'
341 387 );
388 +
389 + add_submenu_page(
390 + 'hurrytimer',
391 + __( 'Settings', 'hurrytimer' ),
392 + __( 'Settings', 'hurrytimer' ),
393 + 'manage_options',
394 + 'hurrytimer_settings',
395 + [ $this, 'settings' ]
396 + );
342 397 }
343 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 +
344 422 public function activateCampaign()
345 423 {
346 424 if (
347 - isset($_GET['hurrytimer_action']) && $_GET['hurrytimer_action'] === "activate-compaign"
348 - && isset($_GET['_wpnonce'])
349 - && 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' )
350 429 ) {
351 - $postId = intval($_GET['post']);
352 - wp_update_post(['ID' => $postId, 'post_status' => 'publish']);
430 + $postId = intval( $_GET[ 'post' ] );
431 + wp_update_post( [ 'ID' => $postId, 'post_status' => 'publish' ] );
353 432 }
354 433 }
355 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 +
356 523 public function deactivateCampaign()
357 524 {
358 525 if (
359 - isset($_GET['hurrytimer_action'])
360 - && $_GET['hurrytimer_action'] === "deactivate-compaign"
361 - && isset($_GET['_wpnonce'])
362 - && 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' )
363 530 ) {
364 - $postId = intval($_GET['post']);
365 - wp_update_post(['ID' => $postId, 'post_status' => 'draft']);
531 + $postId = intval( $_GET[ 'post' ] );
532 + wp_update_post( [ 'ID' => $postId, 'post_status' => 'draft' ] );
366 533 }
367 534 }
368 535
369 536 public function settingsBox()
370 537 {
371 - require plugin_dir_path(dirname(__FILE__)) . 'admin/CampaignSettings.php';
538 + require plugin_dir_path( dirname( __FILE__ ) ) .
539 + 'admin/CampaignSettings.php';
372 540 new CampaignSettings();
373 541 }
374 542
375 543 //removeIf(pro)
@@ -376,9 +544,9 @@
376 544 public function upgradeBanner()
377 545 {
378 546 add_meta_box(
379 547 'hurrytimer-upgrade-banner',
380 - __('Get the Most of HurryTimer', 'hurrytimer'),
548 + __( 'Get the Most of HurryTimer', 'hurrytimer' ),
381 549 function () {
382 550 include HURRYT_DIR . 'admin/templates/upgrade-banner.php';
383 551 },
384 552 HURRYT_POST_TYPE,
@@ -387,9 +555,8 @@
387 555 );
388 556 }
389 557 //endRemoveIf(pro)
390 558
391 -
392 559 /**
393 560 * Search products
394 561 *
395 562 * @return void
@@ -395,17 +562,17 @@
395 562 * @return void
396 563 */
397 564 public function ajaxWcSearchProducts()
398 565 {
399 - $search = sanitize_text_field($_GET['search']);
400 - $selection = sanitize_text_field($_GET['productsSelection']);
401 - $exclude = array_map('intval', $_GET['exclude']);
566 + $search = sanitize_text_field( $_GET[ 'search' ] );
567 + $selection = sanitize_text_field( $_GET[ 'productsSelection' ] );
568 + $exclude = array_map( 'intval', $_GET[ 'exclude' ] );
402 569
403 570 if (
404 - in_array($selection, [
571 + in_array( $selection, [
405 572 C::WC_PS_TYPE_INCLUDE_CATEGORIES,
406 573 C::WC_PS_TYPE_EXCLUDE_CATEGORIES,
407 - ])
574 + ] )
408 575 ) {
409 576 $args = [
410 577 "hide_empty" => false,
411 578 "taxonomy" => "product_cat",
@@ -412,28 +579,93 @@
412 579 "name__like" => $search,
413 580 'exclude' => $exclude,
414 581 ];
415 582
416 - $items = get_terms($args);
417 - $results = array_map(function ($item) {
583 + $items = get_terms( $args );
584 + $results = array_map( function ( $item ) {
418 585 return [
419 586 "id" => $item->term_id,
420 587 "text" => $item->name,
421 588 ];
422 - }, $items);
589 + }, $items );
423 590 } else {
424 591 $args = [
425 - 's' => $search,
426 - 'post_type' => 'product',
427 - 'post__not_in' => $exclude,
592 + 's' => $search,
593 + 'post_type' => 'product',
594 + 'post__not_in' => $exclude,
595 + 'posts_per_page' => -1,
428 596 ];
429 - $items = get_posts($args);
430 - $results = array_map(function ($item) {
597 + $items = get_posts( $args );
598 + $results = array_map( function ( $item ) {
431 599 return [
432 600 "id" => $item->ID,
433 601 "text" => $item->post_title,
434 602 ];
435 - }, $items);
603 + }, $items );
436 604 }
437 - exit(json_encode(["results" => $results, "pagination" => true]));
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();
438 670 }
439 671 }