[wp-trac] [WordPress Trac] #6531: Recursively search for files in theme and plugin editors

WordPress Trac noreply at wordpress.org
Wed Sep 6 22:48:24 UTC 2017


#6531: Recursively search for files in theme and plugin editors
--------------------------------------+-----------------------------
 Reporter:  torbens                   |       Owner:  chsxf
     Type:  defect (bug)              |      Status:  assigned
 Priority:  normal                    |   Milestone:  4.9
Component:  Themes                    |     Version:  2.5
 Severity:  minor                     |  Resolution:
 Keywords:  theme-editor needs-patch  |     Focuses:  administration
--------------------------------------+-----------------------------

Comment (by westonruter):

 Replying to [comment:31 wonderboymusic]:
 > we need a better solution for recursion here

 @wonderboymusic Do you have specific feedback on what needs improvement?
 Is it that recursion in general is bad or the current implementation in
 the patch needs revision?

 I'm looking for other cases of recursive directory traversal in core and I
 see:

 * `list_files()`, which isn't even used in core. (⁉️)
 * `recurse_dirsize()` used in `get_dirsize()` which is used in
 `get_space_used()` which are then used in `wp_dashboard_quota()`). Results
 are stored in transient.
 * `wpmu_delete_blog()` which is recursing directories via iteration.
 * `WP_Theme::scandir()` which is used in `WP_Theme::get_files()` and
 currently limits depths by file type. This one seems it should be
 refactored to get the full list of files and then split them up by type,
 rather than do multiple directory iterations for each type.

 One thing to consider as well is to add the list of theme/plugin files to
 a transient, with the theme/plugin version in the cache key, so that the
 recursion doesn't have to be done every single time the editor is loaded.

 It seems that `get_plugin_files()` should be using `list_files()`, since
 the former is using nested loops rather than proper recursion.

 I think it would be better to go the route of using a recursive directory
 iterator rather than add filters to extend the depth on a type-by-type
 basis.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/6531#comment:38>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list