Skip to content

Footer credit: only strip the separator next to the credit link - #51581

Merged
RafaelFunchal merged 3 commits into
trunkfrom
fix/dotthem-411-footer-widget-pipe-separator
Nov 26, 2026
Merged

RafaelFunchal merged 3 commits into
trunkfrom
fix/dotthem-411-footer-widget-pipe-separator

Conversation

@jp-imagines

@jp-imagines jp-imagines commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

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:

preg_replace( '/\s\|\s(?=\<a)|…/i', '', $footer )

\s\|\s(?=\<a) matches any | followed by any link, anywhere in the string — and the string here is an output buffer opened on get_footer, so it covers the entire footer, footer widget areas included. A site owner whose footer widget reads Terms | <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 from footer.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:

  • Remove \s\|\s(?=\<a) from the global separator regex. The <span class="sep"> branch is unchanged.
  • Re-do that removal anchored with /\s\|\s$/ to the end of $before — the substring the credit-matching code has already split at the credit link's offset.

Because $before ends 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 the if that 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 call get_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 than footer.php, which also bypasses it.

  1. Add a Paragraph block widget to a footer widget area with content like:
    Terms & Conditions | <a href="https://example.com/privacy">Privacy Policy</a>
  2. View the front end. Before: the | and its preceding space are gone. After: they render as written.
  3. Confirm the footer credit itself still works — on a theme whose footer links to wordpress.org, that link should still be replaced with the WordPress.com credit, with no leftover | in front of it.
  4. On Twenty Eleven, confirm <span class="sep"> | </span> is still removed.

Automated coverage is in projects/plugins/wpcomsh/tests/FooterCreditSeparatorTest.php:

jp docker phpunit wpcomsh -- --filter=FooterCreditSeparatorTest

The two behavioural tests fail on trunk and pass with this change; the two guarding existing behaviour (separator before the credit is removed, .sep span 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.

@github-actions

github-actions Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (WordPress.com Site Helper), and enable the fix/dotthem-411-footer-widget-pipe-separator branch.

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions

github-actions Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

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:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!


Wpcomsh plugin:

  • Next scheduled release: Atomic deploys happen twice daily on weekdays (p9o2xV-2EN-p2)

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Aug 25, 2026
@jp-imagines
jp-imagines force-pushed the fix/dotthem-411-footer-widget-pipe-separator branch from 7d94a0b to 6732fe2 Compare August 25, 2026 21:38
@jp-launch-control

jp-launch-control Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 2 files.

File Coverage Δ% Δ Uncovered
projects/plugins/wpcomsh/footer-credit/footer-credit/footer-credit.php 38/111 (34.23%) 34.23% -38 💚
projects/plugins/wpcomsh/footer-credit/footer-credit-optimizations.php 81/126 (64.29%) 64.29% -80 💚

Full summary · PHP report

@jp-imagines
jp-imagines requested a review from serabi September 3, 2026 18:35
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

This PR has been marked as stale. This happened because:

  • It has been inactive for the past 3 months.
  • It hasn't been labeled `[Pri] BLOCKER`, `[Pri] High`, `[Status] Keep Open`, etc.

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
@jp-imagines
jp-imagines force-pushed the fix/dotthem-411-footer-widget-pipe-separator branch from 6732fe2 to fcad23c Compare November 24, 2026 22:23
samvaidya
samvaidya previously approved these changes Nov 26, 2026

@samvaidya samvaidya 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.

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.

@jp-imagines
jp-imagines marked this pull request as ready for review November 26, 2026 14:27
…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.
@RafaelFunchal

Copy link
Copy Markdown
Contributor

I reviewed this and pushed two small commits on top. The fix itself is unchanged.

4b201f7: code

  • The anchored removal is now /\s\|\s*$/ (it was \s$). Twotone's wpcom_better_footer_credit_regex filter turns #<a into #\s<a, so the match starts on the space and $before ends in |. With \s$, a | was left in front of the new credit.
  • The .sep span match is now lazy (.*?). The greedy .* ran to the last </span> on the line, so a footer printed on one line lost everything between the separator and any later span, footer widget content included. This is the same kind of bug as the pipe one, so it seemed worth fixing here.
  • Shortened the two comments to fit AGENTS.md, and updated the changelog entry to match.

f2ad138: tests

  • Moved the separator cases into one data provider (one test per behaviour), plus a test for a regex filter that starts the match on the space.
  • Trimmed the class docblock, as samvaidya suggested.
  • Dropped test_footer_without_a_credit_link_is_unchanged. It only failed together with the footer-widget test. Also, a footer with no credit isn't left fully unchanged, because .sep spans are still removed.
  • I ran each test against a deliberate break of the code it covers, and every break failed a test:
Break Test that fails
Global | removal restored pipe in a footer widget is kept
Anchored removal deleted pipe before the credit is removed, leading-space test
\s*$ reverted to \s$ leading-space test
.sep match made greedy again sep span is removed, spans after it are kept

I checked these with a stubbed harness, not jp docker phpunit, so CI is the real run.

Two notes, no change made:

  • A pipe after the credit now stays. <a wordpress.org>…</a> | <a>Foo</a> used to render as Blog at WordPress.com.<a>Foo</a>, with the two links run together. It now renders Blog at WordPress.com. | <a>Foo</a>. I think that's an improvement, but it changes what themes with that layout show.
  • Existing behaviour: array_pop replaces the last wordpress.org link in the buffer. If a footer widget after the theme credit links to wordpress.org, the widget's link and its | are replaced instead of the theme credit. Fixing that would mean changing which link is chosen as the credit, so I left it for a separate change.
  • Existing behaviour: .sep spans are still removed anywhere in the footer, not only next to the credit. A site owner rarely writes class="sep" themselves. These spans also often sit between the theme and designer credits rather than right before the WordPress link, so anchoring them would change how theme credits render.

The same two regex changes would apply to the wpcom copy (237867-ghe-Automattic/wpcom).

@RafaelFunchal
RafaelFunchal merged commit 5882572 into trunk Nov 26, 2026
83 checks passed
@RafaelFunchal
RafaelFunchal deleted the fix/dotthem-411-footer-widget-pipe-separator branch November 26, 2026 17:15
@github-actions github-actions Bot removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [Status] In Progress labels Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants