'async', 'in_footer' => false)); }); /* AI assistants and search engines: seen on the server. ------------------ */ /** * The crawlers Delmora names, by a word in their user agent (the same list * as Delmora's own, edge/powers.js); Delmora checks again before counting. */ function delmora_is_crawler($user_agent) { if ($user_agent === '') { return false; } $tokens = array( 'GPTBot', 'ChatGPT-User', 'OAI-SearchBot', 'ClaudeBot', 'Claude-User', 'Claude-SearchBot', 'anthropic-ai', 'PerplexityBot', 'Perplexity-User', 'Google-Extended', 'Google-CloudVertexBot', 'Applebot', 'Meta-ExternalAgent', 'Meta-ExternalFetcher', 'FacebookBot', 'Bytespider', 'CCBot', 'Amazonbot', 'DuckAssistBot', 'MistralAI-User', 'cohere-ai', 'YouBot', 'Googlebot', 'Google-InspectionTool', 'bingbot', 'DuckDuckBot', 'YandexBot', 'Baiduspider', 'Slurp', ); foreach ($tokens as $token) { if (stripos($user_agent, $token) !== false) { return true; } } return false; } /** A page the site served to a reader: a GET that answered with HTML, outside the admin, feeds and APIs. */ function delmora_is_page_view() { if (is_admin() || wp_doing_ajax() || wp_doing_cron() || (defined('REST_REQUEST') && REST_REQUEST) || is_feed() || is_robots()) { return false; } if (!isset($_SERVER['REQUEST_METHOD']) || $_SERVER['REQUEST_METHOD'] !== 'GET') { return false; } $status = http_response_code(); if (!(($status >= 200 && $status < 300) || $status === 304)) { return false; } foreach (headers_list() as $header) { if (stripos($header, 'content-type:') === 0 && stripos($header, 'text/html') === false) { return false; } } return true; } add_action('shutdown', function () { $key = delmora_key(); $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? substr(sanitize_text_field(wp_unslash($_SERVER['HTTP_USER_AGENT'])), 0, 500) : ''; if ($key === '' || !delmora_is_crawler($user_agent) || !delmora_is_page_view()) { return; } $host = isset($_SERVER['HTTP_HOST']) ? sanitize_text_field(wp_unslash($_SERVER['HTTP_HOST'])) : (string) wp_parse_url(home_url(), PHP_URL_HOST); $path = isset($_SERVER['REQUEST_URI']) ? esc_url_raw(wp_unslash($_SERVER['REQUEST_URI'])) : '/'; $page = (is_ssl() ? 'https://' : 'http://') . $host . $path; // Sent without waiting for an answer: the crawler's page is never slowed down. wp_remote_post(delmora_origin() . '/c/' . $key, array( 'blocking' => false, 'timeout' => 1, 'headers' => array('Content-Type' => 'text/plain'), 'body' => wp_json_encode(array('u' => substr($page, 0, 800), 'a' => $user_agent)), )); }); /* Forms, from the form plugins themselves (from 0.5.0). ------------------ */ /* * Each form plugin's own "entry received" hook hands the entry to Delmora from * the site's server, so a visitor whose browser blocks trackers still becomes * a lead: the form plugin's own connection, never a way around the blocker * (Nate, 2026-10-27). The tag's script stamps each form it sees sent with * the id it gives the entry (a hidden "_delmora" field, on sites with this * plugin only), so its copy and this one are one entry in Delmora, whichever * arrives first. */ // Tells the tag's script to stamp forms here. add_filter('script_loader_tag', function ($tag, $handle) { return $handle === 'delmora-tag' ? preg_replace('/' . "\n"; if (delmora_has_seo_plugin()) { return; } if ($fixes['description'] !== '') { echo '' . "\n"; } echo '' . "\n"; if ($fixes['image'] !== '') { echo '' . "\n"; } }, 3); // llms.txt: answered here only when the site has no file of its own (a real file never reaches WordPress). add_action('parse_request', function () { if (!isset($_SERVER['REQUEST_URI'])) { return; } $path = (string) wp_parse_url(esc_url_raw(wp_unslash($_SERVER['REQUEST_URI'])), PHP_URL_PATH); if ($path !== '/llms.txt') { return; } $fixes = delmora_fixes(); if (!$fixes || $fixes['llms'] === '') { return; } header('Content-Type: text/plain; charset=utf-8'); echo $fixes['llms']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- plain text, sanitized when saved. exit; }, 5); /** Delmora's connect page, with this site and the way back to this settings page. */ function delmora_connect_url() { return add_query_arg(array( 'site' => home_url('/'), 'admin' => admin_url('options-general.php?page=delmora'), ), delmora_app() . '/connect/wordpress'); } /* Settings → Delmora. ---------------------------------------------------- */ add_action('admin_init', function () { register_setting('delmora', DELMORA_OPTION, array( 'type' => 'string', 'default' => '', 'sanitize_callback' => function ($input) { $key = delmora_parse_key($input); if ($key === '' && trim((string) $input) !== '') { add_settings_error(DELMORA_OPTION, 'delmora_key', __('That is not a Delmora site key. Copy the line from Delmora (Settings → Domains → Your site tag) and paste it here.', 'delmora')); return delmora_key(); } return $key; }, )); }); add_action('admin_menu', function () { add_options_page(__('Delmora', 'delmora'), __('Delmora', 'delmora'), 'manage_options', 'delmora', 'delmora_settings_page'); }); add_filter('plugin_action_links_' . plugin_basename(__FILE__), function ($links) { array_unshift($links, '' . esc_html__('Settings', 'delmora') . ''); return $links; }); function delmora_settings_page() { if (!current_user_can('manage_options')) { return; } $key = delmora_key(); // phpcs:disable WordPress.Security.NonceVerification.Recommended -- only says how Delmora's connect page came back; changes nothing. $outcome = isset($_GET['delmora']) ? sanitize_key(wp_unslash($_GET['delmora'])) : ''; $reason = isset($_GET['reason']) ? sanitize_text_field(wp_unslash($_GET['reason'])) : ''; // phpcs:enable ?>

style="margin-top:24px">