Skip to content

Border: Add a PHP helper for block support classes and styles - #84207

Merged
aaronrobertshaw merged 15 commits into
trunkfrom
update/border-classes-and-styles-php-helper
Nov 4, 2026
Merged

aaronrobertshaw merged 15 commits into
trunkfrom
update/border-classes-and-styles-php-helper

Conversation

@aaronrobertshaw

@aaronrobertshaw aaronrobertshaw commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Follows up on #83122.

Related:

Core backport: wordpress-develop#14094.

What?

Adds a PHP version of the JS getBorderClassesAndStyles(), which turns border attributes into classes and inline styles.

wp_get_border_classes_and_styles( $block_attributes );
// array( 'class' => 'has-border-color has-contrast-border-color', 'style' => 'border-width:2px;' )

The border block support and four blocks now use it.

Why?

Four blocks skip border serialization and rebuild their border styles by hand. Their copies have drifted from the block support:

Unitless 5 Side order
Border block support 5px width, color, style
Avatar, Post Featured Image, Icon dropped color, style, width

0 now outputs 0px, as the block support does.

One helper keeps them all in step.

How?

The helper only builds output. It doesn't check block support.

  • Border block support: keeps its checks, then calls the helper
  • Avatar, Post Featured Image: border functions become one-line wrappers
  • Icon, Post Navigation Link: only their border part changes
  • Build: added to prefixFunctions, so the plugin calls gutenberg_get_border_classes_and_styles()

The only block support output change: a null, false, empty or zero borderColor now falls back to the custom color, as in JS. So does an array, which cannot form a class name.

PHPStan's WordPress stubs are built from Core trunk, which won't have this helper until wordpress-develop#14094 lands. So this PR adds a temporary baseline entry for it. PHPStan will flag the entry for removal once the stubs move to a Core trunk with the helper.

Testing Instructions

Markup matches trunk

  1. Add an Avatar, a Post Featured Image with an overlay, an Icon and a Post Navigation Link.
  2. Give each a border with a preset color and one wider side.
  3. Compare the front end markup with trunk. It should match, apart from the order of the side declarations in Avatar, Post Featured Image and Icon.

Unitless values

  1. In the code editor, set "radius":5 on the Avatar's border.
  2. View the front end. The image now has border-radius:5px. On trunk it has no radius.

Use of AI Tools

Implemented and tested by a Claude Code agent from a predefined task.

