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