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