@aaronrobertshaw aaronrobertshaw added [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi [Type] Enhancement A suggestion for improvement. [Package] Block library /packages/block-library Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json labels Oct 8, 2026
@aaronrobertshaw aaronrobertshaw self-assigned this Oct 8, 2026
@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org>
Co-authored-by: westonruter <westonruter@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: 0 B

Total Size: 8.61 MB

f13d079 Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric e1c6384 trunk % Change
timeToFirstByte 43.7 ms +6.29% -6.29% 43.95 ms +8.87% -3.64% -0.57%
largestContentfulPaint 74 ms +10.81% -5.41% 74 ms +8.11% -5.41% 0%
lcpMinusTtfb 28.8 ms +24.65% -3.99% 29.55 ms +11% -6.43% -2.54%
wpBeforeTemplate 22.04 ms +8.67% -1.27% 22.52 ms +9.06% -2% -2.13%
wpTemplate 17.36 ms +5.07% -9.56% 17.8 ms +5.9% -3.99% -2.47%
wpTotal 40.57 ms +5.96% -6.68% 40.47 ms +9.66% -3.56% 0.25%
wpMemoryUsage 7.72 MB +0% -0% 7.68 MB +0% -0% 0.43%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric e1c6384 trunk % Change
timeToFirstByte 35.2 ms +9.8% -1.99% 35.95 ms +5.01% -2.78% -2.09%
largestContentfulPaint 80 ms +2.5% -5% 80 ms +0% -2.5% 0%
lcpMinusTtfb 42.1 ms +6.53% -1.78% 43.25 ms +3.01% -3.47% -2.66%
wpBeforeTemplate 19.36 ms +5.48% -0.72% 19.55 ms +7.88% -1.89% -0.97%
wpTemplate 13.08 ms +3.21% -2.6% 13.16 ms +3.8% -2.96% -0.61%
wpTotal 32.61 ms +8.13% -2.45% 33.19 ms +5.51% -2.65% -1.75%
wpMemoryUsage 6.41 MB +0% -0% 6.37 MB +0% -0% 0.53%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric e1c6384 trunk % Change
mediaProcessingJpeg 326.59 ms +1.54% -0.96% 328.89 ms +0.04% -0.4% -0.7%
mediaProcessingAvif 4829.32 ms +0.33% -0.27% 4843.93 ms +0.17% -0.2% -0.3%
mediaProcessingJpegToAvif 3382.76 ms +0.2% -0.24% 3382.39 ms +0.85% -0.12% 0.01%

media-upload

Metric e1c6384 trunk % Change
jpegUploadProcessing 1430.98 ms +1.99% -1.52% 1422 ms +0.75% -0.65% 0.63%
pngUploadProcessing 217 ms +5.35% -5.85% 214.48 ms +5.39% -2.05% 1.17%
largeJpegUploadProcessing 1418.24 ms +0.24% -0.38% 1417.97 ms +0.09% -0.52% 0.02%
multipleImageUploadProcessing 1504.82 ms +0.8% -0.95% 1516.99 ms +0.84% -2.17% -0.8%

post-editor

Metric e1c6384 trunk % Change
serverResponse 497.17 ms +0.9% -9.41% 457.92 ms +9.89% -1.95% 8.57%
firstPaint 389.36 ms +13.22% -12.73% 449.38 ms +15.42% -12.67% -13.36%
domContentLoaded 913.03 ms +2.21% -3.94% 913.52 ms +0.52% -0.65% -0.05%
loaded 914.08 ms +2.24% -3.93% 914.68 ms +0.52% -0.63% -0.07%
firstContentfulPaint 531.32 ms +2.6% -3.25% 522.39 ms +3.72% -0.71% 1.71%
firstBlock 2311.44 ms +1.98% -2.05% 2300.01 ms +1.42% -0.89% 0.5%
type 19.67 ms +5.74% -9.41% 22.06 ms +3.9% -6.66% -10.83%
typeWithoutInspector 20.36 ms +5.94% -12.08% 21.51 ms +6.74% -9.76% -5.35%
typeWithTopToolbar 26.5 ms +4.34% -5.89% 26.28 ms +12.21% -4.45% 0.84%
typeContainer 9.55 ms +8.06% -4.29% 10.29 ms +4.28% -10.59% -7.19%
focus 138.44 ms +7.5% -6.3% 126.57 ms +0.97% -1.46% 9.38%
firstFocus 321.21 ms +0% -0% 299.65 ms +0% -0% 7.2%
selectAll 437.03 ms +6.53% -0.24% 450.43 ms +4.5% -0.04% -2.97%
undo 35.25 ms +2.92% -5.36% 34.49 ms +8.61% -3.97% 2.2%
listViewOpen 83.19 ms +17.3% -7.2% 98.81 ms +8.22% -11.1% -15.81%
inserterOpen 48.7 ms +6.34% -8.46% 48.33 ms +10.78% -15.08% 0.77%
inserterHover 13.96 ms +4.8% -17.12% 12.79 ms +14.15% -4.22% 9.15%
inserterSearch 9.76 ms +6.56% -4.61% 9.45 ms +6.14% -8.99% 3.28%
loadPatterns 689.41 ms +9.45% -2.71% 700.26 ms +9.67% -3.81% -1.55%
wpTotal 486.91 ms +1.04% -9.58% 447.79 ms +10.14% -1.93% 8.74%
wpMemoryUsage 14.76 MB +0% -0% 14.73 MB +0% -0% 0.24%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric e1c6384 trunk % Change
serverResponse 394.99 ms +3.9% -6.13% 407.93 ms +0.61% -6.85% -3.17%
firstPaint 310.43 ms +17.39% -19.91% 373.74 ms +24.94% -10.55% -16.94%
domContentLoaded 887.29 ms +1.08% -1.94% 884.65 ms +0.94% -1.93% 0.3%
loaded 888.46 ms +1.07% -1.97% 885.5 ms +0.95% -1.93% 0.33%
firstContentfulPaint 511.24 ms +3.73% -1.82% 503.05 ms +2.68% -1.6% 1.63%
firstBlock 2465.7 ms +5.66% -0.53% 2473.87 ms +0.56% -1.17% -0.33%
type 18.44 ms +9.54% -10.63% 19.53 ms +15.26% -12.54% -5.58%
navigate 126.17 ms +3.05% -2.47% 112.79 ms +8.53% -1.99% 11.86%
loadPatterns 1368.14 ms +7.92% -5.43% 1346.55 ms +14.02% -11.87% 1.6%
loadPages 990.75 ms +1.87% -0.51% 975.85 ms +2.79% -2.59% 1.53%
wpTotal 385.14 ms +4.03% -6.63% 398.17 ms +0.61% -7% -3.27%
wpMemoryUsage 12.78 MB +0% -0% 12.74 MB +0% -0% 0.27%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

f13d079 Run

🏁 Flaky tests

Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

Undo restores the post selection when another synced entity is loaded (RTC WebSocket) in /test/e2e/specs/editor/collaboration/collaboration-undo-redo.spec.ts, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 2
+ Received  + 2

  Object {
    "attributeKey": "content",
    "blockIndex": 0,
    "content": "abcdef",
-   "endOffset": 3,
-   "offset": 3,
+   "endOffset": 2,
+   "offset": 2,
  }

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/collaboration/collaboration-undo-redo.spec.ts:363:5

f13d079 Run

@aaronrobertshaw
aaronrobertshaw force-pushed the update/border-classes-and-styles-php-helper branch 2 times, most recently from 3b87a31 to 4fb89d6 Compare October 8, 2026 05:55
@aaronrobertshaw aaronrobertshaw added [Type] Code Quality Issues or PRs that relate to code quality and removed [Type] Enhancement A suggestion for improvement. Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json labels Oct 8, 2026
@aaronrobertshaw
aaronrobertshaw force-pushed the update/border-classes-and-styles-php-helper branch 2 times, most recently from 6d5fd2d to ce7e5c6 Compare October 13, 2026 04:40
@aaronrobertshaw
aaronrobertshaw force-pushed the update/border-classes-and-styles-php-helper branch 3 times, most recently from 54238c5 to ead2d72 Compare October 20, 2026 05:24
@aaronrobertshaw
aaronrobertshaw force-pushed the update/border-classes-and-styles-php-helper branch from b122008 to bc6a069 Compare October 21, 2026 12:41
@aaronrobertshaw
aaronrobertshaw marked this pull request as ready for review October 21, 2026 13:16
@aaronrobertshaw
aaronrobertshaw force-pushed the update/border-classes-and-styles-php-helper branch from bc6a069 to 79e246d Compare October 27, 2026 07:49

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

tests well. thanks for following up on these. reduces five calls to a function. i like.

Comment thread lib/block-supports/border.php Resolved
Comment thread lib/block-supports/border.php Resolved
@aaronrobertshaw
aaronrobertshaw force-pushed the update/border-classes-and-styles-php-helper branch 2 times, most recently from 08749a9 to 4cf9ad4 Compare November 2, 2026 03:02
@aaronrobertshaw

Copy link
Copy Markdown
Contributor Author

Thanks for the review @ramonjd 👍

I've addressed the feedback here as well as a few grumbles from PHPStan. I'll get this and the other helpers merged today and tomorrow.

@aaronrobertshaw
aaronrobertshaw force-pushed the update/border-classes-and-styles-php-helper branch from ad7e787 to 2c2388e Compare November 4, 2026 04:04
Comment thread tools/phpstan/baseline.neon Resolved
@aaronrobertshaw
aaronrobertshaw force-pushed the update/border-classes-and-styles-php-helper branch from 2d4be1a to 6863bf0 Compare November 4, 2026 13:27
aaronrobertshaw and others added 15 commits November 4, 2026 23:15
…style variables

An empty, null, false or zero borderColor now falls back to the custom color, as in the color helper and JS. The quirk tests for side rules are dropped, and the block tests keep one exact-output test each.
Theme.json slugs are strings and the editor always coerces them, so the
numeric and boolean handling only added code.
The block library calls wp_get_border_classes_and_styles(), which the
build prefixes to gutenberg_get_border_classes_and_styles() for the
plugin, but which PHPStan resolves from the WordPress stubs. The stubs
were generated from core trunk, which lacks the function, so its calls
were baselined as not found.

Generate the stubs from wordpress-develop PR 14094, which backports the
helper, and drop the four baselined errors. Regenerate them from trunk
once the backport is committed.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>
Claude-Code-Session-Id: cfcf15e8-ccc1-4d78-a7c9-51f73e8e4b92
This reverts commit f919ae5, which was 2d4be1a before the rebase.
@aaronrobertshaw
aaronrobertshaw force-pushed the update/border-classes-and-styles-php-helper branch from 6863bf0 to f13d079 Compare November 4, 2026 15:17
@aaronrobertshaw
aaronrobertshaw enabled auto-merge (squash) November 4, 2026 15:18
@aaronrobertshaw
aaronrobertshaw merged commit 061a785 into trunk Nov 4, 2026
80 checks passed
@aaronrobertshaw
aaronrobertshaw deleted the update/border-classes-and-styles-php-helper branch November 4, 2026 15:41
@github-actions github-actions Bot added this to the Gutenberg 24.5 milestone Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi [Package] Block library /packages/block-library [Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants