Make WordPress Core

Opened 3 years ago

Last modified 7 months ago

#21403 new enhancement

Introduce wp_scandir, remove opendir / closedir code

Reported by: wonderboymusic Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.0
Component: Filesystem API Keywords: needs-refresh dev-feedback
Focuses: Cc:


There is @opendir code all over the place that is not standardized. On top of that, there is plenty of code that is duplicated and could be condensed into one handy function. Plus, in all of the places we are using opendir(), we really want to be using scandir().

I have created a master function in load.php called wp_scandir() that does the basics:

  • scans a directory for files / subdirectories
  • filters list by extension(s)
  • optionally returns ONLY files

This cleans up code in many places.

Attachments (1)

wp-scandir.diff (16.4 KB) - added by wonderboymusic 3 years ago.

Download all attachments as: .zip

Change History (6)

#1 @scribu
3 years ago

Wouldn't glob() be more appropriate?

#2 @markoheijnen
3 years ago

I'm curious how this effect the performance

#3 @wonderboymusic
3 years ago

opendir is the PHP4 alternative to scandir - scandir is faster and requires less code. glob might be ok but is less standard. I was following @nacin's lead, he used scandir in WP_Theme

#4 @Mamaduka
3 years ago

  • Cc georgemamadashvili@… added

#5 @chriscct7
7 months ago

  • Keywords needs-refresh dev-feedback added; has-patch removed
Note: See TracTickets for help on using tickets.