'All in One SEO', 'all-in-one-seo-pack-pro/' => 'All in One SEO', 'wp-seopress/' => 'SEOPress', 'wp-seopress-pro/' => 'SEOPress', 'autodescription/' => 'The SEO Framework', 'slim-seo/' => 'Slim SEO', 'squirrly-seo/' => 'Squirrly SEO', ); /** * Adapter by key (null = unknown key). * * @param string $key rank_math|yoast|none. */ public static function for_key( string $key ): ?SeoAdapterInterface { switch ( $key ) { case 'rank_math': return new RankMathAdapter(); case 'yoast': return new YoastAdapter(); case 'none': return new NoneAdapter(); } return null; } /** * The adapter to use now. */ public static function current(): SeoAdapterInterface { return self::detect()['adapter']; } /** * Detection result. * * @return array{adapter:SeoAdapterInterface,others:array} */ public static function detect(): array { /** * Overrides the SEO adapter: an adapter object or a key (rank_math|yoast|none). * * @param SeoAdapterInterface|string|null $adapter Adapter. */ $forced = apply_filters( 'addsynapse_assistant_seo_adapter', null ); if ( $forced instanceof SeoAdapterInterface ) { return array( 'adapter' => $forced, 'others' => array(), ); } if ( is_string( $forced ) && '' !== $forced ) { return array( 'adapter' => self::for_key( $forced ) ?? new NoneAdapter(), 'others' => array(), ); } $active = self::active_plugins(); $rank = defined( 'RANK_MATH_VERSION' ) || class_exists( 'RankMath' ) || self::has( $active, 'seo-by-rank-math/' ); $yoast = defined( 'WPSEO_VERSION' ) || self::has( $active, 'wordpress-seo/' ) || self::has( $active, 'wordpress-seo-premium/' ); $others = array(); foreach ( self::UNSUPPORTED as $prefix => $name ) { if ( self::has( $active, $prefix ) ) { $others[] = $name; } } if ( $rank ) { $adapter = new RankMathAdapter(); if ( $yoast ) { $others[] = 'Yoast SEO'; } } elseif ( $yoast ) { $adapter = new YoastAdapter(); } else { $adapter = new NoneAdapter( $others ? $others[0] : '' ); $others = array_slice( $others, 1 ); } return array( 'adapter' => $adapter, 'others' => array_values( array_unique( $others ) ), ); } /** * Active plugin files (site + network). * * @return array */ private static 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() ) ) ); } return array_map( 'strval', array_values( $active ) ); } /** * Whether a plugin folder is active. * * @param array $active Active files. * @param string $prefix Folder prefix ("slug/"). */ private static function has( array $active, string $prefix ): bool { foreach ( $active as $file ) { if ( 0 === strpos( $file, $prefix ) ) { return true; } } return false; } }