Skip to content

Add rule to suggest replacing WP constants with function calls#276

Merged
szepeviktor merged 1 commit intoszepeviktor:2.xfrom
IanDelMar:wp-constants
Dec 17, 2024
Merged

Add rule to suggest replacing WP constants with function calls#276
szepeviktor merged 1 commit intoszepeviktor:2.xfrom
IanDelMar:wp-constants

Conversation

@IanDelMar
Copy link
Copy Markdown
Contributor

Adds a rule that checks for the use of certain WordPress constants. If such constants are found, an error will be triggered, suggesting replacing the constant with a function call.

I also suggest removing the following lines:
https://github.com/szepeviktor/phpstan-wordpress/blob/6686dc2412cdf544556d428e67aa8f0b645164ca/bootstrap.php#L69C1-L72C49
as STYLESHEETPATH and TEMPLATEPATH were deprecated in WordPress v6.4.0. Additionally, these constants may need to be added to dynamicConstantNames to avoid always-true and always-false errors.

@szepeviktor
Copy link
Copy Markdown
Owner

Are we in the space age? 🙃

@IanDelMar
Copy link
Copy Markdown
Contributor Author

Additionally, these constants may need to be added to dynamicConstantNames to avoid always-true and always-false errors.

If this is the case, it would apply to all other constants that are likely to have values different from those defined in bootstrap.php.

@szepeviktor
Copy link
Copy Markdown
Owner

I also suggest removing the following lines:
https://github.com/szepeviktor/phpstan-wordpress/blob/6686dc2412cdf544556d428e67aa8f0b645164ca/bootstrap.php#L69C1-L72C49
as STYLESHEETPATH and TEMPLATEPATH were deprecated in WordPress v6.4.0. Additionally, these constants may need to be added to dynamicConstantNames to avoid always-true and always-false errors.

"php-stubs/wordpress-stubs": "^6.6.2",

@westonruter it was your PR.
What do you think about removing them from 2.x?

@westonruter
Copy link
Copy Markdown
Contributor

What do you think about removing them from 2.x?

Make it so.

@szepeviktor
Copy link
Copy Markdown
Owner

Going in ...

@szepeviktor szepeviktor merged commit 22aaab0 into szepeviktor:2.x Dec 17, 2024
@IanDelMar IanDelMar deleted the wp-constants branch December 23, 2024 19:28
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.

3 participants