Install the plugin
Download the zip, upload it in WordPress, and activate SearchCue from your plugins screen.
The SearchCue WordPress plugin makes it easy to add SearchCue to your WordPress site. You can read the source code below, or download the plugin ready to install.
Download the zip, upload it in WordPress, and activate SearchCue from your plugins screen.
Sign in to SearchCue, copy your site settings, and let the hosted crawler index your public content.
SearchCue runs search and answers from our hosted index instead of adding a heavy search engine to your database.
The browser below is generated from the plugin files during the site build. Pick a file to read it without downloading anything.
@font-face {
font-family: "Schibsted Grotesk";
src: url("../fonts/searchcue/SchibstedGrotesk-Regular.woff2") format("woff2");
font-weight: 400;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: "Schibsted Grotesk";
src: url("../fonts/searchcue/SchibstedGrotesk-Medium.woff2") format("woff2");
font-weight: 500;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: "Schibsted Grotesk";
src: url("../fonts/searchcue/SchibstedGrotesk-SemiBold.woff2") format("woff2");
font-weight: 600;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: "Schibsted Grotesk";
src: url("../fonts/searchcue/SchibstedGrotesk-Bold.woff2") format("woff2");
font-weight: 700;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: "Spline Sans Mono";
src: url("../fonts/searchcue/SplineSansMono-Regular.woff2") format("woff2");
font-weight: 400;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: "Spline Sans Mono";
src: url("../fonts/searchcue/SplineSansMono-Medium.woff2") format("woff2");
font-weight: 500;
font-style: normal;
font-display: swap;
}
.searchcue-admin {
--searchcue-ink-900: #1b1b19;
--searchcue-ink-700: #44443f;
--searchcue-ink-500: #6e6e66;
--searchcue-ink-300: #b0b0a7;
--searchcue-paper: #fafaf6;
--searchcue-paper-shade: #f2f2ec;
--searchcue-surface: #ffffff;
--searchcue-line-strong: #cfcfc6;
--searchcue-line: #e2e2da;
--searchcue-line-soft: #edede6;
--searchcue-cue: #1e6b50;
--searchcue-cue-deep: #14503b;
--searchcue-cue-wash: #e9f2ec;
--searchcue-cue-line: #bfd9cb;
--searchcue-ok: #1e6b50;
--searchcue-ok-wash: #e9f2ec;
--searchcue-warn: #8a6018;
--searchcue-warn-wash: #f7f0df;
--searchcue-font-mono: "Spline Sans Mono", ui-monospace, "SF Mono", Menlo, monospace;
color: var(--searchcue-ink-900);
font-family: "Schibsted Grotesk", "Helvetica Neue", Helvetica, Arial, sans-serif;
max-width: 1120px;
}
.searchcue-admin * {
box-sizing: border-box;
}
.searchcue-mono {
font-family: var(--searchcue-font-mono);
}
.searchcue-hero {
align-items: stretch;
background: var(--searchcue-paper);
border: 1px solid var(--searchcue-line);
border-radius: 6px;
display: grid;
gap: 0;
grid-template-columns: minmax(0, 1fr);
margin: 22px 0;
overflow: hidden;
}
.searchcue-hero-copy {
padding: 34px;
}
.searchcue-admin h1,
.searchcue-admin h2 {
color: var(--searchcue-ink-900);
font-weight: 600;
letter-spacing: 0;
}
.searchcue-admin h1 {
font-size: 42px;
line-height: 1.08;
margin: 0;
max-width: 720px;
}
.searchcue-admin .searchcue-wordmark {
align-items: baseline;
display: inline-flex;
font-weight: 700;
gap: 3px;
letter-spacing: -0.022em;
line-height: 1;
white-space: nowrap;
}
.searchcue-wordmark-caret {
background: var(--searchcue-cue);
border-radius: 1px;
display: inline-block;
height: 0.78em;
transform: translateY(0.04em);
width: 0.09em;
}
.searchcue-connected-status {
align-items: center;
color: var(--searchcue-ink-700);
display: flex;
font-size: 15px;
font-weight: 600;
gap: 8px;
margin: 16px 0 0;
}
.searchcue-connected-check {
align-items: center;
background: var(--searchcue-ok-wash);
border-radius: 9999px;
color: var(--searchcue-ok);
display: inline-flex;
height: 20px;
justify-content: center;
width: 20px;
}
.searchcue-connected-check svg {
display: block;
height: 12px;
width: 12px;
}
.searchcue-intro {
color: var(--searchcue-ink-500);
font-size: 17px;
line-height: 1.6;
margin: 18px 0 0;
max-width: 680px;
}
.searchcue-status-badge {
border-radius: 2px;
display: inline-flex;
font-size: 12px;
font-weight: 700;
line-height: 1;
margin: 0 0 18px;
padding: 6px 8px;
}
.searchcue-status-badge.is-connected {
background: var(--searchcue-cue-wash);
color: var(--searchcue-cue);
}
.searchcue-status-badge.is-needed {
background: var(--searchcue-warn-wash);
color: var(--searchcue-warn);
}
.searchcue-settings {
background: var(--searchcue-surface);
border: 1px solid var(--searchcue-line);
border-radius: 6px;
margin: 0 0 18px;
padding: 30px 34px 18px;
}
.searchcue-field {
max-width: 720px;
}
.searchcue-label {
color: var(--searchcue-ink-900);
display: block;
font-size: 14px;
font-weight: 500;
margin-bottom: 8px;
}
.searchcue-input {
border-color: var(--searchcue-line-strong);
border-radius: 4px;
font-size: 18px;
max-width: 440px;
min-height: 46px;
padding: 8px 12px;
width: 100%;
}
.searchcue-input:focus {
border-color: var(--searchcue-cue);
box-shadow: 0 0 0 3px var(--searchcue-cue-wash);
outline: none;
}
.searchcue-help {
color: var(--searchcue-ink-500);
font-size: 14px;
line-height: 1.55;
margin: 8px 0 0;
}
.searchcue-toggle {
align-items: flex-start;
cursor: pointer;
display: flex;
gap: 14px;
margin-top: 0;
max-width: 720px;
padding-top: 0;
position: relative;
}
.searchcue-toggle .searchcue-switch-input {
height: 1px;
left: 0;
margin: 0;
min-height: 1px;
min-width: 1px;
opacity: 0;
position: absolute;
top: 0;
width: 1px;
}
.searchcue-switch {
background: var(--searchcue-line-strong);
border-radius: 999px;
flex: 0 0 auto;
height: 20px;
margin-top: 1px;
position: relative;
transition: background-color 120ms ease-out;
width: 34px;
}
.searchcue-switch::after {
background: var(--searchcue-surface);
border-radius: 999px;
content: "";
height: 16px;
left: 2px;
position: absolute;
top: 2px;
transition: transform 120ms ease-out;
width: 16px;
}
.searchcue-switch-input:checked + .searchcue-switch {
background: var(--searchcue-ink-900);
}
.searchcue-switch-input:checked + .searchcue-switch::after {
transform: translateX(14px);
}
.searchcue-switch-input:focus-visible + .searchcue-switch {
outline: 2px solid var(--searchcue-cue);
outline-offset: 2px;
}
.searchcue-toggle-title {
display: block;
font-size: 15px;
font-weight: 700;
margin-bottom: 4px;
}
.searchcue-actions {
margin-top: 26px;
}
.searchcue-onboarding {
background: var(--searchcue-surface);
border: 1px solid var(--searchcue-line);
border-radius: 6px;
margin: 0 0 18px;
padding: 30px 34px;
}
.searchcue-onboarding h2 {
font-size: 22px;
margin: 0;
}
.searchcue-setup-intro {
margin: 8px 0 24px;
max-width: 720px;
}
.searchcue-setup-toggle {
margin-top: 24px;
}
.searchcue-setup-consent {
font-size: 12px;
margin-top: 22px;
max-width: 720px;
}
.searchcue-alert {
background: var(--searchcue-cue-wash);
border: 1px solid var(--searchcue-cue-line);
border-radius: 6px;
color: var(--searchcue-cue-deep);
font-size: 14px;
line-height: 1.5;
margin: 0 0 18px;
padding: 14px 16px;
width: 100%;
}
.searchcue-alert.is-error {
background: var(--searchcue-warn-wash);
border-color: var(--searchcue-line-strong);
color: var(--searchcue-warn);
}
.searchcue-setup-consent a,
.searchcue-advanced a,
.searchcue-activation a {
color: var(--searchcue-cue);
text-decoration: underline;
text-decoration-thickness: 1px;
text-underline-offset: 3px;
}
.searchcue-setup-consent a:hover,
.searchcue-advanced a:hover,
.searchcue-activation a:hover {
color: var(--searchcue-cue-deep);
}
.searchcue-setup-consent a::after,
.searchcue-activation a::after {
background-color: currentColor;
content: "";
display: inline-block;
height: 0.78em;
-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 3.5h3.5V7'/%3E%3Cpath d='M12.5 3.5 7 9'/%3E%3Cpath d='M3.5 7v5.5H9'/%3E%3C/svg%3E") no-repeat center / contain;
mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 3.5h3.5V7'/%3E%3Cpath d='M12.5 3.5 7 9'/%3E%3Cpath d='M3.5 7v5.5H9'/%3E%3C/svg%3E") no-repeat center / contain;
margin-left: 0.18em;
transform: translateY(0.05em);
width: 0.78em;
}
.searchcue-actions .button-primary,
.searchcue-actions button[type="submit"] {
background: var(--searchcue-ink-900);
border-color: var(--searchcue-ink-900);
border-radius: 4px;
box-shadow: none;
color: var(--searchcue-paper);
font-weight: 600;
min-height: 40px;
padding-left: 18px;
padding-right: 18px;
}
.searchcue-actions .button-primary:hover,
.searchcue-actions button[type="submit"]:hover {
background: #000000;
border-color: #000000;
color: var(--searchcue-paper);
}
.searchcue-actions .button-primary:focus,
.searchcue-actions button[type="submit"]:focus {
border-color: var(--searchcue-cue);
box-shadow: none;
color: var(--searchcue-paper);
outline: 2px solid var(--searchcue-cue);
outline-offset: 2px;
}
.searchcue-actions .button-primary:disabled,
.searchcue-actions button[type="submit"]:disabled {
background: var(--searchcue-paper-shade) !important;
border-color: var(--searchcue-line-soft) !important;
box-shadow: none !important;
color: var(--searchcue-ink-300) !important;
cursor: not-allowed;
opacity: 1;
}
.searchcue-analytics {
background: var(--searchcue-surface);
border: 1px solid var(--searchcue-line);
border-radius: 6px;
margin: 0 0 18px;
padding: 30px 34px;
}
.searchcue-analytics.is-in-hero {
background: var(--searchcue-surface);
border: 0;
border-radius: 0;
border-top: 1px solid var(--searchcue-line);
margin: 0;
padding: 30px 34px;
}
.searchcue-analytics-header {
align-items: flex-start;
display: flex;
flex-wrap: wrap;
gap: 18px;
justify-content: space-between;
}
.searchcue-analytics-header > div:first-child {
flex: 1 1 360px;
min-width: 0;
}
.searchcue-analytics h2,
.searchcue-analytics h3 {
color: var(--searchcue-ink-900);
margin: 0;
}
.searchcue-analytics h2 {
font-size: 24px;
font-weight: 500;
}
.searchcue-analytics h3 {
font-size: 15px;
font-weight: 700;
}
.searchcue-analytics-kicker,
.searchcue-analytics-state {
color: var(--searchcue-ink-500);
font-size: 14px;
line-height: 1.55;
}
.searchcue-analytics-kicker {
margin: 12px 0 0;
}
.searchcue-analytics-state {
margin: 8px 0 0;
}
.searchcue-analytics-range {
color: var(--searchcue-cue);
font-size: 13px;
font-weight: 700;
}
.searchcue-analytics-link {
color: var(--searchcue-cue);
font-size: 14px;
font-weight: 700;
line-height: 1.2;
}
.searchcue-analytics-meta {
align-items: flex-end;
display: flex;
flex: 0 0 auto;
flex-direction: column;
gap: 8px;
margin-left: auto;
margin-top: 4px;
text-align: right;
}
.searchcue-analytics-metrics {
border-top: 1px solid var(--searchcue-line-soft);
display: grid;
gap: 24px;
grid-template-columns: repeat(3, minmax(0, 1fr));
margin-top: 24px;
padding-top: 24px;
}
.searchcue-analytics-metric {
min-width: 0;
}
.searchcue-analytics-metric span {
color: var(--searchcue-ink-500);
display: block;
font-size: 13px;
margin-bottom: 6px;
}
.searchcue-analytics-metric strong {
color: var(--searchcue-ink-900);
display: block;
font-size: 28px;
font-variant-numeric: tabular-nums;
font-weight: 600;
line-height: 1.1;
}
.searchcue-analytics-detail {
display: grid;
gap: 26px;
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
margin-top: 26px;
}
.searchcue-query-table {
margin-top: 14px;
overflow-x: auto;
}
.searchcue-query-table table {
border-collapse: collapse;
width: 100%;
}
.searchcue-query-table thead th {
border-bottom: 1px solid var(--searchcue-line);
color: var(--searchcue-ink-500);
font-size: 13px;
font-weight: 500;
padding: 0 0 10px;
text-align: left;
}
.searchcue-query-table thead th.searchcue-query-num {
text-align: right;
}
.searchcue-query-table tbody td {
border-bottom: 1px solid var(--searchcue-line-soft);
color: var(--searchcue-ink-700);
font-size: 14px;
padding: 11px 0;
}
.searchcue-query-table tbody tr:last-child td {
border-bottom: 0;
}
.searchcue-query-table tbody tr {
transition: background-color 140ms ease;
}
.searchcue-query-table tbody tr:hover {
background: var(--searchcue-paper-shade);
}
.searchcue-query-term {
color: var(--searchcue-ink-900);
font-weight: 600;
max-width: 0;
overflow: hidden;
padding-right: 16px;
text-overflow: ellipsis;
white-space: nowrap;
width: 100%;
}
.searchcue-query-num {
font-variant-numeric: tabular-nums;
text-align: right;
white-space: nowrap;
width: 1%;
}
.searchcue-volume-chart {
margin-top: 12px;
min-height: 180px;
}
.searchcue-volume-chart svg {
display: block;
height: 180px;
overflow: visible;
width: 100%;
}
.searchcue-volume-chart text {
fill: var(--searchcue-ink-500);
font-family: inherit;
font-size: 11px;
}
.searchcue-volume-grid {
stroke: var(--searchcue-line);
stroke-width: 1;
}
.searchcue-volume-axis {
stroke: var(--searchcue-ink-500);
stroke-width: 1;
}
.searchcue-volume-line {
fill: none;
stroke: var(--searchcue-cue);
stroke-linecap: round;
stroke-linejoin: round;
stroke-width: 3;
}
.searchcue-volume-point {
fill: var(--searchcue-surface);
stroke: var(--searchcue-cue);
stroke-width: 2.5;
}
.searchcue-empty {
color: var(--searchcue-ink-500);
font-size: 14px;
line-height: 1.55;
margin: 12px 0 0;
}
.searchcue-hidden {
display: none;
}
.searchcue-advanced {
margin-top: 28px;
max-width: 760px;
padding-top: 0;
}
.searchcue-advanced summary {
color: var(--searchcue-ink-900);
cursor: pointer;
font-size: 15px;
font-weight: 700;
}
.searchcue-advanced-body {
padding-top: 18px;
}
.searchcue-activation {
background: var(--searchcue-surface);
border: 1px solid var(--searchcue-line);
border-radius: 6px;
margin: 0 0 18px;
padding: 30px 34px;
}
.searchcue-activation h2 {
font-size: 22px;
margin: 0;
}
.searchcue-activation-intro {
color: var(--searchcue-ink-500);
font-size: 15px;
line-height: 1.6;
margin: 8px 0 0;
max-width: 720px;
}
.searchcue-activation-list {
list-style: none;
margin: 26px 0 0;
padding: 0;
}
.searchcue-activation-item {
padding: 22px 0;
}
.searchcue-activation-item:first-child {
padding-top: 0;
}
.searchcue-activation-item + .searchcue-activation-item {
border-top: 1px solid var(--searchcue-line);
}
.searchcue-activation-item h3 {
align-items: center;
color: var(--searchcue-ink-900);
display: flex;
flex-wrap: wrap;
font-size: 15px;
font-weight: 600;
gap: 10px;
margin: 0 0 6px;
}
.searchcue-activation-item .searchcue-status-badge {
margin: 0;
}
.searchcue-activation-body {
color: var(--searchcue-ink-700);
font-size: 15px;
line-height: 1.6;
margin: 0;
max-width: 720px;
}
.searchcue-activation-body code {
background: var(--searchcue-paper-shade);
border-radius: 3px;
font-size: 0.92em;
padding: 1px 5px;
}
.searchcue-code {
background: var(--searchcue-paper-shade);
border: 1px solid var(--searchcue-line);
border-radius: 4px;
color: var(--searchcue-ink-900);
font-family: var(--searchcue-font-mono);
font-size: 13px;
line-height: 1.6;
margin: 12px 0 0;
max-width: 720px;
overflow-x: auto;
padding: 12px 14px;
}
.searchcue-activation-docs {
color: var(--searchcue-ink-500);
font-size: 14px;
line-height: 1.55;
margin: 30px 0 0;
}
@media (prefers-reduced-motion: reduce) {
.searchcue-switch,
.searchcue-switch::after,
.searchcue-query-table tbody tr {
transition: none;
}
}
@media (max-width: 900px) {
.searchcue-hero {
grid-template-columns: 1fr;
}
.searchcue-analytics-detail,
.searchcue-analytics-metrics {
grid-template-columns: 1fr;
}
.searchcue-admin h1 {
font-size: 34px;
}
.searchcue-hero-copy,
.searchcue-analytics.is-in-hero,
.searchcue-analytics,
.searchcue-settings {
padding-left: 22px;
padding-right: 22px;
}
} Copyright 2023 The Schibsted-Grotesk Project Authors (https://github.com/schibsted/schibsted-grotesk)
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
https://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE. Copyright 2022 The Spline Sans Mono Project Authors (https://github.com/SorkinType/SplineSansMono)
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
https://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE. (function renderSettingsFormDirtyState() {
var form = document.querySelector("[data-searchcue-settings]");
if (!form) {
return;
}
var saveButton = form.querySelector("[data-searchcue-save]");
if (!saveButton) {
return;
}
var fields = Array.prototype.slice.call(
form.querySelectorAll("input[name^='donoharm_searchcue_options']")
);
function currentValue(field) {
return field.type === "checkbox" ? (field.checked ? "1" : "0") : field.value;
}
fields.forEach(function (field) {
field.dataset.searchcueInitialValue = currentValue(field);
});
function hasChanges() {
return fields.some(function (field) {
return currentValue(field) !== field.dataset.searchcueInitialValue;
});
}
function syncSaveButton() {
saveButton.disabled = !hasChanges();
}
fields.forEach(function (field) {
field.addEventListener("change", syncSaveButton);
field.addEventListener("input", syncSaveButton);
});
syncSaveButton();
})();
(function () {
var setup = document.querySelector("[data-searchcue-setup]");
if (!setup) {
return;
}
var endpoint = setup.getAttribute("data-endpoint");
var nonce = setup.getAttribute("data-nonce");
function checkSetup() {
var url = endpoint + "?action=donoharm_searchcue_setup_status&_ajax_nonce=" + encodeURIComponent(nonce);
fetch(url, { credentials: "same-origin" })
.then(function (response) { return response.json(); })
.then(function (payload) {
if (payload && payload.success && payload.data && payload.data.connected) {
window.location.reload();
}
})
.catch(function () {});
}
window.setInterval(checkSetup, 5000);
})();
(function () {
var card = document.querySelector("[data-searchcue-analytics]");
if (!card || card.getAttribute("data-enabled") !== "1") {
return;
}
var endpoint = card.getAttribute("data-endpoint");
var nonce = card.getAttribute("data-nonce");
var messages = window.donoharmSearchCueAdmin || {};
var state = card.querySelector("[data-searchcue-analytics-state]");
var content = card.querySelector("[data-searchcue-analytics-content]");
function setText(selector, value) {
var node = card.querySelector(selector);
if (node) {
node.textContent = formatCount(value);
}
}
function formatCount(value) {
var number = parseInt(value, 10);
if (isNaN(number)) {
number = 0;
}
return number.toLocaleString();
}
function showEmpty(selector, show) {
var node = card.querySelector(selector);
if (node) {
node.classList.toggle("searchcue-hidden", !show);
}
}
function formatSearchCount(value) {
return formatCount(value) + " " +
(value === 1 ? messages.searchSingular : messages.searchPlural);
}
function renderQueries(queries) {
var body = card.querySelector("[data-searchcue-analytics-queries]");
var table = card.querySelector("[data-searchcue-analytics-query-table]");
if (!body) {
return;
}
body.innerHTML = "";
if (!queries || !queries.length) {
if (table) {
table.classList.add("searchcue-hidden");
}
showEmpty("[data-searchcue-analytics-empty-queries]", true);
return;
}
if (table) {
table.classList.remove("searchcue-hidden");
}
showEmpty("[data-searchcue-analytics-empty-queries]", false);
queries.forEach(function (query) {
var row = document.createElement("tr");
var term = document.createElement("td");
var count = document.createElement("td");
term.className = "searchcue-query-term";
term.textContent = query.term || "";
count.className = "searchcue-query-num";
count.textContent = formatCount(query.searches);
row.appendChild(term);
row.appendChild(count);
body.appendChild(row);
});
}
function renderVolume(points) {
var chart = card.querySelector("[data-searchcue-analytics-volume]");
if (!chart) {
return;
}
chart.innerHTML = "";
if (!points || !points.length) {
chart.classList.add("searchcue-hidden");
showEmpty("[data-searchcue-analytics-empty-volume]", true);
return;
}
chart.classList.remove("searchcue-hidden");
showEmpty("[data-searchcue-analytics-empty-volume]", false);
var max = points.reduce(function (current, point) {
return Math.max(current, parseInt(point.count, 10) || 0);
}, 0);
var width = 360;
var height = 160;
var plot = {
left: 32,
right: 354,
top: 8,
bottom: 132
};
var plotWidth = plot.right - plot.left;
var plotHeight = plot.bottom - plot.top;
var svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
var chartPoints = points.map(function (point, index) {
var value = parseInt(point.count, 10) || 0;
return {
label: point.label || "",
value: value,
x: points.length === 1
? plot.left + plotWidth / 2
: plot.left + index / (points.length - 1) * plotWidth,
y: max > 0
? plot.top + (1 - value / max) * plotHeight
: plot.bottom
};
});
svg.setAttribute("viewBox", "0 0 " + width + " " + height);
svg.setAttribute("role", "img");
svg.setAttribute(
"aria-label",
messages.searchVolumeByDay + " " + chartPoints.map(function (point) {
return point.label + ": " + formatSearchCount(point.value);
}).join(", ")
);
var tickValues = max > 0 ? [max, max / 2, 0] : [0];
tickValues.forEach(function (tickValue) {
var tickY = max > 0
? plot.top + (1 - tickValue / max) * plotHeight
: plot.bottom;
var grid = document.createElementNS("http://www.w3.org/2000/svg", "line");
var label = document.createElementNS("http://www.w3.org/2000/svg", "text");
var roundedTick = Math.round(tickValue * 10) / 10;
grid.setAttribute("x1", plot.left);
grid.setAttribute("y1", tickY);
grid.setAttribute("x2", plot.right);
grid.setAttribute("y2", tickY);
grid.setAttribute(
"class",
tickValue === 0 ? "searchcue-volume-axis" : "searchcue-volume-grid"
);
label.setAttribute("x", plot.left - 8);
label.setAttribute("y", tickY);
label.setAttribute("text-anchor", "end");
label.setAttribute("dominant-baseline", "middle");
label.textContent = roundedTick.toLocaleString();
svg.appendChild(grid);
svg.appendChild(label);
});
chartPoints.forEach(function (point) {
var xLabel = document.createElementNS("http://www.w3.org/2000/svg", "text");
xLabel.setAttribute("x", point.x);
xLabel.setAttribute("y", plot.bottom + 20);
xLabel.setAttribute("text-anchor", "middle");
xLabel.textContent = point.label;
svg.appendChild(xLabel);
});
var line = document.createElementNS("http://www.w3.org/2000/svg", "polyline");
line.setAttribute("class", "searchcue-volume-line");
line.setAttribute("points", chartPoints.map(function (point) {
return point.x + "," + point.y;
}).join(" "));
svg.appendChild(line);
chartPoints.forEach(function (point) {
var circle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
var title = document.createElementNS("http://www.w3.org/2000/svg", "title");
circle.setAttribute("class", "searchcue-volume-point");
circle.setAttribute("cx", point.x);
circle.setAttribute("cy", point.y);
circle.setAttribute("r", 4);
title.textContent = point.label + ": " + formatSearchCount(point.value);
circle.appendChild(title);
svg.appendChild(circle);
});
chart.appendChild(svg);
}
fetch(endpoint + "?action=donoharm_searchcue_analytics&_ajax_nonce=" + encodeURIComponent(nonce), {
credentials: "same-origin"
})
.then(function (response) { return response.json(); })
.then(function (payload) {
if (!payload || !payload.success || !payload.data) {
throw new Error("analytics unavailable");
}
var data = payload.data;
var range = card.querySelector("[data-searchcue-analytics-range]");
if (range && data.range && data.range.label) {
range.textContent = data.range.label;
}
setText("[data-searchcue-analytics-searches]", data.totals && data.totals.searches);
setText("[data-searchcue-analytics-clicks]", data.totals && data.totals.clicks);
setText("[data-searchcue-analytics-zero-results]", data.totals && data.totals.zeroResults);
renderQueries(data.topQueries || []);
renderVolume(data.dailyVolume || []);
if (state) {
state.classList.add("searchcue-hidden");
}
if (content) {
content.classList.remove("searchcue-hidden");
}
})
.catch(function () {
if (state) {
state.textContent = messages.analyticsUnavailable;
}
});
})(); GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
<https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print such an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
SearchCue WordPress Plugin
Copyright (C) 2026 DoNoHarm - Bauer & Eide GbR
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, see <https://www.gnu.org/licenses/>. # SearchCue - WordPress Plugin
SearchCue is a hosted site search service with results that appear as visitors type, typo-tolerant matching, semantic search, and optional cited AI answers grounded in indexed content from your site.
The SearchCue WordPress plugin connects supported public pages, WooCommerce products, documents, and image content to that hosted search service. It can also notify SearchCue when public content changes, helping the hosted index stay current without building a search index in the WordPress database.
Please note that SearchCue is a paid service. You can try it for free for 15 days, and there are no bad feelings if you decide it isn't for you. We won't try to upsell you or trick you to become a customer. If you want more information about what the service costs before getting started, please check our [website here](https://searchcue.com).
## Plugin features
- Adds the SearchCue embed script into the `<head>` of every public page
- Adds a **SearchCue** admin menu page to configure SearchCue
- Optional automatic pings to SearchCue when content changes in order to keep the search index up to date
- Exposes the published, visible WooCommerce catalog to the connected SearchCue backend through an authenticated endpoint
- No third-party PHP dependencies
- The search index is hosted by SearchCue rather than built or queried in the WordPress database
## SearchCue features
- Typeahead keyword search
- AI answers and conversational search
- Design editor making it easy to adapt the search interface to the design of your site
- Search analytics
- Advanced tuning controls
- The ability to upload additional custom data you want to make searchable
- Rich WooCommerce product and variation results with prices, images, attributes, and faceted filters
## Installation
### From ZIP (for production use)
1. Download the plugin ZIP
2. In WordPress admin, go to **Plugins > Add New > Upload Plugin**
3. Upload the ZIP and activate
## Configuration
1. Open **SearchCue** from the WordPress admin menu
2. Enter your email and follow the sign-in link to connect the site
3. Keep **Automatic updates** checked if you want SearchCue to re-index changed pages automatically
4. Optionally set a different Site ID under **Advanced settings**
5. Save changes
The embed script will appear in the `<head>` of all public pages that call `wp_head()`.
## External Service and Privacy
The plugin requires the hosted SearchCue service; it has no third-party PHP dependencies. A SearchCue account is required, and continued service after the free trial requires a paid subscription.
Once connected, the plugin loads SearchCue's executable browser embed, sends public content updates when enabled, and exchanges setup and analytics data with SearchCue. SearchCue also pulls the WooCommerce catalog through an authenticated endpoint, including product names, descriptions, public URLs, product and variation IDs, SKUs, prices and currency, sale and stock status, categories and tags, attributes, images, and timestamps. Only published, visible catalog data is shared. The plugin does not share drafts, hidden or password-protected products, orders, customers, or download files. Automatic updates sends the parent product URL after product or variation changes. The embed processes visitor searches and interaction metrics. The settings page uses locally bundled SearchCue font files under the SIL Open Font License 1.1.
See the complete data-flow disclosure in [`readme.txt`](readme.txt), the [SearchCue terms and conditions](https://searchcue.com/terms/), and the [SearchCue privacy policy](https://donoharm.world/privacy-policy/searchcue/).
## Uninstalling
When you delete the plugin through WordPress, `uninstall.php` runs automatically and removes all stored options from the database.
## License
This plugin is licensed under the [GNU General Public License v2.0 or later](https://www.gnu.org/licenses/gpl-2.0.html) (GPLv2+), which is the same license as WordPress itself. This is required for plugins published in the [WordPress.org Plugin Directory](https://developer.wordpress.org/plugins/wordpress-org/detailed-plugin-guidelines/#1-plugins-must-be-compatible-with-the-gnu-general-public-license). === SearchCue: AI Site Search & Answers ===
Contributors: donoharm
Tags: search, site search, ai search, chatbot, agent
Requires at least: 6.0
Tested up to: 7.1
Stable tag: 0.2
Requires PHP: 7.4
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Fast, typo-tolerant site search with cited AI answers for your pages, products, and documents. Fast setup, no code, and no local search index.
== Description ==
Give your visitors instant, typo-tolerant search, combined with AI answers that are based on your content only. SearchCue takes five minutes to install, and since you don't have to hold the local index in your database, it keeps your backend clean.
[Live demo](https://searchcue.com/) | [Pricing](https://searchcue.com/#pricing) | [Docs](https://searchcue.com/docs/) | [Privacy policy](https://donoharm.world/privacy-policy/searchcue/)
**What you get**
Search that works:
* Real-time, typo-tolerant results that appear as visitors type
* Search across pages, PDFs, Word documents, PowerPoint presentations, and other supported documents
* OCR and image understanding that can make image content discoverable when useful text is missing
* Rich WooCommerce product and variation results with prices, sale and stock status, images, attributes, categories, tags, and faceted filters
Answers, not just links:
* Optional cited AI answers generated from your indexed site content, with links to the sources used
* Semantic matching that can find relevant pages even when a query uses different wording
You stay in control:
* Search lenses for including or excluding URL paths and serving the right content for different site sections or language paths
* Built-in search analytics showing popular terms, clicks, and searches that returned no results
* A hosted design editor for adapting the search interface without changing the plugin
* Optional automatic content-update notifications when public pages, posts, custom post types, or attachments change
**Works beyond WordPress**
The same SearchCue account can also provide search for Webflow, Shopify, Squarespace, and hand-built sites.
**Pricing**
The plugin is free and GPL-licensed. The hosted service starts with a 15-day free trial, no credit card required. After that, plans start at €9 per month and include an AI answer allowance. You can set a hard monthly AI budget; once it is reached, SearchCue can fall back to keyword results at no extra cost. Paying for AI answers beyond the allowance is always optional. See the [current SearchCue pricing and plan limits](https://searchcue.com/#pricing).
== Screenshots ==
1. One search window for keyword results and cited AI answers
2. Easily change colours, layout, position and more in the design editor
== Installation ==
1. Install and activate SearchCue through the WordPress Plugins screen.
2. Open SearchCue in WordPress admin and enter your email address.
3. Follow the magic link to sign up or sign in and connect the site.
4. SearchCue crawls the site and enables its floating search launcher. It can also use your existing search input or any link to `/search`.
== Frequently Asked Questions ==
= What are cited AI answers? =
SearchCue can answer a visitor's question using indexed content from your site and link to the sources used. AI answers can be incomplete or inaccurate, so visitors should use the cited sources to verify important information.
= What does it cost? =
The plugin is free. The hosted service has a 15-day free trial with no credit card. Paid plans currently start at €9 per month. Current prices and limits are listed on the [SearchCue pricing page](https://searchcue.com/#pricing).
= Does it slow down my site or database? =
The browser embed loads asynchronously, and SearchCue does not build or query a local search index. The plugin stores its settings in WordPress and, when Automatic updates is enabled, sends notifications after public content changes.
= Does it answer unrelated general-knowledge questions? =
SearchCue is designed to answer from the content indexed for your site. If the indexed sources do not support an answer, it should say that it could not find one rather than inventing an answer.
= Does it search images? =
SearchCue can use OCR to read text inside images and image understanding to describe what they show. This can make image content discoverable even when captions or alt text are missing.
= Do I need to change my theme or add code? =
No. SearchCue includes a floating search launcher and can take over a standard search input or any link to `/search`. As with other frontend plugins, the theme must call the standard WordPress `wp_head()` function.
= Does it search PDFs and office documents? =
Yes. Supported PDFs, Word documents, PowerPoint presentations, and spreadsheets can be indexed alongside your pages, so manuals, specifications, and price lists can appear in results.
= Does it provide faceted filters or refinement menus? =
Yes. When WooCommerce is active, SearchCue indexes published, catalog-visible products and visible variations as rich product results. Their prices, sale and stock status, categories, tags, and attributes can power faceted filters and refinement menus. Ordinary page crawling remains available if the catalog cannot be retrieved.
= Can I limit search to one section or language? =
Yes. Search lenses can include or exclude URL paths and select different content for sections or language paths on your site.
= Can I disable automatic content updates? =
Yes. Disable Automatic updates in the SearchCue settings page to stop the plugin from sending changed public URLs.
= Does SearchCue work without an account? =
No. The plugin is an interface to the hosted SearchCue service. An account and an active trial or paid subscription are required for hosted search.
= Is this compatible with my WordPress version? =
The clean-install matrix covers WordPress 6.0 through 7.1 and PHP 7.4 through 8.5. It tests the PHP 7.4 floor on WordPress 6.0, every PHP 8 minor, and the available PHP 8.2 and 8.5 boundaries on WordPress 7.1 with debugging enabled.
== External services ==
SearchCue is a hosted site search and optional cited AI answer service. The plugin makes these external requests:
* Setup and admin analytics: When an administrator submits the connection form, the plugin sends the email address, site URL, WordPress admin return URL, and a random setup state to `https://central.searchcue.com`. It later exchanges a one-time handoff token there and uses the assigned API key to retrieve site search analytics.
* Automatic content updates: While Automatic updates is enabled, the plugin sends the site hostname, an IndexNow verification key, and changed public URLs to `https://central.searchcue.com` so SearchCue can refresh the index. It sends the parent product URL after product or variation changes. Administrators can disable this in SearchCue settings.
* WooCommerce catalog indexing: SearchCue requests WooCommerce products and visible variations from an authenticated plugin endpoint. The plugin returns names, descriptions, public URLs, product and variation IDs, SKUs, prices and currency, sale and stock status, categories and tags, attributes, images, and timestamps. Only published, visible catalog data is returned. The plugin excludes drafts, hidden or password-protected products, orders, customers, and download files.
* Visitor search: After the site is connected, public pages load executable code from `https://searchcue.com/search-embed.js`. That embed contacts `https://central.searchcue.com` and `https://edge.searchcue.com` to load settings, perform searches, and record visitor search terms, originating page paths, whether searches returned results, clicked result paths, and search performance and outcome metrics. If cited answers are enabled, visitor questions and relevant indexed excerpts are sent to SearchCue for cited answer generation.
Admin interface fonts are bundled with the plugin under the SIL Open Font License 1.1 and do not make external requests. The font license texts are included with the font files.
Like other web requests, these connections disclose network information such as the requester IP address and browser user agent. SearchCue uses the data to provide, secure, maintain, troubleshoot, and improve the service and to show search analytics to the site administrator. Site administrators are responsible for providing any visitor privacy notices and obtaining any consent required for their site.
Use of the service is governed by the [SearchCue Terms and Conditions](https://searchcue.com/terms/). Data handling is described in the [SearchCue Privacy Policy](https://donoharm.world/privacy-policy/searchcue/).
== Hosted service disclosure ==
SearchCue is a software-as-a-service (SaaS) product operated by DoNoHarm GmbH. This plugin connects your site to SearchCue, which crawls or receives public content, hosts the search index, and serves visitor searches and optional AI answers. A SearchCue account is required. The plugin does not provide search locally without the hosted service.
By connecting a site, an administrator agrees to the SearchCue terms and acknowledges the privacy policy:
* Service: [https://searchcue.com/](https://searchcue.com/)
* Terms and Conditions: [https://searchcue.com/terms/](https://searchcue.com/terms/)
* Privacy Policy: [https://donoharm.world/privacy-policy/searchcue/](https://donoharm.world/privacy-policy/searchcue/)
== Changelog ==
= 0.2 =
* Add support for WooCommerce products.
= 0.1.2 =
* Fixes redirect to the SearchCue administrative interface after activation to help users complete the required setup.
= 0.1.1 =
* Declare compatibility with WordPress 7.1.
= 0.1.0 =
* Initial WordPress.org release. <?php
/**
* Plugin Name: SearchCue: AI Site Search & Answers
* Plugin URI: https://searchcue.com
* Description: Fast, typo-tolerant site search with cited AI answers for your pages, products, and documents. Fast setup, no code, and no local search index.
* Version: 0.2
* Requires at least: 6.0
* Requires PHP: 7.4
* Author: DoNoHarm
* Author URI: https://donoharm.world
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: searchcue
*
* @package DoNoHarm_SearchCue
*/
declare(strict_types=1);
namespace DoNoHarm\SearchCue;
if (!defined("ABSPATH")) {
exit();
}
const VERSION = "0.2";
const OPTION_NAME = "donoharm_searchcue_options";
const ACTIVATION_REDIRECT_OPTION = "donoharm_searchcue_activation_redirect";
const SETTINGS_GROUP = "donoharm_searchcue_settings";
const SETTINGS_PAGE = "searchcue";
const SETTINGS_SECTION = "donoharm_searchcue_main";
const EMBED_SCRIPT_HANDLE = "donoharm-searchcue-embed";
const ADMIN_ASSET_HANDLE = "donoharm-searchcue-admin";
const EMBED_SCRIPT_URL = "https://searchcue.com/search-embed.js";
const SEARCHCUE_APP_ENDPOINT = "https://searchcue.com";
const INDEXNOW_ENDPOINT = "https://central.searchcue.com/indexnow";
const WORDPRESS_INTEGRATION_ENDPOINT = "https://central.searchcue.com/site-search/integrations/wordpress";
const STAGING_SERVICE_ENDPOINT = "https://staging.searchcue.com";
const PRODUCT_EXPORT_PAGE_SIZE = 100;
const PRODUCT_EXPORT_MAX_VARIATIONS = 1000;
const PRODUCT_EXPORT_MAX_PAGES = 10000;
$donoharm_searchcue_pending_indexnow_urls = [];
function bootstrap(): void
{
add_action("wp_enqueue_scripts", __NAMESPACE__ . '\\enqueue_embed');
add_filter("script_loader_tag", __NAMESPACE__ . '\\add_embed_script_attributes', 10, 2);
add_action("admin_enqueue_scripts", __NAMESPACE__ . '\\enqueue_admin_assets');
add_action("template_redirect", __NAMESPACE__ . '\\serve_indexnow_keyfile');
add_action("admin_menu", __NAMESPACE__ . '\\register_admin_page');
add_action("admin_init", __NAMESPACE__ . '\\register_settings');
add_action("admin_init", __NAMESPACE__ . '\\maybe_complete_setup_from_handoff');
add_action("admin_init", __NAMESPACE__ . '\\maybe_redirect_after_activation');
add_action("admin_post_donoharm_searchcue_send_setup_link", __NAMESPACE__ . "\\send_setup_link");
add_action("wp_ajax_donoharm_searchcue_setup_status", __NAMESPACE__ . "\\ajax_setup_status");
add_action("wp_ajax_donoharm_searchcue_analytics", __NAMESPACE__ . "\\ajax_search_analytics");
add_action("rest_api_init", __NAMESPACE__ . "\\register_product_export_route");
register_update_hooks();
register_activation_hook(__FILE__, __NAMESPACE__ . "\\activate");
}
function activate(bool $network_wide = false): void
{
add_option(OPTION_NAME, default_options(), "", false);
if (!$network_wide && effective_site_id(get_searchcue_options()) === "") {
add_option(ACTIVATION_REDIRECT_OPTION, "1", "", false);
} else {
delete_option(ACTIVATION_REDIRECT_OPTION);
}
}
function maybe_redirect_after_activation(): void
{
if (
get_option(ACTIVATION_REDIRECT_OPTION) === false ||
(defined("WP_CLI") && WP_CLI === true) ||
wp_doing_ajax() ||
is_network_admin() ||
!current_user_can("manage_options") ||
(isset($_SERVER["REQUEST_METHOD"]) &&
sanitize_key(wp_unslash($_SERVER["REQUEST_METHOD"])) !== "get")
) {
return;
}
delete_option(ACTIVATION_REDIRECT_OPTION);
// phpcs:disable WordPress.Security.NonceVerification.Recommended -- These read-only markers only suppress a redirect.
$page = isset($_GET["page"])
? sanitize_key(sanitize_text_field(wp_unslash($_GET["page"])))
: "";
if (isset($_GET["activate-multi"]) || $page === SETTINGS_PAGE) {
return;
}
// phpcs:enable WordPress.Security.NonceVerification.Recommended
redirect_to_settings([]);
}
/**
* @return array{site_id: string, assigned_site_id: string, api_key: string, setup_state: string, push_updates: string, indexnow_key: string}
*/
function default_options(): array
{
return [
"site_id" => "",
"assigned_site_id" => "",
"api_key" => "",
"setup_state" => generate_setup_state(),
"push_updates" => "1",
"indexnow_key" => generate_indexnow_key(),
];
}
function product_export_secret(string $api_key): string
{
$key = hash("sha256", $api_key, true);
$signature = hash_hmac("sha256", "searchcue_wordpress_products_v1", $key, true);
return rtrim(strtr(base64_encode($signature), "+/", "-_"), "=");
}
function register_product_export_route(): void
{
register_rest_route("searchcue/v1", "/products", [
"methods" => "GET",
"callback" => __NAMESPACE__ . "\\export_products",
"permission_callback" => __NAMESPACE__ . "\\authorize_product_export",
]);
}
function authorize_product_export(\WP_REST_Request $request): bool
{
$api_key = get_searchcue_options()["api_key"];
if ($api_key === "") {
return false;
}
$authorization = $request->get_headers()["authorization"] ?? [];
if (
!is_array($authorization) ||
count($authorization) !== 1 ||
!is_string($authorization[0]) ||
preg_match('/\ABearer ([A-Za-z0-9_-]+)\z/', $authorization[0], $matches) !== 1
) {
return false;
}
return hash_equals(product_export_secret($api_key), $matches[1]);
}
function export_products(\WP_REST_Request $request): \WP_REST_Response
{
$page = min(max(1, (int) $request->get_param("page")), PRODUCT_EXPORT_MAX_PAGES);
if (!function_exists("wc_get_products")) {
return product_export_response([], $page, 0);
}
$query = wc_get_products([
"status" => "publish",
"limit" => PRODUCT_EXPORT_PAGE_SIZE,
"page" => $page,
"paginate" => true,
"orderby" => "id",
"order" => "ASC",
]);
if (
!is_object($query) ||
!isset($query->products, $query->max_num_pages) ||
!is_array($query->products) ||
!is_numeric($query->max_num_pages)
) {
return product_export_response([], $page, 0);
}
$products = [];
foreach ($query->products as $product) {
if (
!($product instanceof \WC_Product) ||
$product->get_parent_id() !== 0 ||
!$product->is_visible() ||
post_password_required($product->get_id())
) {
continue;
}
$records = product_export_records($product);
if ($records === null) {
return product_export_response([], $page, 0);
}
$products = array_merge($products, $records);
}
return product_export_response($products, $page, max(0, (int) $query->max_num_pages));
}
function product_export_response(array $products, int $page, int $total_pages): \WP_REST_Response
{
$response = new \WP_REST_Response([
"products" => $products,
"page" => $page,
"total_pages" => $total_pages,
]);
$response->header("Cache-Control", "private, no-store");
return $response;
}
function product_export_records(\WC_Product $parent): ?array
{
$url = get_permalink($parent->get_id());
if (!is_string($url) || $url === "") {
return [];
}
$name = product_export_text($parent->get_name());
$tags = product_export_terms($parent->get_id());
$records = [];
if ($parent instanceof \WC_Product_Variable) {
$child_ids = $parent->get_visible_children();
// ponytail: fail safely above this ceiling; add cursor pagination if real catalogs exceed it.
if (count($child_ids) > PRODUCT_EXPORT_MAX_VARIATIONS) {
return null;
}
foreach ($child_ids as $child_id) {
$variation = wc_get_product((int) $child_id);
if ($variation instanceof \WC_Product) {
$records[] = product_export_record($parent, $variation, $url, $name, $tags);
}
}
}
return $records === []
? [product_export_record($parent, $parent, $url, $name, $tags)]
: $records;
}
function product_export_record(
\WC_Product $parent,
\WC_Product $product,
string $url,
string $name,
array $tags
): array {
$price = product_export_price($product, $parent);
$sku = product_export_text($product->get_sku());
if ($sku === "" && $product !== $parent) {
$sku = product_export_text($parent->get_sku());
}
return [
"id" => (string) $product->get_id(),
"product_id" => (string) $parent->get_id(),
"sku" => $sku,
"name" => $name,
"description" => product_export_description($product, $parent),
"blocks" => [],
"store" => "",
"url" => $url,
"tags" => $tags,
"attributes" => product_export_attributes($product, $parent),
"on_sale" => $price["onSale"],
"in_stock" => $product->is_in_stock(),
"current_price" => $price[$price["onSale"] ? "salePrice" : "basePrice"],
"image" => product_export_image($product, $parent),
"price" => $price,
"created_at" => product_export_date($product, $parent),
];
}
function product_export_price(\WC_Product $product, \WC_Product $parent): array
{
$regular_price = (string) $product->get_regular_price();
$current_price = (string) $product->get_price();
$price_source = $product;
if ($product !== $parent && $regular_price === "" && $current_price === "") {
$regular_price = (string) $parent->get_regular_price();
$current_price = (string) $parent->get_price();
$price_source = $parent;
}
$base_price = $regular_price !== "" ? $regular_price : $current_price;
$on_sale = $price_source->is_on_sale();
$sale_price = $on_sale ? $current_price : $base_price;
$currency = (string) get_woocommerce_currency();
return [
"basePrice" => ["currency" => $currency, "value" => $base_price],
"salePrice" => ["currency" => $currency, "value" => $sale_price],
"onSale" => $on_sale,
];
}
function product_export_attributes(\WC_Product $product, \WC_Product $parent): array
{
$parent_attributes = $parent->get_attributes();
$visible_names = [];
$hidden_names = [];
foreach ($parent_attributes as $attribute_name => $attribute) {
$attribute_name = (string) $attribute_name;
if ($attribute instanceof \WC_Product_Attribute && !$attribute->get_visible()) {
$hidden_names[] = $attribute_name;
} else {
$visible_names[] = $attribute_name;
}
}
$attribute_names = $visible_names;
if ($product !== $parent) {
foreach (array_keys($product->get_attributes()) as $attribute_name) {
$attribute_name = (string) $attribute_name;
if (
!in_array($attribute_name, $hidden_names, true) &&
!in_array($attribute_name, $attribute_names, true)
) {
$attribute_names[] = $attribute_name;
}
}
}
$result = [];
foreach ($attribute_names as $attribute_name) {
$value = product_export_text($product->get_attribute($attribute_name));
if ($value === "" && $product !== $parent) {
$value = product_export_text($parent->get_attribute($attribute_name));
}
$label = product_export_text(wc_attribute_label($attribute_name, $parent));
if ($label !== "" && $value !== "") {
$result[$label] = $value;
}
}
return $result;
}
function product_export_terms(int $product_id): array
{
$terms = wp_get_post_terms(
$product_id,
["product_cat", "product_tag"],
["fields" => "names"],
);
if (is_wp_error($terms) || !is_array($terms)) {
return [];
}
$names = [];
foreach ($terms as $term) {
if (is_string($term)) {
$name = product_export_text($term);
if ($name !== "" && !in_array($name, $names, true)) {
$names[] = $name;
}
}
}
return $names;
}
function product_export_image(\WC_Product $product, \WC_Product $parent): ?array
{
$image_id = $product->get_image_id();
if ($image_id <= 0 && $product !== $parent) {
$image_id = $parent->get_image_id();
}
$image = $image_id > 0 ? wp_get_attachment_image_src($image_id, "full") : false;
if (
!is_array($image) ||
!isset($image[0], $image[1], $image[2]) ||
!is_string($image[0]) ||
$image[0] === ""
) {
return null;
}
return [
"url" => $image[0],
"width" => (int) $image[1],
"height" => (int) $image[2],
"focal_point_x" => 50,
"focal_point_y" => 50,
];
}
function product_export_description(\WC_Product $product, \WC_Product $parent): string
{
$description = product_export_text($product->get_description());
if ($description === "") {
$description = product_export_text($product->get_short_description());
}
if ($description === "" && $product !== $parent) {
$description = product_export_text($parent->get_description());
if ($description === "") {
$description = product_export_text($parent->get_short_description());
}
}
return $description;
}
function product_export_date(\WC_Product $product, \WC_Product $parent): ?string
{
$date = $product->get_date_created();
if (!($date instanceof \DateTimeInterface) && $product !== $parent) {
$date = $parent->get_date_created();
}
return $date instanceof \DateTimeInterface ? $date->format(DATE_ATOM) : null;
}
function product_export_text(string $text): string
{
$text = strip_shortcodes($text);
$text =
preg_replace(
'/<\/?(?:p|div|br|li|h[1-6]|tr|td|th|blockquote)\b[^>]*>/i',
" ",
$text,
) ?? $text;
$text = wp_strip_all_tags($text);
return trim(preg_replace('/\s+/', " ", $text) ?? $text);
}
/**
* @return array{site_id: string, assigned_site_id: string, api_key: string, setup_state: string, push_updates: string, indexnow_key: string}
*/
function get_searchcue_options(): array
{
$stored_options = get_option(OPTION_NAME);
return is_array($stored_options) ? normalize_options($stored_options) : default_options();
}
/**
* @return array{site_id: string, assigned_site_id: string, api_key: string, setup_state: string, push_updates: string, indexnow_key: string}
*/
function normalize_options(array $input): array
{
return [
"site_id" => sanitize_identifier($input["site_id"] ?? ""),
"assigned_site_id" => sanitize_identifier($input["assigned_site_id"] ?? ""),
"api_key" => sanitize_identifier($input["api_key"] ?? ""),
"setup_state" => sanitize_identifier($input["setup_state"] ?? ""),
"push_updates" => isset($input["push_updates"]) && $input["push_updates"] === "1" ? "1" : "0",
"indexnow_key" => sanitize_identifier($input["indexnow_key"] ?? ""),
];
}
/**
* Sanitizes the complete option array registered with WordPress.
*
* @param mixed $input
*
* @return array{site_id: string, assigned_site_id: string, api_key: string, setup_state: string, push_updates: string, indexnow_key: string}
*/
function sanitize_options($input): array
{
if (!is_array($input)) {
$input = get_searchcue_options();
}
$input["assigned_site_id"] = sanitize_hidden_option($input, "assigned_site_id");
$input["api_key"] = sanitize_hidden_option($input, "api_key");
$input["setup_state"] = sanitize_hidden_option($input, "setup_state");
$input["indexnow_key"] = sanitize_hidden_option($input, "indexnow_key");
$options = normalize_options($input);
if ($options["indexnow_key"] === "") {
$options["indexnow_key"] = generate_indexnow_key();
}
if ($options["setup_state"] === "") {
$options["setup_state"] = generate_setup_state();
}
return $options;
}
function sanitize_hidden_option(array $input, string $key): string
{
if (isset($input[$key]) && is_string($input[$key])) {
return sanitize_identifier($input[$key]);
}
$stored_options = get_option(OPTION_NAME, []);
$stored_value = is_array($stored_options) ? $stored_options[$key] ?? "" : "";
return sanitize_identifier($stored_value);
}
/**
* @param mixed $value
*/
function sanitize_identifier($value): string
{
if (!is_string($value)) {
return "";
}
$value = sanitize_text_field($value);
return preg_replace("/[^A-Za-z0-9_-]/", "", $value) ?? "";
}
function effective_site_id(array $options): string
{
return $options["site_id"] !== "" ? $options["site_id"] : $options["assigned_site_id"];
}
function enqueue_embed(): void
{
if (effective_site_id(get_searchcue_options()) === "") {
return;
}
wp_enqueue_script(
EMBED_SCRIPT_HANDLE,
searchcue_service_url(EMBED_SCRIPT_URL),
[],
VERSION,
false,
);
}
function add_embed_script_attributes(string $tag, string $handle): string
{
if ($handle !== EMBED_SCRIPT_HANDLE) {
return $tag;
}
$site_id = effective_site_id(get_searchcue_options());
if ($site_id === "") {
return $tag;
}
return str_replace(
" src=",
' async siteid="' . esc_attr($site_id) . '" src=',
$tag,
);
}
function enqueue_admin_assets(string $hook_suffix): void
{
if ($hook_suffix !== "toplevel_page_" . SETTINGS_PAGE) {
return;
}
$asset_url = plugin_dir_url(__FILE__) . "assets/";
wp_enqueue_style(ADMIN_ASSET_HANDLE, $asset_url . "css/admin.css", [], VERSION);
wp_enqueue_script(ADMIN_ASSET_HANDLE, $asset_url . "js/admin.js", [], VERSION, true);
wp_localize_script(ADMIN_ASSET_HANDLE, "donoharmSearchCueAdmin", [
"analyticsUnavailable" => __("Search activity is not available right now.", "searchcue"),
"searchVolumeByDay" => __("Search volume by day.", "searchcue"),
"searchSingular" => __("search", "searchcue"),
"searchPlural" => __("searches", "searchcue"),
]);
}
function register_admin_page(): void
{
add_menu_page(
__("SearchCue", "searchcue"),
__("SearchCue", "searchcue"),
"manage_options",
SETTINGS_PAGE,
__NAMESPACE__ . '\\render_settings_page',
"dashicons-search",
);
$options = get_searchcue_options();
if ($options["api_key"] === "") {
return;
}
$links = [
["documentation", __("Documentation", "searchcue")],
["design", __("Design", "searchcue")],
["analytics", __("Analytics", "searchcue")],
["more", __("SearchCue Dashboard", "searchcue")],
];
foreach ($links as [$destination, $label]) {
add_submenu_page(
SETTINGS_PAGE,
$label,
$label,
"manage_options",
searchcue_admin_url($options, $destination),
);
}
}
function register_settings(): void
{
register_setting(
SETTINGS_GROUP,
OPTION_NAME,
array(
"type" => "array",
"sanitize_callback" => "DoNoHarm\\SearchCue\\sanitize_options",
"default" => default_options(),
),
);
add_settings_section(
SETTINGS_SECTION,
__("Settings", "searchcue"),
"__return_empty_string",
SETTINGS_PAGE,
);
add_settings_field(
"donoharm_searchcue_site_id",
__("SearchCue Site ID", "searchcue"),
__NAMESPACE__ . '\\render_site_id_field',
SETTINGS_PAGE,
SETTINGS_SECTION,
);
add_settings_field(
"donoharm_searchcue_push_updates",
__("Automatic updates", "searchcue"),
__NAMESPACE__ . '\\render_push_updates_field',
SETTINGS_PAGE,
SETTINGS_SECTION,
);
}
function render_site_id_field(): void
{
$options = get_searchcue_options(); ?>
<input
id="donoharm_searchcue_site_id"
class="regular-text"
name="<?php echo esc_attr(OPTION_NAME); ?>[site_id]"
type="text"
value="<?php echo esc_attr($options["site_id"]); ?>"
placeholder="site_..."
autocomplete="off"
>
<p class="description">
<?php echo esc_html__(
"Only change this if you want to use a different search index than the default SearchCue assigned.",
"searchcue",
); ?>
</p>
<?php
}
function render_push_updates_field(): void
{
$options = get_searchcue_options(); ?>
<label for="donoharm_searchcue_push_updates">
<input
id="donoharm_searchcue_push_updates"
name="<?php echo esc_attr(OPTION_NAME); ?>[push_updates]"
type="checkbox"
value="1"
<?php checked($options["push_updates"], "1"); ?>
>
<?php echo esc_html__(
"Keep the SearchCue search index current as public pages and files change.",
"searchcue",
); ?>
</label>
<?php
}
function render_settings_page(): void
{
if (!current_user_can("manage_options")) {
return;
}
settings_errors();
$options = get_searchcue_options();
$effective_site_id = effective_site_id($options);
if ($effective_site_id === "") {
render_first_run_settings_page($options);
return;
}
render_connected_settings_page($options);
}
function render_first_run_settings_page(array $options): void
{
// phpcs:disable WordPress.Security.NonceVerification.Recommended -- This read-only status only controls a confirmation message.
$setup_status =
isset($_GET["donoharm_searchcue_setup"]) || isset($_GET["searchcue_setup"])
? sanitize_text_field(
wp_unslash($_GET["donoharm_searchcue_setup"] ?? $_GET["searchcue_setup"] ?? ""),
)
: "";
// phpcs:enable WordPress.Security.NonceVerification.Recommended
$setup_notices = [
"sent" => [
"message" => __("Check your email for the SearchCue sign-in link. This page will update when setup finishes in another tab.", "searchcue"),
"error" => false,
],
"invalid_email" => [
"message" => __("Enter a valid email address and try again.", "searchcue"),
"error" => true,
],
"send_failed" => [
"message" => __("SearchCue could not send the sign-in link. Please try again.", "searchcue"),
"error" => true,
],
"state_mismatch" => [
"message" => __("The setup link could not be verified. Request a new link and try again.", "searchcue"),
"error" => true,
],
"claim_failed" => [
"message" => __("SearchCue could not finish connecting this site. Please try again.", "searchcue"),
"error" => true,
],
"setup_verification_failed" => [
"message" => __("SearchCue could not verify control of this site. Check that the site address is correct and reachable, then request a new link.", "searchcue"),
"error" => true,
],
];
$setup_notice = $setup_notices[$setup_status] ?? null;
?>
<div class="wrap searchcue-admin">
<section class="searchcue-hero">
<div class="searchcue-hero-copy">
<h1>
<?php
printf(
/* translators: %s: SearchCue brand wordmark. */
esc_html__("Welcome to %s", "searchcue"),
'<span class="searchcue-wordmark"><span>' .
esc_html__("SearchCue", "searchcue") .
'</span><span class="searchcue-wordmark-caret" aria-hidden="true"></span></span>',
);
?>
</h1>
<p class="searchcue-intro">
<?php echo esc_html__(
"You can try SearchCue for free on your site. Once connected, SearchCue indexes your public content and keeps your search index managed as you publish.",
"searchcue",
); ?>
</p>
</div>
</section>
<section
class="searchcue-onboarding"
data-searchcue-setup
data-endpoint="<?php echo esc_url(admin_url("admin-ajax.php")); ?>"
data-nonce="<?php echo esc_attr(wp_create_nonce("donoharm_searchcue_setup_status")); ?>"
>
<span class="searchcue-status-badge is-needed">
<?php echo esc_html__("Setup needed", "searchcue"); ?>
</span>
<?php if (is_array($setup_notice)): ?>
<p
class="searchcue-alert<?php echo esc_attr($setup_notice["error"] ? " is-error" : ""); ?>"
role="<?php echo esc_attr($setup_notice["error"] ? "alert" : "status"); ?>"
>
<?php echo esc_html($setup_notice["message"]); ?>
</p>
<?php endif; ?>
<h2><?php echo esc_html__("Connect to SearchCue", "searchcue"); ?></h2>
<p class="searchcue-help searchcue-setup-intro">
<?php echo esc_html__(
"You need an account to use SearchCue. Enter your e-mail address and we will send you a link that can be used to sign up and connect your account to this site. If you already have a SearchCue account (welcome back), then please use the e-mail address associated with your existing account.",
"searchcue",
); ?>
</p>
<form action="<?php echo esc_url(admin_url("admin-post.php")); ?>" method="post">
<input type="hidden" name="action" value="donoharm_searchcue_send_setup_link">
<?php wp_nonce_field("donoharm_searchcue_setup", "donoharm_searchcue_setup_nonce"); ?>
<div class="searchcue-field">
<label class="searchcue-label" for="donoharm_searchcue_setup_email">
<?php echo esc_html__("E-mail", "searchcue"); ?>
</label>
<input
id="donoharm_searchcue_setup_email"
class="searchcue-input regular-text"
name="donoharm_searchcue_setup_email"
type="email"
autocomplete="email"
required
placeholder="my@email.com"
>
</div>
<label class="searchcue-toggle searchcue-setup-toggle" for="donoharm_searchcue_setup_push_updates">
<input
class="searchcue-switch-input"
id="donoharm_searchcue_setup_push_updates"
name="donoharm_searchcue_setup_push_updates"
type="checkbox"
value="1"
<?php checked($options["push_updates"], "1"); ?>
>
<span class="searchcue-switch" aria-hidden="true"></span>
<span>
<span class="searchcue-toggle-title">
<?php echo esc_html__("Automatic updates", "searchcue"); ?>
</span>
<span class="searchcue-help">
<?php echo esc_html__(
"Keep the search index current as you update public pages, posts, custom content, and files.",
"searchcue",
); ?>
</span>
</span>
</label>
<p class="searchcue-help searchcue-setup-consent">
<?php
echo wp_kses_post(
sprintf(
/* translators: 1: SearchCue Terms and Conditions link, 2: SearchCue Privacy Policy link. */
__(
'By submitting this form, you agree to the SearchCue %1$s and acknowledge the %2$s. Your email address and site URL will be sent to SearchCue to connect this site.',
"searchcue",
),
'<a href="' . esc_url("https://searchcue.com/terms/") . '" target="_blank" rel="noopener noreferrer">' . esc_html__("Terms and Conditions", "searchcue") . "</a>",
'<a href="' . esc_url("https://donoharm.world/privacy-policy/searchcue/") . '" target="_blank" rel="noopener noreferrer">' . esc_html__("Privacy Policy", "searchcue") . "</a>",
),
);
?>
</p>
<div class="searchcue-actions">
<button class="button button-primary" type="submit">
<?php echo esc_html__("Sign up or in", "searchcue"); ?>
</button>
</div>
</form>
</section>
</div>
<?php
}
function render_search_activation_card(array $options): void
{
?>
<section class="searchcue-activation">
<h2><?php echo esc_html__("Activate the search interface", "searchcue"); ?></h2>
<p class="searchcue-activation-intro">
<?php echo esc_html__(
"Visitors can open SearchCue in any of these ways. Use one, or combine them.",
"searchcue",
); ?>
</p>
<ul class="searchcue-activation-list">
<li class="searchcue-activation-item">
<h3>
<?php echo esc_html__("Use the floating search icon", "searchcue"); ?>
<span class="searchcue-status-badge is-connected"><?php echo esc_html__("Active by default", "searchcue"); ?></span>
</h3>
<p class="searchcue-activation-body">
<?php
printf(
/* translators: %s: link to the SearchCue design section. */
esc_html__(
"We have added a floating search icon to the bottom right of your site. You can change how it looks or remove it in the %s.",
"searchcue",
),
'<a href="' .
esc_url(searchcue_admin_url($options, "design") . "#search-launcher") .
'" target="_blank" rel="noopener noreferrer">' .
esc_html__("design section", "searchcue") .
"</a>",
);
?>
</p>
</li>
<li class="searchcue-activation-item">
<h3><?php echo esc_html__("Add a search link", "searchcue"); ?></h3>
<p class="searchcue-activation-body">
<?php
printf(
/* translators: %s: the /search path shown in monospace. */
esc_html__(
"Link to %s anywhere on your site, for example as a search button in your header or navigation. SearchCue opens automatically when a visitor clicks it.",
"searchcue",
),
'<code class="searchcue-mono">/search</code>',
);
?>
</p>
</li>
<li class="searchcue-activation-item">
<h3><?php echo esc_html__("Add a search input", "searchcue"); ?></h3>
<p class="searchcue-activation-body">
<?php echo esc_html__(
"Add an input of type search to your theme. SearchCue takes it over as soon as a visitor focuses it.",
"searchcue",
); ?>
</p>
<pre class="searchcue-code"><code><?php echo esc_html('<input type="search" placeholder="Search..." />'); ?></code></pre>
</li>
</ul>
<p class="searchcue-activation-docs">
<?php
printf(
/* translators: %s: link to the WordPress guide. */
esc_html__("For the full walkthrough, read the %s.", "searchcue"),
'<a href="' .
esc_url("https://searchcue.com/docs/tutorial-wordpress") .
'" target="_blank" rel="noopener noreferrer">' .
esc_html__("WordPress guide", "searchcue") .
"</a>",
);
?>
</p>
</section>
<?php
}
function render_connected_settings_page(array $options): void
{
?>
<div class="wrap searchcue-admin">
<section class="searchcue-hero is-connected">
<div class="searchcue-hero-copy">
<h1 class="searchcue-wordmark">
<span><?php echo esc_html__("SearchCue", "searchcue"); ?></span>
<span class="searchcue-wordmark-caret" aria-hidden="true"></span>
</h1>
<p class="searchcue-connected-status">
<span class="searchcue-connected-check" aria-hidden="true">
<svg viewBox="0 0 16 16" fill="none">
<path
d="M3.5 8.5 6.5 11.5 12.5 4.5"
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
/>
</svg>
</span>
<span><?php echo esc_html__("SearchCue is connected", "searchcue"); ?></span>
</p>
</div>
<?php render_search_analytics_card($options); ?>
</section>
<?php render_search_activation_card($options); ?>
<form class="searchcue-settings" action="options.php" method="post" data-searchcue-settings>
<?php settings_fields(SETTINGS_GROUP); ?>
<label class="searchcue-toggle" for="donoharm_searchcue_push_updates">
<input
class="searchcue-switch-input"
id="donoharm_searchcue_push_updates"
name="<?php echo esc_attr(OPTION_NAME); ?>[push_updates]"
type="checkbox"
value="1"
<?php checked($options["push_updates"], "1"); ?>
>
<span class="searchcue-switch" aria-hidden="true"></span>
<span>
<span class="searchcue-toggle-title">
<?php echo esc_html__("Automatic updates", "searchcue"); ?>
</span>
<span class="searchcue-help">
<?php echo esc_html__(
"Keep the search index current as you update public pages, posts, custom content, and files.",
"searchcue",
); ?>
</span>
</span>
</label>
<details class="searchcue-advanced">
<summary><?php echo esc_html__("Advanced settings", "searchcue"); ?></summary>
<div class="searchcue-advanced-body">
<div class="searchcue-field">
<label class="searchcue-label" for="donoharm_searchcue_site_id">
<?php echo esc_html__("SearchCue Site ID", "searchcue"); ?>
</label>
<input
id="donoharm_searchcue_site_id"
class="searchcue-input regular-text searchcue-mono"
name="<?php echo esc_attr(OPTION_NAME); ?>[site_id]"
type="text"
value="<?php echo esc_attr($options["site_id"]); ?>"
placeholder="<?php echo esc_attr($options["assigned_site_id"] !== "" ? $options["assigned_site_id"] : "site_..."); ?>"
autocomplete="off"
>
<p class="searchcue-help">
<?php echo esc_html__(
"Only change this if you want to use a different search index than the default SearchCue assigned.",
"searchcue",
); ?>
</p>
</div>
</div>
</details>
<div class="searchcue-actions">
<button
class="button button-primary searchcue-save"
type="submit"
name="submit"
data-searchcue-save
>
<?php echo esc_html__("Save SearchCue settings", "searchcue"); ?>
</button>
</div>
</form>
</div>
<?php
}
function render_search_analytics_card(array $options): void
{
$can_load_analytics = $options["api_key"] !== "";
?>
<div
class="searchcue-analytics is-in-hero"
data-searchcue-analytics
data-endpoint="<?php echo esc_url(admin_url("admin-ajax.php")); ?>"
data-nonce="<?php echo esc_attr(wp_create_nonce("donoharm_searchcue_analytics")); ?>"
data-enabled="<?php echo esc_attr($can_load_analytics ? "1" : "0"); ?>"
>
<div class="searchcue-analytics-header">
<div>
<h2><?php echo esc_html__("Search activity", "searchcue"); ?></h2>
<p class="searchcue-analytics-kicker">
<?php echo esc_html__(
"A quick view of how visitors use SearchCue on this site.",
"searchcue",
); ?>
</p>
</div>
<div class="searchcue-analytics-meta">
<span class="searchcue-analytics-range" data-searchcue-analytics-range>
<?php echo esc_html__("Last 30 days", "searchcue"); ?>
</span>
</div>
</div>
<p
class="searchcue-analytics-state"
role="status" aria-live="polite"
data-searchcue-analytics-state
>
<?php
echo $can_load_analytics
? esc_html__("Loading search activity...", "searchcue")
: esc_html__(
"Search activity will appear here once this site is connected with a SearchCue API key.",
"searchcue",
);
?>
</p>
<div class="searchcue-hidden" data-searchcue-analytics-content>
<div class="searchcue-analytics-metrics">
<div class="searchcue-analytics-metric">
<span><?php echo esc_html__("Searches", "searchcue"); ?></span>
<strong data-searchcue-analytics-searches>0</strong>
</div>
<div class="searchcue-analytics-metric">
<span><?php echo esc_html__("Clicks", "searchcue"); ?></span>
<strong data-searchcue-analytics-clicks>0</strong>
</div>
<div class="searchcue-analytics-metric">
<span><?php echo esc_html__("No-result searches", "searchcue"); ?></span>
<strong data-searchcue-analytics-zero-results>0</strong>
</div>
</div>
<div class="searchcue-analytics-detail">
<div>
<h3><?php echo esc_html__("Recent search terms", "searchcue"); ?></h3>
<div class="searchcue-query-table" data-searchcue-analytics-query-table>
<table>
<caption class="screen-reader-text">
<?php echo esc_html__("Recent search terms", "searchcue"); ?>
</caption>
<thead>
<tr>
<th scope="col">
<?php echo esc_html__("Search term", "searchcue"); ?>
</th>
<th scope="col" class="searchcue-query-num">
<?php echo esc_html__("Searches", "searchcue"); ?>
</th>
</tr>
</thead>
<tbody data-searchcue-analytics-queries></tbody>
</table>
</div>
<p class="searchcue-empty searchcue-hidden" data-searchcue-analytics-empty-queries>
<?php echo esc_html__(
"Search terms will appear once visitors start searching.",
"searchcue",
); ?>
</p>
</div>
<div>
<h3><?php echo esc_html__("Search volume", "searchcue"); ?></h3>
<div class="searchcue-volume-chart" data-searchcue-analytics-volume></div>
<p class="searchcue-empty searchcue-hidden" data-searchcue-analytics-empty-volume>
<?php echo esc_html__(
"Search volume will appear once there is activity in the current period.",
"searchcue",
); ?>
</p>
</div>
</div>
</div>
</div>
<?php
}
function send_setup_link(): void
{
if (!current_user_can("manage_options")) {
status_header(403);
return;
}
check_admin_referer("donoharm_searchcue_setup", "donoharm_searchcue_setup_nonce");
$email = isset($_POST["donoharm_searchcue_setup_email"])
? sanitize_email(
sanitize_text_field(wp_unslash($_POST["donoharm_searchcue_setup_email"])),
)
: "";
if (!is_email($email)) {
redirect_to_settings(["donoharm_searchcue_setup" => "invalid_email"]);
return;
}
$options = ensure_setup_state(get_searchcue_options());
$push_updates = isset($_POST["donoharm_searchcue_setup_push_updates"])
? sanitize_text_field(wp_unslash($_POST["donoharm_searchcue_setup_push_updates"]))
: "0";
$options["push_updates"] = $push_updates === "1" ? "1" : "0";
update_option(OPTION_NAME, sanitize_options($options));
$response = wp_safe_remote_post(wordpress_integration_url("/setup-link"), [
"timeout" => 10,
"headers" => [
"Content-Type" => "application/json",
],
"body" => wp_json_encode([
"email" => $email,
"site_url" => home_url("/"),
"return_url" => settings_page_url(),
"state" => $options["setup_state"],
]),
]);
if (!is_wp_error($response) && wp_remote_retrieve_response_code($response) === 200) {
redirect_to_settings(["donoharm_searchcue_setup" => "sent"]);
return;
}
redirect_to_settings(["donoharm_searchcue_setup" => "send_failed"]);
}
function maybe_complete_setup_from_handoff(): void
{
if (!current_user_can("manage_options")) {
return;
}
// phpcs:disable WordPress.Security.NonceVerification.Recommended -- The SearchCue setup state is verified below.
$page = isset($_GET["page"])
? sanitize_key(sanitize_text_field(wp_unslash($_GET["page"])))
: "";
if ($page !== SETTINGS_PAGE || !isset($_GET["state"], $_GET["handoff"])) {
return;
}
$state = sanitize_identifier(sanitize_text_field(wp_unslash($_GET["state"])));
$handoff = sanitize_identifier(sanitize_text_field(wp_unslash($_GET["handoff"])));
// phpcs:enable WordPress.Security.NonceVerification.Recommended
$options = get_searchcue_options();
$stored_state = $options["setup_state"] ?? "";
if (
$state === "" ||
$handoff === "" ||
!is_string($stored_state) ||
!hash_equals($stored_state, $state)
) {
redirect_to_settings(["donoharm_searchcue_setup" => "state_mismatch"]);
return;
}
$claim = claim_handoff($handoff);
if ($claim === null) {
redirect_to_settings(["donoharm_searchcue_setup" => "claim_failed"]);
return;
}
$options["api_key"] = $claim["api_key"];
$options["assigned_site_id"] = $claim["site_id"];
$options["setup_state"] = generate_setup_state();
update_option(OPTION_NAME, sanitize_options($options));
redirect_to_settings(["donoharm_searchcue_setup" => "connected"]);
}
function ajax_setup_status(): void
{
if (!current_user_can("manage_options")) {
wp_send_json_error(["connected" => false]);
return;
}
check_ajax_referer("donoharm_searchcue_setup_status");
$options = get_searchcue_options();
$site_id = effective_site_id($options);
wp_send_json_success([
"connected" => $site_id !== "",
"siteId" => $site_id,
"assignedSiteId" => $options["assigned_site_id"],
]);
}
function ajax_search_analytics(): void
{
if (!current_user_can("manage_options")) {
wp_send_json_error(["message" => "forbidden"]);
return;
}
check_ajax_referer("donoharm_searchcue_analytics");
$options = get_searchcue_options();
if ($options["api_key"] === "") {
wp_send_json_error(["message" => "missing_api_key"]);
return;
}
$analytics = fetch_site_analytics($options["api_key"]);
if ($analytics === null) {
wp_send_json_error(["message" => "analytics_unavailable"]);
return;
}
wp_send_json_success($analytics);
}
/**
* @return array{range: array{label: string, days: int}, totals: array{searches: int, zeroResults: int, clicks: int}, topQueries: array<int, array{term: string, searches: int}>, dailyVolume: array<int, array{label: string, count: int}>}|null
*/
function fetch_site_analytics(string $api_key): ?array
{
$response = wp_remote_get(wordpress_integration_url("/analytics.json"), [
"timeout" => 10,
"headers" => [
"Accept" => "application/json",
"Authorization" => "Bearer " . $api_key,
],
]);
if (is_wp_error($response) || wp_remote_retrieve_response_code($response) !== 200) {
return null;
}
$payload = json_decode(wp_remote_retrieve_body($response), true);
return sanitize_site_analytics_payload($payload);
}
/**
* @param mixed $payload
*
* @return array{range: array{label: string, days: int}, totals: array{searches: int, zeroResults: int, clicks: int}, topQueries: array<int, array{term: string, searches: int}>, dailyVolume: array<int, array{label: string, count: int}>}|null
*/
function sanitize_site_analytics_payload($payload): ?array
{
if (!is_array($payload)) {
return null;
}
$range = is_array($payload["range"] ?? null) ? $payload["range"] : [];
$totals = is_array($payload["totals"] ?? null) ? $payload["totals"] : [];
$top_queries = is_array($payload["topQueries"] ?? null) ? $payload["topQueries"] : [];
$daily_volume = is_array($payload["dailyVolume"] ?? null) ? $payload["dailyVolume"] : [];
return [
"range" => [
"label" => sanitize_text_field($range["label"] ?? "30 days"),
"days" => max(0, (int) ($range["days"] ?? 30)),
],
"totals" => [
"searches" => max(0, (int) ($totals["searches"] ?? 0)),
"zeroResults" => max(0, (int) ($totals["zeroResults"] ?? 0)),
"clicks" => max(0, (int) ($totals["clicks"] ?? 0)),
],
"topQueries" => sanitize_site_analytics_queries($top_queries),
"dailyVolume" => sanitize_site_analytics_volume($daily_volume),
];
}
/**
* @param array<int, mixed> $queries
*
* @return array<int, array{term: string, searches: int}>
*/
function sanitize_site_analytics_queries(array $queries): array
{
$sanitized = [];
foreach (array_slice($queries, 0, 5) as $query) {
if (!is_array($query)) {
continue;
}
$term = sanitize_text_field($query["term"] ?? "");
if ($term === "") {
continue;
}
$sanitized[] = [
"term" => $term,
"searches" => max(0, (int) ($query["searches"] ?? 0)),
];
}
return $sanitized;
}
/**
* @param array<int, mixed> $points
*
* @return array<int, array{label: string, count: int}>
*/
function sanitize_site_analytics_volume(array $points): array
{
$sanitized = [];
foreach (array_slice($points, -7) as $point) {
if (!is_array($point)) {
continue;
}
$label = sanitize_text_field($point["label"] ?? "");
if ($label === "") {
continue;
}
$sanitized[] = [
"label" => $label,
"count" => max(0, (int) ($point["count"] ?? 0)),
];
}
return $sanitized;
}
/**
* @return array{api_key: string, site_id: string}|null
*/
function claim_handoff(string $handoff): ?array
{
$response = wp_safe_remote_post(wordpress_integration_url("/claim"), [
"timeout" => 10,
"headers" => [
"Content-Type" => "application/json",
],
"body" => wp_json_encode([
"handoff" => $handoff,
"state" => get_searchcue_options()["setup_state"],
]),
]);
if (is_wp_error($response) || wp_remote_retrieve_response_code($response) !== 200) {
return null;
}
$payload = json_decode(wp_remote_retrieve_body($response), true);
if (
!is_array($payload) ||
!isset($payload["apiKey"], $payload["siteId"]) ||
!is_string($payload["apiKey"]) ||
!is_string($payload["siteId"])
) {
return null;
}
$api_key = sanitize_hidden_value($payload["apiKey"]);
$site_id = sanitize_hidden_value($payload["siteId"]);
return $api_key !== "" && $site_id !== ""
? ["api_key" => $api_key, "site_id" => $site_id]
: null;
}
function searchcue_admin_url(array $options, string $destination): string
{
$site_id = rawurlencode(effective_site_id($options));
switch ($destination) {
case "documentation":
return searchcue_app_url("/docs");
case "design":
return searchcue_app_url("/site-search/app/site/" . $site_id . "/design");
case "analytics":
return searchcue_app_url("/site-search/app/site/" . $site_id . "/analytics");
case "more":
default:
return searchcue_app_url("/site-search/app/site/" . $site_id);
}
}
function searchcue_service_url(string $production_url): string
{
if (
!defined("DONOHARM_SEARCHCUE_STAGING") ||
constant("DONOHARM_SEARCHCUE_STAGING") !== true
) {
return $production_url;
}
$path = wp_parse_url($production_url, PHP_URL_PATH);
return STAGING_SERVICE_ENDPOINT . (is_string($path) ? $path : "");
}
function searchcue_app_url(string $path): string
{
return rtrim(searchcue_service_url(SEARCHCUE_APP_ENDPOINT), "/") . "/" . ltrim($path, "/");
}
function wordpress_integration_url(string $path): string
{
return rtrim(searchcue_service_url(WORDPRESS_INTEGRATION_ENDPOINT), "/") . "/" . ltrim($path, "/");
}
function settings_page_url(): string
{
return admin_url("admin.php?page=" . SETTINGS_PAGE);
}
function redirect_to_settings(array $params): void
{
wp_safe_redirect(add_query_arg($params, settings_page_url()));
if (!defined("DONOHARM_SEARCHCUE_TESTING") || DONOHARM_SEARCHCUE_TESTING !== true) {
exit();
}
}
function ensure_setup_state(array $options): array
{
if ($options["setup_state"] === "") {
$options["setup_state"] = generate_setup_state();
update_option(OPTION_NAME, sanitize_options($options));
}
return $options;
}
function sanitize_hidden_value(string $value): string
{
return sanitize_identifier($value);
}
function register_update_hooks(): void
{
add_action("save_post", __NAMESPACE__ . "\\queue_post_update", 10, 3);
add_action("pre_post_update", __NAMESPACE__ . "\\queue_current_post_urls");
add_action("before_delete_post", __NAMESPACE__ . "\\queue_current_post_urls");
add_action("add_attachment", __NAMESPACE__ . "\\queue_attachment_update");
add_action("edit_attachment", __NAMESPACE__ . "\\queue_attachment_update");
add_action("delete_attachment", __NAMESPACE__ . "\\queue_current_post_urls");
add_action("woocommerce_update_product", __NAMESPACE__ . "\\queue_post_update", 10, 1);
add_action("woocommerce_update_product_variation", __NAMESPACE__ . "\\queue_post_update", 10, 1);
add_action("shutdown", __NAMESPACE__ . "\\flush_indexnow_updates");
}
function serve_indexnow_keyfile(): void
{
$request_uri = isset($_SERVER["REQUEST_URI"])
? sanitize_text_field(wp_unslash($_SERVER["REQUEST_URI"]))
: "";
$path = wp_parse_url($request_uri, PHP_URL_PATH);
$path = is_string($path) ? $path : "";
$verification_state = setup_verification_content_for_path($path);
if ($verification_state !== null) {
status_header(200);
header("Content-Type: text/plain; charset=utf-8");
header("Cache-Control: no-store");
echo esc_html(setup_verification_body($verification_state));
if (!defined("DONOHARM_SEARCHCUE_TESTING") || DONOHARM_SEARCHCUE_TESTING !== true) {
exit();
}
return;
}
$content = keyfile_content_for_path($path);
if ($content === null) {
return;
}
status_header(200);
header("Content-Type: text/plain; charset=utf-8");
header("X-Robots-Tag: noindex");
echo esc_html($content);
if (!defined("DONOHARM_SEARCHCUE_TESTING") || DONOHARM_SEARCHCUE_TESTING !== true) {
exit();
}
}
function setup_verification_content_for_path(string $path): ?string
{
$state = get_searchcue_options()["setup_state"];
if ($state === "") {
return null;
}
return rawurldecode($path) === "/" . $state . ".txt" ? $state : null;
}
function setup_verification_body(string $state): string
{
return rtrim(
strtr(
base64_encode(hash("sha256", "searchcue_wordpress_setup_verification:" . $state, true)),
"+/",
"-_",
),
"=",
);
}
function keyfile_content_for_path(string $path): ?string
{
$options = get_searchcue_options();
if ($options["push_updates"] !== "1" || $options["indexnow_key"] === "") {
return null;
}
$expected_path = "/" . $options["indexnow_key"] . ".txt";
return rawurldecode($path) === $expected_path ? $options["indexnow_key"] : null;
}
function queue_post_update(int $post_id): void
{
if (!updates_enabled() || wp_is_post_revision($post_id) || wp_is_post_autosave($post_id)) {
return;
}
$post = get_post($post_id);
if ($post) {
queue_post_url($post);
}
}
function queue_current_post_urls(int $post_id): void
{
if (!updates_enabled()) {
return;
}
$post = get_post($post_id);
if ($post) {
queue_post_url($post);
if (is_post_publicly_viewable($post)) {
if (get_post_type($post) === "attachment") {
queue_attachment_url($post_id);
} else {
queue_attached_media_urls($post_id);
}
}
}
}
function queue_post_url($post): void
{
$post_id = is_object($post) && isset($post->ID) ? (int) $post->ID : 0;
if ($post_id > 0 && get_post_type($post) === "product_variation") {
$post = get_post(wp_get_post_parent_id($post_id));
$post_id = is_object($post) && isset($post->ID) ? (int) $post->ID : 0;
}
if ($post_id <= 0 || !is_post_publicly_viewable($post)) {
return;
}
$url = get_permalink($post);
if (is_string($url) && $url !== "") {
queue_indexnow_url($url);
}
}
function queue_attachment_update(int $post_id): void
{
if (!updates_enabled() || !is_post_publicly_viewable($post_id)) {
return;
}
queue_attachment_url($post_id);
}
function queue_attachment_url(int $post_id): void
{
$url = wp_get_attachment_url($post_id);
$parts = is_string($url) ? wp_parse_url($url) : false;
if (
!is_string($url) ||
$url === "" ||
!is_array($parts) ||
!isset($parts["scheme"], $parts["host"]) ||
!in_array(strtolower($parts["scheme"]), ["http", "https"], true) ||
isset($parts["user"]) ||
isset($parts["pass"]) ||
isset($parts["query"]) ||
isset($parts["fragment"])
) {
return;
}
queue_indexnow_url($url);
}
function queue_attached_media_urls(int $post_id): void
{
foreach (get_attached_media("", $post_id) as $attachment) {
if (is_object($attachment) && isset($attachment->ID)) {
queue_attachment_update((int) $attachment->ID);
}
}
}
function queue_indexnow_url(string $url): void
{
global $donoharm_searchcue_pending_indexnow_urls;
if (!updates_enabled() || !same_host_url($url)) {
return;
}
$donoharm_searchcue_pending_indexnow_urls[] = $url;
}
function flush_indexnow_updates(): void
{
global $donoharm_searchcue_pending_indexnow_urls;
if (!updates_enabled() || empty($donoharm_searchcue_pending_indexnow_urls)) {
$donoharm_searchcue_pending_indexnow_urls = [];
return;
}
$options = get_searchcue_options();
$urls = array_values(array_unique($donoharm_searchcue_pending_indexnow_urls));
$donoharm_searchcue_pending_indexnow_urls = [];
$host = home_host();
if ($host === null || empty($urls)) {
return;
}
wp_remote_post(searchcue_service_url(INDEXNOW_ENDPOINT), [
"timeout" => 2,
"blocking" => false,
"headers" => [
"Content-Type" => "application/json",
],
"body" => wp_json_encode([
"host" => $host,
"key" => $options["indexnow_key"],
"keyLocation" => indexnow_key_location($options["indexnow_key"]),
"urlList" => $urls,
]),
]);
}
function updates_enabled(): bool
{
$options = get_searchcue_options();
return effective_site_id($options) !== "" &&
$options["push_updates"] === "1" &&
$options["indexnow_key"] !== "";
}
function same_host_url(string $url): bool
{
$home_host = home_host();
$url_host = wp_parse_url($url, PHP_URL_HOST);
return is_string($home_host) &&
is_string($url_host) &&
strcasecmp($home_host, $url_host) === 0;
}
function home_host(): ?string
{
$host = wp_parse_url(home_url("/"), PHP_URL_HOST);
return is_string($host) && $host !== "" ? $host : null;
}
function indexnow_key_location(string $key): string
{
return (string) preg_replace("/^http:/i", "https:", home_url("/" . $key . ".txt"));
}
function generate_indexnow_key(): string
{
return wp_generate_password(48, false, false);
}
function generate_setup_state(): string
{
return wp_generate_password(32, false, false);
}
bootstrap(); <?php
/**
* SearchCue uninstall handler.
*
* Runs when the plugin is deleted through the WordPress admin.
* Removes all plugin options from the database.
*
* @package DoNoHarm_SearchCue
*/
declare(strict_types=1);
namespace DoNoHarm\SearchCue;
if (!defined('WP_UNINSTALL_PLUGIN')) {
exit;
}
if (is_multisite()) {
$donoharm_searchcue_site_ids = get_sites(array('fields' => 'ids', 'number' => 0));
foreach ($donoharm_searchcue_site_ids as $donoharm_searchcue_site_id) {
switch_to_blog((int) $donoharm_searchcue_site_id);
delete_option('donoharm_searchcue_options');
delete_option('donoharm_searchcue_activation_redirect');
restore_current_blog();
}
} else {
delete_option('donoharm_searchcue_options');
delete_option('donoharm_searchcue_activation_redirect');
}