Automattic / VIP-Coding-Standards

PHP_CodeSniffer ruleset to enforce WordPress VIP coding standards.

Home Page:https://wpvip.com/documentation/how-to-install-php-code-sniffer-for-wordpress-com-vip/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

get_404_template() triggers WordPressVIPMinimum.Files.IncludingFile.NotAbsolutePath

alexmerz opened this issue · comments

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() );

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.

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

@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....

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.

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.

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.