Skip to content

[Feature Request]: Flag direct access to WordPress constants that are exposed via API functions #13

@tfrommen

Description

@tfrommen

Is your feature request related to a problem?

There are PHP constants (i.e., define('SOMETHING')) in WordPress that should not typically be accessed directly. Instead, there are various WordPress API functions that allow accessing the constant values, usually also filtered. It would be good if there was a custom PHP_CodeSniffer sniff that flagged direct access to these constants, and also highlighted the recommended way to retrieve the respective value.

Describe the desired solution

Let's add a custom sniff, Syde.WordPress.DiscourageConstantAccess, that flags direct access to WordPress constants that are exposed via one or more API functions.

A good initial list can be found in the phpstan-wordpress extension.

Describe the alternatives that you have considered

The phpstan-wordpress extension flags direct access to constants that are exposed via WordPress API functions. However, we are not using it (deliberately, due to its functionality specific to WordPress hook callback argument types that we do not want).

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestgood first issueGood for newcomersphpPull requests that update Php code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions