WPSEO_Option

This abstract class and it's concrete classes implement defaults and value validation for all WPSEO options and subkeys within options.

Defined (1)

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

/inc/options/class-wpseo-option.php  
  1. abstract class WPSEO_Option { 
  2.  
  3. /** 
  4. * @var string Option name - MUST be set in concrete class and set to public. 
  5. */ 
  6. protected $option_name; 
  7.  
  8. /** 
  9. * @var string Option group name for use in settings forms 
  10. * - will be set automagically if not set in concrete class 
  11. * (i.e. if it confirm to the normal pattern 'yoast' . $option_name . 'options',  
  12. * only set in conrete class if it doesn't) 
  13. */ 
  14. public $group_name; 
  15.  
  16. /** 
  17. * @var bool Whether to include the option in the return for WPSEO_Options::get_all(). 
  18. * Also determines which options are copied over for ms_(re)set_blog(). 
  19. */ 
  20. public $include_in_all = true; 
  21.  
  22. /** 
  23. * @var bool Whether this option is only for when the install is multisite. 
  24. */ 
  25. public $multisite_only = false; 
  26.  
  27. /** 
  28. * @var array Array of defaults for the option - MUST be set in concrete class. 
  29. * Shouldn't be requested directly, use $this->get_defaults(); 
  30. */ 
  31. protected $defaults; 
  32.  
  33. /** 
  34. * @var array Array of variable option name patterns for the option - if any - 
  35. * Set this when the option contains array keys which vary based on post_type 
  36. * or taxonomy 
  37. */ 
  38. protected $variable_array_key_patterns; 
  39.  
  40. /** 
  41. * @var array Array of sub-options which should not be overloaded with multi-site defaults 
  42. */ 
  43. public $ms_exclude = array(); 
  44.  
  45. /** 
  46. * @var object Instance of this class 
  47. */ 
  48. protected static $instance; 
  49.  
  50.  
  51. /** *********** INSTANTIATION METHODS *********** */ 
  52.  
  53. /** 
  54. * Add all the actions and filters for the option 
  55. * @return \WPSEO_Option 
  56. */ 
  57. protected function __construct() { 
  58.  
  59. /** Add filters which get applied to the get_options() results */ 
  60. $this->add_default_filters(); // Return defaults if option not set. 
  61. $this->add_option_filters(); // Merge with defaults if option *is* set. 
  62.  
  63.  
  64. if ( $this->multisite_only !== true ) { 
  65. /** 
  66. * The option validation routines remove the default filters to prevent failing 
  67. * to insert an option if it's new. Let's add them back afterwards. 
  68. */ 
  69. add_action( 'add_option', array( $this, 'add_default_filters' ) ); // Adding back after INSERT. 
  70.  
  71. add_action( 'update_option', array( $this, 'add_default_filters' ) ); 
  72. else if ( is_multisite() ) { 
  73. /** 
  74. The option validation routines remove the default filters to prevent failing 
  75. to insert an option if it's new. Let's add them back afterwards. 
  76.   
  77. For site_options, this method is not foolproof as these actions are not fired 
  78. on an insert/update failure. Please use the WPSEO_Options::update_site_option() method 
  79. for updating site options to make sure the filters are in place. 
  80. */ 
  81. add_action( 'add_site_option_' . $this->option_name, array( $this, 'add_default_filters' ) ); 
  82. add_action( 'update_site_option_' . $this->option_name, array( $this, 'add_default_filters' ) ); 
  83.  
  84.  
  85.  
  86. /** 
  87. Make sure the option will always get validated, independently of register_setting() 
  88. (only available on back-end) 
  89. */ 
  90. add_filter( 'sanitize_option_' . $this->option_name, array( $this, 'validate' ) ); 
  91.  
  92. /** Register our option for the admin pages */ 
  93. add_action( 'admin_init', array( $this, 'register_setting' ) ); 
  94.  
  95.  
  96. /** Set option group name if not given */ 
  97. if ( ! isset( $this->group_name ) || $this->group_name === '' ) { 
  98. $this->group_name = 'yoast_' . $this->option_name . '_options'; 
  99.  
  100. /** Translate some defaults as early as possible - textdomain is loaded in init on priority 1 */ 
  101. if ( method_exists( $this, 'translate_defaults' ) ) { 
  102. add_action( 'init', array( $this, 'translate_defaults' ), 2 ); 
  103.  
  104. /** 
  105. * Enrich defaults once custom post types and taxonomies have been registered 
  106. * which is normally done on the init action. 
  107. * @todo - [JRF/testers] verify that none of the options which are only available after 
  108. * enrichment are used before the enriching 
  109. */ 
  110. if ( method_exists( $this, 'enrich_defaults' ) ) { 
  111. add_action( 'init', array( $this, 'enrich_defaults' ), 99 ); 
  112.  
  113. // @codingStandardsIgnoreStart 
  114.  
  115. /** 
  116. * All concrete classes *must* contain the get_instance method 
  117. * @internal Unfortunately I can't define it as an abstract as it also *has* to be static.... 
  118. */ 
  119. // abstract protected static function get_instance(); 
  120.  
  121.  
  122. /** 
  123. * Concrete classes *may* contain a translate_defaults method 
  124. */ 
  125. // abstract public function translate_defaults(); 
  126.  
  127.  
  128. /** 
  129. * Concrete classes *may* contain a enrich_defaults method to add additional defaults once 
  130. * all post_types and taxonomies have been registered 
  131. */ 
  132. // abstract public function enrich_defaults(); 
  133.  
  134. /** *********** METHODS INFLUENCING get_option() *********** */ 
  135.  
  136. /** 
  137. * Add filters to make sure that the option default is returned if the option is not set 
  138. * @return void 
  139. */ 
  140. public function add_default_filters() { 
  141. // Don't change, needs to check for false as could return prio 0 which would evaluate to false. 
  142. if ( has_filter( 'default_option_' . $this->option_name, array( $this, 'get_defaults' ) ) === false ) { 
  143. add_filter( 'default_option_' . $this->option_name, array( $this, 'get_defaults' ) ); 
  144.  
  145. // @codingStandardsIgnoreStart 
  146. /** 
  147. * Abusing a filter to re-add our default filters 
  148. * WP 3.7 specific as update_option action hook was in the wrong place temporarily 
  149. * @see http://core.trac.wordpress.org/ticket/25705 
  150. * @param mixed $new_value Pass through value in filter. 
  151. * @deprecated 3.0 WP 3.7 is no longer supported. 
  152. * @todo Drop this and logic adding it. R. 
  153. * @return mixed unchanged value 
  154. */ 
  155. public function wp37_add_default_filters( $new_value ) { 
  156. _deprecated_function( __METHOD__, 'WPSEO 3.0' ); 
  157.  
  158. $this->add_default_filters(); 
  159.  
  160. return $new_value; 
  161.  
  162. /** 
  163. * Validate webmaster tools & Pinterest verification strings 
  164. * @param string $key Key to check, by type of service. 
  165. * @param array $dirty Dirty data. 
  166. * @param array $old Old data. 
  167. * @param array $clean Clean data by reference. 
  168. */ 
  169. public function validate_verification_string( $key, $dirty, $old, &$clean ) { 
  170. if ( isset( $dirty[ $key ] ) && $dirty[ $key ] !== '' ) { 
  171. $meta = $dirty[ $key ]; 
  172. if ( strpos( $meta, 'content=' ) ) { 
  173. // Make sure we only have the real key, not a complete meta tag. 
  174. preg_match( '`content=([\'"])?([^\'"> ]+)(?:\1|[ />])`', $meta, $match ); 
  175. if ( isset( $match[2] ) ) { 
  176. $meta = $match[2]; 
  177. unset( $match ); 
  178.  
  179. $meta = sanitize_text_field( $meta ); 
  180. if ( $meta !== '' ) { 
  181. $regex = '`^[A-Fa-f0-9_-]+$`'; 
  182. $service = ''; 
  183.  
  184. switch ( $key ) { 
  185. case 'googleverify': 
  186. $regex = '`^[A-Za-z0-9_-]+$`'; 
  187. $service = 'Google Webmaster tools'; 
  188. break; 
  189.  
  190. case 'msverify': 
  191. $service = 'Bing Webmaster tools'; 
  192. break; 
  193.  
  194. case 'pinterestverify': 
  195. $service = 'Pinterest'; 
  196. break; 
  197.  
  198. case 'yandexverify': 
  199. $service = 'Yandex Webmaster tools'; 
  200. break; 
  201.  
  202. if ( preg_match( $regex, $meta ) ) { 
  203. $clean[ $key ] = $meta; 
  204. else { 
  205. if ( isset( $old[ $key ] ) && preg_match( $regex, $old[ $key ] ) ) { 
  206. $clean[ $key ] = $old[ $key ]; 
  207. if ( function_exists( 'add_settings_error' ) ) { 
  208. add_settings_error( 
  209. $this->group_name, // Slug title of the setting. 
  210. '_' . $key, // Suffix-id for the error message box. 
  211. /** translators: 1: Verification string from user input; 2: Service name. */ 
  212. sprintf( __( '%1$s does not seem to be a valid %2$s verification string. Please correct.', 'wordpress-seo' ), '<strong>' . esc_html( $meta ) . '</strong>', $service ), // The error message. 
  213. 'error' // Error type, either 'error' or 'updated'. 
  214. ); 
  215.  
  216. /** 
  217. * @param string $key Key to check, by type of service. 
  218. * @param array $dirty Dirty data. 
  219. * @param array $old Old data. 
  220. * @param array $clean Clean data by reference. 
  221. */ 
  222. public function validate_url( $key, $dirty, $old, &$clean ) { 
  223. if ( isset( $dirty[ $key ] ) && $dirty[ $key ] !== '' ) { 
  224. $url = WPSEO_Utils::sanitize_url( $dirty[ $key ] ); 
  225. if ( $url !== '' ) { 
  226. $clean[ $key ] = $url; 
  227. else { 
  228. if ( isset( $old[ $key ] ) && $old[ $key ] !== '' ) { 
  229. $url = WPSEO_Utils::sanitize_url( $old[ $key ] ); 
  230. if ( $url !== '' ) { 
  231. $clean[ $key ] = $url; 
  232. if ( function_exists( 'add_settings_error' ) ) { 
  233. $url = WPSEO_Utils::sanitize_url( $dirty[ $key ] ); 
  234. add_settings_error( 
  235. $this->group_name, // Slug title of the setting. 
  236. '_' . $key, // Suffix-id for the error message box. 
  237. sprintf( __( '%s does not seem to be a valid url. Please correct.', 'wordpress-seo' ), '<strong>' . esc_html( $url ) . '</strong>' ), // The error message. 
  238. 'error' // Error type, either 'error' or 'updated'. 
  239. ); 
  240.  
  241. /** 
  242. * Remove the default filters. 
  243. * Called from the validate() method to prevent failure to add new options 
  244. * @return void 
  245. */ 
  246. public function remove_default_filters() { 
  247. remove_filter( 'default_option_' . $this->option_name, array( $this, 'get_defaults' ) ); 
  248.  
  249.  
  250. /** 
  251. * Get the enriched default value for an option 
  252. * Checks if the concrete class contains an enrich_defaults() method and if so, runs it. 
  253. * @internal the enrich_defaults method is used to set defaults for variable array keys in an option,  
  254. * such as array keys depending on post_types and/or taxonomies 
  255. * @return array 
  256. */ 
  257. public function get_defaults() { 
  258. if ( method_exists( $this, 'translate_defaults' ) ) { 
  259. $this->translate_defaults(); 
  260.  
  261. if ( method_exists( $this, 'enrich_defaults' ) ) { 
  262. $this->enrich_defaults(); 
  263.  
  264. return apply_filters( 'wpseo_defaults', $this->defaults, $this->option_name ); 
  265.  
  266.  
  267. /** 
  268. * Add filters to make sure that the option is merged with its defaults before being returned 
  269. * @return void 
  270. */ 
  271. public function add_option_filters() { 
  272. // Don't change, needs to check for false as could return prio 0 which would evaluate to false. 
  273. if ( has_filter( 'option_' . $this->option_name, array( $this, 'get_option' ) ) === false ) { 
  274. add_filter( 'option_' . $this->option_name, array( $this, 'get_option' ) ); 
  275.  
  276.  
  277. /** 
  278. * Remove the option filters. 
  279. * Called from the clean_up methods to make sure we retrieve the original old option 
  280. * @return void 
  281. */ 
  282. public function remove_option_filters() { 
  283. remove_filter( 'option_' . $this->option_name, array( $this, 'get_option' ) ); 
  284.  
  285.  
  286. /** 
  287. * Merge an option with its default values 
  288. * This method should *not* be called directly!!! It is only meant to filter the get_option() results 
  289. * @param mixed $options Option value. 
  290. * @return mixed Option merged with the defaults for that option 
  291. */ 
  292. public function get_option( $options = null ) { 
  293. $filtered = $this->array_filter_merge( $options ); 
  294.  
  295. /** 
  296. If the option contains variable option keys, make sure we don't remove those settings 
  297. - even if the defaults are not complete yet. 
  298. Unfortunately this means we also won't be removing the settings for post types or taxonomies 
  299. which are no longer in the WP install, but rather that than the other way around 
  300. */ 
  301. if ( isset( $this->variable_array_key_patterns ) ) { 
  302. $filtered = $this->retain_variable_keys( $options, $filtered ); 
  303.  
  304. return $filtered; 
  305.  
  306.  
  307. /** *********** METHODS influencing add_uption(), update_option() and saving from admin pages *********** */ 
  308.  
  309. /** 
  310. * Register (whitelist) the option for the configuration pages. 
  311. * The validation callback is already registered separately on the sanitize_option hook,  
  312. * so no need to double register. 
  313. * @return void 
  314. */ 
  315. public function register_setting() { 
  316. if ( WPSEO_Utils::grant_access() ) { 
  317. register_setting( $this->group_name, $this->option_name ); 
  318.  
  319.  
  320. /** 
  321. * Validate the option 
  322. * @param mixed $option_value The unvalidated new value for the option. 
  323. * @return array Validated new value for the option 
  324. */ 
  325. public function validate( $option_value ) { 
  326. $clean = $this->get_defaults(); 
  327.  
  328. /** Return the defaults if the new value is empty */ 
  329. if ( ! is_array( $option_value ) || $option_value === array() ) { 
  330. return $clean; 
  331.  
  332.  
  333. $option_value = array_map( array( 'WPSEO_Utils', 'trim_recursive' ), $option_value ); 
  334. if ( $this->multisite_only !== true ) { 
  335. $old = get_option( $this->option_name ); 
  336. else { 
  337. $old = get_site_option( $this->option_name ); 
  338. $clean = $this->validate_option( $option_value, $clean, $old ); 
  339.  
  340. /** Retain the values for variable array keys even when the post type/taxonomy is not yet registered */ 
  341. if ( isset( $this->variable_array_key_patterns ) ) { 
  342. $clean = $this->retain_variable_keys( $option_value, $clean ); 
  343.  
  344. $this->remove_default_filters(); 
  345.  
  346. return $clean; 
  347.  
  348.  
  349. /** 
  350. * All concrete classes must contain a validate_option() method which validates all 
  351. * values within the option 
  352. * @param array $dirty New value for the option. 
  353. * @param array $clean Clean value for the option, normally the defaults. 
  354. * @param array $old Old value of the option. 
  355. */ 
  356. abstract protected function validate_option( $dirty, $clean, $old ); 
  357.  
  358.  
  359. /** *********** METHODS for ADDING/UPDATING/UPGRADING the option *********** */ 
  360.  
  361. /** 
  362. * Retrieve the real old value (unmerged with defaults) 
  363. * @return array|bool the original option value (which can be false if the option doesn't exist) 
  364. */ 
  365. protected function get_original_option() { 
  366. $this->remove_default_filters(); 
  367. $this->remove_option_filters(); 
  368.  
  369. // Get (unvalidated) array, NOT merged with defaults. 
  370. if ( $this->multisite_only !== true ) { 
  371. $option_value = get_option( $this->option_name ); 
  372. else { 
  373. $option_value = get_site_option( $this->option_name ); 
  374.  
  375. $this->add_option_filters(); 
  376. $this->add_default_filters(); 
  377.  
  378. return $option_value; 
  379.  
  380. /** 
  381. * Add the option if it doesn't exist for some strange reason 
  382. * @uses WPSEO_Option::get_original_option() 
  383. * @return void 
  384. */ 
  385. public function maybe_add_option() { 
  386. if ( $this->get_original_option() === false ) { 
  387. if ( $this->multisite_only !== true ) { 
  388. update_option( $this->option_name, $this->get_defaults() ); 
  389. else { 
  390. $this->update_site_option( $this->get_defaults() ); 
  391.  
  392.  
  393. /** 
  394. * Update a site_option 
  395. * @internal This special method is only needed for multisite options, but very needed indeed there. 
  396. * The order in which certain functions and hooks are run is different between get_option() and 
  397. * get_site_option() which means in practice that the removing of the default filters would be 
  398. * done too late and the re-adding of the default filters might not be done at all. 
  399. * Aka: use the WPSEO_Options::update_site_option() method (which calls this method) for 
  400. * safely adding/updating multisite options. 
  401. * @param mixed $value The new value for the option. 
  402. * @return bool whether the update was succesfull 
  403. */ 
  404. public function update_site_option( $value ) { 
  405. if ( $this->multisite_only === true && is_multisite() ) { 
  406. $this->remove_default_filters(); 
  407. $result = update_site_option( $this->option_name, $value ); 
  408. $this->add_default_filters(); 
  409.  
  410. return $result; 
  411. else { 
  412. return false; 
  413.  
  414.  
  415. /** 
  416. * Retrieve the real old value (unmerged with defaults), clean and re-save the option 
  417. * @uses WPSEO_Option::get_original_option() 
  418. * @uses WPSEO_Option::import() 
  419. * @param string $current_version (optional) Version from which to upgrade, if not set, version specific upgrades will be disregarded. 
  420. * @return void 
  421. */ 
  422. public function clean( $current_version = null ) { 
  423. $option_value = $this->get_original_option(); 
  424. $this->import( $option_value, $current_version ); 
  425.  
  426.  
  427. /** 
  428. * Clean and re-save the option 
  429. * @uses clean_option() method from concrete class if it exists 
  430. * @todo [JRF/whomever] Figure out a way to show settings error during/after the upgrade - maybe 
  431. * something along the lines of: 
  432. * -> add them to a property in this class 
  433. * -> if that property isset at the end of the routine and add_settings_error function does not exist,  
  434. * save as transient (or update the transient if one already exists) 
  435. * -> next time an admin is in the WP back-end, show the errors and delete the transient or only delete it 
  436. * once the admin has dismissed the message (add ajax function) 
  437. * Important: all validation routines which add_settings_errors would need to be changed for this to work 
  438. * @param array $option_value Option value to be imported. 
  439. * @param string $current_version (optional) Version from which to upgrade, if not set, version specific upgrades will be disregarded. 
  440. * @param array $all_old_option_values (optional) Only used when importing old options to have access to the real old values, in contrast to the saved ones. 
  441. * @return void 
  442. */ 
  443. public function import( $option_value, $current_version = null, $all_old_option_values = null ) { 
  444. if ( $option_value === false ) { 
  445. $option_value = $this->get_defaults(); 
  446. elseif ( is_array( $option_value ) && method_exists( $this, 'clean_option' ) ) { 
  447. $option_value = $this->clean_option( $option_value, $current_version, $all_old_option_values ); 
  448.  
  449. /** 
  450. Save the cleaned value - validation will take care of cleaning out array keys which 
  451. should no longer be there 
  452. */ 
  453. if ( $this->multisite_only !== true ) { 
  454. update_option( $this->option_name, $option_value ); 
  455. else { 
  456. $this->update_site_option( $this->option_name, $option_value ); 
  457.  
  458.  
  459. /** 
  460. * Concrete classes *may* contain a clean_option method which will clean out old/renamed 
  461. * values within the option 
  462. */ 
  463. // abstract public function clean_option( $option_value, $current_version = null, $all_old_option_values = null ); 
  464. /** *********** HELPER METHODS for internal use *********** */ 
  465.  
  466. /** 
  467. * Helper method - Combines a fixed array of default values with an options array 
  468. * while filtering out any keys which are not in the defaults array. 
  469. * @todo [JRF] - shouldn't this be a straight array merge ? at the end of the day, the validation 
  470. * removes any invalid keys on save 
  471. * @param array $options (Optional) Current options. If not set, the option defaults for the $option_key will be returned. 
  472. * @return array Combined and filtered options array. 
  473. */ 
  474. protected function array_filter_merge( $options = null ) { 
  475.  
  476. $defaults = $this->get_defaults(); 
  477.  
  478. if ( ! isset( $options ) || $options === false || $options === array() ) { 
  479. return $defaults; 
  480.  
  481. $options = (array) $options; 
  482.  
  483. /** 
  484. $filtered = array(); 
  485.   
  486. if ( $defaults !== array() ) { 
  487. foreach ( $defaults as $key => $default_value ) { 
  488. // @todo should this walk through array subkeys ? 
  489. $filtered[ $key ] = ( isset( $options[ $key ] ) ? $options[ $key ] : $default_value ); 
  490. */ 
  491. $filtered = array_merge( $defaults, $options ); 
  492.  
  493. return $filtered; 
  494.  
  495.  
  496. /** 
  497. * Make sure that any set option values relating to post_types and/or taxonomies are retained,  
  498. * even when that post_type or taxonomy may not yet have been registered. 
  499. * @internal The wpseo_titles concrete class overrules this method. Make sure that any changes 
  500. * applied here, also get ported to that version. 
  501. * @param array $dirty Original option as retrieved from the database. 
  502. * @param array $clean Filtered option where any options which shouldn't be in our option 
  503. * have already been removed and any options which weren't set 
  504. * have been set to their defaults. 
  505. * @return array 
  506. */ 
  507. protected function retain_variable_keys( $dirty, $clean ) { 
  508. if ( ( is_array( $this->variable_array_key_patterns ) && $this->variable_array_key_patterns !== array() ) && ( is_array( $dirty ) && $dirty !== array() ) ) { 
  509. foreach ( $dirty as $key => $value ) { 
  510.  
  511. // Do nothing if already in filtered options. 
  512. if ( isset( $clean[ $key ] ) ) { 
  513. continue; 
  514.  
  515. foreach ( $this->variable_array_key_patterns as $pattern ) { 
  516.  
  517. if ( strpos( $key, $pattern ) === 0 ) { 
  518. $clean[ $key ] = $value; 
  519. break; 
  520.  
  521. return $clean; 
  522.  
  523.  
  524. /** 
  525. * Check whether a given array key conforms to one of the variable array key patterns for this option 
  526. * @usedby validate_option() methods for options with variable array keys 
  527. * @param string $key Array key to check. 
  528. * @return string Pattern if it conforms, original array key if it doesn't or if the option 
  529. * does not have variable array keys 
  530. */ 
  531. protected function get_switch_key( $key ) { 
  532. if ( ! isset( $this->variable_array_key_patterns ) || ( ! is_array( $this->variable_array_key_patterns ) || $this->variable_array_key_patterns === array() ) ) { 
  533. return $key; 
  534.  
  535. foreach ( $this->variable_array_key_patterns as $pattern ) { 
  536. if ( strpos( $key, $pattern ) === 0 ) { 
  537. return $pattern; 
  538.  
  539. return $key; 
  540.  
  541.  
  542. /** *********** DEPRECATED METHODS *********** */ 
  543.  
  544. // @codeCoverageIgnoreStart 
  545.  
  546. /** 
  547. * Emulate the WP native sanitize_text_field function in a %%variable%% safe way 
  548. * @see https://core.trac.wordpress.org/browser/trunk/src/wp-includes/formatting.php for the original 
  549. * @deprecated 1.5.6.1 
  550. * @deprecated use WPSEO_Utils::sanitize_text_field() 
  551. * @see WPSEO_Utils::sanitize_text_field() 
  552. * @param string $value String value to sanitize. 
  553. * @return string 
  554. */ 
  555. public static function sanitize_text_field( $value ) { 
  556. _deprecated_function( __METHOD__, 'WPSEO 1.5.6.1', 'WPSEO_Utils::sanitize_text_field()' ); 
  557.  
  558. return WPSEO_Utils::sanitize_text_field( $value ); 
  559.  
  560.  
  561. /** 
  562. * Sanitize a url for saving to the database 
  563. * Not to be confused with the old native WP function 
  564. * @deprecated 1.5.6.1 
  565. * @deprecated use WPSEO_Utils::sanitize_url() 
  566. * @see WPSEO_Utils::sanitize_url() 
  567. * @param string $value URL string to sanitize. 
  568. * @param array $allowed_protocols Set of allowed protocols. 
  569. * @return string 
  570. */ 
  571. public static function sanitize_url( $value, $allowed_protocols = array( 'http', 'https' ) ) { 
  572. _deprecated_function( __METHOD__, 'WPSEO 1.5.6.1', 'WPSEO_Utils::sanitize_url()' ); 
  573.  
  574. return WPSEO_Utils::sanitize_url( $value, $allowed_protocols ); 
  575.  
  576. /** 
  577. * Validate a value as boolean 
  578. * @deprecated 1.5.6.1 
  579. * @deprecated use WPSEO_Utils::validate_bool() 
  580. * @see WPSEO_Utils::validate_bool() 
  581. * @static 
  582. * @param mixed $value Value to validate. 
  583. * @return bool 
  584. */ 
  585. public static function validate_bool( $value ) { 
  586. _deprecated_function( __METHOD__, 'WPSEO 1.5.6.1', 'WPSEO_Utils::validate_bool()' ); 
  587.  
  588. return WPSEO_Utils::validate_bool( $value ); 
  589.  
  590. /** 
  591. * Cast a value to bool 
  592. * @deprecated 1.5.6.1 
  593. * @deprecated use WPSEO_Utils::emulate_filter_bool() 
  594. * @see WPSEO_Utils::emulate_filter_bool() 
  595. * @static 
  596. * @param mixed $value Value to cast. 
  597. * @return bool 
  598. */ 
  599. public static function emulate_filter_bool( $value ) { 
  600. _deprecated_function( __METHOD__, 'WPSEO 1.5.6.1', 'WPSEO_Utils::emulate_filter_bool()' ); 
  601.  
  602. return WPSEO_Utils::emulate_filter_bool( $value ); 
  603.  
  604.  
  605. /** 
  606. * Validate a value as integer 
  607. * @deprecated 1.5.6.1 
  608. * @deprecated use WPSEO_Utils::validate_int() 
  609. * @see WPSEO_Utils::validate_int() 
  610. * @param mixed $value Value to validate. 
  611. * @return mixed int or false in case of failure to convert to int 
  612. */ 
  613. public static function validate_int( $value ) { 
  614. _deprecated_function( __METHOD__, 'WPSEO 1.5.6.1', 'WPSEO_Utils::validate_int()' ); 
  615.  
  616. return WPSEO_Utils::validate_int( $value ); 
  617.  
  618. /** 
  619. * Cast a value to integer 
  620. * @deprecated 1.5.6.1 
  621. * @deprecated use WPSEO_Utils::emulate_filter_int() 
  622. * @see WPSEO_Utils::emulate_filter_int() 
  623. * @static 
  624. * @param mixed $value Value to cast. 
  625. * @return int|bool 
  626. */ 
  627. public static function emulate_filter_int( $value ) { 
  628. _deprecated_function( __METHOD__, 'WPSEO 1.5.6.1', 'WPSEO_Utils::emulate_filter_int()' ); 
  629.  
  630. return WPSEO_Utils::emulate_filter_int( $value ); 
  631.  
  632.  
  633. /** 
  634. * Recursively trim whitespace round a string value or of string values within an array 
  635. * Only trims strings to avoid typecasting a variable (to string) 
  636. * @deprecated 1.5.6.1 
  637. * @deprecated use WPSEO_Utils::trim_recursive() 
  638. * @see WPSEO_Utils::trim_recursive() 
  639. * @static 
  640. * @param mixed $value Value to trim or array of values to trim. 
  641. * @return mixed Trimmed value or array of trimmed values 
  642. */ 
  643. public static function trim_recursive( $value ) { 
  644. _deprecated_function( __METHOD__, 'WPSEO 1.5.6.1', 'WPSEO_Utils::trim_recursive()' ); 
  645.  
  646. return WPSEO_Utils::trim_recursive( $value ); 
  647. // @codeCoverageIgnoreEnd