'Yoast SEO', 'wordpress-seo-premium' => 'Yoast SEO Premium', 'seo-by-rank-math' => 'Rank Math', 'all-in-one-seo-pack' => 'All in One SEO', 'all-in-one-seo-pack-pro' => 'All in One SEO Pro', 'wp-seopress' => 'SEOPress', 'autodescription' => 'The SEO Framework', 'slim-seo' => 'Slim SEO', ); $active = (array) get_option( 'active_plugins', array() ); if ( is_multisite() ) { $active = array_merge( $active, array_keys( (array) get_site_option( 'active_sitewide_plugins', array() ) ) ); } $found = array(); foreach ( $active as $file ) { $slug = strtok( (string) $file, '/' ); if ( isset( $known[ $slug ] ) ) { $found[] = $known[ $slug ]; } } $constants = array( 'WPSEO_VERSION' => 'Yoast SEO', 'RANK_MATH_VERSION' => 'Rank Math', 'AIOSEO_VERSION' => 'All in One SEO', 'SEOPRESS_VERSION' => 'SEOPress', 'THE_SEO_FRAMEWORK_VERSION' => 'The SEO Framework', 'SLIM_SEO_VER' => 'Slim SEO', ); foreach ( $constants as $constant => $name ) { if ( defined( $constant ) ) { $found[] = $name; } } $found = array_values( array_unique( $found ) ); return $found; } /** * List metadata owners that suppress every STS SEO feature. * * Unchanged contract since 0.1: a non-empty result turns all frontend output * off. Since 0.3.0 Jetpack is no longer listed here; it is handled per feature. * * @return string[] Human-readable names. */ function sts_seo_conflicts() { /** * Filter detected providers; integrations may add a custom metadata owner. * * @param string[] $found Names of active full SEO suites. */ $found = apply_filters( 'sts_seo_conflicts', sts_seo_detected_suites() ); return is_array( $found ) ? array_values( array_filter( $found, 'is_string' ) ) : array( 'Unknown metadata provider' ); } /** * Whether the site keeps Jetpack's own social tags instead of STS SEO's. * * @return bool True when STS SEO should manage social tags (default). */ function sts_seo_manages_jetpack_social() { /** * Filter whether STS SEO, rather than Jetpack, outputs social sharing tags. * * Return false to keep Jetpack's Open Graph and Twitter Card tags; STS SEO * then skips its own social tags wherever Jetpack outputs them. * * @param bool $manage Default true. */ return (bool) apply_filters( 'sts_seo_jetpack_social', true ); } /** * Features currently provided by Jetpack, which STS SEO therefore leaves alone. * * Uses only Jetpack's public module check and its documented filters. * * @return string[] Feature keys. */ function sts_seo_jetpack_features() { if ( ! class_exists( 'Jetpack' ) || ! is_callable( array( 'Jetpack', 'is_module_active' ) ) ) { return array(); } $owned = array(); // phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Reading Jetpack's documented filters. if ( Jetpack::is_module_active( 'seo-tools' ) && ! apply_filters( 'jetpack_disable_seo_tools', false ) ) { if ( apply_filters( 'jetpack_seo_custom_titles', true ) ) { $owned[] = 'title'; } if ( apply_filters( 'jetpack_seo_meta_tags_enabled', true ) ) { $owned[] = 'description'; } } // Jetpack decides whether to load its Open Graph tags at wp_head priority 1. if ( ! sts_seo_manages_jetpack_social() && apply_filters( 'jetpack_enable_open_graph', false ) ) { $owned[] = 'social'; } // phpcs:enable return $owned; } /** * The plugin that owns a feature instead of STS SEO, or '' when STS SEO does. * * @param string $feature Feature key from sts_seo_features(). * @return string Owner name, or ''. */ function sts_seo_feature_owner( $feature ) { $owner = in_array( $feature, sts_seo_jetpack_features(), true ) ? 'Jetpack' : ''; /** * Filter which plugin owns a single STS SEO feature. * * Return a non-empty name to let another plugin provide that feature; STS * SEO then skips only that output. Return '' to let STS SEO provide it. * * @param string $owner Current owner name, or ''. * @param string $feature One of title, description, social, posts_canonical, schema. */ $owner = apply_filters( 'sts_seo_feature_owner', $owner, $feature ); return is_string( $owner ) ? $owner : 'Unknown metadata provider'; } /** * Whether STS SEO should output a feature on this request. * * @param string $feature Feature key from sts_seo_features(). * @return bool */ function sts_seo_feature_enabled( $feature ) { if ( ! apply_filters( 'sts_seo_enabled', true ) || sts_seo_conflicts() ) { return false; } return '' === sts_seo_feature_owner( $feature ); } /** * Turn off Jetpack's Open Graph and Twitter Card tags where STS SEO outputs its own. * * Hooked to Jetpack's documented `jetpack_enable_open_graph` filter at priority * 100, after Jetpack's own defaults (0) and its conflict list (99). Applies only * on requests where STS SEO actually prints social tags (public Posts, Pages and * the posts index), so Jetpack keeps archives and other views. Nothing is stored: * deactivating STS SEO or returning false from `sts_seo_jetpack_social` restores * Jetpack's tags immediately. * * @param bool $enabled Whether Jetpack will output Open Graph tags. * @return bool */ function sts_seo_jetpack_open_graph( $enabled ) { if ( ! $enabled || is_admin() || ! sts_seo_manages_jetpack_social() || ! sts_seo_feature_enabled( 'social' ) ) { return $enabled; } return sts_seo_metadata() ? false : $enabled; }