PageRenderTime 47ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/wp-content/plugins/wordpress-seo/inc/class-wpseo-options.php

https://github.com/Fishgate/privatecollectionswp
PHP | 4056 lines | 1984 code | 591 blank | 1481 comment | 450 complexity | 8a74451f2d3dd70f3c333871271cefda MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * @package Internals
  4. */
  5. // Avoid direct calls to this file
  6. if ( ! defined( 'WPSEO_VERSION' ) ) {
  7. header( 'Status: 403 Forbidden' );
  8. header( 'HTTP/1.1 403 Forbidden' );
  9. exit();
  10. }
  11. if ( ! class_exists( 'WPSEO_Option' ) ) {
  12. /**
  13. * @package WordPress\Plugins\WPSeo
  14. * @subpackage Internals
  15. * @since 1.5.0
  16. * @version 1.5.0
  17. *
  18. * This abstract class and it's concrete classes implement defaults and value validation for
  19. * all WPSEO options and subkeys within options.
  20. *
  21. * Some guidelines:
  22. * [Retrieving options]
  23. * - Use the normal get_option() to retrieve an option. You will receive a complete array for the option.
  24. * Any subkeys which were not set, will have their default values in place.
  25. * - In other words, you will normally not have to check whether a subkey isset() as they will *always* be set.
  26. * They will also *always* be of the correct variable type.
  27. * The only exception to this are the options with variable option names based on post_type or taxonomy
  28. * as those will not always be available before the taxonomy/post_type is registered.
  29. * (they will be available if a value was set, they won't be if it wasn't as the class won't know
  30. * that a default needs to be injected).
  31. * Oh and the very few options where the default value is null, i.e. wpseo->'theme_has_description'
  32. *
  33. * [Updating/Adding options]
  34. * - For multisite site_options, please use the WPSEO_Options::update_site_option() method.
  35. * - For normal options, use the normal add/update_option() functions. As long a the classes here
  36. * are instantiated, validation for all options and their subkeys will be automatic.
  37. * - On (succesfull) update of a couple of options, certain related actions will be run automatically.
  38. * Some examples:
  39. * - on change of wpseo[yoast_tracking], the cron schedule will be adjusted accordingly
  40. * - on change of wpseo_permalinks and wpseo_xml, the rewrite rules will be flushed
  41. * - on change of wpseo and wpseo_title, some caches will be cleared
  42. *
  43. *
  44. * [Important information about add/updating/changing these classes]
  45. * - Make sure that option array key names are unique across options. The WPSEO_Options::get_all()
  46. * method merges most options together. If any of them have non-unique names, even if they
  47. * are in a different option, they *will* overwrite each other.
  48. * - When you add a new array key in an option: make sure you add proper defaults and add the key
  49. * to the validation routine in the proper place or add a new validation case.
  50. * You don't need to do any upgrading as any option returned will always be merged with the
  51. * defaults, so new options will automatically be available.
  52. * If the default value is a string which need translating, add this to the concrete class
  53. * translate_defaults() method.
  54. * - When you remove an array key from an option: if it's important that the option is really removed,
  55. * add the WPSEO_Option::clean_up( $option_name ) method to the upgrade run.
  56. * This will re-save the option and automatically remove the array key no longer in existance.
  57. * - When you rename a sub-option: add it to the clean_option() routine and run that in the upgrade run.
  58. * - When you change the default for an option sub-key, make sure you verify that the validation routine will
  59. * still work the way it should.
  60. * Example: changing a default from '' (empty string) to 'text' with a validation routine with tests
  61. * for an empty string will prevent a user from saving an empty string as the real value. So the
  62. * test for '' with the validation routine would have to be removed in that case.
  63. * - If an option needs specific actions different from defined in this abstract class, you can just overrule
  64. * a method by defining it in the concrete class.
  65. *
  66. *
  67. * @todo - [JRF => testers] double check that validation will not cause errors when called
  68. * from upgrade routine (some of the WP functions may not yet be available)
  69. */
  70. abstract class WPSEO_Option {
  71. /**
  72. * @var string Option name - MUST be set in concrete class and set to public.
  73. */
  74. protected $option_name;
  75. /**
  76. * @var string Option group name for use in settings forms
  77. * - will be set automagically if not set in concrete class
  78. * (i.e. if it confirm to the normal pattern 'yoast' . $option_name . 'options',
  79. * only set in conrete class if it doesn't)
  80. */
  81. public $group_name;
  82. /**
  83. * @var bool Whether to include the option in the return for WPSEO_Options::get_all().
  84. * Also determines which options are copied over for ms_(re)set_blog().
  85. */
  86. public $include_in_all = true;
  87. /**
  88. * @var bool Whether this option is only for when the install is multisite.
  89. */
  90. public $multisite_only = false;
  91. /**
  92. * @var array Array of defaults for the option - MUST be set in concrete class.
  93. * Shouldn't be requested directly, use $this->get_defaults();
  94. */
  95. protected $defaults;
  96. /**
  97. * @var array Array of variable option name patterns for the option - if any -
  98. * Set this when the option contains array keys which vary based on post_type
  99. * or taxonomy
  100. */
  101. protected $variable_array_key_patterns;
  102. /**
  103. * @var array Array of sub-options which should not be overloaded with multi-site defaults
  104. */
  105. public $ms_exclude = array();
  106. /**
  107. * @var object Instance of this class
  108. */
  109. protected static $instance;
  110. /**
  111. *
  112. * @var bool Whether the filter extension is loaded
  113. */
  114. public static $has_filters = true;
  115. /* *********** INSTANTIATION METHODS *********** */
  116. /**
  117. * Add all the actions and filters for the option
  118. *
  119. * @return \WPSEO_Option
  120. */
  121. protected function __construct() {
  122. self::$has_filters = extension_loaded( 'filter' );
  123. /* Add filters which get applied to the get_options() results */
  124. $this->add_default_filters(); // return defaults if option not set
  125. $this->add_option_filters(); // merge with defaults if option *is* set
  126. if ( $this->multisite_only !== true ) {
  127. /* The option validation routines remove the default filters to prevent failing
  128. to insert an option if it's new. Let's add them back afterwards. */
  129. add_action( 'add_option', array( $this, 'add_default_filters' ) ); // adding back after INSERT
  130. if ( version_compare( $GLOBALS['wp_version'], '3.7', '!=' ) ) { // adding back after non-WP 3.7 UPDATE
  131. add_action( 'update_option', array( $this, 'add_default_filters' ) );
  132. } else { // adding back after WP 3.7 UPDATE
  133. add_filter( 'pre_update_option_' . $this->option_name, array( $this, 'wp37_add_default_filters' ) );
  134. }
  135. }
  136. else if ( is_multisite() ) {
  137. /* The option validation routines remove the default filters to prevent failing
  138. to insert an option if it's new. Let's add them back afterwards.
  139. For site_options, this method is not foolproof as these actions are not fired
  140. on an insert/update failure. Please use the WPSEO_Options::update_site_option() method
  141. for updating site options to make sure the filters are in place. */
  142. add_action( 'add_site_option_' . $this->option_name, array( $this, 'add_default_filters' ) );
  143. add_action( 'update_site_option_' . $this->option_name, array( $this, 'add_default_filters' ) );
  144. }
  145. /* Make sure the option will always get validated, independently of register_setting()
  146. (only available on back-end) */
  147. add_filter( 'sanitize_option_' . $this->option_name, array( $this, 'validate' ) );
  148. /* Register our option for the admin pages */
  149. add_action( 'admin_init', array( $this, 'register_setting' ) );
  150. /* Set option group name if not given */
  151. if ( ! isset( $this->group_name ) || $this->group_name === '' ) {
  152. $this->group_name = 'yoast_' . $this->option_name . '_options';
  153. }
  154. /* Translate some defaults as early as possible - textdomain is loaded in init on priority 1 */
  155. if ( method_exists( $this, 'translate_defaults' ) ) {
  156. add_action( 'init', array( $this, 'translate_defaults' ), 2 );
  157. }
  158. /**
  159. * Enrich defaults once custom post types and taxonomies have been registered
  160. * which is normally done on the init action.
  161. *
  162. * @todo - [JRF/testers] verify that none of the options which are only available after
  163. * enrichment are used before the enriching
  164. */
  165. if ( method_exists( $this, 'enrich_defaults' ) ) {
  166. add_action( 'init', array( $this, 'enrich_defaults' ), 99 );
  167. }
  168. }
  169. /**
  170. * All concrete classes *must* contain the get_instance method
  171. * @internal Unfortunately I can't define it as an abstract as it also *has* to be static....
  172. */
  173. //abstract protected static function get_instance();
  174. /**
  175. * Concrete classes *may* contain a translate_defaults method
  176. */
  177. //abstract public function translate_defaults();
  178. /**
  179. * Concrete classes *may* contain a enrich_defaults method to add additional defaults once
  180. * all post_types and taxonomies have been registered
  181. */
  182. //abstract public function enrich_defaults();
  183. /* *********** METHODS INFLUENCING get_option() *********** */
  184. /**
  185. * Add filters to make sure that the option default is returned if the option is not set
  186. *
  187. * @return void
  188. */
  189. public function add_default_filters() {
  190. // Don't change, needs to check for false as could return prio 0 which would evaluate to false
  191. if ( has_filter( 'default_option_' . $this->option_name, array( $this, 'get_defaults' ) ) === false ) {
  192. add_filter( 'default_option_' . $this->option_name, array( $this, 'get_defaults' ) );
  193. }
  194. }
  195. /**
  196. * Abusing a filter to re-add our default filters
  197. * WP 3.7 specific as update_option action hook was in the wrong place temporarily
  198. * @see http://core.trac.wordpress.org/ticket/25705
  199. *
  200. * @param mixed $new_value
  201. *
  202. * @return mixed unchanged value
  203. */
  204. public function wp37_add_default_filters( $new_value ) {
  205. $this->add_default_filters();
  206. return $new_value;
  207. }
  208. /**
  209. * Remove the default filters.
  210. * Called from the validate() method to prevent failure to add new options
  211. *
  212. * @return void
  213. */
  214. public function remove_default_filters() {
  215. remove_filter( 'default_option_' . $this->option_name, array( $this, 'get_defaults' ) );
  216. }
  217. /**
  218. * Get the enriched default value for an option
  219. *
  220. * Checks if the concrete class contains an enrich_defaults() method and if so, runs it.
  221. *
  222. * @internal the enrich_defaults method is used to set defaults for variable array keys in an option,
  223. * such as array keys depending on post_types and/or taxonomies
  224. *
  225. * @return array
  226. */
  227. public function get_defaults() {
  228. if ( method_exists( $this, 'translate_defaults' ) ) {
  229. $this->translate_defaults();
  230. }
  231. if ( method_exists( $this, 'enrich_defaults' ) ) {
  232. $this->enrich_defaults();
  233. }
  234. return apply_filters( 'wpseo_defaults', $this->defaults, $this->option_name );
  235. }
  236. /**
  237. * Add filters to make sure that the option is merged with its defaults before being returned
  238. *
  239. * @return void
  240. */
  241. public function add_option_filters() {
  242. // Don't change, needs to check for false as could return prio 0 which would evaluate to false
  243. if ( has_filter( 'option_' . $this->option_name, array( $this, 'get_option' ) ) === false ) {
  244. add_filter( 'option_' . $this->option_name, array( $this, 'get_option' ) );
  245. }
  246. }
  247. /**
  248. * Remove the option filters.
  249. * Called from the clean_up methods to make sure we retrieve the original old option
  250. *
  251. * @return void
  252. */
  253. public function remove_option_filters() {
  254. remove_filter( 'option_' . $this->option_name, array( $this, 'get_option' ) );
  255. }
  256. /**
  257. * Merge an option with its default values
  258. *
  259. * This method should *not* be called directly!!! It is only meant to filter the get_option() results
  260. *
  261. * @param mixed $options Option value
  262. *
  263. * @return mixed Option merged with the defaults for that option
  264. */
  265. public function get_option( $options = null ) {
  266. $filtered = $this->array_filter_merge( $options );
  267. /* If the option contains variable option keys, make sure we don't remove those settings
  268. - even if the defaults are not complete yet.
  269. Unfortunately this means we also won't be removing the settings for post types or taxonomies
  270. which are no longer in the WP install, but rather that than the other way around */
  271. if ( isset( $this->variable_array_key_patterns ) ) {
  272. $filtered = $this->retain_variable_keys( $options, $filtered );
  273. }
  274. return $filtered;
  275. }
  276. /* *********** METHODS influencing add_uption(), update_option() and saving from admin pages *********** */
  277. /**
  278. * Register (whitelist) the option for the configuration pages.
  279. * The validation callback is already registered separately on the sanitize_option hook,
  280. * so no need to double register.
  281. *
  282. * @return void
  283. */
  284. public function register_setting() {
  285. if ( WPSEO_Options::grant_access() ) {
  286. register_setting( $this->group_name, $this->option_name );
  287. }
  288. }
  289. /**
  290. * Validate the option
  291. *
  292. * @param mixed $option_value The unvalidated new value for the option
  293. *
  294. * @return array Validated new value for the option
  295. */
  296. public function validate( $option_value ) {
  297. $clean = $this->get_defaults();
  298. /* Return the defaults if the new value is empty */
  299. if ( ! is_array( $option_value ) || $option_value === array() ) {
  300. return $clean;
  301. }
  302. $option_value = array_map( array( __CLASS__, 'trim_recursive' ), $option_value );
  303. if ( $this->multisite_only !== true ) {
  304. $old = get_option( $this->option_name );
  305. }
  306. else {
  307. $old = get_site_option( $this->option_name );
  308. }
  309. $clean = $this->validate_option( $option_value, $clean, $old );
  310. /* Retain the values for variable array keys even when the post type/taxonomy is not yet registered */
  311. if ( isset( $this->variable_array_key_patterns ) ) {
  312. $clean = $this->retain_variable_keys( $option_value, $clean );
  313. }
  314. $this->remove_default_filters();
  315. return $clean;
  316. }
  317. /**
  318. * All concrete classes must contain a validate_option() method which validates all
  319. * values within the option
  320. */
  321. abstract protected function validate_option( $dirty, $clean, $old );
  322. /* *********** METHODS for ADDING/UPDATING/UPGRADING the option *********** */
  323. /**
  324. * Retrieve the real old value (unmerged with defaults)
  325. *
  326. * @return array|bool the original option value (which can be false if the option doesn't exist)
  327. */
  328. protected function get_original_option() {
  329. $this->remove_default_filters();
  330. $this->remove_option_filters();
  331. // Get (unvalidated) array, NOT merged with defaults
  332. if ( $this->multisite_only !== true ) {
  333. $option_value = get_option( $this->option_name );
  334. }
  335. else {
  336. $option_value = get_site_option( $this->option_name );
  337. }
  338. $this->add_option_filters();
  339. $this->add_default_filters();
  340. return $option_value;
  341. }
  342. /**
  343. * Add the option if it doesn't exist for some strange reason
  344. *
  345. * @uses WPSEO_Option::get_original_option()
  346. *
  347. * @return void
  348. */
  349. public function maybe_add_option() {
  350. if ( $this->get_original_option() === false ) {
  351. if ( $this->multisite_only !== true ) {
  352. update_option( $this->option_name, $this->get_defaults() );
  353. }
  354. else {
  355. $this->update_site_option( $this->get_defaults() );
  356. }
  357. }
  358. }
  359. /**
  360. * Update a site_option
  361. *
  362. * @internal This special method is only needed for multisite options, but very needed indeed there.
  363. * The order in which certain functions and hooks are run is different between get_option() and
  364. * get_site_option() which means in practice that the removing of the default filters would be
  365. * done too late and the re-adding of the default filters might not be done at all.
  366. * Aka: use the WPSEO_Options::update_site_option() method (which calls this method) for
  367. * safely adding/updating multisite options.
  368. *
  369. * @return bool whether the update was succesfull
  370. */
  371. public function update_site_option( $value ) {
  372. if ( $this->multisite_only === true && is_multisite() ) {
  373. $this->remove_default_filters();
  374. $result = update_site_option( $this->option_name, $value );
  375. $this->add_default_filters();
  376. return $result;
  377. }
  378. else {
  379. return false;
  380. }
  381. }
  382. /**
  383. * Retrieve the real old value (unmerged with defaults), clean and re-save the option
  384. *
  385. * @uses WPSEO_Option::get_original_option()
  386. * @uses WPSEO_Option::import()
  387. *
  388. * @param string $current_version (optional) Version from which to upgrade, if not set,
  389. * version specific upgrades will be disregarded
  390. *
  391. * @return void
  392. */
  393. public function clean( $current_version = null ) {
  394. $option_value = $this->get_original_option();
  395. $this->import( $option_value, $current_version );
  396. }
  397. /**
  398. * Clean and re-save the option
  399. * @uses clean_option() method from concrete class if it exists
  400. *
  401. * @todo [JRF/whomever] Figure out a way to show settings error during/after the upgrade - maybe
  402. * something along the lines of:
  403. * -> add them to a property in this class
  404. * -> if that property isset at the end of the routine and add_settings_error function does not exist,
  405. * save as transient (or update the transient if one already exists)
  406. * -> next time an admin is in the WP back-end, show the errors and delete the transient or only delete it
  407. * once the admin has dismissed the message (add ajax function)
  408. * Important: all validation routines which add_settings_errors would need to be changed for this to work
  409. *
  410. * @param array $option_value Option value to be imported
  411. * @param string $current_version (optional) Version from which to upgrade, if not set,
  412. * version specific upgrades will be disregarded
  413. * @param array $all_old_option_values (optional) Only used when importing old options to have
  414. * access to the real old values, in contrast to the saved ones
  415. *
  416. * @return void
  417. */
  418. public function import( $option_value, $current_version = null, $all_old_option_values = null ) {
  419. if ( $option_value === false ) {
  420. $option_value = $this->get_defaults();
  421. } elseif ( is_array( $option_value ) && method_exists( $this, 'clean_option' ) ) {
  422. $option_value = $this->clean_option( $option_value, $current_version, $all_old_option_values );
  423. }
  424. /* Save the cleaned value - validation will take care of cleaning out array keys which
  425. should no longer be there */
  426. if ( $this->multisite_only !== true ) {
  427. update_option( $this->option_name, $option_value );
  428. }
  429. else {
  430. $this->update_site_option( $this->option_name, $option_value );
  431. }
  432. }
  433. /**
  434. * Concrete classes *may* contain a clean_option method which will clean out old/renamed
  435. * values within the option
  436. */
  437. //abstract public function clean_option( $option_value, $current_version = null, $all_old_option_values = null );
  438. /* *********** HELPER METHODS for internal use *********** */
  439. /**
  440. * Helper method - Combines a fixed array of default values with an options array
  441. * while filtering out any keys which are not in the defaults array.
  442. *
  443. * @todo [JRF] - shouldn't this be a straight array merge ? at the end of the day, the validation
  444. * removes any invalid keys on save
  445. *
  446. * @param array $options (Optional) Current options
  447. * - if not set, the option defaults for the $option_key will be returned.
  448. *
  449. * @return array Combined and filtered options array.
  450. */
  451. protected function array_filter_merge( $options = null ) {
  452. $defaults = $this->get_defaults();
  453. if ( ! isset( $options ) || $options === false || $options === array() ) {
  454. return $defaults;
  455. }
  456. $options = (array) $options;
  457. /*$filtered = array();
  458. if ( $defaults !== array() ) {
  459. foreach ( $defaults as $key => $default_value ) {
  460. // @todo should this walk through array subkeys ?
  461. $filtered[ $key ] = ( isset( $options[ $key ] ) ? $options[ $key ] : $default_value );
  462. }
  463. }*/
  464. $filtered = array_merge( $defaults, $options );
  465. return $filtered;
  466. }
  467. /**
  468. * Make sure that any set option values relating to post_types and/or taxonomies are retained,
  469. * even when that post_type or taxonomy may not yet have been registered.
  470. *
  471. * @internal The wpseo_titles concrete class overrules this method. Make sure that any changes
  472. * applied here, also get ported to that version.
  473. *
  474. * @param array $dirty Original option as retrieved from the database
  475. * @param array $clean Filtered option where any options which shouldn't be in our option
  476. * have already been removed and any options which weren't set
  477. * have been set to their defaults
  478. *
  479. * @return array
  480. */
  481. protected function retain_variable_keys( $dirty, $clean ) {
  482. if ( ( is_array( $this->variable_array_key_patterns ) && $this->variable_array_key_patterns !== array() ) && ( is_array( $dirty ) && $dirty !== array() ) ) {
  483. foreach ( $dirty as $key => $value ) {
  484. foreach ( $this->variable_array_key_patterns as $pattern ) {
  485. if ( strpos( $key, $pattern ) === 0 && ! isset( $clean[ $key ] ) ) {
  486. $clean[ $key ] = $value;
  487. break;
  488. }
  489. }
  490. }
  491. }
  492. return $clean;
  493. }
  494. /**
  495. * Check whether a given array key conforms to one of the variable array key patterns for this option
  496. *
  497. * @usedby validate_option() methods for options with variable array keys
  498. *
  499. * @param string $key Array key to check
  500. *
  501. * @return string Pattern if it conforms, original array key if it doesn't or if the option
  502. * does not have variable array keys
  503. */
  504. protected function get_switch_key( $key ) {
  505. if ( ! isset( $this->variable_array_key_patterns ) || ( ! is_array( $this->variable_array_key_patterns ) || $this->variable_array_key_patterns === array() ) ) {
  506. return $key;
  507. }
  508. foreach ( $this->variable_array_key_patterns as $pattern ) {
  509. if ( strpos( $key, $pattern ) === 0 ) {
  510. return $pattern;
  511. }
  512. }
  513. return $key;
  514. }
  515. /* *********** GENERIC HELPER METHODS *********** */
  516. /**
  517. * Emulate the WP native sanitize_text_field function in a %%variable%% safe way
  518. * @see https://core.trac.wordpress.org/browser/trunk/src/wp-includes/formatting.php for the original
  519. *
  520. * Sanitize a string from user input or from the db
  521. *
  522. * check for invalid UTF-8,
  523. * Convert single < characters to entity,
  524. * strip all tags,
  525. * remove line breaks, tabs and extra white space,
  526. * strip octets - BUT DO NOT REMOVE (part of) VARIABLES WHICH WILL BE REPLACED.
  527. *
  528. * @param string $value
  529. *
  530. * @return string
  531. */
  532. public static function sanitize_text_field( $value ) {
  533. $filtered = wp_check_invalid_utf8( $value );
  534. if ( strpos( $filtered, '<' ) !== false ) {
  535. $filtered = wp_pre_kses_less_than( $filtered );
  536. // This will strip extra whitespace for us.
  537. $filtered = wp_strip_all_tags( $filtered, true );
  538. } else {
  539. $filtered = trim( preg_replace( '`[\r\n\t ]+`', ' ', $filtered ) );
  540. }
  541. $found = false;
  542. while ( preg_match( '`[^%](%[a-f0-9]{2})`i', $filtered, $match ) ) {
  543. $filtered = str_replace( $match[1], '', $filtered );
  544. $found = true;
  545. }
  546. if ( $found ) {
  547. // Strip out the whitespace that may now exist after removing the octets.
  548. $filtered = trim( preg_replace( '` +`', ' ', $filtered ) );
  549. }
  550. /**
  551. * Filter a sanitized text field string.
  552. *
  553. * @since WP 2.9.0
  554. *
  555. * @param string $filtered The sanitized string.
  556. * @param string $str The string prior to being sanitized.
  557. */
  558. return apply_filters( 'sanitize_text_field', $filtered, $value );
  559. }
  560. /**
  561. * Sanitize a url for saving to the database
  562. * Not to be confused with the old native WP function
  563. *
  564. * @todo [JRF => whomever] check/improve url verification
  565. *
  566. * @todo [JRF => whomever] when someone would reorganize the classes, this should maybe
  567. * be moved to a general WPSEO_Utils class. Obviously all calls to this method should be
  568. * adjusted in that case.
  569. *
  570. * @param string $value
  571. * @param array $allowed_protocols
  572. *
  573. * @return string
  574. */
  575. public static function sanitize_url( $value, $allowed_protocols = array( 'http', 'https' ) ) {
  576. return esc_url_raw( sanitize_text_field( rawurldecode( $value ) ), $allowed_protocols );
  577. }
  578. /**
  579. * Validate a value as boolean
  580. *
  581. * @todo [JRF => whomever] when someone would reorganize the classes, this (and the emulate method
  582. * below) should maybe be moved to a general WPSEO_Utils class. Obviously all calls to this method
  583. * should be adjusted in that case.
  584. *
  585. * @static
  586. *
  587. * @param mixed $value
  588. *
  589. * @return bool
  590. */
  591. public static function validate_bool( $value ) {
  592. if ( self::$has_filters ) {
  593. return filter_var( $value, FILTER_VALIDATE_BOOLEAN );
  594. } else {
  595. return self::emulate_filter_bool( $value );
  596. }
  597. }
  598. /**
  599. * Cast a value to bool
  600. *
  601. * @static
  602. *
  603. * @param mixed $value Value to cast
  604. *
  605. * @return bool
  606. */
  607. public static function emulate_filter_bool( $value ) {
  608. $true = array(
  609. '1',
  610. 'true',
  611. 'True',
  612. 'TRUE',
  613. 'y',
  614. 'Y',
  615. 'yes',
  616. 'Yes',
  617. 'YES',
  618. 'on',
  619. 'On',
  620. 'On',
  621. );
  622. $false = array(
  623. '0',
  624. 'false',
  625. 'False',
  626. 'FALSE',
  627. 'n',
  628. 'N',
  629. 'no',
  630. 'No',
  631. 'NO',
  632. 'off',
  633. 'Off',
  634. 'OFF',
  635. );
  636. if ( is_bool( $value ) ) {
  637. return $value;
  638. } else if ( is_int( $value ) && ( $value === 0 || $value === 1 ) ) {
  639. return (bool) $value;
  640. } else if ( ( is_float( $value ) && ! is_nan( $value ) ) && ( $value === (float) 0 || $value === (float) 1 ) ) {
  641. return (bool) $value;
  642. } else if ( is_string( $value ) ) {
  643. $value = trim( $value );
  644. if ( in_array( $value, $true, true ) ) {
  645. return true;
  646. } else if ( in_array( $value, $false, true ) ) {
  647. return false;
  648. } else {
  649. return false;
  650. }
  651. }
  652. return false;
  653. }
  654. /**
  655. * Validate a value as integer
  656. *
  657. * @todo [JRF => whomever] when someone would reorganize the classes, this (and the emulate method
  658. * below) should maybe be moved to a general WPSEO_Utils class. Obviously all calls to this method
  659. * should be adjusted in that case.
  660. *
  661. * @static
  662. *
  663. * @param mixed $value
  664. *
  665. * @return mixed int or false in case of failure to convert to int
  666. */
  667. public static function validate_int( $value ) {
  668. if ( self::$has_filters ) {
  669. return filter_var( $value, FILTER_VALIDATE_INT );
  670. } else {
  671. return self::emulate_filter_int( $value );
  672. }
  673. }
  674. /**
  675. * Cast a value to integer
  676. *
  677. * @static
  678. *
  679. * @param mixed $value Value to cast
  680. *
  681. * @return int|bool
  682. */
  683. public static function emulate_filter_int( $value ) {
  684. if ( is_int( $value ) ) {
  685. return $value;
  686. } else if ( is_float( $value ) ) {
  687. if ( (int) $value == $value && ! is_nan( $value ) ) {
  688. return (int) $value;
  689. } else {
  690. return false;
  691. }
  692. } else if ( is_string( $value ) ) {
  693. $value = trim( $value );
  694. if ( $value === '' ) {
  695. return false;
  696. } else if ( ctype_digit( $value ) ) {
  697. return (int) $value;
  698. } else if ( strpos( $value, '-' ) === 0 && ctype_digit( substr( $value, 1 ) ) ) {
  699. return (int) $value;
  700. } else {
  701. return false;
  702. }
  703. }
  704. return false;
  705. }
  706. /**
  707. * Recursively trim whitespace round a string value or of string values within an array
  708. * Only trims strings to avoid typecasting a variable (to string)
  709. *
  710. * @todo [JRF => whomever] when someone would reorganize the classes, this should maybe
  711. * be moved to a general WPSEO_Utils class. Obviously all calls to this method should be
  712. * adjusted in that case.
  713. *
  714. * @static
  715. *
  716. * @param mixed $value Value to trim or array of values to trim
  717. *
  718. * @return mixed Trimmed value or array of trimmed values
  719. */
  720. public static function trim_recursive( $value ) {
  721. if ( is_string( $value ) ) {
  722. $value = trim( $value );
  723. } elseif ( is_array( $value ) ) {
  724. $value = array_map( array( __CLASS__, 'trim_recursive' ), $value );
  725. }
  726. return $value;
  727. }
  728. } /* End of class WPSEO_Option */
  729. } /* End of class-exists wrapper */
  730. /*******************************************************************
  731. * Option: wpseo
  732. *******************************************************************/
  733. if ( ! class_exists( 'WPSEO_Option_Wpseo' ) ) {
  734. class WPSEO_Option_Wpseo extends WPSEO_Option {
  735. /**
  736. * @var string option name
  737. */
  738. public $option_name = 'wpseo';
  739. /**
  740. * @var array Array of defaults for the option
  741. * Shouldn't be requested directly, use $this->get_defaults();
  742. */
  743. protected $defaults = array(
  744. // Non-form fields, set via (ajax) function
  745. 'blocking_files' => array(),
  746. 'ignore_blog_public_warning' => false,
  747. 'ignore_meta_description_warning' => null, // overwrite in __construct()
  748. 'ignore_page_comments' => false,
  749. 'ignore_permalink' => false,
  750. 'ignore_tour' => false,
  751. 'ms_defaults_set' => false,
  752. 'theme_description_found' => null, // overwrite in __construct()
  753. 'theme_has_description' => null, // overwrite in __construct()
  754. 'tracking_popup_done' => false,
  755. // Non-form field, should only be set via validation routine
  756. 'version' => '', // leave default as empty to ensure activation/upgrade works
  757. // Form fields:
  758. 'alexaverify' => '', // text field
  759. 'disableadvanced_meta' => true,
  760. 'googleverify' => '', // text field
  761. 'msverify' => '', // text field
  762. 'pinterestverify' => '',
  763. 'yandexverify' => '',
  764. 'yoast_tracking' => false,
  765. );
  766. public static $desc_defaults = array(
  767. 'ignore_meta_description_warning' => false,
  768. 'theme_description_found' => '', // text string description
  769. 'theme_has_description' => null,
  770. );
  771. /**
  772. * @var array Array of sub-options which should not be overloaded with multi-site defaults
  773. */
  774. public $ms_exclude = array(
  775. 'ignore_blog_public_warning',
  776. 'ignore_meta_description_warning',
  777. 'ignore_page_comments',
  778. 'ignore_permalink',
  779. 'ignore_tour',
  780. /* theme dependent */
  781. 'theme_description_found',
  782. 'theme_has_description',
  783. /* privacy */
  784. 'alexaverify',
  785. 'googleverify',
  786. 'msverify',
  787. 'pinterestverify',
  788. 'yandexverify',
  789. );
  790. /**
  791. * Add the actions and filters for the option
  792. *
  793. * @todo [JRF => testers] Check if the extra actions below would run into problems if an option
  794. * is updated early on and if so, change the call to schedule these for a later action on add/update
  795. * instead of running them straight away
  796. *
  797. * @return \WPSEO_Option_Wpseo
  798. */
  799. protected function __construct() {
  800. /* Dirty fix for making certain defaults available during activation while still only
  801. defining them once */
  802. foreach ( self::$desc_defaults as $key => $value ) {
  803. $this->defaults[ $key ] = $value;
  804. }
  805. parent::__construct();
  806. /* Clear the cache on update/add */
  807. add_action( 'add_option_' . $this->option_name, array( 'WPSEO_Options', 'clear_cache' ) );
  808. add_action( 'update_option_' . $this->option_name, array( 'WPSEO_Options', 'clear_cache' ) );
  809. /* Check if the yoast tracking cron job needs adding/removing on successfull option add/update */
  810. add_action( 'add_option_' . $this->option_name, array(
  811. 'WPSEO_Options',
  812. 'schedule_yoast_tracking',
  813. ), 15, 2 );
  814. add_action( 'update_option_' . $this->option_name, array(
  815. 'WPSEO_Options',
  816. 'schedule_yoast_tracking',
  817. ), 15, 2 );
  818. }
  819. /**
  820. * Get the singleton instance of this class
  821. *
  822. * @return object
  823. */
  824. public static function get_instance() {
  825. if ( ! ( self::$instance instanceof self ) ) {
  826. self::$instance = new self();
  827. }
  828. return self::$instance;
  829. }
  830. /**
  831. * Validate the option
  832. *
  833. * @param array $dirty New value for the option
  834. * @param array $clean Clean value for the option, normally the defaults
  835. * @param array $old Old value of the option
  836. *
  837. * @return array Validated clean value for the option to be saved to the database
  838. */
  839. protected function validate_option( $dirty, $clean, $old ) {
  840. foreach ( $clean as $key => $value ) {
  841. switch ( $key ) {
  842. case 'version':
  843. $clean[ $key ] = WPSEO_VERSION;
  844. break;
  845. case 'blocking_files':
  846. /* @internal [JRF] to really validate this we should also do a file_exists()
  847. * on each array entry and remove files which no longer exist, but that might be overkill */
  848. if ( isset( $dirty[ $key ] ) && is_array( $dirty[ $key ] ) ) {
  849. $clean[ $key ] = array_unique( $dirty[ $key ] );
  850. } elseif ( isset( $old[ $key ] ) && is_array( $old[ $key ] ) ) {
  851. $clean[ $key ] = array_unique( $old[ $key ] );
  852. }
  853. break;
  854. case 'theme_description_found':
  855. if ( isset( $dirty[ $key ] ) && is_string( $dirty[ $key ] ) ) {
  856. $clean[ $key ] = $dirty[ $key ]; // @todo [JRF/whomever] maybe do wp_kses ?
  857. } elseif ( isset( $old[ $key ] ) && is_string( $old[ $key ] ) ) {
  858. $clean[ $key ] = $old[ $key ];
  859. }
  860. break;
  861. /* text fields */
  862. case 'alexaverify':
  863. case 'googleverify':
  864. case 'msverify':
  865. case 'pinterestverify':
  866. case 'yandexverify':
  867. if ( isset( $dirty[ $key ] ) && $dirty[ $key ] !== '' ) {
  868. $meta = $dirty[ $key ];
  869. if ( strpos( $meta, 'content=' ) ) {
  870. // Make sure we only have the real key, not a complete meta tag
  871. preg_match( '`content=([\'"])?([^\'"> ]+)(?:\1|[ />])`', $meta, $match );
  872. if ( isset( $match[2] ) ) {
  873. $meta = $match[2];
  874. }
  875. unset( $match );
  876. }
  877. $meta = sanitize_text_field( $meta );
  878. if ( $meta !== '' ) {
  879. $regex = '`^[A-Fa-f0-9_-]+$`';
  880. $service = '';
  881. switch ( $key ) {
  882. case 'googleverify':
  883. $regex = '`^[A-Za-z0-9_-]+$`';
  884. $service = 'Google Webmaster tools';
  885. break;
  886. case 'msverify':
  887. $service = 'Bing Webmaster tools';
  888. break;
  889. case 'pinterestverify':
  890. $service = 'Pinterest';
  891. break;
  892. case 'yandexverify':
  893. $service = 'Yandex Webmaster tools';
  894. break;
  895. case 'alexaverify':
  896. $regex = '`^[A-Za-z0-9_-]{20,}$`';
  897. $service = 'Alexa ID';
  898. }
  899. if ( preg_match( $regex, $meta ) ) {
  900. $clean[ $key ] = $meta;
  901. } else {
  902. if ( isset( $old[ $key ] ) && preg_match( $regex, $old[ $key ] ) ) {
  903. $clean[ $key ] = $old[ $key ];
  904. }
  905. if ( function_exists( 'add_settings_error' ) ) {
  906. add_settings_error(
  907. $this->group_name, // slug title of the setting
  908. '_' . $key, // suffix-id for the error message box
  909. sprintf( __( '%s does not seem to be a valid %s verification string. Please correct.', 'wordpress-seo' ), '<strong>' . esc_html( $meta ) . '</strong>', $service ), // the error message
  910. 'error' // error type, either 'error' or 'updated'
  911. );
  912. }
  913. }
  914. }
  915. unset( $meta, $regex, $service );
  916. }
  917. break;
  918. /* boolean|null fields - if set a check was done, if null, it hasn't */
  919. case 'theme_has_description':
  920. if ( isset( $dirty[ $key ] ) ) {
  921. $clean[ $key ] = self::validate_bool( $dirty[ $key ] );
  922. } elseif ( isset( $old[ $key ] ) ) {
  923. $clean[ $key ] = self::validate_bool( $old[ $key ] );
  924. }
  925. break;
  926. /* boolean dismiss warnings - not fields - may not be in form
  927. (and don't need to be either as long as the default is false) */
  928. case 'ignore_blog_public_warning':
  929. case 'ignore_meta_description_warning':
  930. case 'ignore_page_comments':
  931. case 'ignore_permalink':
  932. case 'ignore_tour':
  933. case 'ms_defaults_set':
  934. case 'tracking_popup_done':
  935. if ( isset( $dirty[ $key ] ) ) {
  936. $clean[ $key ] = self::validate_bool( $dirty[ $key ] );
  937. } elseif ( isset( $old[ $key ] ) ) {
  938. $clean[ $key ] = self::validate_bool( $old[ $key ] );
  939. }
  940. break;
  941. /* boolean (checkbox) fields */
  942. case 'disableadvanced_meta':
  943. case 'yoast_tracking':
  944. default:
  945. $clean[ $key ] = ( isset( $dirty[ $key ] ) ? self::validate_bool( $dirty[ $key ] ) : false );
  946. break;
  947. }
  948. }
  949. return $clean;
  950. }
  951. /**
  952. * Clean a given option value
  953. *
  954. * @param array $option_value Old (not merged with defaults or filtered) option value to
  955. * clean according to the rules for this option
  956. * @param string $current_version (optional) Version from which to upgrade, if not set,
  957. * version specific upgrades will be disregarded
  958. * @param array $all_old_option_values (optional) Only used when importing old options to have
  959. * access to the real old values, in contrast to the saved ones
  960. *
  961. * @return array Cleaned option
  962. */
  963. protected function clean_option( $option_value, $current_version = null, $all_old_option_values = null ) {
  964. // Rename some options *and* change their value
  965. $rename = array(
  966. 'presstrends' => array(
  967. 'new_name' => 'yoast_tracking',
  968. 'new_value' => true,
  969. ),
  970. 'presstrends_popup' => array(
  971. 'new_name' => 'tracking_popup_done',
  972. 'new_value' => true,
  973. ),
  974. );
  975. foreach ( $rename as $old => $new ) {
  976. if ( isset( $option_value[ $old ] ) && ! isset( $option_value[ $new['new_name'] ] ) ) {
  977. $option_value[ $new['new_name'] ] = $new['new_value'];
  978. unset( $option_value[ $old ] );
  979. }
  980. }
  981. unset( $rename, $old, $new );
  982. // Deal with renaming of some options without losing the settings
  983. $rename = array(
  984. 'tracking_popup' => 'tracking_popup_done',
  985. 'meta_description_warning' => 'ignore_meta_description_warning',
  986. );
  987. foreach ( $rename as $old => $new ) {
  988. if ( isset( $option_value[ $old ] ) && ! isset( $option_value[ $new ] ) ) {
  989. $option_value[ $new ] = $option_value[ $old ];
  990. unset( $option_value[ $old ] );
  991. }
  992. }
  993. unset( $rename, $old, $new );
  994. // Change a array sub-option to two straight sub-options
  995. if ( isset( $option_value['theme_check']['description'] ) && ! isset( $option_value['theme_has_description'] ) ) {
  996. // @internal the negate is by design!
  997. $option_value['theme_has_description'] = ! $option_value['theme_check']['description'];
  998. }
  999. if ( isset( $option_values['theme_check']['description_found'] ) && ! isset( $option_value['theme_description_found'] ) ) {
  1000. $option_value['theme_description_found'] = $option_value['theme_check']['description_found'];
  1001. }
  1002. // Deal with value change from text string to boolean
  1003. $value_change = array(
  1004. 'ignore_blog_public_warning',
  1005. 'ignore_meta_description_warning',
  1006. 'ignore_page_comments',
  1007. 'ignore_permalink',
  1008. 'ignore_tour',
  1009. //'disableadvanced_meta', => not needed as is 'on' which will auto-convert to true
  1010. 'tracking_popup_done',
  1011. );
  1012. foreach ( $value_change as $key ) {
  1013. if ( isset( $option_value[ $key ] ) && in_array( $option_value[ $key ], array(
  1014. 'ignore',
  1015. 'done',
  1016. ), true )
  1017. ) {
  1018. $option_value[ $key ] = true;
  1019. }
  1020. }
  1021. return $option_value;
  1022. }
  1023. } /* End of class WPSEO_Option_Wpseo */
  1024. } /* End of class-exists wrapper */
  1025. /*******************************************************************
  1026. * Option: wpseo_permalinks
  1027. *******************************************************************/
  1028. if ( ! class_exists( 'WPSEO_Option_Permalinks' ) ) {
  1029. /**
  1030. * @internal Clean routine for 1.5 not needed as values used to be saved as string 'on' and those will convert
  1031. * automatically
  1032. */
  1033. class WPSEO_Option_Permalinks extends WPSEO_Option {
  1034. /**
  1035. * @var string option name
  1036. */
  1037. public $option_name = 'wpseo_permalinks';
  1038. /**
  1039. * @var array Array of defaults for the option
  1040. * Shouldn't be requested directly, use $this->get_defaults();
  1041. */
  1042. protected $defaults = array(
  1043. 'cleanpermalinks' => false,
  1044. 'cleanpermalink-extravars' => '', // text field
  1045. 'cleanpermalink-googlecampaign' => false,
  1046. 'cleanpermalink-googlesitesearch' => false,
  1047. 'cleanreplytocom' => false,
  1048. 'cleanslugs' => true,
  1049. 'force_transport' => 'default',
  1050. 'redirectattachment' => false,
  1051. 'stripcategorybase' => false,
  1052. 'trailingslash' => false,
  1053. );
  1054. /**
  1055. * @static
  1056. * @var array $force_transport_options Available options for the force_transport setting
  1057. * Used for input validation
  1058. *
  1059. * @internal Important: Make sure the options added to the array here are in line with the keys
  1060. * for the options set for the select box in the admin/pages/permalinks.php file
  1061. */
  1062. public static $force_transport_options = array(
  1063. 'default', // = leave as-is
  1064. 'http',
  1065. 'https',
  1066. );
  1067. /**
  1068. * Add the actions and filters for the option
  1069. *
  1070. * @todo [JRF => testers] Check if the extra actions below would run into problems if an option
  1071. * is updated early on and if so, change the call to schedule these for a later action on add/update
  1072. * instead of running them straight away
  1073. *
  1074. * @return \WPSEO_Option_Permalinks
  1075. */
  1076. protected function __construct() {
  1077. parent::__construct();
  1078. add_action( 'update_option_' . $this->option_name, array( 'WPSEO_Options', 'clear_rewrites' ) );
  1079. }
  1080. /**
  1081. * Get the singleton instance of this class
  1082. *
  1083. * @return object
  1084. */
  1085. public static function get_instance() {
  1086. if ( ! ( self::$instance instanceof self ) ) {
  1087. self::$instance = new self();
  1088. }
  1089. return self::$instance;
  1090. }
  1091. /**
  1092. * Validate the option
  1093. *
  1094. * @param array $dirty New value for the option
  1095. * @param array $clean Clean value for the option, normally the defaults
  1096. * @param array $old Old value of the option (not used here as all fields will always be in the form)
  1097. *
  1098. * @return array Validated clean value for the option to be saved to the database
  1099. */
  1100. protected function validate_option( $dirty, $clean, $old ) {
  1101. foreach ( $clean as $key => $value ) {
  1102. switch ( $key ) {
  1103. case 'force_transport':
  1104. if ( isset( $dirty[ $key ] ) && in_array( $dirty[ $key ], self::$force_transport_options, true ) ) {
  1105. $clean[ $key ] = $dirty[ $key ];
  1106. } else {
  1107. if ( isset( $old[ $key ] ) && in_array( $old[ $key ], self::$force_transport_options, true ) ) {
  1108. $clean[ $key ] = $old[ $key ];
  1109. }
  1110. if ( function_exists( 'add_settings_error' ) ) {
  1111. add_settings_error(
  1112. $this->group_name, // slug title of the setting
  1113. '_' . $key, // suffix-id for the error message box
  1114. __( 'Invalid transport mode set for the canonical settings. Value reset to default.', 'wordpress-seo' ), // the error message
  1115. 'error' // error type, either 'error' or 'updated'
  1116. );
  1117. }
  1118. }
  1119. break;
  1120. /* text fields */
  1121. case 'cleanpermalink-extravars':
  1122. if ( isset( $dirty[ $key ] ) && $dirty[ $key ] !== '' ) {
  1123. $clean[ $key ] = sanitize_text_field( $dirty[ $key ] );
  1124. }
  1125. break;
  1126. /* boolean (checkbox) fields */
  1127. case 'cleanpermalinks':
  1128. case 'cleanpermalink-googlesitesearch':
  1129. case 'cleanpermalink-googlecampaign':
  1130. case 'cleanreplytocom':
  1131. case 'cleanslugs':
  1132. case 'redirectattachment':
  1133. case 'stripcategorybase':
  1134. case 'trailingslash':
  1135. default:
  1136. $clean[ $key ] = ( isset( $dirty[ $key ] ) ? self::validate_bool( $dirty[ $key ] ) : false );
  1137. break;
  1138. }
  1139. }
  1140. return $clean;
  1141. }
  1142. /**
  1143. * Clean a given option value
  1144. *
  1145. * @param array $option_value Old (not merged with defaults or filtered) option value to
  1146. * clean according to the rules for this option
  1147. * @param string $current_version (optional) Version from which to upgrade, if not set,
  1148. * version specific upgrades will be disregarded
  1149. * @param array $all_old_option_values (optional) Only used when importing old options to have
  1150. * access to the real old values, in contrast to the saved ones
  1151. *
  1152. * @return array Cleaned option
  1153. */
  1154. /*protected function clean_option( $option_value, $current_version = null, $all_old_option_values = null ) {
  1155. return $option_value;
  1156. }*/
  1157. } /* End of class WPSEO_Option_Permalinks */
  1158. } /* End of class-exists wrapper */
  1159. /*******************************************************************
  1160. * Option: wpseo_titles
  1161. *******************************************************************/
  1162. if ( ! class_exists( 'WPSEO_Option_Titles' ) ) {
  1163. class WPSEO_Option_Titles extends WPSEO_Option {
  1164. /**
  1165. * @var string option name
  1166. */
  1167. public $option_name = 'wpseo_titles';
  1168. /**
  1169. * @var array Array of defaults for the option
  1170. * Shouldn't be requested directly, use $this->get_defaults();
  1171. * @internal Note: Some of the default values are added via the translate_defaults() method
  1172. */
  1173. protected $defaults = array(
  1174. // Non-form fields, set via (ajax) function
  1175. 'title_test' => 0,
  1176. // Form fields
  1177. 'forcerewritetitle' => false,
  1178. 'separator' => 'sc-dash',
  1179. 'hide-feedlinks' => false,
  1180. 'hide-rsdlink' => false,
  1181. 'hide-shortlink' => false,
  1182. 'hide-wlwmanifest' => false,
  1183. 'noodp' => false,
  1184. 'noydir' => false,
  1185. 'usemetakeywords' => false,
  1186. 'title-home-wpseo' => '%%sitename%% %%page%% %%sep%% %%sitedesc%%', // text field
  1187. 'title-author-wpseo' => '', // text field
  1188. 'title-archive-wpseo' => '%%date%% %%page%% %%sep%% %%sitename%%', // text field
  1189. 'title-search-wpseo' => '', // text field
  1190. 'title-404-wpseo' => '', // text field
  1191. 'metadesc-home-wpseo' => '', // text area
  1192. 'metadesc-author-wpseo' => '', // text area
  1193. 'metadesc-archive-wpseo' => '', // text area
  1194. 'metakey-home-wpseo' => '', // text field
  1195. 'metakey-author-wpseo' => '', // text field
  1196. 'noindex-subpages-wpseo' => false,
  1197. 'noindex-author-wpseo' => false,
  1198. 'noindex-archive-wpseo' => true,
  1199. 'disable-author' => false,
  1200. 'disable-date' => false,
  1201. /**
  1202. * Uses enrich_defaults to add more along the lines of:
  1203. * - 'title-' . $pt->name => ''; // text field
  1204. * - 'metadesc-' . $pt->name => ''; // text field
  1205. * - 'metakey-' . $pt->name => ''; // text field
  1206. * - 'noindex-' . $pt->name => false;
  1207. * - 'noauthorship-' . $pt->name => false;
  1208. * - 'showdate-' . $pt->name => false;
  1209. * - 'hideeditbox-' . $pt->name => false;
  1210. *
  1211. * - 'title-ptarchive-' . $pt->name => ''; // text field
  1212. * - 'metadesc-ptarchive-' . $pt->name => ''; // text field
  1213. * - 'metakey-ptarchive-' . $pt->name => ''; // text field
  1214. * - 'bctitle-ptarchive-' . $pt->name => ''; // text field
  1215. * - 'noindex-ptarchive-' . $pt->name => false;
  1216. *
  1217. * - 'title-tax-' . $tax->name => '''; // text field
  1218. * - 'metadesc-tax-' . $tax->name => ''; // text field
  1219. * - 'metakey-tax-' . $tax->name => ''; // text field
  1220. * - 'noindex-tax-' . $tax->name => false;
  1221. * - 'hideeditbox-tax-' . $tax->name => false;
  1222. */
  1223. );
  1224. /**
  1225. * @var array Array of variable option name patterns for the option
  1226. */
  1227. protected $variable_array_key_patterns = array(
  1228. 'title-',
  1229. 'metadesc-',
  1230. 'metakey-',
  1231. 'noindex-',
  1232. 'noauthorship-',
  1233. 'showdate-',
  1234. 'hideeditbox-',
  1235. 'bctitle-ptarchive-',
  1236. );
  1237. /**
  1238. * @var array Array of sub-options which should not be overloaded with multi-site defaults
  1239. */
  1240. public $ms_exclude = array(
  1241. /* theme dependent */
  1242. 'title_test',
  1243. 'forcerewritetitle',
  1244. );
  1245. /**
  1246. * @var array Array of the separator options. To get these options use WPSEO_Option_Titles::get_instance()->get_separator_options()
  1247. */
  1248. private $separator_options = array(
  1249. 'sc-dash' => '-',
  1250. 'sc-ndash' => '&ndash;',
  1251. 'sc-mdash' => '&mdash;',
  1252. 'sc-middot' => '&middot;',
  1253. 'sc-bull' => '&bull;',
  1254. 'sc-star' => '*',
  1255. 'sc-smstar' => '&#8902;',
  1256. 'sc-pipe' => '|',
  1257. 'sc-tilde' => '~',
  1258. 'sc-laquo' => '&laquo;',
  1259. 'sc-raquo' => '&raquo;',
  1260. 'sc-lt' => '&lt;',
  1261. 'sc-gt' => '&gt;',
  1262. );
  1263. /**
  1264. * Add the actions and filters for the option
  1265. *
  1266. * @todo [JRF => testers] Check if the extra actions below would run into problems if an option
  1267. * is updated early on and if so, change the call to schedule these for a later action on add/update
  1268. * instead of running them straight away
  1269. *
  1270. * @return \WPSEO_Option_Titles
  1271. */
  1272. protected function __construct() {
  1273. parent::__construct();
  1274. add_action( 'update_option_' . $this->option_name, array( 'WPSEO_Options', 'clear_cache' ) );
  1275. add_action( 'init', array( $this, 'end_of_init' ), 999 );
  1276. }
  1277. /**
  1278. * Make sure we can recognize the right action for the double cleaning
  1279. */
  1280. public function end_of_init() {
  1281. do_action( 'wpseo_double_clean_titles' );
  1282. }
  1283. /**
  1284. * Get the …

Large files files are truncated, but you can click here to view the full file