PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.9
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.9
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 / admin / views / class-yoast-feature-toggles.php

class-yoast-feature-toggles.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.9, at admin/views/class-yoast-feature-toggles.php

282 lines 12.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPSEO plugin file.
4 *
5 * @package WPSEO\Admin
6 */
7
8 use Yoast\WP\SEO\Helpers\Language_Helper;
9 use Yoast\WP\SEO\Presenters\Admin\Alert_Presenter;
10
11 /**
12 * Class for managing feature toggles.
13 */
14 class Yoast_Feature_Toggles {
15
16 /**
17 * Available feature toggles.
18 *
19 * @var array
20 */
21 protected $toggles;
22
23 /**
24 * Instance holder.
25 *
26 * @var self|null
27 */
28 protected static $instance = null;
29
30 /**
31 * Gets the main feature toggles manager instance used.
32 *
33 * This essentially works like a Singleton, but for its drawbacks does not restrict
34 * instantiation otherwise.
35 *
36 * @return self Main instance.
37 */
38 public static function instance() {
39 self::$instance ??= new self();
40
41 return self::$instance;
42 }
43
44 /**
45 * Gets all available feature toggles.
46 *
47 * @return array List of sorted Yoast_Feature_Toggle instances.
48 */
49 public function get_all() {
50 $this->toggles ??= $this->load_toggles();
51
52 return $this->toggles;
53 }
54
55 /**
56 * Loads the available feature toggles.
57 *
58 * Also ensures that the toggles are all Yoast_Feature_Toggle instances and sorted by their order value.
59 *
60 * @return array List of sorted Yoast_Feature_Toggle instances.
61 */
62 protected function load_toggles() {
63 $xml_sitemap_extra = false;
64 if ( WPSEO_Options::get( 'enable_xml_sitemap' ) ) {
65 $xml_sitemap_extra = '<a href="' . esc_url( WPSEO_Sitemaps_Router::get_base_url( 'sitemap_index.xml' ) )
66 . '" target="_blank">' . esc_html__( 'See the XML sitemap.', 'wordpress-seo' ) . '</a>';
67 }
68
69 $feature_toggles = [
70 (object) [
71 'name' => __( 'SEO analysis', 'wordpress-seo' ),
72 'setting' => 'keyword_analysis_active',
73 'label' => __( 'The SEO analysis offers suggestions to improve the SEO of your text.', 'wordpress-seo' ),
74 'read_more_label' => __( 'Learn how the SEO analysis can help you rank.', 'wordpress-seo' ),
75 'read_more_url' => 'https://yoa.st/2ak',
76 'order' => 10,
77 ],
78 (object) [
79 'name' => __( 'Readability analysis', 'wordpress-seo' ),
80 'setting' => 'content_analysis_active',
81 'label' => __( 'The readability analysis offers suggestions to improve the structure and style of your text.', 'wordpress-seo' ),
82 'read_more_label' => __( 'Discover why readability is important for SEO.', 'wordpress-seo' ),
83 'read_more_url' => 'https://yoa.st/2ao',
84 'order' => 20,
85 ],
86 (object) [
87 'name' => __( 'Inclusive language analysis', 'wordpress-seo' ),
88 'supported_languages' => Language_Helper::$languages_with_inclusive_language_support,
89 'setting' => 'inclusive_language_analysis_active',
90 'label' => __( 'The inclusive language analysis offers suggestions to write more inclusive copy.', 'wordpress-seo' ),
91 'read_more_label' => __( 'Discover why inclusive language is important for SEO.', 'wordpress-seo' ),
92 'read_more_url' => 'https://yoa.st/inclusive-language-features-free',
93 'order' => 25,
94 ],
95 (object) [
96 'name' => __( 'Cornerstone content', 'wordpress-seo' ),
97 'setting' => 'enable_cornerstone_content',
98 'label' => __( 'The cornerstone content feature lets you to mark and filter cornerstone content on your website.', 'wordpress-seo' ),
99 'read_more_label' => __( 'Find out how cornerstone content can help you improve your site structure.', 'wordpress-seo' ),
100 'read_more_url' => 'https://yoa.st/dashboard-help-cornerstone',
101 'order' => 30,
102 ],
103 (object) [
104 'name' => __( 'Text link counter', 'wordpress-seo' ),
105 'setting' => 'enable_text_link_counter',
106 'label' => __( 'The text link counter helps you improve your site structure.', 'wordpress-seo' ),
107 'read_more_label' => __( 'Find out how the text link counter can enhance your SEO.', 'wordpress-seo' ),
108 'read_more_url' => 'https://yoa.st/2aj',
109 'order' => 40,
110 ],
111 (object) [
112 'name' => __( 'Insights', 'wordpress-seo' ),
113 'setting' => 'enable_metabox_insights',
114 'label' => __( 'Find relevant data about your content right in the Insights section in the Yoast SEO metabox. You’ll see what words you use most often and if they’re a match with your keywords! ', 'wordpress-seo' ),
115 'read_more_label' => __( 'Find out how Insights can help you improve your content.', 'wordpress-seo' ),
116 'read_more_url' => 'https://yoa.st/4ew',
117 'premium_url' => 'https://yoa.st/2ai',
118 'order' => 41,
119 ],
120 (object) [
121 'name' => __( 'Link suggestions', 'wordpress-seo' ),
122 'premium' => true,
123 'setting' => 'enable_link_suggestions',
124 'label' => __( 'Get relevant internal linking suggestions — while you’re writing! The link suggestions metabox shows a list of posts on your blog with similar content that might be interesting to link to. ', 'wordpress-seo' ),
125 'read_more_label' => __( 'Read more about how internal linking can improve your site structure.', 'wordpress-seo' ),
126 'read_more_url' => 'https://yoa.st/4ev',
127 'premium_url' => 'https://yoa.st/17g',
128 'premium_upsell_url' => 'https://yoa.st/get-link-suggestions',
129 'order' => 42,
130 ],
131 (object) [
132 'name' => __( 'XML sitemaps', 'wordpress-seo' ),
133 'setting' => 'enable_xml_sitemap',
134 /* translators: %s: Yoast SEO */
135 'label' => sprintf( __( 'Enable the XML sitemaps that %s generates.', 'wordpress-seo' ), 'Yoast SEO' ),
136 'read_more_label' => __( 'Read why XML Sitemaps are important for your site.', 'wordpress-seo' ),
137 'read_more_url' => 'https://yoa.st/2a-',
138 'extra' => $xml_sitemap_extra,
139 'after' => $this->sitemaps_toggle_after(),
140 'order' => 60,
141 ],
142 (object) [
143 'name' => __( 'Admin bar menu', 'wordpress-seo' ),
144 'setting' => 'enable_admin_bar_menu',
145 /* translators: 1: Yoast SEO */
146 'label' => sprintf( __( 'The %1$s admin bar menu contains useful links to third-party tools for analyzing pages and makes it easy to see if you have new notifications.', 'wordpress-seo' ), 'Yoast SEO' ),
147 'order' => 80,
148 ],
149 (object) [
150 'name' => __( 'Security: no advanced or schema settings for authors', 'wordpress-seo' ),
151 'setting' => 'disableadvanced_meta',
152 'label' => sprintf(
153 /* translators: 1: Yoast SEO, 2: translated version of "Off" */
154 __( 'The advanced section of the %1$s meta box allows a user to remove posts from the search results or change the canonical. The settings in the schema tab allows a user to change schema meta data for a post. These are things you might not want any author to do. That\'s why, by default, only editors and administrators can do this. Setting to "%2$s" allows all users to change these settings.', 'wordpress-seo' ),
155 'Yoast SEO',
156 __( 'Off', 'wordpress-seo' ),
157 ),
158 'order' => 90,
159 ],
160 (object) [
161 'name' => __( 'Usage tracking', 'wordpress-seo' ),
162 'label' => __( 'Usage tracking', 'wordpress-seo' ),
163 'setting' => 'tracking',
164 'read_more_label' => sprintf(
165 /* translators: 1: Yoast SEO */
166 __( 'Allow us to track some data about your site to improve our plugin.', 'wordpress-seo' ),
167 'Yoast SEO',
168 ),
169 'read_more_url' => 'https://yoa.st/usage-tracking-2',
170 'order' => 95,
171 ],
172 (object) [
173 'name' => __( 'REST API: Head endpoint', 'wordpress-seo' ),
174 'setting' => 'enable_headless_rest_endpoints',
175 'label' => sprintf(
176 /* translators: 1: Yoast SEO */
177 __( 'This %1$s REST API endpoint gives you all the metadata you need for a specific URL. This will make it very easy for headless WordPress sites to use %1$s for all their SEO meta output.', 'wordpress-seo' ),
178 'Yoast SEO',
179 ),
180 'order' => 100,
181 ],
182 (object) [
183 'name' => __( 'Enhanced Slack sharing', 'wordpress-seo' ),
184 'setting' => 'enable_enhanced_slack_sharing',
185 'label' => __( 'This adds an author byline and reading time estimate to the article’s snippet when shared on Slack.', 'wordpress-seo' ),
186 'read_more_label' => __( 'Find out how a rich snippet can improve visibility and click-through-rate.', 'wordpress-seo' ),
187 'read_more_url' => 'https://yoa.st/help-slack-share',
188 'order' => 105,
189 ],
190 (object) [
191 'name' => __( 'IndexNow', 'wordpress-seo' ),
192 'premium' => true,
193 'setting' => 'enable_index_now',
194 'label' => __( 'Automatically ping search engines like Bing and Yandex whenever you publish, update or delete a post.', 'wordpress-seo' ),
195 'read_more_label' => __( 'Find out how IndexNow can help your site.', 'wordpress-seo' ),
196 'read_more_url' => 'https://yoa.st/index-now-read-more',
197 'premium_url' => 'https://yoa.st/index-now-feature',
198 'premium_upsell_url' => 'https://yoa.st/get-indexnow',
199 'order' => 110,
200 ],
201 (object) [
202 'name' => __( 'AI title & description generator', 'wordpress-seo' ),
203 'premium' => true,
204 'setting' => 'enable_ai_generator',
205 'label' => __( 'Use the power of Yoast AI to automatically generate compelling titles and descriptions for your posts and pages.', 'wordpress-seo' ),
206 'read_more_label' => __( 'Learn more', 'wordpress-seo' ),
207 'read_more_url' => 'https://yoa.st/ai-generator-read-more',
208 'premium_url' => 'https://yoa.st/ai-generator-feature',
209 'premium_upsell_url' => 'https://yoa.st/get-ai-generator',
210 'order' => 115,
211 ],
212 ];
213
214 /**
215 * Filter to add feature toggles from add-ons.
216 *
217 * @param array $feature_toggles Array with feature toggle objects where each object
218 * should have a `name`, `setting` and `label` property.
219 */
220 $feature_toggles = apply_filters( 'wpseo_feature_toggles', $feature_toggles );
221
222 $feature_toggles = array_map( [ $this, 'ensure_toggle' ], $feature_toggles );
223 usort( $feature_toggles, [ $this, 'sort_toggles_callback' ] );
224
225 return $feature_toggles;
226 }
227
228 /**
229 * Returns html for a warning that core sitemaps are enabled when yoast seo sitemaps are disabled.
230 *
231 * @return string HTML string for the warning.
232 */
233 protected function sitemaps_toggle_after() {
234 $out = '<div id="yoast-seo-sitemaps-disabled-warning" style="display:none;">';
235 $alert = new Alert_Presenter(
236 /* translators: %1$s: expands to an opening anchor tag, %2$s: expands to a closing anchor tag */
237 sprintf( esc_html__( 'Disabling Yoast SEO\'s XML sitemaps will not disable WordPress\' core sitemaps. In some cases, this %1$s may result in SEO errors on your site%2$s. These may be reported in Google Search Console and other tools.', 'wordpress-seo' ), '<a target="_blank" href="' . WPSEO_Shortlinker::get( 'https://yoa.st/44z' ) . '">', '</a>' ),
238 'warning',
239 );
240 $out .= $alert->present();
241 $out .= '</div>';
242
243 return $out;
244 }
245
246 /**
247 * Ensures that the passed value is a Yoast_Feature_Toggle.
248 *
249 * @param Yoast_Feature_Toggle|object|array $toggle_data Feature toggle instance, or raw object or array
250 * containing feature toggle data.
251 *
252 * @return Yoast_Feature_Toggle Feature toggle instance based on $toggle_data.
253 */
254 protected function ensure_toggle( $toggle_data ) {
255 if ( $toggle_data instanceof Yoast_Feature_Toggle ) {
256 return $toggle_data;
257 }
258
259 if ( is_object( $toggle_data ) ) {
260 $toggle_data = get_object_vars( $toggle_data );
261 }
262
263 return new Yoast_Feature_Toggle( $toggle_data );
264 }
265
266 /**
267 * Callback for sorting feature toggles by their order.
268 *
269 * {@internal Once the minimum PHP version goes up to PHP 7.0, the logic in the function
270 * can be replaced with the spaceship operator `<=>`.}
271 *
272 * @param Yoast_Feature_Toggle $feature_a Feature A.
273 * @param Yoast_Feature_Toggle $feature_b Feature B.
274 *
275 * @return int An integer less than, equal to, or greater than zero indicating respectively
276 * that feature A is considered to be less than, equal to, or greater than feature B.
277 */
278 protected function sort_toggles_callback( Yoast_Feature_Toggle $feature_a, Yoast_Feature_Toggle $feature_b ) {
279 return ( $feature_a->order - $feature_b->order );
280 }
281 }
282