From cf2ca657ef9ad8fd1cabb70d58e99be2f488bcdd Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 22 Aug 2023 17:49:09 +0200 Subject: [PATCH 1/2] Files/IncludingFile: alphabetize the list of path functions --- WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php b/WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php index bf18a028..3c4804d0 100644 --- a/WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php +++ b/WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php @@ -25,13 +25,13 @@ class IncludingFileSniff extends AbstractFunctionRestrictionsSniff { * @var array */ public $getPathFunctions = [ - 'plugin_dir_path', 'dirname', + 'get_parent_theme_file_path', 'get_stylesheet_directory', 'get_template_directory', - 'locate_template', - 'get_parent_theme_file_path', 'get_theme_file_path', + 'locate_template', + 'plugin_dir_path', ]; /** From 08c3909f11d3fdd1f5946f12d14351dcf5564994 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 22 Aug 2023 17:47:44 +0200 Subject: [PATCH 2/2] Files/IncludingFile: allow for more path-returning functions 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 --- .../Sniffs/Files/IncludingFileSniff.php | 20 +++++++++++++++++++ .../Tests/Files/IncludingFileUnitTest.inc | 7 ++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php b/WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php index 3c4804d0..5d294a6b 100644 --- a/WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php +++ b/WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php @@ -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', ]; diff --git a/WordPressVIPMinimum/Tests/Files/IncludingFileUnitTest.inc b/WordPressVIPMinimum/Tests/Files/IncludingFileUnitTest.inc index 63dcf460..032eefd0 100644 --- a/WordPressVIPMinimum/Tests/Files/IncludingFileUnitTest.inc +++ b/WordPressVIPMinimum/Tests/Files/IncludingFileUnitTest.inc @@ -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. \ No newline at end of file + 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' );