/canonical/schema — a duplicate is worse for SEO than * emitting nothing. * * Covers all five plugins the TZ names (Yoast, Rank Math, All in One SEO, * SEOPress, The SEO Framework), which is broader than the migration * module's three adapters — migration only needs the ones it can import * FROM, but compatibility must yield to any competitor that would also * print tags. Each is detected by a defined constant or loaded class. * * The signal check is injectable so the pure "is any competitor active" * logic is unit-tested without a live WordPress; production uses the * real defined()/class_exists() checker. * * @package ABDS_SEO */ if ( ! defined( 'ABSPATH' ) ) { exit; } /** * Competitor-SEO-plugin presence detection for compatibility mode. */ class ABDS_SEO_Compat_Detector { /** * Competitor slug => the signals (constant names / class names) that * indicate it is active. A competitor counts as active if ANY of its * signals is present. */ const COMPETITOR_SIGNALS = array( 'yoast' => array( 'WPSEO_VERSION', 'WPSEO_FILE' ), 'rankmath' => array( 'RANK_MATH_VERSION', 'RankMath' ), 'aioseo' => array( 'AIOSEO_VERSION', 'AIOSEO\\Plugin\\AIOSEO' ), 'seopress' => array( 'SEOPRESS_VERSION', 'SEOPRESS_PLUGIN_FILE' ), 'seo_framework' => array( 'THE_SEO_FRAMEWORK_VERSION', 'the_seo_framework' ), ); /** * Signal checker: fn( string $signal ): bool — true when the named * constant is defined or the named class/function exists. Injectable * for tests. * * @var callable */ protected $signal_checker; /** * Constructor. * * @param callable|null $signal_checker Optional override for tests; * defaults to the real * defined()/class_exists() checker. */ public function __construct( ?callable $signal_checker = null ) { $this->signal_checker = $signal_checker ?? array( self::class, 'default_signal_present' ); } /** * Whether any competing SEO plugin is active. * * @return bool */ public function has_active_competitor(): bool { return array() !== $this->active_competitors(); } /** * Slugs of every competing SEO plugin currently detected as active. * * @return string[] */ public function active_competitors(): array { $active = array(); foreach ( self::COMPETITOR_SIGNALS as $slug => $signals ) { foreach ( $signals as $signal ) { if ( (bool) call_user_func( $this->signal_checker, $signal ) ) { $active[] = $slug; break; } } } return $active; } /** * Display name of a competitor slug from COMPETITOR_SIGNALS (brand names, * not translated). * * @param string $slug Slug, e.g. 'yoast'. * @return string The plugin's name; the slug itself when unknown. */ public static function label( string $slug ): string { $labels = array( 'yoast' => 'Yoast SEO', 'rankmath' => 'Rank Math SEO', 'aioseo' => 'All in One SEO', 'seopress' => 'SEOPress', 'seo_framework' => 'The SEO Framework', ); return $labels[ $slug ] ?? $slug; } /** * Real signal check: the constant is defined, or a class/function of * that name exists. * * @param string $signal Constant, class, or function name. * @return bool */ public static function default_signal_present( string $signal ): bool { return defined( $signal ) || class_exists( $signal ) || function_exists( $signal ); } }