Skip to content

wp-build: Pass false instead of empty string as src in wp_register_script - #86106

Merged
westonruter merged 4 commits into
WordPress:trunkfrom
noruzzamans:fix/phpstan-wp-build-register-script-src
Nov 3, 2026
Merged

westonruter merged 4 commits into
WordPress:trunkfrom
noruzzamans:fix/phpstan-wp-build-register-script-src

Conversation

@noruzzamans

Copy link
Copy Markdown
Member

What?

See #86088

Passes false instead of an empty string '' as the $src parameter of wp_register_script() in the page registration templates, and removes the resolved entries from the PHPStan baseline.

Why?

wp_register_script() expects $src to be string|false. When registering an alias/prerequisite script handle that has no physical source file and only exists to load dependencies or host inline scripts, WordPress Core conventions specify passing false as the source.

Passing an empty string '' is flagged by PHPStan as argument.type (Parameter #2 $src of function wp_register_script expects non-empty-string|false, '' given). Together, these changes resolve 2 of the errors initially baselined in #66693.

How?

  • In packages/wp-build/templates/page.php.template and packages/wp-build/templates/page-wp-admin.php.template, changed the $src argument in wp_register_script( ..., '', ... ) to false.
  • Removed the 2 corresponding argument.type entries from tools/phpstan/baseline.neon.

Testing Instructions

  1. Run composer phpstan and confirm it passes with no unmatched ignored errors.
  2. Run composer phpstan:baselines and confirm tools/phpstan/baseline.neon has no further changes.
  3. Run npm run build to verify page templates compile without errors.

Testing Instructions for Keyboard

Not applicable. There are no UI changes.

Screenshots or screencast

Not applicable.

Use of AI Tools

I used Claude Code to identify the affected occurrences and draft the change. I reviewed the diff and take responsibility for it.

@github-actions github-actions Bot added the [Package] wp-build /packages/wp-build label Nov 1, 2026
@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground

🎉 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: noruzzamans <noruzzaman@git.wordpress.org>
Co-authored-by: westonruter <westonruter@git.wordpress.org>
Co-authored-by: huzaifaalmesbah <huzaifaalmesbah@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.

@huzaifaalmesbah huzaifaalmesbah added the [Type] Code Quality Issues or PRs that relate to code quality label Nov 1, 2026
@huzaifaalmesbah

Copy link
Copy Markdown
Member

Looks good. false is also what Core uses for alias handles such as jquery in script-loader.php, and WP_Scripts treats '' and false the same way, so there's no change in output.

westonruter and others added 2 commits November 2, 2026 20:43
Register the `wp-core-data` alias in the collaboration settings test with `false` as the source, matching the `non-empty-string|false` type that `wp_register_script()` documents and the template fix in this branch.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>
Claude-Code-Session-Id: 4cabd15-c517-4b36-900a-33071f846550
@westonruter
westonruter self-requested a review as a code owner November 3, 2026 05:40
@westonruter westonruter added the No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core label Nov 3, 2026
@westonruter
westonruter merged commit e3ec9e3 into WordPress:trunk Nov 3, 2026
92 of 93 checks passed
@github-actions github-actions Bot added this to the Gutenberg 24.4 milestone Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core [Package] wp-build /packages/wp-build [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