is_amp() ) { return; } if ( Options::instance()->get( 'enable_amp_auto_ads', 'adsense', true ) && AdSense::instance()->current_adsense_publisher_id() ) { if ( apply_filters( 'adcmdr_amp_auto_ads_enabled', true ) ) { /** * Head script */ add_action( 'amp_post_template_data', array( $this, 'amp_auto_ads_head_script' ) ); /** * Body script */ add_action( 'wp_footer', array( $this, 'amp_auto_ads_body_code' ) ); add_action( 'amp_post_template_footer', array( $this, 'amp_auto_ads_body_code' ) ); } } } /** * Get the base URL for Amp JS * * @return string */ public function amp_auto_ads_js_base_url() { return apply_filters( 'adcmdr_amp_auto_ads_js_base_url', 'https://cdn.ampproject.org/v0/amp-auto-ads-0.1.js' ); } /** * Get full AMP script tag. * * @return string */ public function get_amp_auto_ads_script_tag() { // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript -- This script is output using custom AMP plugin hooks and cannot be output reliably with wp_enqueue_script. return ''; } /** * Gets the full AMP auto-ads element. * * @param bool|string $publisher_id The publisher ID. * @param bool|string $fallback_id A fake publisher id used for display purposes. * * @return string */ public function get_amp_auto_ads_element( $publisher_id = false, $fallback_id = false ) { if ( ! $publisher_id ) { $publisher_id = AdSense::instance()->current_adsense_publisher_id(); } if ( ! $publisher_id && $fallback_id ) { $publisher_id = $fallback_id; } if ( ! $publisher_id ) { return ''; } return ''; } /** * Output the AMP auto ads head script. * * @return void */ public function amp_auto_ads_head_script() { $script = apply_filters( 'adcmdr_amp_auto_ads_script_tag', $this->get_amp_auto_ads_script_tag() ); if ( $script && $script !== '' ) { echo wp_kses( $script, apply_filters( 'adcmdr_amp_auto_ads_script_tag_allowed_html', array( 'script' => array( 'async' => array(), 'src' => array(), 'nomodule' => array(), 'crossorigin' => array(), 'custom-element' => array(), ), ) ) ); } } /** * Output the AMP auto ads body code. * * @return void */ public function amp_auto_ads_body_code() { $code = apply_filters( 'adcmdr_amp_auto_ads_body_code', $this->get_amp_auto_ads_element() ); if ( $code && $code !== '' ) { echo wp_kses( $code, apply_filters( 'adcmdr_amp_auto_ads_body_code_allowed_html', array( 'amp-auto-ads' => array( 'type' => array(), 'data-ad-client' => array(), 'class' => array(), ), ) ) ); } } }