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