PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.2
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.2
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 / inc / options / class-wpseo-option-ms.php

class-wpseo-option-ms.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.2, at inc/options/class-wpseo-option-ms.php

260 lines 9.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\Internals\Options
6 */
7
8 /**
9 * Site option for Multisite installs only
10 *
11 * Overloads a number of methods of the abstract class to ensure the use of the correct site_option
12 * WP functions.
13 */
14 class WPSEO_Option_MS extends WPSEO_Option {
15
16 /**
17 * Option name.
18 *
19 * @var string
20 */
21 public $option_name = 'wpseo_ms';
22
23 /**
24 * Option group name for use in settings forms.
25 *
26 * @var string
27 */
28 public $group_name = 'yoast_wpseo_multisite_options';
29
30 /**
31 * Whether to include the option in the return for WPSEO_Options::get_all().
32 *
33 * @var bool
34 */
35 public $include_in_all = false;
36
37 /**
38 * Whether this option is only for when the install is multisite.
39 *
40 * @var bool
41 */
42 public $multisite_only = true;
43
44 /**
45 * Array of defaults for the option.
46 *
47 * Shouldn't be requested directly, use $this->get_defaults();
48 *
49 * @var array
50 */
51 protected $defaults = [];
52
53 /**
54 * Available options for the 'access' setting. Used for input validation.
55 *
56 * {@internal Important: Make sure the options added to the array here are in line
57 * with the keys for the options set for the select box in the
58 * admin/pages/network.php file.}}
59 *
60 * @var array
61 */
62 public static $allowed_access_options = [
63 'admin',
64 'superadmin',
65 ];
66
67 /**
68 * Get the singleton instance of this class.
69 *
70 * @return object
71 */
72 public static function get_instance() {
73 if ( ! ( self::$instance instanceof self ) ) {
74 self::$instance = new self();
75 }
76
77 return self::$instance;
78 }
79
80 /**
81 * Only run parent constructor in multisite context.
82 */
83 public function __construct() {
84 $allow_prefix = self::ALLOW_KEY_PREFIX;
85 $this->defaults = [
86 'access' => 'admin',
87 'defaultblog' => '', // Numeric blog ID or empty.
88 "{$allow_prefix}disableadvanced_meta" => true,
89 "{$allow_prefix}ryte_indexability" => false,
90 "{$allow_prefix}content_analysis_active" => true,
91 "{$allow_prefix}keyword_analysis_active" => true,
92 "{$allow_prefix}inclusive_language_analysis_active" => true,
93 "{$allow_prefix}enable_admin_bar_menu" => true,
94 "{$allow_prefix}enable_cornerstone_content" => true,
95 "{$allow_prefix}enable_xml_sitemap" => true,
96 "{$allow_prefix}enable_text_link_counter" => true,
97 "{$allow_prefix}enable_headless_rest_endpoints" => true,
98 "{$allow_prefix}enable_metabox_insights" => true,
99 "{$allow_prefix}enable_link_suggestions" => true,
100 "{$allow_prefix}tracking" => true,
101 "{$allow_prefix}enable_enhanced_slack_sharing" => true,
102 "{$allow_prefix}semrush_integration_active" => true,
103 "{$allow_prefix}wincher_integration_active" => false,
104 "{$allow_prefix}remove_feed_global" => true,
105 "{$allow_prefix}remove_feed_global_comments" => true,
106 "{$allow_prefix}remove_feed_post_comments" => true,
107 "{$allow_prefix}enable_index_now" => true,
108 "{$allow_prefix}enable_ai_generator" => true,
109 "{$allow_prefix}remove_feed_authors" => true,
110 "{$allow_prefix}remove_feed_categories" => true,
111 "{$allow_prefix}remove_feed_tags" => true,
112 "{$allow_prefix}remove_feed_custom_taxonomies" => true,
113 "{$allow_prefix}remove_feed_post_types" => true,
114 "{$allow_prefix}remove_feed_search" => true,
115 "{$allow_prefix}remove_atom_rdf_feeds" => true,
116 "{$allow_prefix}remove_shortlinks" => true,
117 "{$allow_prefix}remove_rest_api_links" => true,
118 "{$allow_prefix}remove_rsd_wlw_links" => true,
119 "{$allow_prefix}remove_oembed_links" => true,
120 "{$allow_prefix}remove_generator" => true,
121 "{$allow_prefix}remove_emoji_scripts" => true,
122 "{$allow_prefix}remove_powered_by_header" => true,
123 "{$allow_prefix}remove_pingback_header" => true,
124 "{$allow_prefix}clean_campaign_tracking_urls" => true,
125 "{$allow_prefix}clean_permalinks" => true,
126 "{$allow_prefix}search_cleanup" => true,
127 "{$allow_prefix}search_cleanup_emoji" => true,
128 "{$allow_prefix}search_cleanup_patterns" => true,
129 "{$allow_prefix}redirect_search_pretty_urls" => true,
130 "{$allow_prefix}algolia_integration_active" => true,
131 ];
132
133 if ( is_multisite() ) {
134 parent::__construct();
135
136 add_filter( 'admin_title', [ 'Yoast_Input_Validation', 'add_yoast_admin_document_title_errors' ] );
137 }
138 }
139
140 /**
141 * Add filters to make sure that the option default is returned if the option is not set
142 *
143 * @return void
144 */
145 public function add_default_filters() {
146 // Don't change, needs to check for false as could return prio 0 which would evaluate to false.
147 if ( has_filter( 'default_site_option_' . $this->option_name, [ $this, 'get_defaults' ] ) === false ) {
148 add_filter( 'default_site_option_' . $this->option_name, [ $this, 'get_defaults' ] );
149 }
150 }
151
152 /**
153 * Remove the default filters.
154 * Called from the validate() method to prevent failure to add new options.
155 *
156 * @return void
157 */
158 public function remove_default_filters() {
159 remove_filter( 'default_site_option_' . $this->option_name, [ $this, 'get_defaults' ] );
160 }
161
162 /**
163 * Add filters to make sure that the option is merged with its defaults before being returned.
164 *
165 * @return void
166 */
167 public function add_option_filters() {
168 // Don't change, needs to check for false as could return prio 0 which would evaluate to false.
169 if ( has_filter( 'site_option_' . $this->option_name, [ $this, 'get_option' ] ) === false ) {
170 add_filter( 'site_option_' . $this->option_name, [ $this, 'get_option' ] );
171 }
172 }
173
174 /**
175 * Remove the option filters.
176 * Called from the clean_up methods to make sure we retrieve the original old option.
177 *
178 * @return void
179 */
180 public function remove_option_filters() {
181 remove_filter( 'site_option_' . $this->option_name, [ $this, 'get_option' ] );
182 }
183
184 /* *********** METHODS influencing add_uption(), update_option() and saving from admin pages *********** */
185
186 /**
187 * Validate the option.
188 *
189 * @param array $dirty New value for the option.
190 * @param array $clean Clean value for the option, normally the defaults.
191 * @param array $old Old value of the option.
192 *
193 * @return array Validated clean value for the option to be saved to the database.
194 */
195 protected function validate_option( $dirty, $clean, $old ) {
196
197 foreach ( $clean as $key => $value ) {
198 switch ( $key ) {
199 case 'access':
200 if ( isset( $dirty[ $key ] ) && in_array( $dirty[ $key ], self::$allowed_access_options, true ) ) {
201 $clean[ $key ] = $dirty[ $key ];
202 }
203 elseif ( function_exists( 'add_settings_error' ) ) {
204 add_settings_error(
205 $this->group_name, // Slug title of the setting.
206 $key, // Suffix-ID for the error message box.
207 /* translators: %1$s expands to the option name and %2$sexpands to Yoast SEO */
208 sprintf( __( '%1$s is not a valid choice for who should be allowed access to the %2$s settings. Value reset to the default.', 'wordpress-seo' ), esc_html( sanitize_text_field( $dirty[ $key ] ) ), 'Yoast SEO' ), // The error message.
209 'error', // Message type.
210 );
211 }
212 break;
213
214 case 'defaultblog':
215 if ( isset( $dirty[ $key ] ) && ( $dirty[ $key ] !== '' && $dirty[ $key ] !== '-' ) ) {
216 $int = WPSEO_Utils::validate_int( $dirty[ $key ] );
217 if ( $int !== false && $int > 0 ) {
218 // Check if a valid blog number has been received.
219 $exists = get_blog_details( $int, false );
220 if ( $exists && $exists->deleted === '0' ) {
221 $clean[ $key ] = $int;
222 }
223 elseif ( function_exists( 'add_settings_error' ) ) {
224 add_settings_error(
225 $this->group_name, // Slug title of the setting.
226 $key, // Suffix-ID for the error message box.
227 esc_html__( 'The default blog setting must be the numeric blog id of the blog you want to use as default.', 'wordpress-seo' )
228 . '<br>'
229 . sprintf(
230 /* translators: %s is the ID number of a blog. */
231 esc_html__( 'This must be an existing blog. Blog %s does not exist or has been marked as deleted.', 'wordpress-seo' ),
232 '<strong>' . esc_html( sanitize_text_field( $dirty[ $key ] ) ) . '</strong>',
233 ), // The error message.
234 'error', // Message type.
235 );
236 }
237 unset( $exists );
238 }
239 elseif ( function_exists( 'add_settings_error' ) ) {
240 add_settings_error(
241 $this->group_name, // Slug title of the setting.
242 $key, // Suffix-ID for the error message box.
243 esc_html__( 'The default blog setting must be the numeric blog id of the blog you want to use as default.', 'wordpress-seo' ) . '<br>' . esc_html__( 'No numeric value was received.', 'wordpress-seo' ), // The error message.
244 'error', // Message type.
245 );
246 }
247 unset( $int );
248 }
249 break;
250
251 default:
252 $clean[ $key ] = ( isset( $dirty[ $key ] ) ? WPSEO_Utils::validate_bool( $dirty[ $key ] ) : false );
253 break;
254 }
255 }
256
257 return $clean;
258 }
259 }
260