| @@ -1,11 +1,21 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace Hurrytimer; |
| 3 | 3 | |
| 4 | +use Hurrytimer\Utils\Helpers; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * | |
| 8 | + * This class handle actions executions | |
| 9 | + * | |
| 10 | + * Class ActionManager | |
| 11 | + * | |
| 12 | + * @package Hurrytimer | |
| 13 | + */ | |
| 4 | 14 | class ActionManager |
| 5 | 15 | { |
| 6 | 16 | /** |
| 7 | - * @var \Hurrytimer\Campaign | |
| 17 | + * @var Campaign | |
| 8 | 18 | */ |
| 9 | 19 | protected $campaign; |
| 10 | 20 | |
| 11 | 21 | public function __construct($campaign) |
| @@ -12,32 +22,42 @@ | ||
| 12 | 22 | { |
| 13 | 23 | $this->campaign = $campaign; |
| 14 | 24 | } |
| 15 | 25 | |
| 16 | - function redirect($url) | |
| 26 | + /** | |
| 27 | + * Execute registered campaign actions. | |
| 28 | + */ | |
| 29 | + public function run() | |
| 17 | 30 | { |
| 18 | - ob_start(); | |
| 19 | - header("Location: $url"); | |
| 20 | - exit; | |
| 21 | - } | |
| 31 | + $pluginSettings = new PluginSettings(); | |
| 32 | + $settings = $pluginSettings->getSettings(); | |
| 33 | + if(Helpers::isUsingDashboard() && $settings['disable_actions']){ | |
| 34 | + return; | |
| 35 | + } | |
| 22 | 36 | |
| 23 | - function run() | |
| 24 | - { | |
| 25 | 37 | foreach ($this->campaign->actions as $action) { |
| 26 | 38 | switch ($action['id']) { |
| 39 | + | |
| 40 | + // Hide. | |
| 27 | 41 | case C::ACTION_HIDE: |
| 28 | - add_filter('hurryt_campaign_template', function () { return ''; }, 1); | |
| 42 | + add_filter('hurryt_campaign_template', '__return_empty_string', 1); | |
| 29 | 43 | break; |
| 44 | + | |
| 45 | + // URL redirect. | |
| 30 | 46 | case C::ACTION_REDIRECT; |
| 31 | - $this->redirect($action['redirectUrl']); | |
| 47 | + @wp_redirect($action['redirectUrl']); | |
| 32 | 48 | break; |
| 49 | + | |
| 50 | + // Change stock status (regular mode) | |
| 33 | 51 | case C::ACTION_CHANGE_STOCK_STATUS: |
| 34 | 52 | $wcCampaign = new WCCampaign(); |
| 35 | 53 | $wcCampaign->changeStockStatus($this->campaign, $action['wcStockStatus']); |
| 36 | 54 | break; |
| 55 | + | |
| 56 | + // Display message. | |
| 37 | 57 | case C::ACTION_DISPLAY_MESSAGE: |
| 38 | 58 | add_filter('hurryt_campaign_template', |
| 39 | - function ($template) use ($action) { | |
| 59 | + function () use ($action) { | |
| 40 | 60 | return |
| 41 | 61 | "<div class='hurrytimer-campaign-message'>{$action['message']}</div>"; |
| 42 | 62 | }, 2); |
| 43 | 63 | break; |
| @@ -44,6 +64,5 @@ | ||
| 44 | 64 | } |
| 45 | 65 | } |
| 46 | 66 | } |
| 47 | 67 | |
| 48 | - | |
| 49 | -} | |
| 68 | + } | |