Repository navigation
Conversation
Covers `remove_all_shortcodes()`, `get_shortcode_tags_in_content()`, `apply_shortcodes()` and `unescape_invalid_shortcodes()`, which had no tests. See #66500.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
There was a problem hiding this comment.
🟢 Approval recommended
The shortcode unit-test additions have no active review issues requiring resolution.
No open issues 🎉
What changed in this PR
Adds dedicated unit tests for four shortcode registry and helper functions in src/wp-includes/shortcodes.php, without changing production behavior.
Changes:
- Covers shortcode removal, re-registration, and tag discovery, including nested and repeated tags.
- Tests
apply_shortcodes()output, equivalence todo_shortcode(), and HTML-handling options. - Verifies bracket-placeholder replacement and preservation of unrelated content.
| File | Description |
|---|---|
tests/phpunit/tests/shortcodes/unescapeInvalidShortcodes.php |
Tests bracket unescaping in text and HTML. |
tests/phpunit/tests/shortcodes/removeAllShortcodes.php |
Tests clearing the registry and registering shortcodes again. |
tests/phpunit/tests/shortcodes/getShortcodeTagsInContent.php |
Tests tag discovery, nesting, ordering, and registry changes. |
tests/phpunit/tests/shortcodes/applyShortcodes.php |
Tests shortcode processing and forwarding of HTML-handling options. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds unit tests for four functions in
src/wp-includes/shortcodes.phpthat were not referenced by any test. No behavior is changed.Functions covered, each in its own test class in
tests/phpunit/tests/shortcodes/:remove_all_shortcodes()get_shortcode_tags_in_content()apply_shortcodes()do_shortcode()for self closing, enclosing, escaped, unregistered and empty content.$ignore_htmlon, so shortcodes inside HTML elements are skipped only when it is true.unescape_invalid_shortcodes()[and]with the square brackets, in text and inside HTML, and leaves any other content and other character references as they are.The tests change the global
$shortcode_tags, so they save and restore it. Escaped shortcodes ([[tag]]) are not covered forget_shortcode_tags_in_content(), because the function currently returns their tag too and that behavior is not asserted.Testing:
vendor/bin/phpunit --filter 'Tests_Shortcodes_'vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter 'Tests_Shortcodes_'vendor/bin/phpcs tests/phpunit/tests/shortcodes/I also temporarily broke the functions in
src/wp-includes/shortcodes.php(not clearing the list, not looking at nested content, returning unique tags, not passing$ignore_htmlon,apply_shortcodes()returning the content as it is, and each of the two bracket replacements) and confirmed that a new test fails for each one. Removing the early return for content without a bracket inget_shortcode_tags_in_content()does not change the result, because the regular expression finds nothing in that case.Trac ticket: https://core.trac.wordpress.org/ticket/66500
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5.5
Used for: Written with AI and manually reviewed by me.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.