class-ad-display-condition.php
1 year ago
class-ad-renderer.php
1 week ago
class-debug-ads.php
1 year ago
class-manager.php
1 year ago
class-scripts.php
2 months ago
class-stats.php
1 year ago
class-ad-renderer.php
77 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Frontend Ad Renderer. |
| 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\Widget; |
| 13 | use AdvancedAds\Framework\Interfaces\Integration_Interface; |
| 14 | |
| 15 | defined( 'ABSPATH' ) || exit; |
| 16 | |
| 17 | /** |
| 18 | * Frontend Ad Renderer. |
| 19 | */ |
| 20 | class Ad_Renderer implements Integration_Interface { |
| 21 | |
| 22 | /** |
| 23 | * Hook into WordPress. |
| 24 | * |
| 25 | * @return void |
| 26 | */ |
| 27 | public function hooks(): void { |
| 28 | add_action( 'advanced-ads-frontend', [ $this, 'init' ] ); |
| 29 | add_action( 'widgets_init', [ $this, 'register_widget' ] ); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Inject ads into various sections of our site |
| 34 | * |
| 35 | * @return void |
| 36 | */ |
| 37 | public function init(): void { |
| 38 | // TODO: move priority to 0 for head. |
| 39 | add_action( 'wp_head', [ $this, 'inject_header' ], 20 ); |
| 40 | // TODO: move priority to 9999 for footer. |
| 41 | add_action( 'wp_footer', [ $this, 'inject_footer' ], 20 ); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Injected ad into header |
| 46 | * |
| 47 | * @return void |
| 48 | */ |
| 49 | public function inject_header(): void { |
| 50 | $placements = wp_advads_get_placements_by_types( 'header', \OBJECT, true ); |
| 51 | foreach ( $placements as $placement ) { |
| 52 | the_ad_placement( $placement->get_id() ); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Injected ads into footer |
| 58 | * |
| 59 | * @return void |
| 60 | */ |
| 61 | public function inject_footer(): void { |
| 62 | $placements = wp_advads_get_placements_by_types( 'footer', \OBJECT, true ); |
| 63 | foreach ( $placements as $placement ) { |
| 64 | the_ad_placement( $placement->get_id() ); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Register the Advanced Ads widget |
| 70 | * |
| 71 | * @return void |
| 72 | */ |
| 73 | public function register_widget(): void { |
| 74 | register_widget( Widget::class ); |
| 75 | } |
| 76 | } |
| 77 |