#53659 closed enhancement (fixed)
Optional skipping of hidden files/folders in list_files
Reported by: | yani.iliev | Owned by: | kirasong |
---|---|---|---|
Milestone: | 6.3 | Priority: | normal |
Severity: | normal | Version: | 4.9 |
Component: | Filesystem API | Keywords: | has-patch has-unit-tests has-testing-info commit add-to-field-guide |
Focuses: | Cc: |
Description
The function always skips hidden files/folders that begin with a dot (.
)
This allows for files like .htaccess
and .git
to be skipped when listing a folder.
This ticket is about allow to suppress this behavior in the function and return hidden files/folders that begin with a dot (.
).
One possible solution is to add a new argument to the function so that the function is defined as such:
function list_files( $folder = '', $levels = 100, $exclusions = array(), $skip_dots = true )
Attachments (4)
Change History (19)
This ticket was mentioned in PR #4223 on WordPress/wordpress-develop by @costdev.
21 months ago
#3
- Keywords has-patch has-unit-tests added
#4
@
21 months ago
- Milestone changed from Awaiting Review to 6.3
- Version set to 4.9
- PR 4223 introduces the
$include_hidden
parameter to allow the inclusion of hidden ("." prefixed) files. - The parameter name
$include_hidden
is used as this is consistent with the parameter name used in the::dirlist()
filesystem abstraction classes, which defaults totrue
. - However, this new parameter in
list_files()
defaults tofalse
for backward compatibility.
- Hidden file exclusion was introduced in [41806]. See this comment. Setting the
Version
property to4.9
. - Milestoning this ticket for 6.3.
This ticket was mentioned in Slack in #core by oglekler. View the logs.
19 months ago
#6
@
19 months ago
- Keywords needs-testing-info needs-testing added
This ticket was discussed in the recent bug scrub.
It seems we need testing instructions/info and testing the PR.
#7
@
19 months ago
- Keywords has-testing-info added; needs-testing-info removed
Testing Instructions
Steps to Test
- Create a directory with several files and subdirectories.
- Make sure each directory and subdirectory has a file called
.hidden-file
and a file called.hidden-file-2
. - The
.
denotes a hidden file.
- Make sure each directory and subdirectory has a file called
- Call
list_files( $path_to_folder )
. - Call
list_files( $path_to_folder, 100, array(), true )
. - Call
list_files( $path_to_folder, 100, array( '.hidden-file-2' ), true )
.
Expected Results
Before the patch:
- The result should not contain the hidden files.
- The result should not contain the hidden files.
- The result should not contain the hidden files.
After the patch:
- The result should not contain the hidden files.
- The result should contain all of the hidden files.
- The result should only contain
.hidden-file
entries for$path_to_folder
, but should include.hidden-file
and.hidden-file-2
entries for its sub-directories.
This ticket was mentioned in Slack in #core-test by boniu91. View the logs.
18 months ago
#9
@
18 months ago
Test Report
This report validates that the indicated patch addresses the issue.
Patch tested: https://patch-diff.githubusercontent.com/raw/WordPress/wordpress-develop/pull/4223.diff
Environment
- OS: Windows 11 (22H2)
- Web Server: nginx/1.23.4
- PHP: 7.4.33
- WordPress: 6.3-alpha-55505-src
- Browser: Chrome Version 114.0.5735.110 (Official Build) (64-bit)
- Theme: Twenty Twenty-Three
Before Applying The Patch
- Followed the instructions of @costdev
- ❌ The hidden files did not show up in all three results
After Applying The Patch
- Followed the same instructions
- ✅ The hidden files appeared according to the calls made
Plugins Used
- Attached: test-53659.zip
#10
@
18 months ago
- Keywords commit added; needs-testing removed
Thanks for testing @zunaid321!
Adding for commit
consideration so a committer can take a look and see if this is ready to go into Core.
This ticket was mentioned in Slack in #core by mukeshpanchal27. View the logs.
18 months ago
#12
@
18 months ago
- Owner set to mikeschroder
- Status changed from new to assigned
If there are no objections / the replies in the PR seem sufficient, @azaozz, I'm willing to do a bit of testing, and assuming things seem good, commit in my evening before Beta.
#14
@
18 months ago
- Keywords add-to-field-guide added
This doesn't need its own post, but would be useful to mention as an enhancement for folks in the field guide.
17 months ago
#15
Committed in https://core.trac.wordpress.org/changeset/56069.
This adds a new optional
$include_hidden
parameter to allow the inclusion of hidden ("." prefixed) files.Defaults to
false
for backward compatibility.Trac ticket: https://core.trac.wordpress.org/ticket/53659