) 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( '/id, [ 'plugins', 'settings_page_addexion-ads' ], true ) ) { return; } $message = sprintf( /* translators: %s: URL of the plugin settings page. */ __( 'Addexion Ads: enter your site ID in Settings → Addexion Ads. You will find it on your site page, in your Addexion publisher dashboard.', 'addexion-ads' ), esc_url( admin_url( 'options-general.php?page=addexion-ads' ) ) ); echo '

' . wp_kses( $message, [ 'strong' => [], 'a' => [ 'href' => [] ] ] ) . '

'; } public function settings_link( array $links ): array { array_unshift( $links, '' . esc_html__( 'Settings', 'addexion-ads' ) . '' ); return $links; } // ── Shortcode [addexion slot="TOKEN" class=""] ──────────────────────────── public function shortcode( $atts ): string { $atts = shortcode_atts( [ 'slot' => '', 'class' => '', ], $atts, 'addexion' ); $slot = sanitize_text_field( $atts['slot'] ); if ( ! $slot ) { return ''; } $class = 'addexion-slot' . ( $atts['class'] ? ' ' . sanitize_html_class( $atts['class'] ) : '' ); return '
'; } // ── Automatic placement ─────────────────────────────────────────────────── public function inject_in_content( $content ) { $slot = get_option( 'addexion_content_slot', '' ); $position = get_option( 'addexion_content_position', 'after' ); if ( ! $slot || ! is_single() ) { return $content; } $ad = '
'; return 'before' === $position ? $ad . $content : $content . $ad; } public function inject_in_header(): void { $slot = get_option( 'addexion_header_slot', '' ); if ( $slot ) { echo '
'; } } public function inject_in_footer(): void { $slot = get_option( 'addexion_footer_slot', '' ); if ( $slot ) { echo ''; } } // ── Widgets ─────────────────────────────────────────────────────────────── public function register_widget(): void { register_widget( 'Addexion_Widget' ); } /** * Loaded only when Elementor asks for its widgets: WordPress loads plugins in alphabetical order, * so Elementor is not available yet when this file runs. */ public function register_elementor_widget( $manager ): void { require_once ADDEXION_PLUGIN_DIR . 'includes/class-addexion-elementor-widget.php'; $manager->register( new Addexion_Elementor_Widget() ); } // ── Settings ────────────────────────────────────────────────────────────── public function add_admin_menu(): void { add_options_page( 'Addexion Ads', 'Addexion Ads', 'manage_options', 'addexion-ads', [ $this, 'settings_page' ] ); } public static function sanitize_position( $value ): string { return 'before' === $value ? 'before' : 'after'; } public function register_settings(): void { register_setting( 'addexion_group', 'addexion_site_id', [ 'sanitize_callback' => [ self::class, 'sanitize_site_id' ], ] ); register_setting( 'addexion_group', 'addexion_api_url', [ 'sanitize_callback' => 'esc_url_raw', 'default' => 'https://addexion.com', ] ); register_setting( 'addexion_group', 'addexion_auto_header', [ 'sanitize_callback' => 'absint' ] ); register_setting( 'addexion_group', 'addexion_header_slot', [ 'sanitize_callback' => 'sanitize_text_field' ] ); register_setting( 'addexion_group', 'addexion_auto_content', [ 'sanitize_callback' => 'absint' ] ); register_setting( 'addexion_group', 'addexion_content_slot', [ 'sanitize_callback' => 'sanitize_text_field' ] ); register_setting( 'addexion_group', 'addexion_content_position', [ 'sanitize_callback' => [ self::class, 'sanitize_position' ] ] ); register_setting( 'addexion_group', 'addexion_auto_footer', [ 'sanitize_callback' => 'absint' ] ); register_setting( 'addexion_group', 'addexion_footer_slot', [ 'sanitize_callback' => 'sanitize_text_field' ] ); } public function settings_page(): void { if ( ! current_user_can( 'manage_options' ) ) { return; } $site_id = self::site_id(); $api_url = get_option( 'addexion_api_url', 'https://addexion.com' ); $auto_header = get_option( 'addexion_auto_header', 0 ); $header_slot = get_option( 'addexion_header_slot', '' ); $auto_content = get_option( 'addexion_auto_content', 0 ); $content_slot = get_option( 'addexion_content_slot', '' ); $content_position = get_option( 'addexion_content_position', 'after' ); $auto_footer = get_option( 'addexion_auto_footer', 0 ); $footer_slot = get_option( 'addexion_footer_slot', '' ); ?>

Addexion Ads