WPSEO_Option_MS

Site option for Multisite installs only.

Defined (1)

The class is defined in the following location(s).

/inc/options/class-wpseo-option-ms.php  
  1. class WPSEO_Option_MS extends WPSEO_Option { 
  2.  
  3. /** 
  4. * @var string option name 
  5. */ 
  6. public $option_name = 'wpseo_ms'; 
  7.  
  8. /** 
  9. * @var string option group name for use in settings forms 
  10. */ 
  11. public $group_name = 'yoast_wpseo_multisite_options'; 
  12.  
  13. /** 
  14. * @var bool whether to include the option in the return for WPSEO_Options::get_all() 
  15. */ 
  16. public $include_in_all = false; 
  17.  
  18. /** 
  19. * @var bool whether this option is only for when the install is multisite 
  20. */ 
  21. public $multisite_only = true; 
  22.  
  23. /** 
  24. * @var array Array of defaults for the option 
  25. * Shouldn't be requested directly, use $this->get_defaults(); 
  26. */ 
  27. protected $defaults = array( 
  28. 'access' => 'admin',  
  29. 'defaultblog' => '', // Numeric blog ID or empty. 
  30. ); 
  31.  
  32. /** 
  33. * @var array $allowed_access_options Available options for the 'access' setting 
  34. * Used for input validation 
  35. * @static 
  36. * @internal Important: Make sure the options added to the array here are in line with the keys 
  37. * for the options set for the select box in the admin/pages/network.php file 
  38. */ 
  39. public static $allowed_access_options = array( 
  40. 'admin',  
  41. 'superadmin',  
  42. ); 
  43.  
  44.  
  45. /** 
  46. * Get the singleton instance of this class 
  47. * @return object 
  48. */ 
  49. public static function get_instance() { 
  50. if ( ! ( self::$instance instanceof self ) ) { 
  51. self::$instance = new self(); 
  52.  
  53. return self::$instance; 
  54.  
  55. /** 
  56. * Only run parent constructor in multisite context. 
  57. */ 
  58. public function __construct() { 
  59. if ( is_multisite() ) { 
  60. parent::__construct(); 
  61.  
  62. /** 
  63. * Add filters to make sure that the option default is returned if the option is not set 
  64. * @return void 
  65. */ 
  66. public function add_default_filters() { 
  67. // Don't change, needs to check for false as could return prio 0 which would evaluate to false. 
  68. if ( has_filter( 'default_site_option_' . $this->option_name, array( $this, 'get_defaults' ) ) === false ) { 
  69. add_filter( 'default_site_option_' . $this->option_name, array( $this, 'get_defaults' ) ); 
  70.  
  71.  
  72. /** 
  73. * Remove the default filters. 
  74. * Called from the validate() method to prevent failure to add new options 
  75. * @return void 
  76. */ 
  77. public function remove_default_filters() { 
  78. remove_filter( 'default_site_option_' . $this->option_name, array( $this, 'get_defaults' ) ); 
  79.  
  80.  
  81. /** 
  82. * Add filters to make sure that the option is merged with its defaults before being returned 
  83. * @return void 
  84. */ 
  85. public function add_option_filters() { 
  86. // Don't change, needs to check for false as could return prio 0 which would evaluate to false. 
  87. if ( has_filter( 'site_option_' . $this->option_name, array( $this, 'get_option' ) ) === false ) { 
  88. add_filter( 'site_option_' . $this->option_name, array( $this, 'get_option' ) ); 
  89.  
  90.  
  91. /** 
  92. * Remove the option filters. 
  93. * Called from the clean_up methods to make sure we retrieve the original old option 
  94. * @return void 
  95. */ 
  96. public function remove_option_filters() { 
  97. remove_filter( 'site_option_' . $this->option_name, array( $this, 'get_option' ) ); 
  98.  
  99.  
  100. /** *********** METHODS influencing add_uption(), update_option() and saving from admin pages *********** */ 
  101.  
  102.  
  103. /** 
  104. * Validate the option 
  105. * @param array $dirty New value for the option. 
  106. * @param array $clean Clean value for the option, normally the defaults. 
  107. * @param array $old Old value of the option. 
  108. * @return array Validated clean value for the option to be saved to the database 
  109. */ 
  110. protected function validate_option( $dirty, $clean, $old ) { 
  111.  
  112. foreach ( $clean as $key => $value ) { 
  113. switch ( $key ) { 
  114. case 'access': 
  115. if ( isset( $dirty[ $key ] ) && in_array( $dirty[ $key ], self::$allowed_access_options, true ) ) { 
  116. $clean[ $key ] = $dirty[ $key ]; 
  117. elseif ( function_exists( 'add_settings_error' ) ) { 
  118. add_settings_error( 
  119. $this->group_name, // Slug title of the setting. 
  120. '_' . $key, // Suffix-id for the error message box. 
  121. /** translators: %1$s expands to the option name and %2$sexpands to Yoast SEO */ 
  122. 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. 
  123. 'error' // Error type, either 'error' or 'updated'. 
  124. ); 
  125. break; 
  126.  
  127.  
  128. case 'defaultblog': 
  129. if ( isset( $dirty[ $key ] ) && ( $dirty[ $key ] !== '' && $dirty[ $key ] !== '-' ) ) { 
  130. $int = WPSEO_Utils::validate_int( $dirty[ $key ] ); 
  131. if ( $int !== false && $int > 0 ) { 
  132. // Check if a valid blog number has been received. 
  133. $exists = get_blog_details( $int, false ); 
  134. if ( $exists && $exists->deleted == 0 ) { 
  135. $clean[ $key ] = $int; 
  136. elseif ( function_exists( 'add_settings_error' ) ) { 
  137. add_settings_error( 
  138. $this->group_name, // Slug title of the setting. 
  139. '_' . $key, // Suffix-id for the error message box. 
  140. esc_html__( 'The default blog setting must be the numeric blog id of the blog you want to use as default.', 'wordpress-seo' ) . '<br>' . sprintf( esc_html__( 'This must be an existing blog. Blog %s does not exist or has been marked as deleted.', 'wordpress-seo' ), '<strong>' . esc_html( sanitize_text_field( $dirty[ $key ] ) ) . '</strong>' ), // The error message. 
  141. 'error' // Error type, either 'error' or 'updated'. 
  142. ); 
  143. unset( $exists ); 
  144. elseif ( function_exists( 'add_settings_error' ) ) { 
  145. add_settings_error( 
  146. $this->group_name, // Slug title of the setting. 
  147. '_' . $key, // Suffix-id for the error message box. 
  148. 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. 
  149. 'error' // Error type, either 'error' or 'updated'. 
  150. ); 
  151. unset( $int ); 
  152. break; 
  153.  
  154. default: 
  155. $clean[ $key ] = ( isset( $dirty[ $key ] ) ? WPSEO_Utils::validate_bool( $dirty[ $key ] ) : false ); 
  156. break; 
  157.  
  158. return $clean; 
  159.  
  160.  
  161. /** 
  162. * Clean a given option value 
  163. * @param array $option_value Old (not merged with defaults or filtered) option value to 
  164. * clean according to the rules for this option. 
  165. * @param string $current_version (optional) Version from which to upgrade, if not set,  
  166. * version specific upgrades will be disregarded. 
  167. * @param array $all_old_option_values (optional) Only used when importing old options to have 
  168. * access to the real old values, in contrast to the saved ones. 
  169. * @return array Cleaned option 
  170. */ 
  171.  
  172. /** 
  173. Protected function clean_option( $option_value, $current_version = null, $all_old_option_values = null ) { 
  174.   
  175. return $option_value; 
  176. */