` snippet was the one legitimate use WP.org's * "no arbitrary code insertion" rule left without a home, so it gets a * typed, sanitized field per provider instead of a free-form textarea. */ final class IntegrationsTab implements TabInterface { private FormControls $ui; private IntegrationsRepositoryInterface $integrations; public function __construct( FormControls $ui, IntegrationsRepositoryInterface $integrations ) { $this->ui = $ui; $this->integrations = $integrations; } public function slug(): string { return 'integrations'; } public function label(): string { return __( 'Integrations', 'acez-seo' ); } public function icon(): string { return 'integrations'; } public function enqueue(): void { } public function handles_form_key( string $raw_tab ): bool { return str_starts_with( $raw_tab, 'integrations:' ); } /** @return array */ public function save( string $raw_tab ): array { // Defence in depth: SettingsPage::handle_save() verifies this nonce // before dispatch; re-checking keeps every entry point independently safe. check_admin_referer( FormControls::NONCE_ACTION ); $card = substr( $raw_tab, strlen( 'integrations:' ) ); if ( 'verification' === $card ) { $codes = array(); // Sanitized here at the point of read (not only in the repository) // so the raw superglobal never travels: WP.org review, 2026-09-07. foreach ( array_keys( IntegrationsRepository::verification_meta_names() ) as $field ) { $codes[ $field ] = isset( $_POST[ $field ] ) ? sanitize_text_field( wp_unslash( $_POST[ $field ] ) ) : ''; } $this->integrations->update( $codes ); } elseif ( 'gtm' === $card ) { $this->integrations->update( array( 'gtm_container_id' => isset( $_POST['gtm_container_id'] ) ? sanitize_text_field( wp_unslash( $_POST['gtm_container_id'] ) ) : '', ) ); } elseif ( 'ga' === $card ) { $this->integrations->update( array( 'ga_measurement_id' => isset( $_POST['ga_measurement_id'] ) ? sanitize_text_field( wp_unslash( $_POST['ga_measurement_id'] ) ) : '', ) ); } elseif ( 'hotjar' === $card ) { $this->integrations->update( array( 'hotjar_site_id' => isset( $_POST['hotjar_site_id'] ) ? sanitize_text_field( wp_unslash( $_POST['hotjar_site_id'] ) ) : '', ) ); } elseif ( 'privacy' === $card ) { $this->integrations->update( array( 'exclude_admins' => isset( $_POST['exclude_admins'] ), ) ); } return array( 'tab' => 'integrations' ); } public function render(): void { $settings = $this->integrations->get(); echo '

' . esc_html__( 'Site ownership verification for search engines and social platforms, plus Google Tag Manager / Google Analytics / Hotjar tracking codes.', 'acez-seo' ) . '

'; $this->ui->card_open( __( 'Site verification', 'acez-seo' ), 'integrations', '', 'integration-verification' ); $conflict = GscVerificationConflictDetector::detect(); if ( null !== $conflict ) { printf( '

%s

', esc_html( sprintf( /* translators: %s: name of the other SEO plugin */ __( 'A Google Search Console verification code is already set in another plugin (%s). Setting it here as well would add a second, redundant meta tag.', 'acez-seo' ), $conflict ) ) ); } echo '

' . esc_html__( 'Each service gives you a whole tag to paste into the page header. Enter only the code itself here — the part after content= — and the tag is built for you. Leave a field empty to output nothing for that service.', 'acez-seo' ) . '

'; $this->ui->form_open( 'integrations:verification' ); echo ''; $verification_fields = array( 'gsc_verification_code' => array( __( 'Google Search Console', 'acez-seo' ), 'abc123XYZ...', 'gsc_verification' ), 'bing_verification_code' => array( __( 'Bing Webmaster Tools', 'acez-seo' ), '0123456789ABCDEF0123456789ABCDEF', 'bing_verification' ), 'yandex_verification_code' => array( __( 'Yandex Webmaster', 'acez-seo' ), '0123456789abcdef', 'yandex_verification' ), 'pinterest_verification_code' => array( __( 'Pinterest', 'acez-seo' ), 'abc123...', 'pinterest_verification' ), 'baidu_verification_code' => array( __( 'Baidu Webmaster', 'acez-seo' ), 'abc123...', 'baidu_verification' ), 'facebook_verification_code' => array( __( 'Facebook / Meta domain', 'acez-seo' ), 'abc123...', 'facebook_verification' ), ); foreach ( $verification_fields as $field_name => $field_data ) { list( $label, $placeholder, $help_key ) = $field_data; $this->ui->text_field( $field_name, $label, (string) $settings[ $field_name ], $placeholder, $help_key, IntegrationsRepository::VERIFICATION_TOKEN_CHARS, __( 'Enter the verification code itself, not the whole tag — letters, digits and _ = . : - only.', 'acez-seo' ) ); } echo '
'; submit_button(); $this->ui->form_close(); $this->ui->card_close(); $this->ui->card_open( __( 'Google Tag Manager', 'acez-seo' ), 'integrations', '', 'integration-gtm' ); $this->ui->form_open( 'integrations:gtm' ); echo ''; $this->ui->text_field( 'gtm_container_id', __( 'Container ID', 'acez-seo' ), (string) $settings['gtm_container_id'], 'GTM-XXXXXXX', 'gtm' ); echo '
'; submit_button(); $this->ui->form_close(); $this->ui->card_close(); $this->ui->card_open( __( 'Google Analytics', 'acez-seo' ), 'integrations', '', 'integration-ga4' ); if ( '' !== (string) $settings['gtm_container_id'] ) { echo '

' . esc_html__( 'You already have Google Tag Manager configured — if Analytics is connected as a tag in GTM, do not enter the Measurement ID here as well, or visits will be counted twice.', 'acez-seo' ) . '

'; } $this->ui->form_open( 'integrations:ga' ); echo ''; $this->ui->text_field( 'ga_measurement_id', __( 'Measurement ID', 'acez-seo' ), (string) $settings['ga_measurement_id'], 'G-XXXXXXXXXX', 'ga4' ); echo '
'; submit_button(); $this->ui->form_close(); $this->ui->card_close(); $this->ui->card_open( __( 'Hotjar', 'acez-seo' ), 'integrations', '', 'integration-hotjar' ); $this->ui->form_open( 'integrations:hotjar' ); echo ''; $this->ui->text_field( 'hotjar_site_id', __( 'Site ID', 'acez-seo' ), (string) $settings['hotjar_site_id'], '1234567', 'hotjar' ); echo '
'; submit_button(); $this->ui->form_close(); $this->ui->card_close(); $this->ui->card_open( __( 'Privacy', 'acez-seo' ), 'integrations', '', 'integration-privacy' ); $this->ui->form_open( 'integrations:privacy' ); echo ''; $this->ui->checkbox_field( 'exclude_admins', __( 'Do not track logged-in administrators (applies to GTM, Google Analytics and Hotjar)', 'acez-seo' ), (bool) $settings['exclude_admins'] ); echo '
'; echo '

' . esc_html__( 'GTM, Google Analytics and Hotjar set cookies and collect visitor data — make sure you have an appropriate privacy policy and (if required) a cookie consent banner. This plugin does not manage consent — use a dedicated CMP plugin for that.', 'acez-seo' ) . '

'; submit_button(); $this->ui->form_close(); $this->ui->card_close(); } }