WPSEO_Option_Wpseo

Option: wpseo.

Defined (1)

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

/inc/options/class-wpseo-option-wpseo.php  
  1. class WPSEO_Option_Wpseo extends WPSEO_Option { 
  2.  
  3. /** 
  4. * @var string option name 
  5. */ 
  6. public $option_name = 'wpseo'; 
  7.  
  8. /** 
  9. * @var array Array of defaults for the option 
  10. * Shouldn't be requested directly, use $this->get_defaults(); 
  11. */ 
  12. protected $defaults = array( 
  13. // Non-form fields, set via (ajax) function. 
  14. 'blocking_files' => array(),  
  15. 'ms_defaults_set' => false,  
  16. // Non-form field, should only be set via validation routine. 
  17. 'version' => '', // Leave default as empty to ensure activation/upgrade works. 
  18.  
  19. // Form fields. 
  20. 'company_logo' => '',  
  21. 'company_name' => '',  
  22. 'company_or_person' => '',  
  23. 'disableadvanced_meta' => true,  
  24. 'onpage_indexability' => true,  
  25. 'googleverify' => '', // Text field. 
  26. 'msverify' => '', // Text field. 
  27. 'person_name' => '',  
  28. 'website_name' => '',  
  29. 'alternate_website_name' => '',  
  30. 'yandexverify' => '',  
  31. 'site_type' => '', // List of options. 
  32. 'has_multiple_authors' => '',  
  33. 'environment_type' => '',  
  34. 'content_analysis_active' => true,  
  35. 'keyword_analysis_active' => true,  
  36. 'enable_setting_pages' => true,  
  37. 'enable_admin_bar_menu' => true,  
  38. 'enable_cornerstone_content' => true,  
  39. 'show_onboarding_notice' => false,  
  40. 'first_activated_on' => false,  
  41. ); 
  42.  
  43. /** 
  44. * @var array Sub-options which should not be overloaded with multi-site defaults 
  45. */ 
  46. public $ms_exclude = array( 
  47. /** privacy */ 
  48. 'alexaverify',  
  49. 'googleverify',  
  50. 'msverify',  
  51. 'yandexverify',  
  52. ); 
  53.  
  54. /** @var array Possible values for the site_type option */ 
  55. protected $site_types = array( 
  56. '',  
  57. 'blog',  
  58. 'news',  
  59. 'smallBusiness',  
  60. 'corporateOther',  
  61. 'personalOther',  
  62. ); 
  63.  
  64. /** @var array Possible environment types. */ 
  65. protected $environment_types = array( 
  66. '',  
  67. 'production',  
  68. 'staging',  
  69. 'development',  
  70. ); 
  71.  
  72. /** 
  73. * Add the actions and filters for the option 
  74. * @todo [JRF => testers] Check if the extra actions below would run into problems if an option 
  75. * is updated early on and if so, change the call to schedule these for a later action on add/update 
  76. * instead of running them straight away 
  77. * @return \WPSEO_Option_Wpseo 
  78. */ 
  79. protected function __construct() { 
  80. parent::__construct(); 
  81.  
  82. /** Clear the cache on update/add */ 
  83. add_action( 'add_option_' . $this->option_name, array( 'WPSEO_Utils', 'clear_cache' ) ); 
  84. add_action( 'update_option_' . $this->option_name, array( 'WPSEO_Utils', 'clear_cache' ) ); 
  85.  
  86. /** 
  87. * Filter the `wpseo` option defaults. 
  88. * @param array $defaults Array the defaults for the `wpseo` option attributes. 
  89. */ 
  90. $this->defaults = apply_filters( 'wpseo_option_wpseo_defaults', $this->defaults ); 
  91.  
  92.  
  93. /** 
  94. * Get the singleton instance of this class 
  95. * @return object 
  96. */ 
  97. public static function get_instance() { 
  98. if ( ! ( self::$instance instanceof self ) ) { 
  99. self::$instance = new self(); 
  100.  
  101. return self::$instance; 
  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 'version': 
  115. $clean[ $key ] = WPSEO_VERSION; 
  116. break; 
  117.  
  118.  
  119. case 'blocking_files': 
  120. /** 
  121. * @internal [JRF] to really validate this we should also do a file_exists() 
  122. * on each array entry and remove files which no longer exist, but that might be overkill 
  123. */ 
  124. if ( isset( $dirty[ $key ] ) && is_array( $dirty[ $key ] ) ) { 
  125. $clean[ $key ] = array_unique( $dirty[ $key ] ); 
  126. elseif ( isset( $old[ $key ] ) && is_array( $old[ $key ] ) ) { 
  127. $clean[ $key ] = array_unique( $old[ $key ] ); 
  128. break; 
  129.  
  130. case 'company_or_person': 
  131. if ( isset( $dirty[ $key ] ) && $dirty[ $key ] !== '' ) { 
  132. if ( in_array( $dirty[ $key ], array( 'company', 'person' ) ) ) { 
  133. $clean[ $key ] = $dirty[ $key ]; 
  134. break; 
  135.  
  136. /** text fields */ 
  137. case 'company_name': 
  138. case 'person_name': 
  139. case 'website_name': 
  140. case 'alternate_website_name': 
  141. if ( isset( $dirty[ $key ] ) && $dirty[ $key ] !== '' ) { 
  142. $clean[ $key ] = sanitize_text_field( $dirty[ $key ] ); 
  143. break; 
  144.  
  145. case 'company_logo': 
  146. $this->validate_url( $key, $dirty, $old, $clean ); 
  147. break; 
  148.  
  149. /** verification strings */ 
  150. case 'googleverify': 
  151. case 'msverify': 
  152. case 'yandexverify': 
  153. $this->validate_verification_string( $key, $dirty, $old, $clean ); 
  154. break; 
  155.  
  156. /** 
  157. Boolean dismiss warnings - not fields - may not be in form 
  158. (and don't need to be either as long as the default is false) 
  159. */ 
  160. case 'ms_defaults_set': 
  161. if ( isset( $dirty[ $key ] ) ) { 
  162. $clean[ $key ] = WPSEO_Utils::validate_bool( $dirty[ $key ] ); 
  163. elseif ( isset( $old[ $key ] ) ) { 
  164. $clean[ $key ] = WPSEO_Utils::validate_bool( $old[ $key ] ); 
  165. break; 
  166.  
  167. case 'site_type': 
  168. $clean[ $key ] = ''; 
  169. if ( isset( $dirty[ $key ] ) && in_array( $dirty[ $key ], $this->site_types, true ) ) { 
  170. $clean[ $key ] = $dirty[ $key ]; 
  171. break; 
  172. case 'environment_type': 
  173. $clean[ $key ] = ''; 
  174. if ( isset( $dirty[ $key ] ) && in_array( $dirty[ $key ], $this->environment_types, true ) ) { 
  175. $clean[ $key ] = $dirty[ $key ]; 
  176. break; 
  177.  
  178. case 'first_activated_on' : 
  179. $clean[ $key ] = false; 
  180. if ( isset( $dirty[ $key ] ) ) { 
  181. if ( $dirty[ $key ] === false || WPSEO_Utils::validate_int( $dirty[ $key ] ) ) { 
  182. $clean[ $key ] = $dirty[ $key ]; 
  183. break; 
  184.  
  185. /** 
  186. Boolean (checkbox) fields 
  187. */ 
  188.  
  189. /** 
  190. Covers 
  191. * 'disableadvanced_meta' 
  192. * 'yoast_tracking' 
  193. */ 
  194. default: 
  195. $clean[ $key ] = ( isset( $dirty[ $key ] ) ? WPSEO_Utils::validate_bool( $dirty[ $key ] ) : false ); 
  196. break; 
  197.  
  198. return $clean; 
  199.  
  200.  
  201. /** 
  202. * Clean a given option value 
  203. * @param array $option_value Old (not merged with defaults or filtered) option value to 
  204. * clean according to the rules for this option. 
  205. * @param string $current_version (optional) Version from which to upgrade, if not set,  
  206. * version specific upgrades will be disregarded. 
  207. * @param array $all_old_option_values (optional) Only used when importing old options to have 
  208. * access to the real old values, in contrast to the saved ones. 
  209. * @return array Cleaned option 
  210. */ 
  211. protected function clean_option( $option_value, $current_version = null, $all_old_option_values = null ) { 
  212. return $option_value;