get_bloginfo('name'),
'logo' => '',
'logo_light' => '',
'phone' => '',
'email' => get_option('admin_email'),
'privacy_url' => function_exists('get_privacy_policy_url') ? get_privacy_policy_url() : '',
'terms_url' => '',
'c_primary' => '#1e4d6b',
'c_accent' => '#e07a5f',
'font' => 'site',
'languages' => ['en'],
'ai_provider' => 'none',
'ai_key' => '',
'ai_model' => '',
'credit' => 0,
'marketing_optin' => 0,
'consent_note' => '',
'whatsapp' => '',
'country' => '',
'reg_label' => '',
'reg_number' => '',
'legal_notice' => '',
];
}
function domo_settings(): array
{
$saved = get_option('domo_settings', []);
$s = wp_parse_args(is_array($saved) ? $saved : [], domo_defaults());
// After a downgrade, keep only languages this edition supports.
$langs = array_values(array_intersect((array) $s['languages'], array_keys(domo_language_names())));
$s['languages'] = array_slice($langs ?: ['en'], 0, domo_max_languages());
return $s;
}
function domo_strings(): array
{
static $strings = null;
if ($strings === null) {
$strings = apply_filters('domopage_strings', require DOMO_DIR . 'includes/strings.php');
}
return $strings;
}
/** Languages a page can use: 3 in Lite, all available languages with Pro. */
function domo_max_languages(): int
{
return (int) apply_filters('domopage_max_languages', DOMO_MAX_LANGUAGES);
}
/** Upgrade hint, hidden once a paid licence is active or white label is on. */
function domo_upsell(string $text): void
{
if (apply_filters('domopage_show_upsells', !domo_is_pro())) {
echo '
' . esc_html($text) . ' ' . esc_html__('Upgrade', 'domopage') . ' ยท ' . esc_html__('I have a licence key', 'domopage') . '
';
}
}
function domo_upgrade_url(): string
{
return function_exists('domo_fs') ? domo_fs()->get_upgrade_url() : DOMO_SITE_URL . '/pricing/';
}
function domo_language_names(): array
{
$out = [];
foreach (domo_strings() as $code => $s) {
$out[$code] = $s['_name'];
}
return $out;
}
function domo_t(string $key, string $lang): string
{
$s = domo_strings();
return $s[$lang][$key] ?? $s['en'][$key] ?? $key;
}
function domo_primary_lang(): string
{
$langs = domo_settings()['languages'];
return $langs[0] ?? 'en';
}
function domo_get_data(int $id): array
{
$d = get_post_meta($id, '_domo_data', true);
return is_array($d) ? $d : [];
}
function domo_save_data(int $id, array $d): void
{
update_post_meta($id, '_domo_data', $d);
}
function domo_register_cpt(): void
{
register_post_type('domo_property', [
'labels' => [
'name' => __('Landing pages', 'domopage'),
'singular_name' => __('Landing page', 'domopage'),
],
'public' => true,
'show_ui' => true,
'show_in_menu' => false,
'show_in_rest' => false,
'exclude_from_search' => true,
'has_archive' => false,
'supports' => ['title'],
'rewrite' => ['slug' => 'property-lp', 'with_front' => false],
'capability_type' => 'post',
'map_meta_cap' => true,
'capabilities' => ['create_posts' => 'do_not_allow'],
]);
}
/** Readable text colour (dark or white) for a background hex colour. */
function domo_contrast(string $hex): string
{
$hex = ltrim($hex, '#');
if (strlen($hex) === 3) {
$hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
}
if (strlen($hex) !== 6) {
return '#ffffff';
}
[$r, $g, $b] = array_map('hexdec', str_split($hex, 2));
$lum = (0.299 * $r + 0.587 * $g + 0.114 * $b) / 255;
return $lum > 0.6 ? '#16232a' : '#ffffff';
}
/** System font stacks only: no third-party font requests, so no GDPR issue. */
function domo_fonts(): array
{
$site = domo_site_fonts();
return [
'site' => ['label' => __('Your website\'s font', 'domopage'), 'head' => $site['head'] ?: "system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif", 'body' => $site['body'] ?: "system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif"],
'classic' => ['label' => 'Classic (serif headings)', 'head' => "Georgia, 'Times New Roman', serif", 'body' => "system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif"],
'modern' => ['label' => 'Modern (all sans-serif)', 'head' => "system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif", 'body' => "system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif"],
'elegant' => ['label' => 'Elegant (Palatino headings)', 'head' => "'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, serif", 'body' => "'Helvetica Neue', Helvetica, Arial, sans-serif"],
];
}
function domo_notice(string $type, string $message): void
{
set_transient('domo_notice_' . get_current_user_id(), ['type' => $type, 'message' => $message], 120);
}
function domo_show_notice(): void
{
$key = 'domo_notice_' . get_current_user_id();
$n = get_transient($key);
if (!$n) {
return;
}
delete_transient($key);
printf('', esc_attr($n['type']), esc_html($n['message']));
}
/** WhatsApp glyph as inline SVG (no external request). */
function domo_wa_icon(): string
{
return '';
}
/** Allowed tags for the plugin's own inline SVG icons and energy label. */
function domo_svg_kses(): array
{
$common = ['fill' => true, 'stroke' => true, 'stroke-width' => true, 'stroke-linecap' => true, 'stroke-linejoin' => true, 'opacity' => true, 'fill-rule' => true];
return [
'svg' => ['class' => true, 'viewbox' => true, 'width' => true, 'height' => true, 'role' => true, 'aria-label' => true, 'aria-hidden' => true, 'xmlns' => true] + $common,
'title' => [],
'path' => ['d' => true] + $common,
'rect' => ['x' => true, 'y' => true, 'width' => true, 'height' => true, 'rx' => true] + $common,
'circle' => ['cx' => true, 'cy' => true, 'r' => true] + $common,
'text' => ['x' => true, 'y' => true, 'font-size' => true, 'font-weight' => true] + $common,
];
}
/** Logo URL: the main logo, else the dark-background logo, else the site's own logo (Site Identity), so branding always appears. */
function domo_logo_url(): string
{
$s = domo_settings();
if (!empty($s['logo'])) {
return $s['logo'];
}
if (!empty($s['logo_light'])) {
return $s['logo_light'];
}
$custom = (int) get_theme_mod('custom_logo');
if ($custom) {
$url = wp_get_attachment_image_url($custom, 'full');
if ($url) {
return $url;
}
}
return '';
}
/** Allowed tags for the hero media block (photo, self-hosted video or a privacy-friendly embed). */
function domo_media_kses(): array
{
return [
'div' => ['class' => true, 'data-src' => true, 'data-kind' => true, 'data-desktop-only' => true, 'data-loop' => true],
'img' => ['src' => true, 'alt' => true, 'fetchpriority' => true, 'class' => true],
'video' => ['class' => true, 'muted' => true, 'loop' => true, 'playsinline' => true, 'preload' => true, 'poster' => true, 'aria-hidden' => true, 'disablepictureinpicture' => true],
'iframe' => ['class' => true, 'title' => true, 'allow' => true, 'tabindex' => true, 'aria-hidden' => true, 'loading' => true, 'referrerpolicy' => true],
];
}
/** Keeps a CSS font-family list safe to print: letters, digits, spaces, commas, quotes and hyphens only. */
function domo_clean_font_stack(string $stack): string
{
$stack = trim(preg_replace('/\s+/', ' ', html_entity_decode($stack, ENT_QUOTES)));
return preg_match('/^[\p{L}\p{N} ,\'"_-]{1,300}$/u', $stack) ? $stack : '';
}
/**
* Reads the active theme's fonts: theme.json / Site Editor styles for block themes, style.css for classic themes.
* Returns ['head' => stack, 'body' => stack, 'names' => readable names]. Empty strings when nothing was found.
*/
function domo_site_fonts(): array
{
static $cache = null;
if ($cache !== null) {
return $cache;
}
$head = '';
$body = '';
if (function_exists('wp_theme_has_theme_json') && wp_theme_has_theme_json() && function_exists('wp_get_global_styles')) {
$styles = wp_get_global_styles();
$body = domo_resolve_font((string) ($styles['typography']['fontFamily'] ?? ''));
$head = domo_resolve_font((string) ($styles['elements']['heading']['typography']['fontFamily'] ?? $styles['elements']['h1']['typography']['fontFamily'] ?? ''));
}
if ($body === '' && $head === '') {
// Classic theme: first body / heading font-family in the child and parent style.css.
foreach (array_unique([get_stylesheet_directory(), get_template_directory()]) as $dir) {
$file = $dir . '/style.css';
if (!is_readable($file)) {
continue;
}
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- reading the active theme's own stylesheet from disk.
$css = preg_replace('~/\*.*?\*/~s', '', (string) file_get_contents($file, false, null, 0, 400000));
// Only rules whose selector list contains plain "body" or "h1" count (language-specific rules are skipped),
// later rules win as in the cascade, and CSS variables such as var(--font-primary) are looked up.
$vars = [];
if (preg_match_all('~(--[\w-]+)\s*:\s*([^;}]+)~', $css, $vm, PREG_SET_ORDER)) {
foreach ($vm as $v) {
$vars[$v[1]] = trim($v[2]);
}
}
$resolve = function (string $value) use ($vars): string {
for ($i = 0; $i < 5 && preg_match('~var\(\s*(--[\w-]+)\s*(?:,[^)]*)?\)~', $value, $m); $i++) {
$value = str_replace($m[0], $vars[$m[1]] ?? '', $value);
}
return domo_clean_font_stack(str_replace('!important', '', $value));
};
$generic = '~^\s*(serif|sans-serif|monospace|system-ui|cursive|fantasy|inherit|initial|unset)\s*$~i';
$found_body = '';
$found_head = '';
if (preg_match_all('~([^{}]+)\{([^{}]*font-family\s*:[^{}]*)\}~i', $css, $rules, PREG_SET_ORDER)) {
foreach ($rules as $rule) {
$selectors = array_map(fn($x) => strtolower(trim($x)), explode(',', $rule[1]));
if (!preg_match('~font-family\s*:\s*([^;}]+)~i', $rule[2], $fm)) {
continue;
}
$stack = $resolve($fm[1]);
if ($stack === '' || preg_match($generic, $stack) || stripos($stack, 'monospace') === 0) {
continue;
}
if (in_array('body', $selectors, true)) {
$found_body = $stack;
}
if (in_array('h1', $selectors, true) && $found_head === '') {
$found_head = $stack;
}
}
}
$body = $body ?: $found_body;
$head = $head ?: $found_head;
}
}
$head = $head ?: $body;
$body = $body ?: $head;
$name = fn($stack) => trim((string) strtok($stack, ','), " '\"");
$cache = ['head' => $head, 'body' => $body, 'names' => $head ? array_values(array_unique([$name($head), $name($body)])) : []];
return $cache;
}
/** Turns "var:preset|font-family|outfit" or "var(--wp--preset--font-family--outfit)" into the real font stack. */
function domo_resolve_font(string $value): string
{
if ($value === '') {
return '';
}
if (preg_match('~font-family(?:\||--)([a-z0-9_-]+)~i', $value, $m)) {
$families = function_exists('wp_get_global_settings') ? (array) wp_get_global_settings(['typography', 'fontFamilies']) : [];
foreach (['custom', 'theme', 'default'] as $origin) {
foreach ((array) ($families[$origin] ?? []) as $f) {
if (($f['slug'] ?? '') === $m[1] && !empty($f['fontFamily'])) {
return domo_clean_font_stack((string) $f['fontFamily']);
}
}
}
return '';
}
return domo_clean_font_stack($value);
}