class-ad-display-condition.php
1 year ago
class-ad-renderer.php
1 year ago
class-debug-ads.php
1 year ago
class-manager.php
1 year ago
class-scripts.php
11 months ago
class-stats.php
1 year ago
class-manager.php
68 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Frontend Manager. |
| 4 | * |
| 5 | * @package AdvancedAds |
| 6 | * @author Advanced Ads <info@wpadvancedads.com> |
| 7 | * @since 1.50.0 |
| 8 | */ |
| 9 | |
| 10 | namespace AdvancedAds\Frontend; |
| 11 | |
| 12 | use AdvancedAds\Utilities\Conditional; |
| 13 | use AdvancedAds\Framework\Interfaces\Integration_Interface; |
| 14 | |
| 15 | defined( 'ABSPATH' ) || exit; |
| 16 | |
| 17 | /** |
| 18 | * Frontend Manager. |
| 19 | */ |
| 20 | class Manager implements Integration_Interface { |
| 21 | |
| 22 | /** |
| 23 | * Page display condition object. |
| 24 | * |
| 25 | * @var Ad_Display_Condition |
| 26 | */ |
| 27 | private $page_display; |
| 28 | |
| 29 | /** |
| 30 | * Magic method to handle dynamic method calls. |
| 31 | * |
| 32 | * @param string $name The name of the method being called. |
| 33 | * @param array $arguments The arguments passed to the method. |
| 34 | * |
| 35 | * @return mixed The result of the method call, if the method exists. Otherwise, null is returned. |
| 36 | */ |
| 37 | public function __call( $name, $arguments ) { |
| 38 | if ( method_exists( $this->page_display, $name ) ) { |
| 39 | return call_user_func_array( [ $this->page_display, $name ], $arguments ); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Hook into WordPress. |
| 45 | * |
| 46 | * @return void |
| 47 | */ |
| 48 | public function hooks(): void { |
| 49 | $this->page_display = new Ad_Display_Condition(); |
| 50 | |
| 51 | add_action( 'rest_api_init', [ $this, 'run_checks' ] ); |
| 52 | add_action( 'template_redirect', [ $this, 'run_checks' ], 11 ); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Run the check. |
| 57 | * |
| 58 | * @return void |
| 59 | */ |
| 60 | public function run_checks(): void { |
| 61 | $this->page_display->run_checks(); |
| 62 | |
| 63 | if ( ! Conditional::is_ad_disabled() ) { |
| 64 | do_action( 'advanced-ads-frontend' ); |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 |