Business Context (Brand DNA)
How to set up brand context for AI generation.
Overview
Business Context is a plain-text brand profile — voice, positioning, target audience, and key values. It is automatically injected into every generation as the dominant baseline. All generated copy must stay within it.
Storage: mdrfts_business_context (WordPress option)
Timestamp: mdrfts_business_context_updated
Location: Settings → Brand tab → Business Context card
How It Is Created
Operators click Fetch from website — MerchantDrafts scrapes the site, sends content to Gemini, and generates a 3–5 paragraph plain-text brand profile (takes ~10 seconds).
The result is saved to the database automatically — update_option( 'mdrfts_business_context', ... ) is called server-side before the AJAX response is returned. The textarea is then populated client-side from the response for review and optional editing.
Operators can also write or edit the profile directly in the textarea and click Save Manual Edits to persist changes.
UI — Button Map (Brand Tab)
| Button | Type | What it does |
|---|---|---|
| Fetch from website | Primary (blue), left-aligned | Scrapes site → Gemini AI → saves to DB automatically → fills textarea |
| Save Manual Edits | Secondary, right-aligned | Submits the form — persists any manual text edits to the textarea |
Copy icon (dashicons-clipboard) | Icon overlay, top-right of textarea | Copies textarea content to clipboard; switches to dashicons-yes for 2 s then reverts |
Trash icon (dashicons-trash) | Icon overlay, top-right of textarea | Clears Business Context (separate hidden form with confirm dialog); only visible when a value exists |
The copy and trash icons live inside .mdrfts-ta-toolbar — a position: absolute overlay that fades in on textarea hover or focus-within (opacity: 0 → 1). At rest it is invisible so it does not obstruct reading. The button row uses justify-content: space-between — Fetch on the left, Save Manual Edits on the right.
Loading Feedback
During a Fetch operation the button shows an inline spinner and its label changes to "Analysing website…". The status paragraph below the textarea uses three visual states:
- Loading (blue text): "Scanning your site and generating a brand profile…"
- Success (green ✓): "✓ Saved automatically at [timestamp]."
- Error (red ✗): "✗ [error message]"
A live word count (<span id="mdrfts-ctx-wordcount">) is shown below the textarea in soft grey, updated on every input event and after each successful fetch.
Spinner implementation
The spinner uses the dashicons-update icon + mdrfts-spin class — the same pattern as the product editor.
- A
<span class="dashicons dashicons-update" id="mdrfts-fetch-spinner">sits inside the Fetch button (hidden by default). - On click:
$spinner.show().addClass('mdrfts-spin')— the icon rotates. On completion:$spinner.hide().removeClass('mdrfts-spin'). - The status line uses
.text()only — no HTML is injected into the status paragraph.
The @keyframes mdrfts-spin animation (rotate 0deg → 360deg, 0.7s linear infinite) is defined inline in the settings page <style> block. assets/style.css is only enqueued on post.php/post-new.php and is not available on the settings page.
Auto-height textarea
The business context textarea grows automatically to fit generated content.
CSS (primary): field-sizing: content with resize: none; overflow: hidden; min-height: 120px. Supported in Chrome 123+, Firefox 128+, and modern Safari.
JS fallback (mdrftsResizeCtx()): checks el.style.fieldSizing === 'content' and skips if the browser handles it natively. Otherwise uses el.style.height = 'auto'; el.style.height = scrollHeight + 'px'. Wired to page load, every input event, and after a successful AJAX fetch.
Textarea styling: font-size: 11px; line-height: 1.4; padding: 36px applied via the textarea.code CSS rule (the element carries class large-text code). Card body padding is 42px.
First-Run Nudge
On plugin activation, if Business Context is empty, a 30-day transient mdrfts_show_bc_nudge is set. An admin notice appears on every wp-admin page (for manage_options users only) with a "Set up Business Context" button linking to Settings. The notice:
- Auto-clears when Business Context is set
- Can be dismissed via × (AJAX call deletes the transient)
- Expires automatically after 30 days
The Business Context card also shows an inline empty-state callout when BC is not yet set: "No Business Context yet. Click Fetch from website below…"
Protection Against Accidental Deletion
- Saving an empty textarea when a value already exists is blocked server-side with a warning notice
- A separate Clear Business Context trash-icon button (destructive, shown in the textarea toolbar only when BC is set) is required to intentionally remove it
- Client-side confirm dialog fires before clearing
Visibility in the Product Editor
Before generating, the operator can see Business Context status directly in the Advanced Options section of the controls sidebar — an Active (green) or Not set (amber) pill with an "Add in Settings" / "Edit in Settings" link to ?page=mdrfts_settings&tab=brand. Rendered in PHP at page load; no JS required.
After generating, the Info tab Active layers row confirms whether Business Context was injected, with a direct Settings link.
Prompt Role
Business Context is injected at layer 4 of the prompt stack, after product data and before Writing Pattern and Product Emphasis. It dominates all layers below it — all copy must stay within the brand baseline it defines.
In the workspace model, Business Context remains a shared mid-stack layer for outputs such as:
- Core Product Content
- Google Merchant Center
- future workspace-specific prompt systems
Do
- Fetch once after installation
- Update whenever brand voice, product range, or target audience changes significantly
- Review the generated profile in the textarea — edit if needed, then click Save Manual Edits to keep changes
Do Not
- Leave Business Context empty in production — copy will lack brand voice
- Use it for per-product instructions (use "What to emphasize" for that)
- Use it for hard rules like forbidden words (use Prompt Supplement for that)
- Fetch once after installation
- Update whenever brand voice, product range, or target audience changes significantly
- Review the generated profile before saving — edit to correct anything inaccurate
Do Not
- Leave Business Context empty in production — copy will lack brand voice
- Use it for per-product instructions (use "What to emphasize" for that)
- Use it for hard rules like forbidden words (use Prompt Supplement for that)