WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 3 weeks 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:

Description

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)

@wonderboymusic3 years ago

comment:1 @scribu3 years ago

Wouldn't glob() be more appropriate?

comment:2 @markoheijnen3 years ago

I'm curious how this effect the performance

comment:3 @wonderboymusic3 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

comment:4 @Mamaduka3 years ago

  • Cc georgemamadashvili@… added

comment:5 @chriscct73 weeks ago

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