Skip to content

Commit

Permalink
Files/IncludingFile: allow for more path-returning functions
Browse files Browse the repository at this point in the history
As per the thread in 740, these functions all return the full path to a file, so these should all be fine.
As things were, use of these in an `include`/`require` statement would throw an unjustified "Absolute include path must be used" warning.

Includes a few extra tests, though I didn't think it would be necessary to have tests with each of these functions.

Fixes 740
  • Loading branch information
jrfnl committed Aug 22, 2023
1 parent cf2ca65 commit 08c3909
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
20 changes: 20 additions & 0 deletions WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,30 @@ class IncludingFileSniff extends AbstractFunctionRestrictionsSniff {
*/
public $getPathFunctions = [
'dirname',
'get_404_template',
'get_archive_template',
'get_attachment_template',
'get_author_template',
'get_category_template',
'get_date_template',
'get_embed_template',
'get_front_page_template',
'get_page_template',
'get_paged_template', // Deprecated, but should still be accepted for the purpose of this sniff.
'get_home_template',
'get_index_template',
'get_parent_theme_file_path',
'get_privacy_policy_template',
'get_query_template',
'get_search_template',
'get_single_template',
'get_singular_template',
'get_stylesheet_directory',
'get_tag_template',
'get_taxonomy_template',
'get_template_directory',
'get_theme_file_path',
'locate_block_template',
'locate_template',
'plugin_dir_path',
];
Expand Down
7 changes: 6 additions & 1 deletion WordPressVIPMinimum/Tests/Files/IncludingFileUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ include_once dir_function(); // Error - custom functionm with keyword from $al
require CUSTOM_CONSTANT_DIR . 'file.php'; // OK.
require_once ( VIPCS_PATH ) . 'file.php'; // OK.
include_once
DIR_CUSTOM , 'file.php'; // OK.
DIR_CUSTOM , 'file.php'; // OK.

// These are valid (previously false positives).
include( get_404_template() );
require get_query_template( 'post' );
include_once locate_block_template( __DIR__, 'silly_block' );

0 comments on commit 08c3909

Please sign in to comment.