Skip to content

fix(assets): restore admin localization of package vars - #1380

Open
marklchaves wants to merge 1 commit into
developfrom
fix/admin-vars-localization-guard
Open

fix(assets): restore admin localization of package vars#1380
marklchaves wants to merge 1 commit into
developfrom
fix/admin-vars-localization-guard

Conversation

@marklchaves

@marklchaves marklchaves commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #1379.

autoload_styles_for_scripts() in classes/Controllers/Assets.php is only ever hooked to wp_print_scripts (front end) and admin_print_scripts (wp-admin). A guard added in 52a17cb1 (#1316) skipped the localization branch whenever the current hook was admin_print_scripts. Since that's the only wp-admin hook this method runs on, the guard stopped wp_localize_script() / pum_localize_script() from ever running in wp-admin, for every non-bundled admin package (block editor, admin bar, CTA admin, CTA editor, dashboard).

In the block editor, this left window.popupMakerBlockEditor undefined. A module reads popupTriggerExcludedBlocks off that object at the top of the file, with no fallback, so it throws right away. The build bundles every module into one file, so the error stopped the rest of that file from running, including the line that registers the Popup Title sidebar panel.

Fix

Drop the 'admin_print_scripts' !== current_filter() check. The $this->localized_packages per-request cache added in the same commit already stops duplicate localization, so the hook-name check was redundant, and wrong.

Test plan

  • Built a clean production zip (pnpm run release) from this branch and installed on a local test site.
  • Opened a popup in the block editor. Confirmed the console error is gone.
  • Confirmed the Popup Title panel shows in the sidebar again.
  • Confirmed the Popup Title panel shows as an option in the editor's Preferences panel list.
  • Confirm other admin packages that use varsName/vars (admin bar, CTA admin, CTA editor, dashboard) still localize correctly in wp-admin.

Summary by CodeRabbit

  • Bug Fixes
    • Package variables are now correctly available on administrative pages, improving script behavior across the application.

autoload_styles_for_scripts() is only ever hooked to wp_print_scripts
(frontend) and admin_print_scripts (wp-admin). The added
'admin_print_scripts' !== current_filter() guard from #1316 meant the
localization branch could never run in wp-admin at all, since that's
the only admin hook it's called on. This silently stopped
wp_localize_script()/pum_localize_script() from running for every
non-bundled admin package (block-editor, admin-bar, cta-admin,
cta-editor, dashboard), leaving window.popupMakerBlockEditor and
similar globals undefined.

In the block editor this crashed block-editor.js at module-evaluation
time (destructuring popupTriggerExcludedBlocks off an undefined
object), which halted the rest of that bundle's top-level code,
including the Popup Title panel's registerPlugin() call.

The $this->localized_packages per-request cache added in the same
commit already prevents double-localizing, making the hook-name check
redundant as well as wrong. Drop it.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 31, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 5c33dc0f-20eb-441e-8921-05b780d9a082

📥 Commits

Reviewing files that changed from the base of the PR and between 39db996 and 46f6b16.

📒 Files selected for processing (1)
  • classes/Controllers/Assets.php

Included review availability: Your plan provides up to 2 included reviews per hour; 0 remain after this review.


Walkthrough

The package-variable localization guard no longer skips admin_print_scripts. Packages with varsName and vars are now localized on admin pages.

Changes

Admin package localization

Layer / File(s) Summary
Enable admin package localization
classes/Controllers/Assets.php
The guard in autoload_styles_for_scripts now permits package-variable localization during admin_print_scripts.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to 46f6b

This localized change restores admin package variables while preserving existing enqueue and duplicate-localization safeguards; no actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: danieliser

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: restoring admin localization of package variables.
Linked Issues check ✅ Passed The change removes the admin hook guard that prevented package localization. This restores window.popupMakerBlockEditor and other admin package variables, which addresses the missing Popup Title panel…
Out of Scope Changes check ✅ Passed The pull request changes only the localization guard in Assets.php. The change directly supports the requirements in issue #1379 and contains no unrelated code changes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files.
Full details: Linked Issues check

Explanation

The change removes the admin hook guard that prevented package localization. This restores window.popupMakerBlockEditor and other admin package variables, which addresses the missing Popup Title panel and related error in issue #1379.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/admin-vars-localization-guard

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant