Automattic / VIP-Coding-Standards

PHP_CodeSniffer ruleset to enforce WordPress VIP coding standards.
https://wpvip.com/documentation/how-to-install-php-code-sniffer-for-wordpress-com-vip/
Other
236 stars 40 forks source link

get_404_template() triggers WordPressVIPMinimum.Files.IncludingFile.NotAbsolutePath #740

Closed alexmerz closed 1 year ago

alexmerz commented 1 year ago

Bug Description

get_404_template() is documented to return "Full path to 404 template file." https://developer.wordpress.org/reference/functions/get_404_template/

VIP Code Analysis Bot still throws a warning ⚠️ Warning( severity 3 ): Absolute include path must be used. Use get_template_directory(), get_stylesheet_directory() or plugin_dir_path() (WordPressVIPMinimum.Files.IncludingFile.NotAbsolutePath).

Minimal Code Snippet

include( get_404_template() );
GaryJones commented 1 year ago

Thanks @alexmerz.

Looks like get_query_template(), and maybe locate_block_template() could be included in this list as well as get_404_template().

And if so, then all of the Used By on https://developer.wordpress.org/reference/functions/get_query_template/ could potentially be added as well. Needs checking.

GaryJones commented 1 year ago

As this would require adding new violations, I'm moving this to 2.4.0.

jrfnl commented 1 year ago

@GaryJones To me, this sounds like it would remove some false positives, not add new violations, so IMO, this can be included in 2.3.4....

jrfnl commented 1 year ago

Looking at this now and - correct me if I'm wrong - but I believe the whole list of get_*_template() functions as per https://developer.wordpress.org/reference/functions/get_query_template/#used-by can be added to the "ignore" list.

jrfnl commented 1 year ago

On top of that, I think the same goes for all functions in the "Used by" list here: https://developer.wordpress.org/reference/functions/locate_template/#used-by

[EDIT] Scratch that, these functions already include the file and don't return the path name.

GaryJones commented 1 year ago

Looking at this now and - correct me if I'm wrong - but I believe the whole list of get_*_template() functions as per developer.wordpress.org/reference/functions/get_query_template/#used-by can be added to the "ignore" list.

They all claim to return a full path, so yes.