<?php
if (!defined('ABSPATH')) {
	exit;
}

function probonoseo_gsc_verify_output() {
	if (get_option('probonoseo_gsc_verify', '1') !== '1') {
		return;
	}

	$probonoseo_raw = trim((string) get_option('probonoseo_gsc_verify_code', ''));
	if (empty($probonoseo_raw)) {
		return;
	}

	$probonoseo_code = $probonoseo_raw;

	if (preg_match('/content\s*=\s*["\']([^"\']+)["\']/i', $probonoseo_raw, $probonoseo_matches)) {
		$probonoseo_code = $probonoseo_matches[1];
	}

	$probonoseo_code = sanitize_text_field($probonoseo_code);

	if (empty($probonoseo_code)) {
		return;
	}

	echo '<meta name="google-site-verification" content="' . esc_attr($probonoseo_code) . '">' . "\n";
}
add_action('wp_head', 'probonoseo_gsc_verify_output', 1);
