Skip to content

Pattern directory: say why a pattern title is invalid - #782

Merged
gedex merged 2 commits into
trunkfrom
fix/title-validation-message
Sep 28, 2026
Merged

gedex merged 2 commits into
trunkfrom
fix/title-validation-message

Conversation

@gedex

@gedex gedex commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #743.

The title error now says why, e.g. Pattern titles cannot include "Test". Disallowed words only match whole words, so "Latest Posts" and "Contest Banner" are no longer rejected.

Testing

  1. Go to http://localhost:8888/new-pattern/, add a block and submit it with the title "Test Pattern". The error says Pattern titles cannot include "Test".
  2. Change the title to "Latest Posts" and submit again. It goes through.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved pattern title validation messages to explain why a title is invalid.
    • Disallowed words are now matched case-insensitively as whole words, so titles like “Latest Posts” and “Testimonial” are accepted when those words appear only as part of another word.
    • Removed the special rejection of the exact title “test.”

The error now names the reason, e.g. `Pattern titles cannot include "Test".`,
instead of a generic "title is invalid". Disallowed words are matched as whole
words, so titles like "Latest Posts" and "Contest Banner" are no longer
rejected.

Fixes #743.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Warning

Review limit reached

Next included review available in 6 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 9a488819-70b1-441c-8725-de59655daded

📥 Commits

Reviewing files that changed from the base of the PR and between ad39c9c and b71268e.

📒 Files selected for processing (2)
  • public_html/wp-content/plugins/pattern-directory/includes/pattern-validation.php
  • public_html/wp-content/plugins/pattern-directory/tests/phpunit/pattern-title-validation-test.php

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: f0d9e894-1a47-430e-a67a-5e5ff69cf6c2

📥 Commits

Reviewing files that changed from the base of the PR and between 4482f38 and ad39c9c.

📒 Files selected for processing (2)
  • public_html/wp-content/plugins/pattern-directory/includes/pattern-validation.php
  • public_html/wp-content/plugins/pattern-directory/tests/phpunit/pattern-title-validation-test.php

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Title validation now returns specific reasons for invalid titles. Disallowed-word checks use case-insensitive whole-word matching, and tests cover valid titles containing those words as substrings and REST error messages.

Changes

Pattern title validation

Layer / File(s) Summary
Title checks and error responses
public_html/wp-content/plugins/pattern-directory/includes/pattern-validation.php, public_html/wp-content/plugins/pattern-directory/tests/phpunit/pattern-title-validation-test.php
get_title_error returns reasons for HTML or shortcodes, interactivity directives, and disallowed words. Word checks use case-insensitive whole-word matching, and validate_title returns the specific error. Tests cover allowed substrings and invalid-title REST responses.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: obenland

Merge Risk: ⚪ Minimal · up to ad39c

The title-validation change appears ready to merge after normal checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to ad39c

Pattern submissions now accept some titles previously rejected and receive more specific error messages. Existing validation and moderation checks appear unchanged, but the public behavior warrants review.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed acceptance rule affects titles submitted through the existing pattern REST update path; the changed test methods do not themselves create a public entrypoint.

Trust Boundaries and Controls

  • observed — Separate status checks still restrict author-initiated moderation changes, and the downstream spam validator still checks publicly visible submissions. Neither control is changed by the title-matching edit.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR implements the coding requirement in issue #743. validate_title now returns the message from get_title_error. The message identifies the matched prohibited word, such as `Pattern titles can…
Out of Scope Changes check ✅ Passed The reviewed changes stay within issue #743. The source change updates title-validation messages and matching behavior. The added PHPUnit cases verify the new messages and prevent false rejections. No…
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files.
Title check ✅ Passed The title clearly describes the main change: explaining why a pattern title is invalid.
Description check ✅ Passed The description explains the validation changes, references issue #743, and provides concrete testing steps. The missing Props and screenshots sections are non-critical because the change has no visua…
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gedex gedex self-assigned this Sep 28, 2026
@gedex
gedex requested a lite review from Copilot September 28, 2026 13:51
@gedex
gedex requested a review from bor0 September 28, 2026 13:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Improve Unicode whole-word matching and assert the interactivity-directive error message.

Review effort: Lite
Findings: None

What changed in this PR

Updates pattern title validation with clearer rejection messages and whole-word matching.

Changes:

  • Adds descriptive validation errors.
  • Prevents false positives within larger words.
  • Expands validation and message tests.
File Summary
public_html/​wp-content/​plugins/​pattern-directory/​includes/​pattern-validation.php Implements detailed errors and whole-word matching; Unicode-aware matching needs adjustment.
public_html/​wp-content/​plugins/​pattern-directory/​tests/​phpunit/​pattern-title-validation-test.php Adds coverage for accepted titles and validation messages.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@bor0 bor0 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. CI is green and it merges cleanly into trunk.

  • is_title_valid() had no other callers, so it's safe to rename it to get_title_error(). Nothing else reads the old error text.
  • I tried the new regex on a few edge cases. "Latest Posts", "Contest Banner" and "Testübersicht" pass. "Test" and "Test-Pattern" are rejected. With /u, \b treats non-ASCII letters as word characters, so a word like "Testübersicht" isn't flagged by mistake.
  • Showing the matched text (e.g. "My Pattern") in the error is safe. Titles with HTML or shortcodes are rejected before this check runs.

Nit, not blocking: matching whole words also lets through plurals that were rejected before, e.g. "My Patterns" and "Examples". "Examples Grid" is intended per the tests. You could still reject "My Patterns" with my patterns? if that's wanted.

Whole-word matching let the plural through, which the old check rejected.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@gedex

gedex commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for testing the edge cases, @bor0. b71268e adds "my patterns" to the list, so "My Patterns" is rejected again like before. It says as little about the pattern as "My Pattern" does. I left "Examples" and "Tests" allowed on purpose. "Examples Grid" can describe a real pattern, and "Tests" on its own rarely comes up as a whole word.

@gedex
gedex merged commit 57e8ef2 into trunk Sep 28, 2026
5 checks passed
@gedex
gedex deleted the fix/title-validation-message branch September 28, 2026 14:23
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.

Clearly state why the title is invalid

3 participants