Skip to content

Conversation

@priethor
Copy link
Contributor

What and why

When working with translations in the client, I ran into some issues with the acfL10n not being initialized properly in my scope. This change ensures acfL10n is available in all browsers and conditions.

Testing instructions

Just use SCF and notice that nothing changed for the current features. However, this change will come in handy in the new features we are working on inside the editor.

@cbravobernal cbravobernal force-pushed the fix/ensure-acfL10n-available-globally branch from 7801775 to 68ce307 Compare April 23, 2025 16:09
@cbravobernal cbravobernal requested a review from Copilot April 23, 2025 16:09
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the initialization of the global acfL10n object in order to ensure it exists in all browsers and scopes. This change replaces the old undefined check with a more concise default assignment.

  • Updated global initialization of acfL10n
  • Improved inline documentation to clarify behavior
Comments suppressed due to low confidence (1)

assets/src/js/_acf.js:677

  • The new initialization logic replaces any falsy value for window.acfL10n with an object. Confirm that this behavior is intended, as it will override non-undefined falsy values (e.g., null, false, or empty string).
window.acfL10n = window.acfL10n || {};

Copy link
Contributor

@cbravobernal cbravobernal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cbravobernal cbravobernal merged commit e23f94e into WordPress:trunk Apr 23, 2025
5 checks passed
@priethor priethor added this to the 6.5.0 milestone Apr 23, 2025
if ( window.acfL10n == undefined ) {
acfL10n = {};
}
// Make sure a global acfL10n object exists to prevent errors in other scopes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outside the scope of this PR, but we should probably add some checks on coding style outside PHP files, e.g. to create a consistent way for commenting etc (https://github.com/WordPress/secure-custom-fields/pull/118/files#diff-2c39fc5eb9675f3ca4efecbc4a219c3c560c52ad26d42d45217ad878755a59dfL852 - note the ending stop symbol)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good catch, thanks for noticing 💯

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not the only inconsistency, don't worry!

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