'wp_dequeue_style', 'wp_scripts' => 'wp_dequeue_script'] as $global => $dequeue) { $registry = $GLOBALS[$global] ?? null; if (!$registry) { continue; } foreach ((array) $registry->queue as $handle) { $src = (string) ($registry->registered[$handle]->src ?? ''); // Keep other plugins' assets (consent banners, analytics), drop the theme and core block styles. $from_plugin = $src !== '' && str_contains($src, '/plugins/'); // "Your website's font": keep the theme's font files (Google Fonts, Adobe Fonts, Bunny or local font CSS). if ($site_font && preg_match('~fonts\.googleapis\.com|fonts\.bunny\.net|use\.typekit\.net|/fonts?/|font~i', $src . ' ' . $handle)) { continue; } if (!in_array($handle, $keep, true) && !$from_plugin && ($global === 'wp_styles' || str_contains($src, '/themes/'))) { $dequeue($handle); } } } } add_action('wp_enqueue_scripts', 'domo_strip_theme_assets', 9999); add_action('wp_print_styles', 'domo_strip_theme_assets', 9999); add_action('wp_print_footer_scripts', 'domo_strip_theme_assets', 1); /** Languages a page can show: enabled in settings and with copy written. */ function domo_page_languages(array $d): array { $langs = domo_settings()['languages']; $available = []; foreach ($langs as $n => $code) { if ($n === 0 || !empty($d['copy'][$code])) { $available[] = $code; } } return $available ?: ['en']; } function domo_lang_url(int $id, string $code, string $primary): string { $url = get_permalink($id); return $code === $primary ? $url : add_query_arg('lang', $code, $url); } function domo_form_signature(int $ts, int $id): string { return wp_hash('domo_form|' . $ts . '|' . $id); } add_action('admin_post_nopriv_domo_enquiry', 'domo_handle_enquiry'); add_action('admin_post_domo_enquiry', 'domo_handle_enquiry'); function domo_handle_enquiry(): void { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- the nonce is verified just below; the post ID is needed to know which nonce to check. $id = absint($_POST['post_id'] ?? 0); $post = $id ? get_post($id) : null; if (!$post || $post->post_type !== 'domo_property' || $post->post_status !== 'publish') { wp_die(esc_html__('This page is not available.', 'domopage'), '', ['response' => 400]); } $d = domo_get_data($id); $s = domo_settings(); $langs = domo_page_languages($d); $lang = sanitize_key(wp_unslash($_POST['lang'] ?? '')); // phpcs:ignore WordPress.Security.NonceVerification.Missing -- read only to build the return URL; the nonce is verified before anything is processed. if (!in_array($lang, $langs, true)) { $lang = $langs[0]; } $back = domo_lang_url($id, $lang, $langs[0]); $fail = function (string $code) use ($back) { wp_safe_redirect(add_query_arg('domo_err', $code, $back) . '#enquiry'); exit; }; // Nonce (CSRF protection), plus a signed timestamp, honeypot and rate limit against spam below. if (!isset($_POST['domo_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['domo_nonce'])), 'domo_enquiry_' . $id)) { $fail('expired'); } // Bots that fill the hidden field get a fake success. if (!empty($_POST['website'])) { wp_safe_redirect(add_query_arg('sent', '1', $back) . '#enquiry'); exit; } $ts = absint(wp_unslash($_POST['ts'] ?? 0)); if (!hash_equals(domo_form_signature($ts, $id), sanitize_text_field(wp_unslash($_POST['sig'] ?? ''))) || time() - $ts > 6 * HOUR_IN_SECONDS) { $fail('expired'); } if (time() - $ts < 3) { $fail('wait'); } $ip_key = 'domo_rl_' . md5(sanitize_text_field(wp_unslash($_SERVER['REMOTE_ADDR'] ?? '')) . wp_salt('nonce')); if (get_transient($ip_key)) { $fail('rate'); } $v = []; foreach (['name', 'email', 'phone', 'date', 'intent'] as $k) { $v[$k] = sanitize_text_field(wp_unslash($_POST[$k] ?? '')); } $v['message'] = sanitize_textarea_field(wp_unslash($_POST['message'] ?? '')); $phone_ok = (bool) preg_match('/^[+0-9() .\-]{7,40}$/', $v['phone']) && strlen(preg_replace('/\D/', '', $v['phone'])) >= 7; if ( mb_strlen($v['name']) < 2 || mb_strlen($v['name']) > 120 || !is_email($v['email']) || !$phone_ok || mb_strlen($v['message']) > 4000 || empty($_POST['consent']) || ($v['date'] !== '' && !preg_match('/^\d{4}-\d{2}-\d{2}$/', $v['date'])) ) { $fail('validation'); } $intent = $v['intent'] === 'viewing' ? 'Viewing request' : 'Information request'; $traffic = domo_source(sanitize_text_field(wp_unslash($_POST['utm'] ?? '')), esc_url_raw(wp_unslash($_POST['ref'] ?? ''))); $lines = [ 'Property: ' . ($d['name'] ?? $post->post_title), 'Page: ' . get_permalink($id), 'Listing source: ' . apply_filters('domopage_listing_source', (string) ($d['source'] ?? ''), $id, $traffic), 'Traffic source: ' . ucfirst($traffic), 'Type: ' . $intent, 'Language: ' . (domo_language_names()[$lang] ?? $lang), '', 'Name: ' . $v['name'], 'Email: ' . $v['email'], 'Phone: ' . $v['phone'], ]; if ($v['date']) { $lines[] = 'Preferred viewing date: ' . $v['date']; } if ($v['message']) { $lines[] = ''; $lines[] = 'Message:'; $lines[] = $v['message']; } $lines[] = ''; if ($s['marketing_optin']) { $lines[] = 'Marketing consent: ' . (empty($_POST['marketing']) ? 'NO - do not add to newsletters' : 'YES, given ' . gmdate('Y-m-d H:i:s') . ' UTC'); } $lines[] = 'Privacy policy accepted: ' . gmdate('Y-m-d H:i:s') . ' UTC (' . $s['privacy_url'] . ')'; $safe_name = trim(preg_replace('/[\r\n<>"]+/', ' ', $v['name'])); $subject = sprintf('[%s] %s: %s', $s['company'] ?: get_bloginfo('name'), $intent, $d['name'] ?? $post->post_title); $headers = ['Content-Type: text/plain; charset=UTF-8', 'Reply-To: ' . $safe_name . ' <' . $v['email'] . '>']; $sent = wp_mail(domo_enquiry_recipient($d), $subject, implode("\n", $lines), $headers); $v['marketing'] = !empty($_POST['marketing']); do_action('domopage_enquiry', $id, $v, $lang, $sent); if (!$sent) { $fail('send'); } set_transient($ip_key, 1, MINUTE_IN_SECONDS); domo_stats_bump($id, $lang, $traffic, ['enquiries' => 1]); wp_safe_redirect(add_query_arg('sent', '1', $back) . '#enquiry'); exit; } // Draft pages and form result pages are kept out of search results. add_filter('wp_robots', function ($robots) { if (is_singular('domo_property') && (is_preview() || isset($_GET['sent']) || isset($_GET['domo_err']))) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only display flags. $robots['noindex'] = true; } return $robots; });