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

234 lines 7.5 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" => true,
90 "{$allow_prefix}content_analysis_active" => true,
91 "{$allow_prefix}keyword_analysis_active" => true,
92 "{$allow_prefix}enable_admin_bar_menu" => true,
93 "{$allow_prefix}enable_cornerstone_content" => true,
94 "{$allow_prefix}enable_xml_sitemap" => true,
95 "{$allow_prefix}enable_text_link_counter" => true,
96 "{$allow_prefix}enable_headless_rest_endpoints" => true,
97 "{$allow_prefix}enable_metabox_insights" => true,
98 "{$allow_prefix}enable_link_suggestions" => true,
99 "{$allow_prefix}tracking" => true,
100 "{$allow_prefix}enable_enhanced_slack_sharing" => true,
101 "{$allow_prefix}semrush_integration_active" => true,
102 "{$allow_prefix}zapier_integration_active" => true,
103 "{$allow_prefix}wincher_integration_active" => false,
104 ];
105
106 if ( is_multisite() ) {
107 parent::__construct();
108
109 add_filter( 'admin_title', [ 'Yoast_Input_Validation', 'add_yoast_admin_document_title_errors' ] );
110 }
111 }
112
113 /**
114 * Add filters to make sure that the option default is returned if the option is not set
115 *
116 * @return void
117 */
118 public function add_default_filters() {
119 // Don't change, needs to check for false as could return prio 0 which would evaluate to false.
120 if ( has_filter( 'default_site_option_' . $this->option_name, [ $this, 'get_defaults' ] ) === false ) {
121 add_filter( 'default_site_option_' . $this->option_name, [ $this, 'get_defaults' ] );
122 }
123 }
124
125 /**
126 * Remove the default filters.
127 * Called from the validate() method to prevent failure to add new options.
128 *
129 * @return void
130 */
131 public function remove_default_filters() {
132 remove_filter( 'default_site_option_' . $this->option_name, [ $this, 'get_defaults' ] );
133 }
134
135 /**
136 * Add filters to make sure that the option is merged with its defaults before being returned.
137 *
138 * @return void
139 */
140 public function add_option_filters() {
141 // Don't change, needs to check for false as could return prio 0 which would evaluate to false.
142 if ( has_filter( 'site_option_' . $this->option_name, [ $this, 'get_option' ] ) === false ) {
143 add_filter( 'site_option_' . $this->option_name, [ $this, 'get_option' ] );
144 }
145 }
146
147 /**
148 * Remove the option filters.
149 * Called from the clean_up methods to make sure we retrieve the original old option.
150 *
151 * @return void
152 */
153 public function remove_option_filters() {
154 remove_filter( 'site_option_' . $this->option_name, [ $this, 'get_option' ] );
155 }
156
157 /* *********** METHODS influencing add_uption(), update_option() and saving from admin pages *********** */
158
159 /**
160 * Validate the option.
161 *
162 * @param array $dirty New value for the option.
163 * @param array $clean Clean value for the option, normally the defaults.
164 * @param array $old Old value of the option.
165 *
166 * @return array Validated clean value for the option to be saved to the database.
167 */
168 protected function validate_option( $dirty, $clean, $old ) {
169
170 foreach ( $clean as $key => $value ) {
171 switch ( $key ) {
172 case 'access':
173 if ( isset( $dirty[ $key ] ) && in_array( $dirty[ $key ], self::$allowed_access_options, true ) ) {
174 $clean[ $key ] = $dirty[ $key ];
175 }
176 elseif ( function_exists( 'add_settings_error' ) ) {
177 add_settings_error(
178 $this->group_name, // Slug title of the setting.
179 $key, // Suffix-ID for the error message box.
180 /* translators: %1$s expands to the option name and %2$sexpands to Yoast SEO */
181 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.
182 'error' // Message type.
183 );
184 }
185 break;
186
187
188 case 'defaultblog':
189 if ( isset( $dirty[ $key ] ) && ( $dirty[ $key ] !== '' && $dirty[ $key ] !== '-' ) ) {
190 $int = WPSEO_Utils::validate_int( $dirty[ $key ] );
191 if ( $int !== false && $int > 0 ) {
192 // Check if a valid blog number has been received.
193 $exists = get_blog_details( $int, false );
194 if ( $exists && $exists->deleted === '0' ) {
195 $clean[ $key ] = $int;
196 }
197 elseif ( function_exists( 'add_settings_error' ) ) {
198 add_settings_error(
199 $this->group_name, // Slug title of the setting.
200 $key, // Suffix-ID for the error message box.
201 esc_html__( 'The default blog setting must be the numeric blog id of the blog you want to use as default.', 'wordpress-seo' )
202 . '<br>'
203 . sprintf(
204 /* translators: %s is the ID number of a blog. */
205 esc_html__( 'This must be an existing blog. Blog %s does not exist or has been marked as deleted.', 'wordpress-seo' ),
206 '<strong>' . esc_html( sanitize_text_field( $dirty[ $key ] ) ) . '</strong>'
207 ), // The error message.
208 'error' // Message type.
209 );
210 }
211 unset( $exists );
212 }
213 elseif ( function_exists( 'add_settings_error' ) ) {
214 add_settings_error(
215 $this->group_name, // Slug title of the setting.
216 $key, // Suffix-ID for the error message box.
217 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.
218 'error' // Message type.
219 );
220 }
221 unset( $int );
222 }
223 break;
224
225 default:
226 $clean[ $key ] = ( isset( $dirty[ $key ] ) ? WPSEO_Utils::validate_bool( $dirty[ $key ] ) : false );
227 break;
228 }
229 }
230
231 return $clean;
232 }
233 }
234