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