) if ( get_option( 'addexion_auto_header' ) ) { add_action( 'wp_body_open', [ $this, 'inject_in_header' ] ); } // Automatic placement in the footer if ( get_option( 'addexion_auto_footer' ) ) { add_action( 'wp_footer', [ $this, 'inject_in_footer' ], 5 ); } } // ── Scripts ─────────────────────────────────────────────────────────────── public function enqueue_scripts(): void { wp_enqueue_script( 'addexion-ads', ADDEXION_PLUGIN_URL . 'addexion-ads.js', [], ADDEXION_VERSION, true ); wp_localize_script( 'addexion-ads', 'addexionConfig', [ 'apiUrl' => esc_url( rtrim( get_option( 'addexion_api_url', 'https://addexion.com' ), '/' ) ), 'siteId' => self::site_id(), 'adLabel' => __( 'Advertisement', 'addexion-ads' ), ] ); } // ── Site ID ─────────────────────────────────────────────────────────────── // // The site's ID on Addexion (site page in the publisher dashboard). It is written in every page in // two ways, to prove the site is controlled by the publisher who declared it: a tag in the //
, and a data-site attribute on the script (like the manual embed code). The tag // survives caching and optimization plugins that combine or rewrite scripts. public static function site_id(): string { return (string) get_option( 'addexion_site_id', '' ); } public function output_site_meta(): void { $site_id = self::site_id(); if ( $site_id ) { echo '' . "\n"; } } public function add_site_attribute( string $tag, string $handle ): string { $site_id = self::site_id(); if ( 'addexion-ads' !== $handle || ! $site_id || false !== strpos( $tag, 'data-site=' ) ) { return $tag; } return preg_replace( '/