" or "theme:". */ public static function all() { if ( ! function_exists( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $out = array(); $self = plugin_basename( LEAPLENS_FILE ); foreach ( get_plugins() as $file => $data ) { if ( $file === $self ) { continue; } $single = false === strpos( $file, '/' ); $out[ 'plugin:' . $file ] = array( 'key' => 'plugin:' . $file, 'type' => 'plugin', 'id' => $file, 'slug' => $single ? basename( $file, '.php' ) : dirname( $file ), 'name' => wp_strip_all_tags( $data['Name'] ), 'version' => wp_strip_all_tags( $data['Version'] ), 'active' => is_plugin_active( $file ), 'root' => wp_normalize_path( $single ? WP_PLUGIN_DIR . '/' . $file : WP_PLUGIN_DIR . '/' . dirname( $file ) ), ); } $active = array( get_stylesheet(), get_template() ); foreach ( wp_get_themes() as $stylesheet => $theme ) { $out[ 'theme:' . $stylesheet ] = array( 'key' => 'theme:' . $stylesheet, 'type' => 'theme', 'id' => (string) $stylesheet, 'slug' => (string) $stylesheet, 'name' => wp_strip_all_tags( $theme->get( 'Name' ) ), 'version' => wp_strip_all_tags( $theme->get( 'Version' ) ), 'active' => in_array( $stylesheet, $active, true ), 'root' => wp_normalize_path( $theme->get_stylesheet_directory() ), ); } return apply_filters( 'leaplens_components', $out ); } public static function readable( $root ) { return is_readable( $root ) && ( is_file( $root ) || is_dir( $root ) ); } /** PHP files relative to the root, sorted; a single-file plugin is its own root; unreadable folders are passed over. */ public static function files( $root ) { if ( is_file( $root ) ) { return array( basename( $root ) ); } if ( ! is_dir( $root ) ) { return array(); } $skip = apply_filters( 'leaplens_excluded_dirs', array( '.git', '.svn', 'node_modules', 'tests', 'test' ) ); $base = strlen( rtrim( wp_normalize_path( $root ), '/' ) ) + 1; $files = array(); try { $tree = new \RecursiveCallbackFilterIterator( new \RecursiveDirectoryIterator( $root, \FilesystemIterator::SKIP_DOTS ), static function ( $item ) use ( $skip ) { if ( $item->isDir() ) { return ! $item->isLink() && ! in_array( $item->getFilename(), $skip, true ); } return in_array( strtolower( $item->getExtension() ), self::EXTENSIONS, true ); } ); foreach ( new \RecursiveIteratorIterator( $tree, \RecursiveIteratorIterator::LEAVES_ONLY, \RecursiveIteratorIterator::CATCH_GET_CHILD ) as $item ) { $files[] = substr( wp_normalize_path( $item->getPathname() ), $base ); } } catch ( \UnexpectedValueException $e ) { return array(); } sort( $files, SORT_STRING ); return $files; } public static function path( $root, $rel ) { return is_file( $root ) ? $root : rtrim( $root, '/' ) . '/' . $rel; } }