Making WordPress.org

Changeset 13136


Ignore:
Timestamp:
01/22/2024 05:31:04 AM (3 years ago)
Author:
dd32
Message:

Plugin Directory: Add the 2nd half of [13135] allowing for directories to be listed.

See #7415.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/tools/class-filesystem.php

    r9995 r13136  
    8787         */
    8888        public static function list_files( $directory, $recursive = false, $pattern = null, $depth = -1 ) {
     89                return self::list( $directory, 'files', $recursive, $pattern, $depth );
     90        }
     91
     92        /**
     93         * Returns all (usable) files/directories of a given directory.
     94         *
     95         * @static
     96         *
     97         * @param string $directory Path to directory to search.
     98         * @param bool   $type      Optional. Whether to return 'files', 'directories', or 'all'. Default: 'all'.
     99         * @param bool   $recursive Optional. Whether to recurse into subdirectories. Default: false.
     100         * @param string $pattern   Optional. A regular expression to match files against. Default: null.
     101         * @param int    $depth     Optional. Recursion depth. Default: -1 (infinite).
     102         * @return array All files within the passed directory.
     103         */
     104        public static function list( $directory, $type = 'all', $recursive = false, $pattern = null, $depth = -1 ) {
    89105                if ( $recursive ) {
    90106                        $iterator = new \RecursiveIteratorIterator(
     
    105121                $files = array();
    106122                foreach ( $filtered as $file ) {
    107                         if ( ! $file->isFile() ) {
     123                        if ( in_array( $file->getFilename(), [ '.', '..' ] ) ) {
     124                                continue;
     125                        } elseif ( 'files' === $type && ! $file->isFile() ) {
     126                                continue;
     127                        } elseif ( 'directories' === $type && ! $file->isDir() ) {
    108128                                continue;
    109129                        } elseif ( stristr( $file->getPathname(), '__MACOSX' ) ) {
Note: See TracChangeset for help on using the changeset viewer.