> */ public static function known(): array { return array( 'yoast' => array( 'label' => 'Yoast SEO', 'test' => static fn(): bool => defined( 'WPSEO_VERSION' ) || class_exists( 'WPSEO_Options' ), 'version' => static fn(): string => defined( 'WPSEO_VERSION' ) ? (string) constant( 'WPSEO_VERSION' ) : '', 'surfaces' => array( 'title', 'description', 'canonical', 'robots', 'open_graph', 'twitter', 'schema', 'breadcrumbs', 'sitemap', 'robots_txt' ), ), 'rankmath' => array( 'label' => 'Rank Math', 'test' => static fn(): bool => class_exists( 'RankMath' ) || defined( 'RANK_MATH_VERSION' ), 'version' => static fn(): string => defined( 'RANK_MATH_VERSION' ) ? (string) constant( 'RANK_MATH_VERSION' ) : '', 'surfaces' => array( 'title', 'description', 'canonical', 'robots', 'open_graph', 'twitter', 'schema', 'breadcrumbs', 'sitemap', 'robots_txt' ), ), 'aioseo' => array( 'label' => 'All in One SEO', 'test' => static fn(): bool => defined( 'AIOSEO_VERSION' ) || function_exists( 'aioseo' ), 'version' => static fn(): string => defined( 'AIOSEO_VERSION' ) ? (string) constant( 'AIOSEO_VERSION' ) : '', 'surfaces' => array( 'title', 'description', 'canonical', 'robots', 'open_graph', 'twitter', 'schema', 'breadcrumbs', 'sitemap', 'robots_txt' ), ), 'seopress' => array( 'label' => 'SEOPress', 'test' => static fn(): bool => defined( 'SEOPRESS_VERSION' ) || function_exists( 'seopress_init' ), 'version' => static fn(): string => defined( 'SEOPRESS_VERSION' ) ? (string) constant( 'SEOPRESS_VERSION' ) : '', 'surfaces' => array( 'title', 'description', 'canonical', 'robots', 'open_graph', 'twitter', 'schema', 'breadcrumbs', 'sitemap', 'robots_txt' ), ), 'seoframe' => array( 'label' => 'The SEO Framework', 'test' => static fn(): bool => defined( 'THE_SEO_FRAMEWORK_VERSION' ) || function_exists( 'tsf' ), 'version' => static fn(): string => defined( 'THE_SEO_FRAMEWORK_VERSION' ) ? (string) constant( 'THE_SEO_FRAMEWORK_VERSION' ) : '', 'surfaces' => array( 'title', 'description', 'canonical', 'robots', 'open_graph', 'twitter', 'schema', 'sitemap' ), ), 'slimseo' => array( 'label' => 'Slim SEO', 'test' => static fn(): bool => defined( 'SLIM_SEO_VER' ) || class_exists( '\SlimSEO\Loader' ), 'version' => static fn(): string => defined( 'SLIM_SEO_VER' ) ? (string) constant( 'SLIM_SEO_VER' ) : '', 'surfaces' => array( 'title', 'description', 'canonical', 'robots', 'open_graph', 'twitter', 'schema', 'sitemap' ), ), 'squirrly' => array( 'label' => 'Squirrly SEO', 'test' => static fn(): bool => defined( 'SQ_VERSION' ) || class_exists( 'SQ_Classes_ObjController' ), 'version' => static fn(): string => defined( 'SQ_VERSION' ) ? (string) constant( 'SQ_VERSION' ) : '', 'surfaces' => array( 'title', 'description', 'canonical', 'robots', 'open_graph', 'twitter', 'schema', 'sitemap' ), ), 'wpsso' => array( 'label' => 'WPSSO Core', 'test' => static fn(): bool => defined( 'WPSSO_VERSION' ) || class_exists( 'Wpsso' ), 'version' => static fn(): string => defined( 'WPSSO_VERSION' ) ? (string) constant( 'WPSSO_VERSION' ) : '', 'surfaces' => array( 'description', 'canonical', 'open_graph', 'twitter', 'schema' ), ), 'schemapro' => array( 'label' => 'Schema Pro', 'test' => static fn(): bool => defined( 'BSF_AIOSRS_PRO_VER' ), 'version' => static fn(): string => defined( 'BSF_AIOSRS_PRO_VER' ) ? (string) constant( 'BSF_AIOSRS_PRO_VER' ) : '', 'surfaces' => array( 'schema' ), ), 'jetpack' => array( 'label' => 'Jetpack (social meta)', 'test' => static fn(): bool => class_exists( 'Jetpack' ), 'version' => static fn(): string => defined( 'JETPACK__VERSION' ) ? (string) constant( 'JETPACK__VERSION' ) : '', 'surfaces' => array( 'open_graph', 'twitter', 'sitemap' ), ), ); } /** * Everything currently active, newest information first. * * @return list> */ public static function active(): array { $out = array(); foreach ( self::known() as $id => $def ) { if ( ! ( $def['test'] )() ) { continue; } $out[] = array( 'id' => $id, 'label' => (string) $def['label'], 'version' => ( $def['version'] )(), 'surfaces' => array_values( (array) $def['surfaces'] ), ); } return $out; } /** * The single most likely conflict partner — the one whose output we would * otherwise duplicate. Full SEO suites win over single-purpose plugins. */ public static function primary(): ?array { $active = self::active(); if ( empty( $active ) ) { return null; } usort( $active, static fn( array $a, array $b ): int => count( $b['surfaces'] ) <=> count( $a['surfaces'] ) ); return $active[0]; } /** * Is something on this site writing SEO tags that we cannot name? * * The list above covers the ten plugins nearly every site runs, and it is * the wrong list to stake the duplicate-tag firewall on. A white-labelled * build, a theme with SEO fields of its own, a niche plugin or somebody's * functions.php all write a canonical and a description just as happily, * and none of them define a constant we know. On those sites detection * came back empty, the firewall never started, and the customer got two * canonicals with a screen telling them nothing else was writing tags. * * So the page itself is the evidence. A scan that finds a description, * Open Graph, Twitter or JSON-LD outside our own markers has found another * writer, whoever it is — those four are chosen because WordPress core * emits none of them, unlike `robots` and `canonical`. */ public static function unknown_writer(): bool { return (bool) get_option( self::OPT_FOREIGN, false ); } /** * Record what the last scan saw. Cleared as readily as it is set: a site * that removes the other plugin should stop being told it has one. */ public static function note_unknown_writer( bool $found ): void { if ( $found === self::unknown_writer() ) { return; } update_option( self::OPT_FOREIGN, $found, false ); } /** * Is anything at all besides us writing to the head? * * The question the firewall actually needs answered — "is there a * competitor", not "which competitor". */ public static function any_competitor(): bool { return ! empty( self::active() ) || self::unknown_writer(); } /** * Surfaces at least one other plugin claims. * * @return list */ public static function contested(): array { $all = array(); foreach ( self::active() as $p ) { $all = array_merge( $all, $p['surfaces'] ); } return array_values( array_unique( $all ) ); } }