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/ActionManager.php +30 -51 trunk2.2.16 View file →
@@ -1,7 +1,8 @@
1 1 <?php
2 +namespace Hurrytimer;
2 3
3 -namespace Hurrytimer;
4 +use Hurrytimer\Utils\Helpers;
4 5
5 6 /**
6 7 *
7 8 * This class handle actions executions
@@ -16,74 +17,52 @@
16 17 * @var Campaign
17 18 */
18 19 protected $campaign;
19 20
20 - public function __construct( $campaign )
21 + public function __construct($campaign)
21 22 {
22 23 $this->campaign = $campaign;
23 - add_filter( 'wp_insert_post_data', function ( $data ) {
24 - global $hurryt_saving_post;
25 - $hurryt_saving_post = true;
26 -
27 - return $data;
28 - } );
29 - add_action( 'save_post', function () {
30 - global $hurryt_saving_post;
31 - $hurryt_saving_post = false;
32 - } );
33 -
34 24 }
35 25
36 - function is_disabled()
37 - {
38 - $disable_actions = hurryt_is_admin_area() && hurryt_settings()[ 'disable_actions' ];
39 - return filter_var( apply_filters( 'hurryt_disable_actions', $disable_actions ), FILTER_VALIDATE_BOOLEAN );
40 - }
41 -
26 + /**
27 + * Execute registered campaign actions.
28 + */
42 29 public function run()
43 30 {
44 -
45 - if ( $this->is_disabled() ) {
31 + $pluginSettings = new PluginSettings();
32 + $settings = $pluginSettings->getSettings();
33 + if(Helpers::isUsingDashboard() && $settings['disable_actions']){
46 34 return;
47 35 }
48 36
49 - /**
50 - * @deprecated 2.3.0 Use `hurryt_campaign_finished` instead.
51 - */
52 - do_action( "hurryt_{$this->campaign->get_id()}_campaign_ended", $this->campaign );
37 + foreach ($this->campaign->actions as $action) {
38 + switch ($action['id']) {
53 39
54 - do_action( "hurryt_campaign_finished", $this->campaign->get_id() );
40 + // Hide.
41 + case C::ACTION_HIDE:
42 + add_filter('hurryt_campaign_template', '__return_empty_string', 1);
43 + break;
55 44
56 - foreach ( $this->campaign->actions as $action ) {
57 - switch ( $action[ 'id' ] ) {
58 -
45 + // URL redirect.
59 46 case C::ACTION_REDIRECT;
60 - $this->redirect_to( $action[ 'redirectUrl' ] );
47 + @wp_redirect($action['redirectUrl']);
61 48 break;
49 +
50 + // Change stock status (regular mode)
62 51 case C::ACTION_CHANGE_STOCK_STATUS:
63 - $this->change_stock_status( $action[ 'wcStockStatus' ] );
52 + $wcCampaign = new WCCampaign();
53 + $wcCampaign->changeStockStatus($this->campaign, $action['wcStockStatus']);
64 54 break;
55 +
56 + // Display message.
57 + case C::ACTION_DISPLAY_MESSAGE:
58 + add_filter('hurryt_campaign_template',
59 + function () use ($action) {
60 + return
61 + "<div class='hurrytimer-campaign-message'>{$action['message']}</div>";
62 + }, 2);
63 + break;
65 64 }
66 65 }
67 66 }
68 67
69 - function redirect_to( $url )
70 - {
71 - global $hurryt_saving_post;
72 - if ( $hurryt_saving_post ) {
73 - return;
74 - }
75 -
76 - if ( !empty( trim( $url ) ) ) {
77 - wp_redirect( esc_url_raw( $url ) );
78 - exit;
79 - }
80 68 }
81 -
82 - function change_stock_status( $stock_status )
83 - {
84 - $wc_campaign = new WCCampaign();
85 - $wc_campaign->change_stock_status( $this->campaign, $stock_status );
86 -
87 - return;
88 - }
89 -}