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