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

253 lines 10.3 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\Presenters\Admin\Alert_Presenter;
9
10 /**
11 * Class for managing feature toggles.
12 */
13 class Yoast_Feature_Toggles {
14
15 /**
16 * Available feature toggles.
17 *
18 * @var array
19 */
20 protected $toggles;
21
22 /**
23 * Instance holder.
24 *
25 * @var self|null
26 */
27 protected static $instance = null;
28
29 /**
30 * Gets the main feature toggles manager instance used.
31 *
32 * This essentially works like a Singleton, but for its drawbacks does not restrict
33 * instantiation otherwise.
34 *
35 * @return self Main instance.
36 */
37 public static function instance() {
38 if ( self::$instance === null ) {
39 self::$instance = new self();
40 }
41
42 return self::$instance;
43 }
44
45 /**
46 * Gets all available feature toggles.
47 *
48 * @return array List of sorted Yoast_Feature_Toggle instances.
49 */
50 public function get_all() {
51 if ( $this->toggles === null ) {
52 $this->toggles = $this->load_toggles();
53 }
54
55 return $this->toggles;
56 }
57
58 /**
59 * Loads the available feature toggles.
60 *
61 * Also ensures that the toggles are all Yoast_Feature_Toggle instances and sorted by their order value.
62 *
63 * @return array List of sorted Yoast_Feature_Toggle instances.
64 */
65 protected function load_toggles() {
66 $xml_sitemap_extra = false;
67 if ( WPSEO_Options::get( 'enable_xml_sitemap' ) ) {
68 $xml_sitemap_extra = '<a href="' . esc_url( WPSEO_Sitemaps_Router::get_base_url( 'sitemap_index.xml' ) )
69 . '" target="_blank">' . esc_html__( 'See the XML sitemap.', 'wordpress-seo' ) . '</a>';
70 }
71
72 $feature_toggles = [
73 (object) [
74 'name' => __( 'SEO analysis', 'wordpress-seo' ),
75 'setting' => 'keyword_analysis_active',
76 'label' => __( 'The SEO analysis offers suggestions to improve the SEO of your text.', 'wordpress-seo' ),
77 'read_more_label' => __( 'Learn how the SEO analysis can help you rank.', 'wordpress-seo' ),
78 'read_more_url' => 'https://yoa.st/2ak',
79 'order' => 10,
80 ],
81 (object) [
82 'name' => __( 'Readability analysis', 'wordpress-seo' ),
83 'setting' => 'content_analysis_active',
84 'label' => __( 'The readability analysis offers suggestions to improve the structure and style of your text.', 'wordpress-seo' ),
85 'read_more_label' => __( 'Discover why readability is important for SEO.', 'wordpress-seo' ),
86 'read_more_url' => 'https://yoa.st/2ao',
87 'order' => 20,
88 ],
89 (object) [
90 'name' => __( 'Cornerstone content', 'wordpress-seo' ),
91 'setting' => 'enable_cornerstone_content',
92 'label' => __( 'The cornerstone content feature lets you to mark and filter cornerstone content on your website.', 'wordpress-seo' ),
93 'read_more_label' => __( 'Find out how cornerstone content can help you improve your site structure.', 'wordpress-seo' ),
94 'read_more_url' => 'https://yoa.st/dashboard-help-cornerstone',
95 'order' => 30,
96 ],
97 (object) [
98 'name' => __( 'Text link counter', 'wordpress-seo' ),
99 'setting' => 'enable_text_link_counter',
100 'label' => __( 'The text link counter helps you improve your site structure.', 'wordpress-seo' ),
101 'read_more_label' => __( 'Find out how the text link counter can enhance your SEO.', 'wordpress-seo' ),
102 'read_more_url' => 'https://yoa.st/2aj',
103 'order' => 40,
104 ],
105 (object) [
106 'name' => __( 'Insights', 'wordpress-seo' ),
107 'premium' => true,
108 'setting' => 'enable_metabox_insights',
109 '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' ),
110 'read_more_label' => __( 'Find out how Insights can help you improve your content.', 'wordpress-seo' ),
111 'read_more_url' => 'https://yoa.st/4ew',
112 'premium_url' => 'https://yoa.st/2ai',
113 'order' => 41,
114 ],
115 (object) [
116 'name' => __( 'Link suggestions', 'wordpress-seo' ),
117 'premium' => true,
118 'setting' => 'enable_link_suggestions',
119 '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' ),
120 'read_more_label' => __( 'Read more about how internal linking can improve your site structure.', 'wordpress-seo' ),
121 'read_more_url' => 'https://yoa.st/4ev',
122 'premium_url' => 'https://yoa.st/17g',
123 'order' => 42,
124 ],
125 (object) [
126 'name' => __( 'XML sitemaps', 'wordpress-seo' ),
127 'setting' => 'enable_xml_sitemap',
128 /* translators: %s: Yoast SEO */
129 'label' => sprintf( __( 'Enable the XML sitemaps that %s generates.', 'wordpress-seo' ), 'Yoast SEO' ),
130 'read_more_label' => __( 'Read why XML Sitemaps are important for your site.', 'wordpress-seo' ),
131 'read_more_url' => 'https://yoa.st/2a-',
132 'extra' => $xml_sitemap_extra,
133 'after' => $this->sitemaps_toggle_after(),
134 'order' => 60,
135 ],
136 (object) [
137 'name' => __( 'Admin bar menu', 'wordpress-seo' ),
138 'setting' => 'enable_admin_bar_menu',
139 /* translators: 1: Yoast SEO */
140 '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' ),
141 'order' => 80,
142 ],
143 (object) [
144 'name' => __( 'Security: no advanced or schema settings for authors', 'wordpress-seo' ),
145 'setting' => 'disableadvanced_meta',
146 'label' => sprintf(
147 /* translators: 1: Yoast SEO, 2: translated version of "Off" */
148 __( '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' ),
149 'Yoast SEO',
150 __( 'Off', 'wordpress-seo' )
151 ),
152 'order' => 90,
153 ],
154 (object) [
155 'name' => __( 'Usage tracking', 'wordpress-seo' ),
156 'label' => __( 'Usage tracking', 'wordpress-seo' ),
157 'setting' => 'tracking',
158 'read_more_label' => sprintf(
159 /* translators: 1: Yoast SEO */
160 __( 'Allow us to track some data about your site to improve our plugin.', 'wordpress-seo' ),
161 'Yoast SEO'
162 ),
163 'read_more_url' => 'https://yoa.st/usage-tracking-2',
164 'order' => 95,
165 ],
166 (object) [
167 'name' => __( 'REST API: Head endpoint', 'wordpress-seo' ),
168 'setting' => 'enable_headless_rest_endpoints',
169 'label' => sprintf(
170 /* translators: 1: Yoast SEO */
171 __( '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' ),
172 'Yoast SEO'
173 ),
174 'order' => 100,
175 ],
176 (object) [
177 'name' => __( 'Enhanced Slack sharing', 'wordpress-seo' ),
178 'setting' => 'enable_enhanced_slack_sharing',
179 'label' => __( 'This adds an author byline and reading time estimate to the article’s snippet when shared on Slack.', 'wordpress-seo' ),
180 'read_more_label' => __( 'Find out how a rich snippet can improve visibility and click-through-rate.', 'wordpress-seo' ),
181 'read_more_url' => 'https://yoa.st/help-slack-share',
182 'order' => 105,
183 ],
184 ];
185
186 /**
187 * Filter to add feature toggles from add-ons.
188 *
189 * @param array $feature_toggles Array with feature toggle objects where each object
190 * should have a `name`, `setting` and `label` property.
191 */
192 $feature_toggles = apply_filters( 'wpseo_feature_toggles', $feature_toggles );
193
194 $feature_toggles = array_map( [ $this, 'ensure_toggle' ], $feature_toggles );
195 usort( $feature_toggles, [ $this, 'sort_toggles_callback' ] );
196
197 return $feature_toggles;
198 }
199
200 /**
201 * Returns html for a warning that core sitemaps are enabled when yoast seo sitemaps are disabled.
202 *
203 * @return string HTML string for the warning.
204 */
205 protected function sitemaps_toggle_after() {
206 $out = '<div id="yoast-seo-sitemaps-disabled-warning" style="display:none;">';
207 $alert = new Alert_Presenter(
208 /* translators: %1$s: expands to an opening anchor tag, %2$s: expands to a closing anchor tag */
209 \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>' ),
210 'warning'
211 );
212 $out .= $alert->present();
213 $out .= '</div>';
214
215 return $out;
216 }
217
218 /**
219 * Ensures that the passed value is a Yoast_Feature_Toggle.
220 *
221 * @param Yoast_Feature_Toggle|object|array $toggle_data Feature toggle instance, or raw object or array
222 * containing feature toggle data.
223 * @return Yoast_Feature_Toggle Feature toggle instance based on $toggle_data.
224 */
225 protected function ensure_toggle( $toggle_data ) {
226 if ( $toggle_data instanceof Yoast_Feature_Toggle ) {
227 return $toggle_data;
228 }
229
230 if ( is_object( $toggle_data ) ) {
231 $toggle_data = get_object_vars( $toggle_data );
232 }
233
234 return new Yoast_Feature_Toggle( $toggle_data );
235 }
236
237 /**
238 * Callback for sorting feature toggles by their order.
239 *
240 * {@internal Once the minimum PHP version goes up to PHP 7.0, the logic in the function
241 * can be replaced with the spaceship operator `<=>`.}
242 *
243 * @param Yoast_Feature_Toggle $feature_a Feature A.
244 * @param Yoast_Feature_Toggle $feature_b Feature B.
245 *
246 * @return int An integer less than, equal to, or greater than zero indicating respectively
247 * that feature A is considered to be less than, equal to, or greater than feature B.
248 */
249 protected function sort_toggles_callback( Yoast_Feature_Toggle $feature_a, Yoast_Feature_Toggle $feature_b ) {
250 return ( $feature_a->order - $feature_b->order );
251 }
252 }
253