Skip to content

Custom Pattern Text Generation#11

Merged
jasperf merged 8 commits into
mainfrom
custom-pattern-text-generation
May 25, 2026
Merged

Custom Pattern Text Generation#11
jasperf merged 8 commits into
mainfrom
custom-pattern-text-generation

Conversation

@jasperf
Copy link
Copy Markdown
Contributor

@jasperf jasperf commented May 25, 2026

This pull request delivers version 0.9.0 of the Waygate plugin, introducing AI-powered themed text personalization for generated pages alongside a security fix that sanitizes AI-rewritten post content before database insertion. The central new capability allows the AI integration layer to rewrite pattern text to match a user-supplied theme or tone, making generated pages more contextually coherent rather than relying solely on static pattern copy. A companion refactor extracts model preference configuration into a dedicated structure within class-ai-integration.php, improving maintainability of the provider fallback chain. The release is accompanied by comprehensive unit test coverage for three previously untested methods and updated documentation across CHANGELOG, README, ROADMAP, and a new code review document.

Feature: Themed Text Personalization

  • class-ai-integration.php gains a rewrite_pattern_texts() method that sends pattern content to the AI with a user-defined theme prompt, returning rewritten copy before the page is assembled.
  • class-pattern-lab.php and class-admin.php are updated to pass theme context through the page creation pipeline, connecting the admin form input to the AI rewriting step.

Security and Code Quality

  • AI-rewritten post content is now sanitized via wp_kses_post() before being passed to wp_insert_post(), preventing potential XSS from untrusted model output.
  • Model provider preferences are extracted into a dedicated configuration structure within the AI integration class, decoupling provider selection logic from prompt-building logic.

Test Coverage

  • Unit tests added in AiIntegrationTest.php and PatternLabTest.php covering get_pattern_content(), create_page_from_content(), and rewrite_pattern_texts(), including bootstrap updates to support the new test cases.
  • The new docs/CODE-REVIEW-text-personalization.md documents the design decisions and security considerations reviewed during development of the personalization feature.

Documentation and Tooling

  • CHANGELOG, README, and ROADMAP updated to reflect the 0.9.0 release, security fix, and expanded test suite.
  • .vibe/config.toml updated to permit cd in the command allowlist, aligning the development environment configuration with current workflow requirements.

Files Changed:

jasperf added 8 commits May 25, 2026 15:20
After the AI selects patterns, an optional second AI call rewrites all
visible text (headings, paragraphs, button labels) inside each pattern's
block markup to match the prompt topic. Block comment markup, HTML tags,
attributes, and CSS classes are left untouched. The page is stored with
the rewritten block content instead of wp:pattern references.

- Pattern_Lab::get_pattern_content() fetches raw block markup by slug
- Pattern_Lab::create_page_from_content() inserts a page from block strings
- AI_Integration::rewrite_pattern_texts() batches all patterns in one AI call
- AI_Integration::generate_page() accepts $personalize_text (default true)
- Admin form adds an opt-out checkbox with speed trade-off noted in the hint
- Result notice shows personalization status; _waygate_personalized post meta stored
…ntent

Extract duplicated model preference list into get_model_preferences() so
both AI calls share a single source of truth. Apply wp_kses_post() to
each block content string in create_page_from_content() before insertion
to strip disallowed HTML from AI responses.
…t, and rewrite_pattern_texts

Add get_registered() to the WP_Block_Patterns_Registry stub and a
wp_kses_post() stub in the test bootstrap. Cover the three methods that
had no tests: get_pattern_content (missing slug, present content, absent
field), create_page_from_content (empty input, valid input, status
fallback, script tag stripping), and rewrite_pattern_texts (empty slugs,
no content, unregistered slugs, AI unavailable).
@jasperf jasperf merged commit 90d9110 into main May 25, 2026
2 checks passed
@jasperf jasperf deleted the custom-pattern-text-generation branch May 25, 2026 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant