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