all(); uasort( $addons, static function ( AddonInterface $a, AddonInterface $b ): int { return strcmp( $a->getName(), $b->getName() ); } ); foreach ( $addons as $id => $addon ) { $source = $this->sourceForAddon( (string) $id, $addon ); if ( null !== $source ) { $sources[] = $source; } } /** * Lets a plugin add or replace help sources. * * @param HelpSource[] $sources */ $filtered = apply_filters( 'f12_doi_help_sources', $sources ); if ( ! is_array( $filtered ) ) { return $sources; } return array_values( array_filter( $filtered, static function ( $source ): bool { return $source instanceof HelpSource; } ) ); } private function sourceForAddon( string $id, AddonInterface $addon ): ?HelpSource { $file = ( new \ReflectionClass( $addon ) )->getFileName(); if ( false === $file ) { return null; } // /src/Addon.php -> $root = dirname( $file, 2 ); $dir = $root . '/help'; if ( ! is_dir( $dir ) ) { return null; } $group = HelpSource::GROUP_MODULE; foreach ( $addon->getCapabilities() as $capability ) { if ( 0 === strpos( (string) $capability, 'form.' ) ) { $group = HelpSource::GROUP_INTEGRATION; break; } } return new HelpSource( sanitize_key( $id ), $addon->getName(), $dir, plugins_url( 'help/', $root . '/addon.php' ), $group ); } }