Admin
2 years ago
Assets
2 years ago
Pages
3 years ago
PostTypes
3 years ago
Shortcodes
2 years ago
Sitemap
3 years ago
Templates
2 years ago
Users
3 years ago
ActionsService.php
3 years ago
CompatibilityService.php
2 years ago
HealthService.php
2 years ago
PluginService.php
3 years ago
PluginServiceProvider.php
2 years ago
RecaptchaValidationService.php
2 years ago
ThemeService.php
3 years ago
ThemeServiceProvider.php
3 years ago
TranslationsServiceProvider.php
3 years ago
ActionsService.php
48 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package SureCartAppCore |
| 4 | * @author SureCart <support@surecart.com> |
| 5 | * @copyright SureCart |
| 6 | * @license https://www.gnu.org/licenses/gpl-2.0.html GPL-2.0 |
| 7 | * @link https://surecart.com |
| 8 | */ |
| 9 | |
| 10 | namespace SureCart\WordPress; |
| 11 | |
| 12 | /** |
| 13 | * Main communication channel with the theme. |
| 14 | */ |
| 15 | class ActionsService { |
| 16 | /** |
| 17 | * Broadcast the php hook. |
| 18 | * This sets the a transient so that it is not accidentally broadcasted twice. |
| 19 | * |
| 20 | * @param string $event Event name. |
| 21 | * @param \SureCart\Model $model Model. |
| 22 | * |
| 23 | * @return void |
| 24 | */ |
| 25 | public function doOnce( $event, $model ) { |
| 26 | $action = get_transient( 'surecart_action_' . $event . $model->id, false ); |
| 27 | if ( false === $action ) { |
| 28 | // perform the action. |
| 29 | do_action( $event, $model ); |
| 30 | set_transient( 'surecart_action_' . $event . $model->id, true, MINUTE_IN_SECONDS ); |
| 31 | } |
| 32 | return $this; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Clear any previous action. |
| 37 | * |
| 38 | * @param string $event Event name. |
| 39 | * @param \SureCart\Model $model Model. |
| 40 | * |
| 41 | * @return void |
| 42 | */ |
| 43 | public function clear( $event, $model ) { |
| 44 | delete_transient( 'surecart_action_' . $event . $model->id ); |
| 45 | return $this; |
| 46 | } |
| 47 | } |
| 48 |