own_dir = trailingslashit( $own_dir ); } /** * The units of the current site. * * @return list `path` is a directory, or a file for a single-file plugin; empty for the options and dump units. */ public function units(): array { $units = array( array( 'type' => self::OPTIONS, 'label' => self::OPTIONS, 'path' => '', ), ); foreach ( $this->active_plugins() as $basename ) { $path = WP_PLUGIN_DIR . '/' . ( '.' === dirname( $basename ) ? $basename : dirname( $basename ) ); if ( trailingslashit( $path ) !== $this->own_dir && file_exists( $path ) ) { $units[] = array( 'type' => self::PLUGIN, 'label' => self::PLUGIN . ':' . ( '.' === dirname( $basename ) ? basename( $basename, '.php' ) : dirname( $basename ) ), 'path' => $path, ); } } $theme = wp_get_theme(); foreach ( array_unique( array( $theme->get_stylesheet_directory(), $theme->get_template_directory() ) ) as $directory ) { $units[] = array( 'type' => self::THEME, 'label' => self::THEME . ':' . basename( $directory ), 'path' => $directory, ); } $units[] = array( 'type' => self::DUMP, 'label' => 'enqueue', 'path' => '', ); return $units; } /** * Plugin basenames, active on the site or network-wide, sorted. * * @return list */ private function active_plugins(): array { $active = (array) get_option( 'active_plugins', array() ); if ( is_multisite() ) { $active = array_merge( $active, array_keys( (array) get_site_option( 'active_sitewide_plugins', array() ) ) ); } $active = array_unique( array_filter( $active, 'is_string' ) ); sort( $active ); return $active; } }