Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add condition for fully-qualified global functions #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

LuigiPulcini
Copy link

The current implementation doesn't cover the case of a WordPress i18n global function written with a leading backslash (e.g. \__()) because the PHP parser does not identify \__() as a T_STRING but rather as a T_NAME_FULLY_QUALIFIED.

The proposed change takes that case into account by adding a new condition that is satisfied when the current token is T_NAME_FULLY_QUALIFIED and its text, starting from the second character (i.e. text.slice(1)), is one of the i18n functions.

This case is necessary when a WordPress component uses external libraries that are automatically namespaced by a processor such as PHP Scoper, which transforms the name of every global function into a fully-qualified name (e.g. esc_html__() becomes \esc_html__()).

When a global function is written as a fully-qualified name (e.g. `\__()`), the PHP parser lists them as `T_NAME_FULLY_QUALIFIED` tokens. This change takes that scenario into account.
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