Repository navigation
Footer credit: only strip the separator next to the credit link - #51581
Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Wpcomsh plugin:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
7d94a0b to
6732fe2
Compare
Code Coverage SummaryCoverage changed in 2 files.
|
|
This PR has been marked as stale. This happened because:
If this PR is still useful, please do a [trunk merge or rebase](https://github.com/Automattic/jetpack/blob/trunk/docs/git-workflow.md#keeping-your-branch-up-to-date) and otherwise make sure it's up to date and has clear testing instructions. You may also want to ping possible reviewers in case they've forgotten about it. Please close this PR if you think it's not valid anymore — if you do, please add a brief explanation. If the PR is not updated (or at least commented on) in another month, it will be automatically closed. |
…HEM-411) wpcom_better_footer_links() runs on an output buffer covering the whole footer, footer widget areas included. Its separator regex matched any " | " before any link, so a footer widget reading "Terms | <a>Privacy Policy</a>" lost the pipe and its leading space. Remove the global pipe alternative and re-do the removal anchored to the end of $before, which the credit-matching code has already split at the credit link's offset. The separator can then only be removed where it directly precedes the credit being replaced, at most once, and only when a credit link was actually found. Fixes DOTTHEM-411
6732fe2 to
fcad23c
Compare
samvaidya
left a comment
There was a problem hiding this comment.
Looks good, approving. It's the same change as wpcom#237867, line for line. I tested the logic on the wpcom copy (your two new tests fail on trunk and pass with the fix, and four deliberate breaks each fail a test), and the wpcomsh suite passes in CI on this head.
Two small, optional notes:
- The repo's AGENTS.md asks test files to skip file-header essays and docblocks that repeat the test name. The class docblock repeats the output-buffer explanation that's already in the new comment in
footer-credit-optimizations.php, so trimming it to one line would match. - On Atomic, wpcomsh only runs this for WordPress.com free themes (
wpcom_better_footer_credit_apply()), so Storefront and Astra in the testing steps won't show the bug. Twenty Seventeen will.
…spans lazily The anchored separator removal missed ' |' when a credit regex filter (Twotone's) starts the match on the space before the link. The greedy .sep span match ran to the last </span> on the line, deleting footer widget content in between.
One test per behavior; drop the no-credit test, which only failed together with the widget test, and add rows for the leading-space match and lazy .sep removal.
|
I reviewed this and pushed two small commits on top. The fix itself is unchanged. 4b201f7: code
f2ad138: tests
I checked these with a stubbed harness, not Two notes, no change made:
The same two regex changes would apply to the wpcom copy (237867-ghe-Automattic/wpcom). |
Related to DOTTHEM-411
Proposed changes
wpcom_better_footer_links()removes the separator that sits between a theme's credit links before it swaps in the WordPress.com credit. It did that with a global replace:\s\|\s(?=\<a)matches any|followed by any link, anywhere in the string — and the string here is an output buffer opened onget_footer, so it covers the entire footer, footer widget areas included. A site owner whose footer widget readsTerms | <a>Privacy Policy</a>loses the pipe and its leading space.This is common in footers, where
|is a conventional separator for terms/privacy links. It shows up on classic themes that render a widget area fromfooter.php— 90+ themes in the pub and premium catalogs do, plus third-party themes on WoA.The separator removal still needs to happen, or replacing the credit leaves a dangling
|. So instead of dropping it, this moves it next to the credit it belongs to:\s\|\s(?=\<a)from the global separator regex. The<span class="sep">branch is unchanged./\s\|\s$/to the end of$before— the substring the credit-matching code has already split at the credit link's offset.Because
$beforeends exactly where the credit link begins, the anchored pattern can only ever match a separator immediately preceding the credit being replaced. It runs at most once, and only inside theifthat found a credit link — so a footer with no WordPress credit link (the usual case on third-party themes) is now left alone entirely, where previously it was still rewritten.Related product discussion/links
DOTTHEM-411: This may be auto-marked "In Progress" by this PR opening. It is not being actively worked by the owning team — this is a Bug Blitz contribution awaiting review.
Does this pull request change what data or activity we track or use?
No.
Testing instructions
Requires a WoA/Atomic site on a classic theme that renders a widget area from
footer.php(Storefront, Astra, Twenty Seventeen). Block themes never callget_footer(), so this code does not run on them, and a few classic themes — Twenty Twenty among them — emit their footer widgets from the page template rather thanfooter.php, which also bypasses it.Terms & Conditions | <a href="https://example.com/privacy">Privacy Policy</a>|and its preceding space are gone. After: they render as written.|in front of it.<span class="sep"> | </span>is still removed.Automated coverage is in
projects/plugins/wpcomsh/tests/FooterCreditSeparatorTest.php:The two behavioural tests fail on trunk and pass with this change; the two guarding existing behaviour (separator before the credit is removed,
.sepspan is removed) pass in both.Also verified end-to-end on a live Atomic site by running the patched function in place of wpcomsh's own, via a temporary mu-plugin, and confirming the widget separator survived while the footer credit was still replaced.