PageRenderTime 68ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-includes/option.php

https://bitbucket.org/theshipswakecreative/psw
PHP | 1440 lines | 566 code | 190 blank | 684 comment | 158 complexity | 7ae4751a42c460911cdbef1bbcec37bb MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0
  1. <?php
  2. /**
  3. * Option API
  4. *
  5. * @package WordPress
  6. * @subpackage Option
  7. */
  8. /**
  9. * Retrieve option value based on name of option.
  10. *
  11. * If the option does not exist or does not have a value, then the return value
  12. * will be false. This is useful to check whether you need to install an option
  13. * and is commonly used during installation of plugin options and to test
  14. * whether upgrading is required.
  15. *
  16. * If the option was serialized then it will be unserialized when it is returned.
  17. *
  18. * @since 1.5.0
  19. *
  20. * @param string $option Name of option to retrieve. Expected to not be SQL-escaped.
  21. * @param mixed $default Optional. Default value to return if the option does not exist.
  22. * @return mixed Value set for the option.
  23. */
  24. function get_option( $option, $default = false ) {
  25. global $wpdb;
  26. $option = trim( $option );
  27. if ( empty( $option ) )
  28. return false;
  29. /**
  30. * Filter the value of an existing option before it is retrieved.
  31. *
  32. * The dynamic portion of the hook name, $option, refers to the option name.
  33. *
  34. * Passing a truthy value to the filter will short-circuit retrieving
  35. * the option value, returning the passed value instead.
  36. *
  37. * @since 1.5.0
  38. *
  39. * @param bool|mixed $pre_option Value to return instead of the option value.
  40. * Default false to skip it.
  41. */
  42. $pre = apply_filters( 'pre_option_' . $option, false );
  43. if ( false !== $pre )
  44. return $pre;
  45. if ( defined( 'WP_SETUP_CONFIG' ) )
  46. return false;
  47. if ( ! defined( 'WP_INSTALLING' ) ) {
  48. // prevent non-existent options from triggering multiple queries
  49. $notoptions = wp_cache_get( 'notoptions', 'options' );
  50. if ( isset( $notoptions[$option] ) )
  51. /**
  52. * Filter the default value for an option.
  53. *
  54. * The dynamic portion of the hook name, $option, refers
  55. * to the option name.
  56. *
  57. * @since 3.4.0
  58. *
  59. * @param mixed $default The default value to return if the option
  60. * does not exist in the database.
  61. */
  62. return apply_filters( 'default_option_' . $option, $default );
  63. $alloptions = wp_load_alloptions();
  64. if ( isset( $alloptions[$option] ) ) {
  65. $value = $alloptions[$option];
  66. } else {
  67. $value = wp_cache_get( $option, 'options' );
  68. if ( false === $value ) {
  69. $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );
  70. // Has to be get_row instead of get_var because of funkiness with 0, false, null values
  71. if ( is_object( $row ) ) {
  72. $value = $row->option_value;
  73. wp_cache_add( $option, $value, 'options' );
  74. } else { // option does not exist, so we must cache its non-existence
  75. $notoptions[$option] = true;
  76. wp_cache_set( 'notoptions', $notoptions, 'options' );
  77. /** This filter is documented in wp-includes/option.php */
  78. return apply_filters( 'default_option_' . $option, $default );
  79. }
  80. }
  81. }
  82. } else {
  83. $suppress = $wpdb->suppress_errors();
  84. $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );
  85. $wpdb->suppress_errors( $suppress );
  86. if ( is_object( $row ) ) {
  87. $value = $row->option_value;
  88. } else {
  89. /** This filter is documented in wp-includes/option.php */
  90. return apply_filters( 'default_option_' . $option, $default );
  91. }
  92. }
  93. // If home is not set use siteurl.
  94. if ( 'home' == $option && '' == $value )
  95. return get_option( 'siteurl' );
  96. if ( in_array( $option, array('siteurl', 'home', 'category_base', 'tag_base') ) )
  97. $value = untrailingslashit( $value );
  98. /**
  99. * Filter the value of an existing option.
  100. *
  101. * The dynamic portion of the hook name, $option, refers to the option name.
  102. *
  103. * @since 1.5.0 As 'option_' . $setting
  104. * @since 3.0.0
  105. *
  106. * @param mixed $value Value of the option. If stored serialized, it will be
  107. * unserialized prior to being returned.
  108. */
  109. return apply_filters( 'option_' . $option, maybe_unserialize( $value ) );
  110. }
  111. /**
  112. * Protect WordPress special option from being modified.
  113. *
  114. * Will die if $option is in protected list. Protected options are 'alloptions'
  115. * and 'notoptions' options.
  116. *
  117. * @since 2.2.0
  118. *
  119. * @param string $option Option name.
  120. */
  121. function wp_protect_special_option( $option ) {
  122. if ( 'alloptions' === $option || 'notoptions' === $option )
  123. wp_die( sprintf( __( '%s is a protected WP option and may not be modified' ), esc_html( $option ) ) );
  124. }
  125. /**
  126. * Print option value after sanitizing for forms.
  127. *
  128. * @uses attr Sanitizes value.
  129. * @since 1.5.0
  130. *
  131. * @param string $option Option name.
  132. */
  133. function form_option( $option ) {
  134. echo esc_attr( get_option( $option ) );
  135. }
  136. /**
  137. * Loads and caches all autoloaded options, if available or all options.
  138. *
  139. * @since 2.2.0
  140. *
  141. * @return array List of all options.
  142. */
  143. function wp_load_alloptions() {
  144. global $wpdb;
  145. if ( !defined( 'WP_INSTALLING' ) || !is_multisite() )
  146. $alloptions = wp_cache_get( 'alloptions', 'options' );
  147. else
  148. $alloptions = false;
  149. if ( !$alloptions ) {
  150. $suppress = $wpdb->suppress_errors();
  151. if ( !$alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" ) )
  152. $alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" );
  153. $wpdb->suppress_errors($suppress);
  154. $alloptions = array();
  155. foreach ( (array) $alloptions_db as $o ) {
  156. $alloptions[$o->option_name] = $o->option_value;
  157. }
  158. if ( !defined( 'WP_INSTALLING' ) || !is_multisite() )
  159. wp_cache_add( 'alloptions', $alloptions, 'options' );
  160. }
  161. return $alloptions;
  162. }
  163. /**
  164. * Loads and caches certain often requested site options if is_multisite() and a persistent cache is not being used.
  165. *
  166. * @since 3.0.0
  167. *
  168. * @param int $site_id Optional site ID for which to query the options. Defaults to the current site.
  169. */
  170. function wp_load_core_site_options( $site_id = null ) {
  171. global $wpdb;
  172. if ( !is_multisite() || wp_using_ext_object_cache() || defined( 'WP_INSTALLING' ) )
  173. return;
  174. if ( empty($site_id) )
  175. $site_id = $wpdb->siteid;
  176. $core_options = array('site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled', 'ms_files_rewriting' );
  177. $core_options_in = "'" . implode("', '", $core_options) . "'";
  178. $options = $wpdb->get_results( $wpdb->prepare("SELECT meta_key, meta_value FROM $wpdb->sitemeta WHERE meta_key IN ($core_options_in) AND site_id = %d", $site_id) );
  179. foreach ( $options as $option ) {
  180. $key = $option->meta_key;
  181. $cache_key = "{$site_id}:$key";
  182. $option->meta_value = maybe_unserialize( $option->meta_value );
  183. wp_cache_set( $cache_key, $option->meta_value, 'site-options' );
  184. }
  185. }
  186. /**
  187. * Update the value of an option that was already added.
  188. *
  189. * You do not need to serialize values. If the value needs to be serialized, then
  190. * it will be serialized before it is inserted into the database. Remember,
  191. * resources can not be serialized or added as an option.
  192. *
  193. * If the option does not exist, then the option will be added with the option
  194. * value, but you will not be able to set whether it is autoloaded. If you want
  195. * to set whether an option is autoloaded, then you need to use the add_option().
  196. *
  197. * @since 1.0.0
  198. *
  199. * @param string $option Option name. Expected to not be SQL-escaped.
  200. * @param mixed $value Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped.
  201. * @return bool False if value was not updated and true if value was updated.
  202. */
  203. function update_option( $option, $value ) {
  204. global $wpdb;
  205. $option = trim($option);
  206. if ( empty($option) )
  207. return false;
  208. wp_protect_special_option( $option );
  209. if ( is_object( $value ) )
  210. $value = clone $value;
  211. $value = sanitize_option( $option, $value );
  212. $old_value = get_option( $option );
  213. /**
  214. * Filter a specific option before its value is (maybe) serialized and updated.
  215. *
  216. * The dynamic portion of the hook name, $option, refers to the option name.
  217. *
  218. * @since 2.6.0
  219. *
  220. * @param mixed $value The new, unserialized option value.
  221. * @param mixed $old_value The old option value.
  222. */
  223. $value = apply_filters( 'pre_update_option_' . $option, $value, $old_value );
  224. /**
  225. * Filter an option before its value is (maybe) serialized and updated.
  226. *
  227. * @since 3.9.0
  228. *
  229. * @param mixed $value The new, unserialized option value.
  230. * @param string $option Name of the option.
  231. * @param mixed $old_value The old option value.
  232. */
  233. $value = apply_filters( 'pre_update_option', $value, $option, $old_value );
  234. // If the new and old values are the same, no need to update.
  235. if ( $value === $old_value )
  236. return false;
  237. if ( false === $old_value )
  238. return add_option( $option, $value );
  239. $serialized_value = maybe_serialize( $value );
  240. /**
  241. * Fires immediately before an option value is updated.
  242. *
  243. * @since 2.9.0
  244. *
  245. * @param string $option Name of the option to update.
  246. * @param mixed $old_value The old option value.
  247. * @param mixed $value The new option value.
  248. */
  249. do_action( 'update_option', $option, $old_value, $value );
  250. $result = $wpdb->update( $wpdb->options, array( 'option_value' => $serialized_value ), array( 'option_name' => $option ) );
  251. if ( ! $result )
  252. return false;
  253. $notoptions = wp_cache_get( 'notoptions', 'options' );
  254. if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) {
  255. unset( $notoptions[$option] );
  256. wp_cache_set( 'notoptions', $notoptions, 'options' );
  257. }
  258. if ( ! defined( 'WP_INSTALLING' ) ) {
  259. $alloptions = wp_load_alloptions();
  260. if ( isset( $alloptions[$option] ) ) {
  261. $alloptions[ $option ] = $serialized_value;
  262. wp_cache_set( 'alloptions', $alloptions, 'options' );
  263. } else {
  264. wp_cache_set( $option, $serialized_value, 'options' );
  265. }
  266. }
  267. /**
  268. * Fires after the value of a specific option has been successfully updated.
  269. *
  270. * The dynamic portion of the hook name, $option, refers to the option name.
  271. *
  272. * @since 2.0.1
  273. *
  274. * @param mixed $old_value The old option value.
  275. * @param mixed $value The new option value.
  276. */
  277. do_action( "update_option_{$option}", $old_value, $value );
  278. /**
  279. * Fires after the value of an option has been successfully updated.
  280. *
  281. * @since 2.9.0
  282. *
  283. * @param string $option Name of the updated option.
  284. * @param mixed $old_value The old option value.
  285. * @param mixed $value The new option value.
  286. */
  287. do_action( 'updated_option', $option, $old_value, $value );
  288. return true;
  289. }
  290. /**
  291. * Add a new option.
  292. *
  293. * You do not need to serialize values. If the value needs to be serialized, then
  294. * it will be serialized before it is inserted into the database. Remember,
  295. * resources can not be serialized or added as an option.
  296. *
  297. * You can create options without values and then update the values later.
  298. * Existing options will not be updated and checks are performed to ensure that you
  299. * aren't adding a protected WordPress option. Care should be taken to not name
  300. * options the same as the ones which are protected.
  301. *
  302. * @since 1.0.0
  303. *
  304. * @param string $option Name of option to add. Expected to not be SQL-escaped.
  305. * @param mixed $value Optional. Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped.
  306. * @param mixed $deprecated Optional. Description. Not used anymore.
  307. * @param bool $autoload Optional. Default is enabled. Whether to load the option when WordPress starts up.
  308. * @return bool False if option was not added and true if option was added.
  309. */
  310. function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) {
  311. global $wpdb;
  312. if ( !empty( $deprecated ) )
  313. _deprecated_argument( __FUNCTION__, '2.3' );
  314. $option = trim($option);
  315. if ( empty($option) )
  316. return false;
  317. wp_protect_special_option( $option );
  318. if ( is_object($value) )
  319. $value = clone $value;
  320. $value = sanitize_option( $option, $value );
  321. // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query
  322. $notoptions = wp_cache_get( 'notoptions', 'options' );
  323. if ( !is_array( $notoptions ) || !isset( $notoptions[$option] ) )
  324. if ( false !== get_option( $option ) )
  325. return false;
  326. $serialized_value = maybe_serialize( $value );
  327. $autoload = ( 'no' === $autoload ) ? 'no' : 'yes';
  328. /**
  329. * Fires before an option is added.
  330. *
  331. * @since 2.9.0
  332. *
  333. * @param string $option Name of the option to add.
  334. * @param mixed $value Value of the option.
  335. */
  336. do_action( 'add_option', $option, $value );
  337. $result = $wpdb->query( $wpdb->prepare( "INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)", $option, $serialized_value, $autoload ) );
  338. if ( ! $result )
  339. return false;
  340. if ( ! defined( 'WP_INSTALLING' ) ) {
  341. if ( 'yes' == $autoload ) {
  342. $alloptions = wp_load_alloptions();
  343. $alloptions[ $option ] = $serialized_value;
  344. wp_cache_set( 'alloptions', $alloptions, 'options' );
  345. } else {
  346. wp_cache_set( $option, $serialized_value, 'options' );
  347. }
  348. }
  349. // This option exists now
  350. $notoptions = wp_cache_get( 'notoptions', 'options' ); // yes, again... we need it to be fresh
  351. if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) {
  352. unset( $notoptions[$option] );
  353. wp_cache_set( 'notoptions', $notoptions, 'options' );
  354. }
  355. /**
  356. * Fires after a specific option has been added.
  357. *
  358. * The dynamic portion of the hook name, $option, refers to the option name.
  359. *
  360. * @since 2.5.0 As "add_option_{$name}"
  361. * @since 3.0.0
  362. *
  363. * @param string $option Name of the option to add.
  364. * @param mixed $value Value of the option.
  365. */
  366. do_action( "add_option_{$option}", $option, $value );
  367. /**
  368. * Fires after an option has been added.
  369. *
  370. * @since 2.9.0
  371. *
  372. * @param string $option Name of the added option.
  373. * @param mixed $value Value of the option.
  374. */
  375. do_action( 'added_option', $option, $value );
  376. return true;
  377. }
  378. /**
  379. * Removes option by name. Prevents removal of protected WordPress options.
  380. *
  381. * @since 1.2.0
  382. *
  383. * @param string $option Name of option to remove. Expected to not be SQL-escaped.
  384. * @return bool True, if option is successfully deleted. False on failure.
  385. */
  386. function delete_option( $option ) {
  387. global $wpdb;
  388. $option = trim( $option );
  389. if ( empty( $option ) )
  390. return false;
  391. wp_protect_special_option( $option );
  392. // Get the ID, if no ID then return
  393. $row = $wpdb->get_row( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) );
  394. if ( is_null( $row ) )
  395. return false;
  396. /**
  397. * Fires immediately before an option is deleted.
  398. *
  399. * @since 2.9.0
  400. *
  401. * @param string $option Name of the option to delete.
  402. */
  403. do_action( 'delete_option', $option );
  404. $result = $wpdb->delete( $wpdb->options, array( 'option_name' => $option ) );
  405. if ( ! defined( 'WP_INSTALLING' ) ) {
  406. if ( 'yes' == $row->autoload ) {
  407. $alloptions = wp_load_alloptions();
  408. if ( is_array( $alloptions ) && isset( $alloptions[$option] ) ) {
  409. unset( $alloptions[$option] );
  410. wp_cache_set( 'alloptions', $alloptions, 'options' );
  411. }
  412. } else {
  413. wp_cache_delete( $option, 'options' );
  414. }
  415. }
  416. if ( $result ) {
  417. /**
  418. * Fires after a specific option has been deleted.
  419. *
  420. * The dynamic portion of the hook name, $option, refers to the option name.
  421. *
  422. * @since 3.0.0
  423. *
  424. * @param string $option Name of the deleted option.
  425. */
  426. do_action( "delete_option_$option", $option );
  427. /**
  428. * Fires after an option has been deleted.
  429. *
  430. * @since 2.9.0
  431. *
  432. * @param string $option Name of the deleted option.
  433. */
  434. do_action( 'deleted_option', $option );
  435. return true;
  436. }
  437. return false;
  438. }
  439. /**
  440. * Delete a transient.
  441. *
  442. * @since 2.8.0
  443. *
  444. * @param string $transient Transient name. Expected to not be SQL-escaped.
  445. * @return bool true if successful, false otherwise
  446. */
  447. function delete_transient( $transient ) {
  448. /**
  449. * Fires immediately before a specific transient is deleted.
  450. *
  451. * The dynamic portion of the hook name, $transient, refers to the transient name.
  452. *
  453. * @since 3.0.0
  454. *
  455. * @param string $transient Transient name.
  456. */
  457. do_action( 'delete_transient_' . $transient, $transient );
  458. if ( wp_using_ext_object_cache() ) {
  459. $result = wp_cache_delete( $transient, 'transient' );
  460. } else {
  461. $option_timeout = '_transient_timeout_' . $transient;
  462. $option = '_transient_' . $transient;
  463. $result = delete_option( $option );
  464. if ( $result )
  465. delete_option( $option_timeout );
  466. }
  467. if ( $result ) {
  468. /**
  469. * Fires after a transient is deleted.
  470. *
  471. * @since 3.0.0
  472. *
  473. * @param string $transient Deleted transient name.
  474. */
  475. do_action( 'deleted_transient', $transient );
  476. }
  477. return $result;
  478. }
  479. /**
  480. * Get the value of a transient.
  481. *
  482. * If the transient does not exist, does not have a value, or has expired,
  483. * then the return value will be false.
  484. *
  485. * @since 2.8.0
  486. *
  487. * @param string $transient Transient name. Expected to not be SQL-escaped.
  488. * @return mixed Value of transient.
  489. */
  490. function get_transient( $transient ) {
  491. /**
  492. * Filter the value of an existing transient.
  493. *
  494. * The dynamic portion of the hook name, $transient, refers to the transient name.
  495. *
  496. * Passing a truthy value to the filter will effectively short-circuit retrieval
  497. * of the transient, returning the passed value instead.
  498. *
  499. * @since 2.8.0
  500. *
  501. * @param mixed $pre_transient The default value to return if the transient does not exist.
  502. * Any value other than false will short-circuit the retrieval
  503. * of the transient, and return the returned value.
  504. */
  505. $pre = apply_filters( 'pre_transient_' . $transient, false );
  506. if ( false !== $pre )
  507. return $pre;
  508. if ( wp_using_ext_object_cache() ) {
  509. $value = wp_cache_get( $transient, 'transient' );
  510. } else {
  511. $transient_option = '_transient_' . $transient;
  512. if ( ! defined( 'WP_INSTALLING' ) ) {
  513. // If option is not in alloptions, it is not autoloaded and thus has a timeout
  514. $alloptions = wp_load_alloptions();
  515. if ( !isset( $alloptions[$transient_option] ) ) {
  516. $transient_timeout = '_transient_timeout_' . $transient;
  517. if ( get_option( $transient_timeout ) < time() ) {
  518. delete_option( $transient_option );
  519. delete_option( $transient_timeout );
  520. $value = false;
  521. }
  522. }
  523. }
  524. if ( ! isset( $value ) )
  525. $value = get_option( $transient_option );
  526. }
  527. /**
  528. * Filter an existing transient's value.
  529. *
  530. * The dynamic portion of the hook name, $transient, refers to the transient name.
  531. *
  532. * @since 2.8.0
  533. *
  534. * @param mixed $value Value of transient.
  535. */
  536. return apply_filters( 'transient_' . $transient, $value );
  537. }
  538. /**
  539. * Set/update the value of a transient.
  540. *
  541. * You do not need to serialize values. If the value needs to be serialized, then
  542. * it will be serialized before it is set.
  543. *
  544. * @since 2.8.0
  545. *
  546. * @param string $transient Transient name. Expected to not be SQL-escaped. Must be
  547. * 45 characters or fewer in length.
  548. * @param mixed $value Transient value. Must be serializable if non-scalar.
  549. * Expected to not be SQL-escaped.
  550. * @param int $expiration Optional. Time until expiration in seconds. Default 0.
  551. * @return bool False if value was not set and true if value was set.
  552. */
  553. function set_transient( $transient, $value, $expiration = 0 ) {
  554. /**
  555. * Filter a specific transient before its value is set.
  556. *
  557. * The dynamic portion of the hook name, $transient, refers to the transient name.
  558. *
  559. * @since 3.0.0
  560. *
  561. * @param mixed $value New value of transient.
  562. */
  563. $value = apply_filters( 'pre_set_transient_' . $transient, $value );
  564. $expiration = (int) $expiration;
  565. if ( wp_using_ext_object_cache() ) {
  566. $result = wp_cache_set( $transient, $value, 'transient', $expiration );
  567. } else {
  568. $transient_timeout = '_transient_timeout_' . $transient;
  569. $transient = '_transient_' . $transient;
  570. if ( false === get_option( $transient ) ) {
  571. $autoload = 'yes';
  572. if ( $expiration ) {
  573. $autoload = 'no';
  574. add_option( $transient_timeout, time() + $expiration, '', 'no' );
  575. }
  576. $result = add_option( $transient, $value, '', $autoload );
  577. } else {
  578. // If expiration is requested, but the transient has no timeout option,
  579. // delete, then re-create transient rather than update.
  580. $update = true;
  581. if ( $expiration ) {
  582. if ( false === get_option( $transient_timeout ) ) {
  583. delete_option( $transient );
  584. add_option( $transient_timeout, time() + $expiration, '', 'no' );
  585. $result = add_option( $transient, $value, '', 'no' );
  586. $update = false;
  587. } else {
  588. update_option( $transient_timeout, time() + $expiration );
  589. }
  590. }
  591. if ( $update ) {
  592. $result = update_option( $transient, $value );
  593. }
  594. }
  595. }
  596. if ( $result ) {
  597. /**
  598. * Fires after the value for a specific transient has been set.
  599. *
  600. * The dynamic portion of the hook name, $transient, refers to the transient name.
  601. *
  602. * @since 3.0.0
  603. *
  604. * @param mixed $value Transient value.
  605. * @param int $expiration Time until expiration in seconds. Default 0.
  606. */
  607. do_action( 'set_transient_' . $transient, $value, $expiration );
  608. /**
  609. * Fires after the value for a transient has been set.
  610. *
  611. * @since 3.0.0
  612. *
  613. * @param string $transient The name of the transient.
  614. * @param mixed $value Transient value.
  615. * @param int $expiration Time until expiration in seconds. Default 0.
  616. */
  617. do_action( 'setted_transient', $transient, $value, $expiration );
  618. }
  619. return $result;
  620. }
  621. /**
  622. * Saves and restores user interface settings stored in a cookie.
  623. *
  624. * Checks if the current user-settings cookie is updated and stores it. When no
  625. * cookie exists (different browser used), adds the last saved cookie restoring
  626. * the settings.
  627. *
  628. * @since 2.7.0
  629. */
  630. function wp_user_settings() {
  631. if ( ! is_admin() || defined( 'DOING_AJAX' ) ) {
  632. return;
  633. }
  634. if ( ! $user_id = get_current_user_id() ) {
  635. return;
  636. }
  637. if ( is_super_admin() && ! is_user_member_of_blog() ) {
  638. return;
  639. }
  640. $settings = (string) get_user_option( 'user-settings', $user_id );
  641. if ( isset( $_COOKIE['wp-settings-' . $user_id] ) ) {
  642. $cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-' . $user_id] );
  643. // No change or both empty
  644. if ( $cookie == $settings )
  645. return;
  646. $last_saved = (int) get_user_option( 'user-settings-time', $user_id );
  647. $current = isset( $_COOKIE['wp-settings-time-' . $user_id]) ? preg_replace( '/[^0-9]/', '', $_COOKIE['wp-settings-time-' . $user_id] ) : 0;
  648. // The cookie is newer than the saved value. Update the user_option and leave the cookie as-is
  649. if ( $current > $last_saved ) {
  650. update_user_option( $user_id, 'user-settings', $cookie, false );
  651. update_user_option( $user_id, 'user-settings-time', time() - 5, false );
  652. return;
  653. }
  654. }
  655. // The cookie is not set in the current browser or the saved value is newer.
  656. $secure = ( 'https' === parse_url( site_url(), PHP_URL_SCHEME ) );
  657. setcookie( 'wp-settings-' . $user_id, $settings, time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure );
  658. setcookie( 'wp-settings-time-' . $user_id, time(), time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure );
  659. $_COOKIE['wp-settings-' . $user_id] = $settings;
  660. }
  661. /**
  662. * Retrieve user interface setting value based on setting name.
  663. *
  664. * @since 2.7.0
  665. *
  666. * @param string $name The name of the setting.
  667. * @param string $default Optional default value to return when $name is not set.
  668. * @return mixed the last saved user setting or the default value/false if it doesn't exist.
  669. */
  670. function get_user_setting( $name, $default = false ) {
  671. $all_user_settings = get_all_user_settings();
  672. return isset( $all_user_settings[$name] ) ? $all_user_settings[$name] : $default;
  673. }
  674. /**
  675. * Add or update user interface setting.
  676. *
  677. * Both $name and $value can contain only ASCII letters, numbers and underscores.
  678. * This function has to be used before any output has started as it calls setcookie().
  679. *
  680. * @since 2.8.0
  681. *
  682. * @param string $name The name of the setting.
  683. * @param string $value The value for the setting.
  684. * @return bool true if set successfully/false if not.
  685. */
  686. function set_user_setting( $name, $value ) {
  687. if ( headers_sent() ) {
  688. return false;
  689. }
  690. $all_user_settings = get_all_user_settings();
  691. $all_user_settings[$name] = $value;
  692. return wp_set_all_user_settings( $all_user_settings );
  693. }
  694. /**
  695. * Delete user interface settings.
  696. *
  697. * Deleting settings would reset them to the defaults.
  698. * This function has to be used before any output has started as it calls setcookie().
  699. *
  700. * @since 2.7.0
  701. *
  702. * @param mixed $names The name or array of names of the setting to be deleted.
  703. * @return bool true if deleted successfully/false if not.
  704. */
  705. function delete_user_setting( $names ) {
  706. if ( headers_sent() ) {
  707. return false;
  708. }
  709. $all_user_settings = get_all_user_settings();
  710. $names = (array) $names;
  711. $deleted = false;
  712. foreach ( $names as $name ) {
  713. if ( isset( $all_user_settings[$name] ) ) {
  714. unset( $all_user_settings[$name] );
  715. $deleted = true;
  716. }
  717. }
  718. if ( $deleted ) {
  719. return wp_set_all_user_settings( $all_user_settings );
  720. }
  721. return false;
  722. }
  723. /**
  724. * Retrieve all user interface settings.
  725. *
  726. * @since 2.7.0
  727. *
  728. * @return array the last saved user settings or empty array.
  729. */
  730. function get_all_user_settings() {
  731. global $_updated_user_settings;
  732. if ( ! $user_id = get_current_user_id() ) {
  733. return array();
  734. }
  735. if ( isset( $_updated_user_settings ) && is_array( $_updated_user_settings ) ) {
  736. return $_updated_user_settings;
  737. }
  738. $user_settings = array();
  739. if ( isset( $_COOKIE['wp-settings-' . $user_id] ) ) {
  740. $cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-' . $user_id] );
  741. if ( strpos( $cookie, '=' ) ) { // '=' cannot be 1st char
  742. parse_str( $cookie, $user_settings );
  743. }
  744. } else {
  745. $option = get_user_option( 'user-settings', $user_id );
  746. if ( $option && is_string( $option ) ) {
  747. parse_str( $option, $user_settings );
  748. }
  749. }
  750. $_updated_user_settings = $user_settings;
  751. return $user_settings;
  752. }
  753. /**
  754. * Private. Set all user interface settings.
  755. *
  756. * @since 2.8.0
  757. *
  758. * @param array $user_settings
  759. * @return bool
  760. */
  761. function wp_set_all_user_settings( $user_settings ) {
  762. global $_updated_user_settings;
  763. if ( ! $user_id = get_current_user_id() ) {
  764. return false;
  765. }
  766. if ( is_super_admin() && ! is_user_member_of_blog() ) {
  767. return;
  768. }
  769. $settings = '';
  770. foreach ( $user_settings as $name => $value ) {
  771. $_name = preg_replace( '/[^A-Za-z0-9_]+/', '', $name );
  772. $_value = preg_replace( '/[^A-Za-z0-9_]+/', '', $value );
  773. if ( ! empty( $_name ) ) {
  774. $settings .= $_name . '=' . $_value . '&';
  775. }
  776. }
  777. $settings = rtrim( $settings, '&' );
  778. parse_str( $settings, $_updated_user_settings );
  779. update_user_option( $user_id, 'user-settings', $settings, false );
  780. update_user_option( $user_id, 'user-settings-time', time(), false );
  781. return true;
  782. }
  783. /**
  784. * Delete the user settings of the current user.
  785. *
  786. * @since 2.7.0
  787. */
  788. function delete_all_user_settings() {
  789. if ( ! $user_id = get_current_user_id() ) {
  790. return;
  791. }
  792. update_user_option( $user_id, 'user-settings', '', false );
  793. setcookie( 'wp-settings-' . $user_id, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH );
  794. }
  795. /**
  796. * Retrieve site option value based on name of option.
  797. *
  798. * @since 2.8.0
  799. *
  800. * @see get_option()
  801. *
  802. * @param string $option Name of option to retrieve. Expected to not be SQL-escaped.
  803. * @param mixed $default Optional value to return if option doesn't exist. Default false.
  804. * @param bool $use_cache Whether to use cache. Multisite only. Default true.
  805. * @return mixed Value set for the option.
  806. */
  807. function get_site_option( $option, $default = false, $use_cache = true ) {
  808. global $wpdb;
  809. /**
  810. * Filter an existing site option before it is retrieved.
  811. *
  812. * The dynamic portion of the hook name, $option, refers to the option name.
  813. *
  814. * Passing a truthy value to the filter will effectively short-circuit retrieval,
  815. * returning the passed value instead.
  816. *
  817. * @since 2.9.0 As 'pre_site_option_' . $key
  818. * @since 3.0.0
  819. *
  820. * @param mixed $pre_option The default value to return if the option does not exist.
  821. */
  822. $pre = apply_filters( 'pre_site_option_' . $option, false );
  823. if ( false !== $pre )
  824. return $pre;
  825. // prevent non-existent options from triggering multiple queries
  826. $notoptions_key = "{$wpdb->siteid}:notoptions";
  827. $notoptions = wp_cache_get( $notoptions_key, 'site-options' );
  828. if ( isset( $notoptions[$option] ) ) {
  829. /**
  830. * Filter a specific default site option.
  831. *
  832. * The dynamic portion of the hook name, $option, refers to the option name.
  833. *
  834. * @since 3.4.0
  835. *
  836. * @param mixed $default The value to return if the site option does not exist
  837. * in the database.
  838. */
  839. return apply_filters( 'default_site_option_' . $option, $default );
  840. }
  841. if ( ! is_multisite() ) {
  842. /** This filter is documented in wp-includes/option.php */
  843. $default = apply_filters( 'default_site_option_' . $option, $default );
  844. $value = get_option($option, $default);
  845. } else {
  846. $cache_key = "{$wpdb->siteid}:$option";
  847. if ( $use_cache )
  848. $value = wp_cache_get($cache_key, 'site-options');
  849. if ( !isset($value) || (false === $value) ) {
  850. $row = $wpdb->get_row( $wpdb->prepare("SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $wpdb->siteid ) );
  851. // Has to be get_row instead of get_var because of funkiness with 0, false, null values
  852. if ( is_object( $row ) ) {
  853. $value = $row->meta_value;
  854. $value = maybe_unserialize( $value );
  855. wp_cache_set( $cache_key, $value, 'site-options' );
  856. } else {
  857. $notoptions[$option] = true;
  858. wp_cache_set( $notoptions_key, $notoptions, 'site-options' );
  859. /** This filter is documented in wp-includes/option.php */
  860. $value = apply_filters( 'default_site_option_' . $option, $default );
  861. }
  862. }
  863. }
  864. /**
  865. * Filter the value of an existing site option.
  866. *
  867. * The dynamic portion of the hook name, $option, refers to the option name.
  868. *
  869. * @since 2.9.0 As 'site_option_' . $key
  870. * @since 3.0.0
  871. *
  872. * @param mixed $value Value of site option.
  873. */
  874. return apply_filters( 'site_option_' . $option, $value );
  875. }
  876. /**
  877. * Add a new site option.
  878. *
  879. * Existing options will not be updated. Note that prior to 3.3 this wasn't the case.
  880. *
  881. * @since 2.8.0
  882. *
  883. * @see add_option()
  884. *
  885. * @param string $option Name of option to add. Expected to not be SQL-escaped.
  886. * @param mixed $value Optional. Option value, can be anything. Expected to not be SQL-escaped.
  887. * @return bool False if option was not added and true if option was added.
  888. */
  889. function add_site_option( $option, $value ) {
  890. global $wpdb;
  891. wp_protect_special_option( $option );
  892. /**
  893. * Filter the value of a specific site option before it is added.
  894. *
  895. * The dynamic portion of the hook name, $option, refers to the option name.
  896. *
  897. * @since 2.9.0 As 'pre_add_site_option_' . $key
  898. * @since 3.0.0
  899. *
  900. * @param mixed $value Value of site option.
  901. */
  902. $value = apply_filters( 'pre_add_site_option_' . $option, $value );
  903. $notoptions_key = "{$wpdb->siteid}:notoptions";
  904. if ( !is_multisite() ) {
  905. $result = add_option( $option, $value );
  906. } else {
  907. $cache_key = "{$wpdb->siteid}:$option";
  908. // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query
  909. $notoptions = wp_cache_get( $notoptions_key, 'site-options' );
  910. if ( ! is_array( $notoptions ) || ! isset( $notoptions[$option] ) )
  911. if ( false !== get_site_option( $option ) )
  912. return false;
  913. $value = sanitize_option( $option, $value );
  914. $serialized_value = maybe_serialize( $value );
  915. $result = $wpdb->insert( $wpdb->sitemeta, array('site_id' => $wpdb->siteid, 'meta_key' => $option, 'meta_value' => $serialized_value ) );
  916. if ( ! $result )
  917. return false;
  918. wp_cache_set( $cache_key, $value, 'site-options' );
  919. // This option exists now
  920. $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); // yes, again... we need it to be fresh
  921. if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) {
  922. unset( $notoptions[$option] );
  923. wp_cache_set( $notoptions_key, $notoptions, 'site-options' );
  924. }
  925. }
  926. if ( $result ) {
  927. /**
  928. * Fires after a specific site option has been successfully added.
  929. *
  930. * The dynamic portion of the hook name, $option, refers to the option name.
  931. *
  932. * @since 2.9.0 As "add_site_option_{$key}"
  933. * @since 3.0.0
  934. *
  935. * @param string $option Name of site option.
  936. * @param mixed $value Value of site option.
  937. */
  938. do_action( "add_site_option_{$option}", $option, $value );
  939. /**
  940. * Fires after a site option has been successfully added.
  941. *
  942. * @since 3.0.0
  943. *
  944. * @param string $option Name of site option.
  945. * @param mixed $value Value of site option.
  946. */
  947. do_action( "add_site_option", $option, $value );
  948. return true;
  949. }
  950. return false;
  951. }
  952. /**
  953. * Removes site option by name.
  954. *
  955. * @since 2.8.0
  956. *
  957. * @see delete_option()
  958. *
  959. * @param string $option Name of option to remove. Expected to not be SQL-escaped.
  960. * @return bool True, if succeed. False, if failure.
  961. */
  962. function delete_site_option( $option ) {
  963. global $wpdb;
  964. // ms_protect_special_option( $option ); @todo
  965. /**
  966. * Fires immediately before a specific site option is deleted.
  967. *
  968. * The dynamic portion of the hook name, $option, refers to the option name.
  969. *
  970. * @since 3.0.0
  971. */
  972. do_action( 'pre_delete_site_option_' . $option );
  973. if ( !is_multisite() ) {
  974. $result = delete_option( $option );
  975. } else {
  976. $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $option, $wpdb->siteid ) );
  977. if ( is_null( $row ) || !$row->meta_id )
  978. return false;
  979. $cache_key = "{$wpdb->siteid}:$option";
  980. wp_cache_delete( $cache_key, 'site-options' );
  981. $result = $wpdb->delete( $wpdb->sitemeta, array( 'meta_key' => $option, 'site_id' => $wpdb->siteid ) );
  982. }
  983. if ( $result ) {
  984. /**
  985. * Fires after a specific site option has been deleted.
  986. *
  987. * The dynamic portion of the hook name, $option, refers to the option name.
  988. *
  989. * @since 2.9.0 As "delete_site_option_{$key}"
  990. * @since 3.0.0
  991. *
  992. * @param string $option Name of the site option.
  993. */
  994. do_action( "delete_site_option_{$option}", $option );
  995. /**
  996. * Fires after a site option has been deleted.
  997. *
  998. * @since 3.0.0
  999. *
  1000. * @param string $option Name of the site option.
  1001. */
  1002. do_action( "delete_site_option", $option );
  1003. return true;
  1004. }
  1005. return false;
  1006. }
  1007. /**
  1008. * Update the value of a site option that was already added.
  1009. *
  1010. * @since 2.8.0
  1011. *
  1012. * @see update_option()
  1013. *
  1014. * @param string $option Name of option. Expected to not be SQL-escaped.
  1015. * @param mixed $value Option value. Expected to not be SQL-escaped.
  1016. * @return bool False if value was not updated and true if value was updated.
  1017. */
  1018. function update_site_option( $option, $value ) {
  1019. global $wpdb;
  1020. wp_protect_special_option( $option );
  1021. $old_value = get_site_option( $option );
  1022. /**
  1023. * Filter a specific site option before its value is updated.
  1024. *
  1025. * The dynamic portion of the hook name, $option, refers to the option name.
  1026. *
  1027. * @since 2.9.0 As 'pre_update_site_option_' . $key
  1028. * @since 3.0.0
  1029. *
  1030. * @param mixed $value New value of site option.
  1031. * @param mixed $old_value Old value of site option.
  1032. */
  1033. $value = apply_filters( 'pre_update_site_option_' . $option, $value, $old_value );
  1034. if ( $value === $old_value )
  1035. return false;
  1036. if ( false === $old_value )
  1037. return add_site_option( $option, $value );
  1038. $notoptions_key = "{$wpdb->siteid}:notoptions";
  1039. $notoptions = wp_cache_get( $notoptions_key, 'site-options' );
  1040. if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) {
  1041. unset( $notoptions[$option] );
  1042. wp_cache_set( $notoptions_key, $notoptions, 'site-options' );
  1043. }
  1044. if ( !is_multisite() ) {
  1045. $result = update_option( $option, $value );
  1046. } else {
  1047. $value = sanitize_option( $option, $value );
  1048. $serialized_value = maybe_serialize( $value );
  1049. $result = $wpdb->update( $wpdb->sitemeta, array( 'meta_value' => $serialized_value ), array( 'site_id' => $wpdb->siteid, 'meta_key' => $option ) );
  1050. if ( $result ) {
  1051. $cache_key = "{$wpdb->siteid}:$option";
  1052. wp_cache_set( $cache_key, $value, 'site-options' );
  1053. }
  1054. }
  1055. if ( $result ) {
  1056. /**
  1057. * Fires after the value of a specific site option has been successfully updated.
  1058. *
  1059. * The dynamic portion of the hook name, $option, refers to the option name.
  1060. *
  1061. * @since 2.9.0 As "update_site_option_{$key}"
  1062. * @since 3.0.0
  1063. *
  1064. * @param string $option Name of site option.
  1065. * @param mixed $value Current value of site option.
  1066. * @param mixed $old_value Old value of site option.
  1067. */
  1068. do_action( "update_site_option_{$option}", $option, $value, $old_value );
  1069. /**
  1070. * Fires after the value of a site option has been successfully updated.
  1071. *
  1072. * @since 3.0.0
  1073. *
  1074. * @param string $option Name of site option.
  1075. * @param mixed $value Current value of site option.
  1076. * @param mixed $old_value Old value of site option.
  1077. */
  1078. do_action( "update_site_option", $option, $value, $old_value );
  1079. return true;
  1080. }
  1081. return false;
  1082. }
  1083. /**
  1084. * Delete a site transient.
  1085. *
  1086. * @since 2.9.0
  1087. *
  1088. * @param string $transient Transient name. Expected to not be SQL-escaped.
  1089. * @return bool True if successful, false otherwise
  1090. */
  1091. function delete_site_transient( $transient ) {
  1092. /**
  1093. * Fires immediately before a specific site transient is deleted.
  1094. *
  1095. * The dynamic portion of the hook name, $transient, refers to the transient name.
  1096. *
  1097. * @since 3.0.0
  1098. *
  1099. * @param string $transient Transient name.
  1100. */
  1101. do_action( 'delete_site_transient_' . $transient, $transient );
  1102. if ( wp_using_ext_object_cache() ) {
  1103. $result = wp_cache_delete( $transient, 'site-transient' );
  1104. } else {
  1105. $option_timeout = '_site_transient_timeout_' . $transient;
  1106. $option = '_site_transient_' . $transient;
  1107. $result = delete_site_option( $option );
  1108. if ( $result )
  1109. delete_site_option( $option_timeout );
  1110. }
  1111. if ( $result ) {
  1112. /**
  1113. * Fires after a transient is deleted.
  1114. *
  1115. * @since 3.0.0
  1116. *
  1117. * @param string $transient Deleted transient name.
  1118. */
  1119. do_action( 'deleted_site_transient', $transient );
  1120. }
  1121. return $result;
  1122. }
  1123. /**
  1124. * Get the value of a site transient.
  1125. *
  1126. * If the transient does not exist, does not have a value, or has expired,
  1127. * then the return value will be false.
  1128. *
  1129. * @since 2.9.0
  1130. *
  1131. * @see get_transient()
  1132. *
  1133. * @param string $transient Transient name. Expected to not be SQL-escaped.
  1134. * @return mixed Value of transient.
  1135. */
  1136. function get_site_transient( $transient ) {
  1137. /**
  1138. * Filter the value of an existing site transient.
  1139. *
  1140. * The dynamic portion of the hook name, $transient, refers to the transient name.
  1141. *
  1142. * Passing a truthy value to the filter will effectively short-circuit retrieval,
  1143. * returning the passed value instead.
  1144. *
  1145. * @since 2.9.0
  1146. *
  1147. * @param mixed $pre_site_transient The default value to return if the site transient does not exist.
  1148. * Any value other than false will short-circuit the retrieval
  1149. * of the transient, and return the returned value.
  1150. */
  1151. $pre = apply_filters( 'pre_site_transient_' . $transient, false );
  1152. if ( false !== $pre )
  1153. return $pre;
  1154. if ( wp_using_ext_object_cache() ) {
  1155. $value = wp_cache_get( $transient, 'site-transient' );
  1156. } else {
  1157. // Core transients that do not have a timeout. Listed here so querying timeouts can be avoided.
  1158. $no_timeout = array('update_core', 'update_plugins', 'update_themes');
  1159. $transient_option = '_site_transient_' . $transient;
  1160. if ( ! in_array( $transient, $no_timeout ) ) {
  1161. $transient_timeout = '_site_transient_timeout_' . $transient;
  1162. $timeout = get_site_option( $transient_timeout );
  1163. if ( false !== $timeout && $timeout < time() ) {
  1164. delete_site_option( $transient_option );
  1165. delete_site_option( $transient_timeout );
  1166. $value = false;
  1167. }
  1168. }
  1169. if ( ! isset( $value ) )
  1170. $value = get_site_option( $transient_option );
  1171. }
  1172. /**
  1173. * Filter the value of an existing site transient.
  1174. *
  1175. * The dynamic portion of the hook name, $transient, refers to the transient name.
  1176. *
  1177. * @since 2.9.0
  1178. *
  1179. * @param mixed $value Value of site transient.
  1180. */
  1181. return apply_filters( 'site_transient_' . $transient, $value );
  1182. }
  1183. /**
  1184. * Set/update the value of a site transient.
  1185. *
  1186. * You do not need to serialize values, if the value needs to be serialize, then
  1187. * it will be serialized before it is set.
  1188. *
  1189. * @since 2.9.0
  1190. *
  1191. * @see set_transient()
  1192. *
  1193. * @param string $transient Transient name. Expected to not be SQL-escaped. Must be
  1194. * 40 characters or fewer in length.
  1195. * @param mixed $value Transient value. Expected to not be SQL-escaped.
  1196. * @param int $expiration Optional. Time until expiration in seconds. Default 0.
  1197. * @return bool False if value was not set and true if value was set.
  1198. */
  1199. function set_site_transient( $transient, $value, $expiration = 0 ) {
  1200. /**
  1201. * Filter the value of a specific site transient before it is set.
  1202. *
  1203. * The dynamic portion of the hook name, $transient, refers to the transient name.
  1204. *
  1205. * @since 3.0.0
  1206. *
  1207. * @param mixed $value Value of site transient.
  1208. */
  1209. $value = apply_filters( 'pre_set_site_transient_' . $transient, $value );
  1210. $expiration = (int) $expiration;
  1211. if ( wp_using_ext_object_cache() ) {
  1212. $result = wp_cache_set( $transient, $value, 'site-transient', $expiration );
  1213. } else {
  1214. $transient_timeout = '_site_transient_timeout_' . $transient;
  1215. $option = '_site_transient_' . $transient;
  1216. if ( false === get_site_option( $option ) ) {
  1217. if ( $expiration )
  1218. add_site_option( $transient_timeout, time() + $expiration );
  1219. $result = add_site_option( $option, $value );
  1220. } else {
  1221. if ( $expiration )
  1222. update_site_option( $transient_timeout, time() + $expiration );
  1223. $result = update_site_option( $option, $value );
  1224. }
  1225. }
  1226. if ( $result ) {
  1227. /**
  1228. * Fires after the value for a specific site transient has been set.
  1229. *
  1230. * The dynamic portion of the hook name, $transient, refers to the transient name.
  1231. *
  1232. * @since 3.0.0
  1233. *
  1234. * @param mixed $value Site transient value.
  1235. * @param int $expiration Time until expiration in seconds. Default 0.
  1236. */
  1237. do_action( 'set_site_transient_' . $transient, $value, $expiration );
  1238. /**
  1239. * Fires after the value for a site transient has been set.
  1240. *
  1241. * @since 3.0.0
  1242. *
  1243. * @param string $transient The name of the site transient.
  1244. * @param mixed $value Site transient value.
  1245. * @param int $expiration Time until expiration in seconds. Default 0.
  1246. */
  1247. do_action( 'setted_site_transient', $transient, $value, $expiration );
  1248. }
  1249. return $result;
  1250. }