public.php
45 lines
| 1 | <?php |
| 2 | |
| 3 | class Advanced_Ads_AdSense_Public { |
| 4 | |
| 5 | private $data; // options |
| 6 | |
| 7 | private static $instance = null; |
| 8 | |
| 9 | private function __construct() { |
| 10 | $this->data = Advanced_Ads_AdSense_Data::get_instance(); |
| 11 | add_action( 'wp_head', array( $this, 'inject_header' ), 20 ); |
| 12 | } |
| 13 | |
| 14 | public static function get_instance() { |
| 15 | if ( null == self::$instance ) { |
| 16 | self::$instance = new self; |
| 17 | } |
| 18 | return self::$instance; |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Print data in the head tag on the front end. |
| 23 | */ |
| 24 | public function inject_header(){ |
| 25 | $options = $this->data->get_options(); |
| 26 | |
| 27 | // Inject CSS to make AdSense background transparent. |
| 28 | if ( ! empty( $options['background'] ) ) { |
| 29 | echo '<style>ins.adsbygoogle { background-color: transparent; }</style>'; |
| 30 | } |
| 31 | /** |
| 32 | * inject page-level header code |
| 33 | * |
| 34 | * @since 1.6.9 |
| 35 | */ |
| 36 | $pub_id = trim( $this->data->get_adsense_id() ); |
| 37 | |
| 38 | if( ! defined( 'ADVADS_ADS_DISABLED' ) && $pub_id && isset( $options['page-level-enabled'] ) && $options['page-level-enabled'] ){ |
| 39 | $pub_id = $this->data->get_adsense_id(); |
| 40 | $client_id = 'ca-' . $pub_id; |
| 41 | include GADSENSE_BASE_PATH . 'public/templates/page-level.php'; |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 |