settings = $settings; } /** * Initializes all hooks. * * @since 1.3.0 */ public function register(): void { add_action( 'web_stories_print_analytics', [ $this, 'print_adsense_tag' ] ); } /** * Get the list of service IDs required for this service to be registered. * * Needed because settings needs to be registered first. * * @since 1.13.0 * * @return string[] List of required services. */ public static function get_requirements(): array { return [ 'settings' ]; } /** * Prints the tag for single stories. * * @since 1.3.0 */ public function print_adsense_tag(): void { $publisher = $this->get_publisher_id(); $slot = $this->get_slot_id(); $enabled = $this->is_enabled(); if ( ! $enabled || ! $publisher || ! $slot ) { return; } ?> settings->get_setting( $this->settings::SETTING_NAME_ADSENSE_PUBLISHER_ID ); return $publisher_id; } /** * Returns the Google AdSense slot ID. * * @since 1.3.0 * * @return string Slot ID. */ private function get_slot_id(): string { /** * Slot ID. * * @var string */ return $this->settings->get_setting( $this->settings::SETTING_NAME_ADSENSE_SLOT_ID ); } /** * Returns if Google AdSense is enabled. * * @since 1.3.0 */ private function is_enabled(): bool { return ( 'adsense' === $this->settings->get_setting( $this->settings::SETTING_NAME_AD_NETWORK, 'none' ) ); } }