PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.5
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.5
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / schema / application / configuration / schema-configuration.php

schema-configuration.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.5, at src/schema/application/configuration/schema-configuration.php

143 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
4 namespace Yoast\WP\SEO\Schema\Application\Configuration;
5
6 use Easy_Digital_Downloads;
7 use SeriouslySimplePodcasting\Integrations\Yoast\Schema\PodcastEpisode;
8 use TEC\Events\Integrations\Plugins\WordPress_SEO\Events_Schema;
9 use WP_Recipe_Maker;
10 use WPSEO_Addon_Manager;
11 use Yoast\WP\SEO\Helpers\Options_Helper;
12 use Yoast\WP\SEO\Helpers\Product_Helper;
13 use Yoast\WP\SEO\Helpers\Woocommerce_Helper;
14
15 /**
16 * Responsible for the schema configuration.
17 *
18 * @makePublic
19 */
20 class Schema_Configuration {
21
22 /**
23 * The WooCommerce helper.
24 *
25 * @var Woocommerce_Helper
26 */
27 private $woocommerce_helper;
28
29 /**
30 * The product helper.
31 *
32 * @var Product_Helper
33 */
34 private $product_helper;
35
36 /**
37 * The addon manager.
38 *
39 * @var WPSEO_Addon_Manager
40 */
41 private $addon_manager;
42
43 /**
44 * The options helper.
45 *
46 * @var Options_Helper
47 */
48 private $options_helper;
49
50 /**
51 * Schema_Configuration constructor.
52 *
53 * @param Woocommerce_Helper $woocommerce_helper The WooCommerce helper.
54 * @param Product_Helper $product_helper The product helper.
55 * @param WPSEO_Addon_Manager $addon_manager The addon manager.
56 * @param Options_Helper $options_helper The options helper.
57 */
58 public function __construct(
59 Woocommerce_Helper $woocommerce_helper,
60 Product_Helper $product_helper,
61 WPSEO_Addon_Manager $addon_manager,
62 Options_Helper $options_helper
63 ) {
64 $this->woocommerce_helper = $woocommerce_helper;
65 $this->product_helper = $product_helper;
66 $this->addon_manager = $addon_manager;
67 $this->options_helper = $options_helper;
68 }
69
70 /**
71 * Returns the schema configuration.
72 *
73 * @return array<string, bool|array<string, array<string, bool|string>>>
74 */
75 public function get_configuration(): array {
76 return [
77 'isSchemaDisabledProgrammatically' => $this->is_schema_disabled_programmatically(),
78 'schemaApiIntegrations' => $this->get_schema_api_integrations(),
79 ];
80 }
81
82 /**
83 * Gets the schema API integrations status.
84 *
85 * @return array<string, array<string, bool|string>> The schema API integrations status.
86 */
87 public function get_schema_api_integrations(): array {
88 $woocommerce_seo_file = 'wpseo-woocommerce/wpseo-woocommerce.php';
89 $woocommerce_active = $this->woocommerce_helper->is_active();
90 $woocommerce_seo_active = \is_plugin_active( $woocommerce_seo_file );
91 $woocommerce_seo_installed = $this->addon_manager->is_installed( WPSEO_Addon_Manager::WOOCOMMERCE_SLUG );
92
93 $woocommerce_seo_activate_url = \wp_nonce_url(
94 \self_admin_url( 'plugins.php?action=activate&plugin=' . $woocommerce_seo_file ),
95 'activate-plugin_' . $woocommerce_seo_file,
96 );
97
98 $is_premium = $this->product_helper->is_premium();
99
100 return [
101 'tec' => [
102 'isActive' => \class_exists( Events_Schema::class ),
103 ],
104 'ssp' => [
105 'isActive' => \class_exists( PodcastEpisode::class ),
106 ],
107 'wp-recipe-maker' => [
108 'isActive' => \class_exists( WP_Recipe_Maker::class ),
109 ],
110 'woocommerce' => [
111 'isPrerequisiteActive' => $woocommerce_active,
112 'isActive' => $woocommerce_seo_active,
113 'isInstalled' => $woocommerce_seo_installed,
114 'activationLink' => $woocommerce_seo_activate_url,
115 ],
116 'edd' => [
117 'isActive' => \class_exists( Easy_Digital_Downloads::class ),
118 'isPremium' => $is_premium,
119 ],
120 ];
121 }
122
123 /**
124 * Checks if the schema is disabled programmatically via the wpseo_json_ld_output filter.
125 *
126 * Only returns true if schema is enabled via the option (toggle) but disabled by external code.
127 *
128 * @return bool Whether schema is disabled by external code.
129 */
130 public function is_schema_disabled_programmatically(): bool {
131 $deprecated_data = [
132 '_deprecated' => 'Please use the "wpseo_schema_*" filters to extend the Yoast SEO schema data - see the WPSEO_Schema class.',
133 ];
134
135 /**
136 * Filter documented in Schema_Presenter::present().
137 */
138 $filtered_schema = \apply_filters( 'wpseo_json_ld_output', $deprecated_data, '' );
139
140 return ( $filtered_schema === [] || $filtered_schema === false );
141 }
142 }
143