<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[27365] trunk/src/wp-includes/option.php: Inline documentation for hooks in wp-includes/option.php.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/27365">27365</a></dd>
<dt>Author</dt> <dd>DrewAPicture</dd>
<dt>Date</dt> <dd>2014-03-02 23:34:08 +0000 (Sun, 02 Mar 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Inline documentation for hooks in wp-includes/option.php.
Props siobhyb for the initial patch. Props DrewAPicture, kpdesign.
Fixes <a href="http://core.trac.wordpress.org/ticket/25905">#25905</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesoptionphp">trunk/src/wp-includes/option.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesoptionphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/option.php (27364 => 27365)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/option.php 2014-03-02 23:25:25 UTC (rev 27364)
+++ trunk/src/wp-includes/option.php 2014-03-02 23:34:08 UTC (rev 27365)
</span><span class="lines">@@ -17,12 +17,6 @@
</span><span class="cx"> * If the option was serialized then it will be unserialized when it is returned.
</span><span class="cx"> *
</span><span class="cx"> * @since 1.5.0
</span><del>- * @uses apply_filters() Calls 'pre_option_$option' before checking the option.
- * Any value other than false will "short-circuit" the retrieval of the option
- * and return the returned value. You should not try to override special options,
- * but you will not be prevented from doing so.
- * @uses apply_filters() Calls 'option_$option', after checking the option, with
- * the option value.
</del><span class="cx"> *
</span><span class="cx"> * @param string $option Name of option to retrieve. Expected to not be SQL-escaped.
</span><span class="cx"> * @param mixed $default Optional. Default value to return if the option does not exist.
</span><span class="lines">@@ -35,7 +29,19 @@
</span><span class="cx"> if ( empty( $option ) )
</span><span class="cx"> return false;
</span><span class="cx">
</span><del>- // Allow plugins to short-circuit options.
</del><ins>+ /**
+ * Filter the value of an existing option before it is retrieved.
+ *
+ * The dynamic portion of the hook name, $option, refers to the option name.
+ *
+ * Passing a truthy value to the filter will short-circuit retrieving
+ * the option value, returning the passed value instead.
+ *
+ * @since 1.5.0
+ *
+ * @param bool|mixed $pre_option Value to return instead of the option value.
+ * Default false to skip it.
+ */
</ins><span class="cx"> $pre = apply_filters( 'pre_option_' . $option, false );
</span><span class="cx"> if ( false !== $pre )
</span><span class="cx"> return $pre;
</span><span class="lines">@@ -47,6 +53,18 @@
</span><span class="cx"> // prevent non-existent options from triggering multiple queries
</span><span class="cx"> $notoptions = wp_cache_get( 'notoptions', 'options' );
</span><span class="cx"> if ( isset( $notoptions[$option] ) )
</span><ins>+
+ /**
+ * Filter the default value for an option.
+ *
+ * The dynamic portion of the hook name, $option, refers
+ * to the option name.
+ *
+ * @since 3.4.0
+ *
+ * @param mixed $default The default value to return if the option
+ * does not exist in the database.
+ */
</ins><span class="cx"> return apply_filters( 'default_option_' . $option, $default );
</span><span class="cx">
</span><span class="cx"> $alloptions = wp_load_alloptions();
</span><span class="lines">@@ -66,6 +84,8 @@
</span><span class="cx"> } else { // option does not exist, so we must cache its non-existence
</span><span class="cx"> $notoptions[$option] = true;
</span><span class="cx"> wp_cache_set( 'notoptions', $notoptions, 'options' );
</span><ins>+
+ /** This filter is documented in wp-includes/option.php */
</ins><span class="cx"> return apply_filters( 'default_option_' . $option, $default );
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="lines">@@ -74,10 +94,12 @@
</span><span class="cx"> $suppress = $wpdb->suppress_errors();
</span><span class="cx"> $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) );
</span><span class="cx"> $wpdb->suppress_errors( $suppress );
</span><del>- if ( is_object( $row ) )
</del><ins>+ if ( is_object( $row ) ) {
</ins><span class="cx"> $value = $row->option_value;
</span><del>- else
</del><ins>+ } else {
+ /** This filter is documented in wp-includes/option.php */
</ins><span class="cx"> return apply_filters( 'default_option_' . $option, $default );
</span><ins>+ }
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // If home is not set use siteurl.
</span><span class="lines">@@ -87,6 +109,17 @@
</span><span class="cx"> if ( in_array( $option, array('siteurl', 'home', 'category_base', 'tag_base') ) )
</span><span class="cx"> $value = untrailingslashit( $value );
</span><span class="cx">
</span><ins>+ /**
+ * Filter the value of an existing option.
+ *
+ * The dynamic portion of the hook name, $option, refers to the option name.
+ *
+ * @since 1.5.0 As 'option_' . $setting
+ * @since 3.0.0
+ *
+ * @param mixed $value Value of the option. If stored serialized, it will be
+ * unserialized prior to being returned.
+ */
</ins><span class="cx"> return apply_filters( 'option_' . $option, maybe_unserialize( $value ) );
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -191,11 +224,6 @@
</span><span class="cx"> *
</span><span class="cx"> * @since 1.0.0
</span><span class="cx"> *
</span><del>- * @uses apply_filters() Calls 'pre_update_option_$option' hook to allow overwriting the
- * option value to be stored.
- * @uses do_action() Calls 'update_option' hook before updating the option.
- * @uses do_action() Calls 'update_option_$option' and 'updated_option' hooks on success.
- *
</del><span class="cx"> * @param string $option Option name. Expected to not be SQL-escaped.
</span><span class="cx"> * @param mixed $value Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped.
</span><span class="cx"> * @return bool False if value was not updated and true if value was updated.
</span><span class="lines">@@ -214,6 +242,17 @@
</span><span class="cx">
</span><span class="cx"> $value = sanitize_option( $option, $value );
</span><span class="cx"> $old_value = get_option( $option );
</span><ins>+
+ /**
+ * Filter a specific option before its value is (maybe) serialized and updated.
+ *
+ * The dynamic portion of the hook name, $option, refers to the option name.
+ *
+ * @since 2.6.0
+ *
+ * @param mixed $value The new, unserialized option value.
+ * @param mixed $old_value The old option value.
+ */
</ins><span class="cx"> $value = apply_filters( 'pre_update_option_' . $option, $value, $old_value );
</span><span class="cx">
</span><span class="cx"> // If the new and old values are the same, no need to update.
</span><span class="lines">@@ -225,7 +264,17 @@
</span><span class="cx">
</span><span class="cx"> $serialized_value = maybe_serialize( $value );
</span><span class="cx">
</span><ins>+ /**
+ * Fires immediately before an option value is updated.
+ *
+ * @since 2.9.0
+ *
+ * @param string $option Name of the option to update.
+ * @param mixed $old_value The old option value.
+ * @param mixed $value The new option value.
+ */
</ins><span class="cx"> do_action( 'update_option', $option, $old_value, $value );
</span><ins>+
</ins><span class="cx"> $result = $wpdb->update( $wpdb->options, array( 'option_value' => $serialized_value ), array( 'option_name' => $option ) );
</span><span class="cx"> if ( ! $result )
</span><span class="cx"> return false;
</span><span class="lines">@@ -246,7 +295,27 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Fires after the value of a specific option has been successfully updated.
+ *
+ * The dynamic portion of the hook name, $option, refers to the option name.
+ *
+ * @since 2.0.1
+ *
+ * @param mixed $old_value The old option value.
+ * @param mixed $value The new option value.
+ */
</ins><span class="cx"> do_action( "update_option_{$option}", $old_value, $value );
</span><ins>+
+ /**
+ * Fires after the value of an option has been successfully updated.
+ *
+ * @since 2.9.0
+ *
+ * @param string $option Name of the updated option.
+ * @param mixed $old_value The old option value.
+ * @param mixed $value The new option value.
+ */
</ins><span class="cx"> do_action( 'updated_option', $option, $old_value, $value );
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="lines">@@ -265,9 +334,6 @@
</span><span class="cx"> *
</span><span class="cx"> * @since 1.0.0
</span><span class="cx"> *
</span><del>- * @uses do_action() Calls 'add_option' hook before adding the option.
- * @uses do_action() Calls 'add_option_$option' and 'added_option' hooks on success.
- *
</del><span class="cx"> * @param string $option Name of option to add. Expected to not be SQL-escaped.
</span><span class="cx"> * @param mixed $value Optional. Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped.
</span><span class="cx"> * @param mixed $deprecated Optional. Description. Not used anymore.
</span><span class="lines">@@ -299,6 +365,15 @@
</span><span class="cx">
</span><span class="cx"> $serialized_value = maybe_serialize( $value );
</span><span class="cx"> $autoload = ( 'no' === $autoload ) ? 'no' : 'yes';
</span><ins>+
+ /**
+ * Fires before an option is added.
+ *
+ * @since 2.9.0
+ *
+ * @param string $option Name of the option to add.
+ * @param mixed $value Value of the option.
+ */
</ins><span class="cx"> do_action( 'add_option', $option, $value );
</span><span class="cx">
</span><span class="cx"> $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 ) );
</span><span class="lines">@@ -322,7 +397,27 @@
</span><span class="cx"> wp_cache_set( 'notoptions', $notoptions, 'options' );
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Fires after a specific option has been added.
+ *
+ * The dynamic portion of the hook name, $option, refers to the option name.
+ *
+ * @since 2.5.0 As "add_option_{$name}"
+ * @since 3.0.0
+ *
+ * @param string $option Name of the option to add.
+ * @param mixed $value Value of the option.
+ */
</ins><span class="cx"> do_action( "add_option_{$option}", $option, $value );
</span><ins>+
+ /**
+ * Fires after an option has been added.
+ *
+ * @since 2.9.0
+ *
+ * @param string $option Name of the added option.
+ * @param mixed $value Value of the option.
+ */
</ins><span class="cx"> do_action( 'added_option', $option, $value );
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="lines">@@ -332,9 +427,6 @@
</span><span class="cx"> *
</span><span class="cx"> * @since 1.2.0
</span><span class="cx"> *
</span><del>- * @uses do_action() Calls 'delete_option' hook before option is deleted.
- * @uses do_action() Calls 'deleted_option' and 'delete_option_$option' hooks on success.
- *
</del><span class="cx"> * @param string $option Name of option to remove. Expected to not be SQL-escaped.
</span><span class="cx"> * @return bool True, if option is successfully deleted. False on failure.
</span><span class="cx"> */
</span><span class="lines">@@ -351,7 +443,16 @@
</span><span class="cx"> $row = $wpdb->get_row( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) );
</span><span class="cx"> if ( is_null( $row ) )
</span><span class="cx"> return false;
</span><ins>+
+ /**
+ * Fires immediately before an option is deleted.
+ *
+ * @since 2.9.0
+ *
+ * @param string $option Name of the option to delete.
+ */
</ins><span class="cx"> do_action( 'delete_option', $option );
</span><ins>+
</ins><span class="cx"> $result = $wpdb->delete( $wpdb->options, array( 'option_name' => $option ) );
</span><span class="cx"> if ( ! defined( 'WP_INSTALLING' ) ) {
</span><span class="cx"> if ( 'yes' == $row->autoload ) {
</span><span class="lines">@@ -365,7 +466,25 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx"> if ( $result ) {
</span><ins>+
+ /**
+ * Fires after a specific option has been deleted.
+ *
+ * The dynamic portion of the hook name, $option, refers to the option name.
+ *
+ * @since 3.0.0
+ *
+ * @param string $option Name of the deleted option.
+ */
</ins><span class="cx"> do_action( "delete_option_$option", $option );
</span><ins>+
+ /**
+ * Fires after an option has been deleted.
+ *
+ * @since 2.9.0
+ *
+ * @param string $option Name of the deleted option.
+ */
</ins><span class="cx"> do_action( 'deleted_option', $option );
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="lines">@@ -377,13 +496,20 @@
</span><span class="cx"> *
</span><span class="cx"> * @since 2.8.0
</span><span class="cx"> *
</span><del>- * @uses do_action() Calls 'delete_transient_$transient' hook before transient is deleted.
- * @uses do_action() Calls 'deleted_transient' hook on success.
- *
</del><span class="cx"> * @param string $transient Transient name. Expected to not be SQL-escaped.
</span><span class="cx"> * @return bool true if successful, false otherwise
</span><span class="cx"> */
</span><span class="cx"> function delete_transient( $transient ) {
</span><ins>+
+ /**
+ * Fires immediately before a specific transient is deleted.
+ *
+ * The dynamic portion of the hook name, $transient, refers to the transient name.
+ *
+ * @since 3.0.0
+ *
+ * @param string $transient Transient name.
+ */
</ins><span class="cx"> do_action( 'delete_transient_' . $transient, $transient );
</span><span class="cx">
</span><span class="cx"> if ( wp_using_ext_object_cache() ) {
</span><span class="lines">@@ -396,8 +522,18 @@
</span><span class="cx"> delete_option( $option_timeout );
</span><span class="cx"> }
</span><span class="cx">
</span><del>- if ( $result )
</del><ins>+ if ( $result ) {
+
+ /**
+ * Fires after a transient is deleted.
+ *
+ * @since 3.0.0
+ *
+ * @param string $transient Deleted transient name.
+ */
</ins><span class="cx"> do_action( 'deleted_transient', $transient );
</span><ins>+ }
+
</ins><span class="cx"> return $result;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -407,18 +543,27 @@
</span><span class="cx"> * If the transient does not exist or does not have a value, then the return value
</span><span class="cx"> * will be false.
</span><span class="cx"> *
</span><del>- * @uses apply_filters() Calls 'pre_transient_$transient' hook before checking the transient.
- * Any value other than false will "short-circuit" the retrieval of the transient
- * and return the returned value.
- * @uses apply_filters() Calls 'transient_$option' hook, after checking the transient, with
- * the transient value.
- *
</del><span class="cx"> * @since 2.8.0
</span><span class="cx"> *
</span><span class="cx"> * @param string $transient Transient name. Expected to not be SQL-escaped
</span><span class="cx"> * @return mixed Value of transient
</span><span class="cx"> */
</span><span class="cx"> function get_transient( $transient ) {
</span><ins>+
+ /**
+ * Filter the value of an existing transient.
+ *
+ * The dynamic portion of the hook name, $transient, refers to the transient name.
+ *
+ * Passing a truthy value to the filter will effectively short-circuit retrieval
+ * of the transient, returning the passed value instead.
+ *
+ * @since 2.8.0
+ *
+ * @param mixed $pre_transient The default value to return if the transient does not exist.
+ * Any value other than false will short-circuit the retrieval
+ * of the transient, and return the returned value.
+ */
</ins><span class="cx"> $pre = apply_filters( 'pre_transient_' . $transient, false );
</span><span class="cx"> if ( false !== $pre )
</span><span class="cx"> return $pre;
</span><span class="lines">@@ -444,6 +589,15 @@
</span><span class="cx"> $value = get_option( $transient_option );
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Filter an existing transient's value.
+ *
+ * The dynamic portion of the hook name, $transient, refers to the transient name.
+ *
+ * @since 2.8.0
+ *
+ * @param mixed $value Value of transient.
+ */
</ins><span class="cx"> return apply_filters( 'transient_' . $transient, $value );
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -455,17 +609,24 @@
</span><span class="cx"> *
</span><span class="cx"> * @since 2.8.0
</span><span class="cx"> *
</span><del>- * @uses apply_filters() Calls 'pre_set_transient_$transient' hook to allow overwriting the
- * transient value to be stored.
- * @uses do_action() Calls 'set_transient_$transient' and 'setted_transient' hooks on success.
- *
</del><span class="cx"> * @param string $transient Transient name. Expected to not be SQL-escaped.
</span><span class="cx"> * @param mixed $value Transient value. Must be serializable if non-scalar. Expected to not be SQL-escaped.
</span><span class="cx"> * @param int $expiration Time until expiration in seconds, default 0
</span><span class="cx"> * @return bool False if value was not set and true if value was set.
</span><span class="cx"> */
</span><span class="cx"> function set_transient( $transient, $value, $expiration = 0 ) {
</span><ins>+
+ /**
+ * Filter a specific transient before its value is set.
+ *
+ * The dynamic portion of the hook name, $transient, refers to the transient name.
+ *
+ * @since 3.0.0
+ *
+ * @param mixed $value New value of transient.
+ */
</ins><span class="cx"> $value = apply_filters( 'pre_set_transient_' . $transient, $value );
</span><ins>+
</ins><span class="cx"> $expiration = (int) $expiration;
</span><span class="cx">
</span><span class="cx"> if ( wp_using_ext_object_cache() ) {
</span><span class="lines">@@ -486,8 +647,30 @@
</span><span class="cx"> $result = update_option( $transient, $value );
</span><span class="cx"> }
</span><span class="cx"> }
</span><ins>+
</ins><span class="cx"> if ( $result ) {
</span><ins>+
+ /**
+ * Fires after the value for a specific transient has been set.
+ *
+ * The dynamic portion of the hook name, $transient, refers to the transient name.
+ *
+ * @since 3.0.0
+ *
+ * @param mixed $value Transient value.
+ * @param int $expiration Time until expiration in seconds. Default 0.
+ */
</ins><span class="cx"> do_action( 'set_transient_' . $transient, $value, $expiration );
</span><ins>+
+ /**
+ * Fires after the value for a transient has been set.
+ *
+ * @since 3.0.0
+ *
+ * @param string $transient The name of the transient.
+ * @param mixed $value Transient value.
+ * @param int $expiration Time until expiration in seconds. Default 0.
+ */
</ins><span class="cx"> do_action( 'setted_transient', $transient, $value, $expiration );
</span><span class="cx"> }
</span><span class="cx"> return $result;
</span><span class="lines">@@ -697,14 +880,9 @@
</span><span class="cx"> /**
</span><span class="cx"> * Retrieve site option value based on name of option.
</span><span class="cx"> *
</span><del>- * @see get_option()
</del><span class="cx"> * @since 2.8.0
</span><span class="cx"> *
</span><del>- * @uses apply_filters() Calls 'pre_site_option_$option' before checking the option.
- * Any value other than false will "short-circuit" the retrieval of the option
- * and return the returned value.
- * @uses apply_filters() Calls 'site_option_$option', after checking the option, with
- * the option value.
</del><ins>+ * @see get_option()
</ins><span class="cx"> *
</span><span class="cx"> * @param string $option Name of option to retrieve. Expected to not be SQL-escaped.
</span><span class="cx"> * @param mixed $default Optional value to return if option doesn't exist. Default false.
</span><span class="lines">@@ -714,18 +892,46 @@
</span><span class="cx"> function get_site_option( $option, $default = false, $use_cache = true ) {
</span><span class="cx"> global $wpdb;
</span><span class="cx">
</span><del>- // Allow plugins to short-circuit site options.
</del><ins>+ /**
+ * Filter an existing site option before it is retrieved.
+ *
+ * The dynamic portion of the hook name, $option, refers to the option name.
+ *
+ * Passing a truthy value to the filter will effectively short-circuit retrieval,
+ * returning the passed value instead.
+ *
+ * @since 2.9.0 As 'pre_site_option_' . $key
+ * @since 3.0.0
+ *
+ * @param mixed $pre_option The default value to return if the option does not exist.
+ */
</ins><span class="cx"> $pre = apply_filters( 'pre_site_option_' . $option, false );
</span><ins>+
</ins><span class="cx"> if ( false !== $pre )
</span><span class="cx"> return $pre;
</span><span class="cx">
</span><span class="cx"> // prevent non-existent options from triggering multiple queries
</span><span class="cx"> $notoptions_key = "{$wpdb->siteid}:notoptions";
</span><span class="cx"> $notoptions = wp_cache_get( $notoptions_key, 'site-options' );
</span><del>- if ( isset( $notoptions[$option] ) )
</del><ins>+
+ if ( isset( $notoptions[$option] ) ) {
+
+ /**
+ * Filter a specific default site option.
+ *
+ * The dynamic portion of the hook name, $option, refers to the option name.
+ *
+ * @since 3.4.0
+ *
+ * @param mixed $default The value to return if the site option does not exist
+ * in the database.
+ */
</ins><span class="cx"> return apply_filters( 'default_site_option_' . $option, $default );
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> if ( ! is_multisite() ) {
</span><ins>+
+ /** This filter is documented in wp-includes/option.php */
</ins><span class="cx"> $default = apply_filters( 'default_site_option_' . $option, $default );
</span><span class="cx"> $value = get_option($option, $default);
</span><span class="cx"> } else {
</span><span class="lines">@@ -744,11 +950,23 @@
</span><span class="cx"> } else {
</span><span class="cx"> $notoptions[$option] = true;
</span><span class="cx"> wp_cache_set( $notoptions_key, $notoptions, 'site-options' );
</span><ins>+
+ /** This filter is documented in wp-includes/option.php */
</ins><span class="cx"> $value = apply_filters( 'default_site_option_' . $option, $default );
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Filter the value of an existing site option.
+ *
+ * The dynamic portion of the hook name, $option, refers to the option name.
+ *
+ * @since 2.9.0 As 'site_option_' . $key
+ * @since 3.0.0
+ *
+ * @param mixed $value Value of site option.
+ */
</ins><span class="cx"> return apply_filters( 'site_option_' . $option, $value );
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -757,12 +975,9 @@
</span><span class="cx"> *
</span><span class="cx"> * Existing options will not be updated. Note that prior to 3.3 this wasn't the case.
</span><span class="cx"> *
</span><del>- * @see add_option()
</del><span class="cx"> * @since 2.8.0
</span><span class="cx"> *
</span><del>- * @uses apply_filters() Calls 'pre_add_site_option_$option' hook to allow overwriting the
- * option value to be stored.
- * @uses do_action() Calls 'add_site_option_$option' and 'add_site_option' hooks on success.
</del><ins>+ * @see add_option()
</ins><span class="cx"> *
</span><span class="cx"> * @param string $option Name of option to add. Expected to not be SQL-escaped.
</span><span class="cx"> * @param mixed $value Optional. Option value, can be anything. Expected to not be SQL-escaped.
</span><span class="lines">@@ -773,7 +988,18 @@
</span><span class="cx">
</span><span class="cx"> wp_protect_special_option( $option );
</span><span class="cx">
</span><ins>+ /**
+ * Filter the value of a specific site option before it is added.
+ *
+ * The dynamic portion of the hook name, $option, refers to the option name.
+ *
+ * @since 2.9.0 As 'pre_add_site_option_' . $key
+ * @since 3.0.0
+ *
+ * @param mixed $value Value of site option.
+ */
</ins><span class="cx"> $value = apply_filters( 'pre_add_site_option_' . $option, $value );
</span><ins>+
</ins><span class="cx"> $notoptions_key = "{$wpdb->siteid}:notoptions";
</span><span class="cx">
</span><span class="cx"> if ( !is_multisite() ) {
</span><span class="lines">@@ -806,8 +1032,30 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> if ( $result ) {
</span><ins>+
+ /**
+ * Fires after a specific site option has been successfully added.
+ *
+ * The dynamic portion of the hook name, $option, refers to the option name.
+ *
+ * @since 2.9.0 As "add_site_option_{$key}"
+ * @since 3.0.0
+ *
+ * @param string $option Name of site option.
+ * @param mixed $value Value of site option.
+ */
</ins><span class="cx"> do_action( "add_site_option_{$option}", $option, $value );
</span><ins>+
+ /**
+ * Fires after a site option has been successfully added.
+ *
+ * @since 3.0.0
+ *
+ * @param string $option Name of site option.
+ * @param mixed $value Value of site option.
+ */
</ins><span class="cx"> do_action( "add_site_option", $option, $value );
</span><ins>+
</ins><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx"> return false;
</span><span class="lines">@@ -816,12 +1064,9 @@
</span><span class="cx"> /**
</span><span class="cx"> * Removes site option by name.
</span><span class="cx"> *
</span><del>- * @see delete_option()
</del><span class="cx"> * @since 2.8.0
</span><span class="cx"> *
</span><del>- * @uses do_action() Calls 'pre_delete_site_option_$option' hook before option is deleted.
- * @uses do_action() Calls 'delete_site_option' and 'delete_site_option_$option'
- * hooks on success.
</del><ins>+ * @see delete_option()
</ins><span class="cx"> *
</span><span class="cx"> * @param string $option Name of option to remove. Expected to not be SQL-escaped.
</span><span class="cx"> * @return bool True, if succeed. False, if failure.
</span><span class="lines">@@ -831,6 +1076,13 @@
</span><span class="cx">
</span><span class="cx"> // ms_protect_special_option( $option ); @todo
</span><span class="cx">
</span><ins>+ /**
+ * Fires immediately before a specific site option is deleted.
+ *
+ * The dynamic portion of the hook name, $option, refers to the option name.
+ *
+ * @since 3.0.0
+ */
</ins><span class="cx"> do_action( 'pre_delete_site_option_' . $option );
</span><span class="cx">
</span><span class="cx"> if ( !is_multisite() ) {
</span><span class="lines">@@ -846,8 +1098,28 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> if ( $result ) {
</span><ins>+
+ /**
+ * Fires after a specific site option has been deleted.
+ *
+ * The dynamic portion of the hook name, $option, refers to the option name.
+ *
+ * @since 2.9.0 As "delete_site_option_{$key}"
+ * @since 3.0.0
+ *
+ * @param string $option Name of the site option.
+ */
</ins><span class="cx"> do_action( "delete_site_option_{$option}", $option );
</span><ins>+
+ /**
+ * Fires after a site option has been deleted.
+ *
+ * @since 3.0.0
+ *
+ * @param string $option Name of the site option.
+ */
</ins><span class="cx"> do_action( "delete_site_option", $option );
</span><ins>+
</ins><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx"> return false;
</span><span class="lines">@@ -856,12 +1128,9 @@
</span><span class="cx"> /**
</span><span class="cx"> * Update the value of a site option that was already added.
</span><span class="cx"> *
</span><del>- * @see update_option()
</del><span class="cx"> * @since 2.8.0
</span><span class="cx"> *
</span><del>- * @uses apply_filters() Calls 'pre_update_site_option_$option' hook to allow overwriting the
- * option value to be stored.
- * @uses do_action() Calls 'update_site_option_$option' and 'update_site_option' hooks on success.
</del><ins>+ * @see update_option()
</ins><span class="cx"> *
</span><span class="cx"> * @param string $option Name of option. Expected to not be SQL-escaped.
</span><span class="cx"> * @param mixed $value Option value. Expected to not be SQL-escaped.
</span><span class="lines">@@ -873,6 +1142,18 @@
</span><span class="cx"> wp_protect_special_option( $option );
</span><span class="cx">
</span><span class="cx"> $old_value = get_site_option( $option );
</span><ins>+
+ /**
+ * Filter a specific site option before its value is updated.
+ *
+ * The dynamic portion of the hook name, $option, refers to the option name.
+ *
+ * @since 2.9.0 As 'pre_update_site_option_' . $key
+ * @since 3.0.0
+ *
+ * @param mixed $value New value of site option.
+ * @param mixed $old_value Old value of site option.
+ */
</ins><span class="cx"> $value = apply_filters( 'pre_update_site_option_' . $option, $value, $old_value );
</span><span class="cx">
</span><span class="cx"> if ( $value === $old_value )
</span><span class="lines">@@ -903,8 +1184,32 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> if ( $result ) {
</span><ins>+
+ /**
+ * Fires after the value of a specific site option has been successfully updated.
+ *
+ * The dynamic portion of the hook name, $option, refers to the option name.
+ *
+ * @since 2.9.0 As "update_site_option_{$key}"
+ * @since 3.0.0
+ *
+ * @param string $option Name of site option.
+ * @param mixed $value Current value of site option.
+ * @param mixed $old_value Old value of site option.
+ */
</ins><span class="cx"> do_action( "update_site_option_{$option}", $option, $value, $old_value );
</span><ins>+
+ /**
+ * Fires after the value of a site option has been successfully updated.
+ *
+ * @since 3.0.0
+ *
+ * @param string $option Name of site option.
+ * @param mixed $value Current value of site option.
+ * @param mixed $old_value Old value of site option.
+ */
</ins><span class="cx"> do_action( "update_site_option", $option, $value, $old_value );
</span><ins>+
</ins><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx"> return false;
</span><span class="lines">@@ -915,14 +1220,22 @@
</span><span class="cx"> *
</span><span class="cx"> * @since 2.9.0
</span><span class="cx"> *
</span><del>- * @uses do_action() Calls 'delete_site_transient_$transient' hook before transient is deleted.
- * @uses do_action() Calls 'deleted_site_transient' hook on success.
- *
</del><span class="cx"> * @param string $transient Transient name. Expected to not be SQL-escaped.
</span><span class="cx"> * @return bool True if successful, false otherwise
</span><span class="cx"> */
</span><span class="cx"> function delete_site_transient( $transient ) {
</span><ins>+
+ /**
+ * Fires immediately before a specific site transient is deleted.
+ *
+ * The dynamic portion of the hook name, $transient, refers to the transient name.
+ *
+ * @since 3.0.0
+ *
+ * @param string $transient Transient name.
+ */
</ins><span class="cx"> do_action( 'delete_site_transient_' . $transient, $transient );
</span><ins>+
</ins><span class="cx"> if ( wp_using_ext_object_cache() ) {
</span><span class="cx"> $result = wp_cache_delete( $transient, 'site-transient' );
</span><span class="cx"> } else {
</span><span class="lines">@@ -932,8 +1245,18 @@
</span><span class="cx"> if ( $result )
</span><span class="cx"> delete_site_option( $option_timeout );
</span><span class="cx"> }
</span><del>- if ( $result )
</del><ins>+ if ( $result ) {
+
+ /**
+ * Fires after a transient is deleted.
+ *
+ * @since 3.0.0
+ *
+ * @param string $transient Deleted transient name.
+ */
</ins><span class="cx"> do_action( 'deleted_site_transient', $transient );
</span><ins>+ }
+
</ins><span class="cx"> return $result;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -943,20 +1266,31 @@
</span><span class="cx"> * If the transient does not exist or does not have a value, then the return value
</span><span class="cx"> * will be false.
</span><span class="cx"> *
</span><del>- * @see get_transient()
</del><span class="cx"> * @since 2.9.0
</span><span class="cx"> *
</span><del>- * @uses apply_filters() Calls 'pre_site_transient_$transient' hook before checking the transient.
- * Any value other than false will "short-circuit" the retrieval of the transient
- * and return the returned value.
- * @uses apply_filters() Calls 'site_transient_$option' hook, after checking the transient, with
- * the transient value.
</del><ins>+ * @see get_transient()
</ins><span class="cx"> *
</span><span class="cx"> * @param string $transient Transient name. Expected to not be SQL-escaped.
</span><span class="cx"> * @return mixed Value of transient
</span><span class="cx"> */
</span><span class="cx"> function get_site_transient( $transient ) {
</span><ins>+
+ /**
+ * Filter the value of an existing site transient.
+ *
+ * The dynamic portion of the hook name, $transient, refers to the transient name.
+ *
+ * Passing a truthy value to the filter will effectively short-circuit retrieval,
+ * returning the passed value instead.
+ *
+ * @since 2.9.0
+ *
+ * @param mixed $pre_site_transient The default value to return if the site transient does not exist.
+ * Any value other than false will short-circuit the retrieval
+ * of the transient, and return the returned value.
+ */
</ins><span class="cx"> $pre = apply_filters( 'pre_site_transient_' . $transient, false );
</span><ins>+
</ins><span class="cx"> if ( false !== $pre )
</span><span class="cx"> return $pre;
</span><span class="cx">
</span><span class="lines">@@ -980,6 +1314,15 @@
</span><span class="cx"> $value = get_site_option( $transient_option );
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Filter the value of an existing site transient.
+ *
+ * The dynamic portion of the hook name, $transient, refers to the transient name.
+ *
+ * @since 2.9.0
+ *
+ * @param mixed $value Value of site transient.
+ */
</ins><span class="cx"> return apply_filters( 'site_transient_' . $transient, $value );
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -989,12 +1332,9 @@
</span><span class="cx"> * You do not need to serialize values, if the value needs to be serialize, then
</span><span class="cx"> * it will be serialized before it is set.
</span><span class="cx"> *
</span><del>- * @see set_transient()
</del><span class="cx"> * @since 2.9.0
</span><span class="cx"> *
</span><del>- * @uses apply_filters() Calls 'pre_set_site_transient_$transient' hook to allow overwriting the
- * transient value to be stored.
- * @uses do_action() Calls 'set_site_transient_$transient' and 'setted_site_transient' hooks on success.
</del><ins>+ * @see set_transient()
</ins><span class="cx"> *
</span><span class="cx"> * @param string $transient Transient name. Expected to not be SQL-escaped.
</span><span class="cx"> * @param mixed $value Transient value. Expected to not be SQL-escaped.
</span><span class="lines">@@ -1002,7 +1342,18 @@
</span><span class="cx"> * @return bool False if value was not set and true if value was set.
</span><span class="cx"> */
</span><span class="cx"> function set_site_transient( $transient, $value, $expiration = 0 ) {
</span><ins>+
+ /**
+ * Filter the value of a specific site transient before it is set.
+ *
+ * The dynamic portion of the hook name, $transient, refers to the transient name.
+ *
+ * @since 3.0.0
+ *
+ * @param mixed $value Value of site transient.
+ */
</ins><span class="cx"> $value = apply_filters( 'pre_set_site_transient_' . $transient, $value );
</span><ins>+
</ins><span class="cx"> $expiration = (int) $expiration;
</span><span class="cx">
</span><span class="cx"> if ( wp_using_ext_object_cache() ) {
</span><span class="lines">@@ -1021,7 +1372,28 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx"> if ( $result ) {
</span><ins>+
+ /**
+ * Fires after the value for a specific site transient has been set.
+ *
+ * The dynamic portion of the hook name, $transient, refers to the transient name.
+ *
+ * @since 3.0.0
+ *
+ * @param mixed $value Site transient value.
+ * @param int $expiration Time until expiration in seconds. Default 0.
+ */
</ins><span class="cx"> do_action( 'set_site_transient_' . $transient, $value, $expiration );
</span><ins>+
+ /**
+ * Fires after the value for a site transient has been set.
+ *
+ * @since 3.0.0
+ *
+ * @param string $transient The name of the site transient.
+ * @param mixed $value Site transient value.
+ * @param int $expiration Time until expiration in seconds. Default 0.
+ */
</ins><span class="cx"> do_action( 'setted_site_transient', $transient, $value, $expiration );
</span><span class="cx"> }
</span><span class="cx"> return $result;
</span></span></pre>
</div>
</div>
</body>
</html>