WordPressを読む 11-7 /blog/wp-includes/option.php 7
2014/11/29
目次
/blog/wp-includes/option.php 7
読込元 : /blog/wp-includes/functions.php 1
関数
delete_site_transient()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | /** * Delete a site transient. * * @since 2.9.0 * * @param string $transient Transient name. Expected to not be SQL-escaped. * @return bool True if successful, false otherwise */ function delete_site_transient( $transient ) { /** * 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. */ do_action( 'delete_site_transient_' . $transient, $transient ); if ( wp_using_ext_object_cache() ) { $result = wp_cache_delete( $transient, 'site-transient' ); } else { $option_timeout = '_site_transient_timeout_' . $transient; $option = '_site_transient_' . $transient; $result = delete_site_option( $option ); if ( $result ) delete_site_option( $option_timeout ); } if ( $result ) { /** * Fires after a transient is deleted. * * @since 3.0.0 * * @param string $transient Deleted transient name. */ do_action( 'deleted_site_transient', $transient ); } return $result; } |
関数
get_site_transient()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | /** * Get the value of a site transient. * * If the transient does not exist, does not have a value, or has expired, * then the return value will be false. * * @since 2.9.0 * * @see get_transient() * * @param string $transient Transient name. Expected to not be SQL-escaped. * @return mixed Value of transient. */ function get_site_transient( $transient ) { /** * 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. */ $pre = apply_filters( 'pre_site_transient_' . $transient, false ); if ( false !== $pre ) return $pre; if ( wp_using_ext_object_cache() ) { $value = wp_cache_get( $transient, 'site-transient' ); } else { // Core transients that do not have a timeout. Listed here so querying timeouts can be avoided. $no_timeout = array('update_core', 'update_plugins', 'update_themes'); $transient_option = '_site_transient_' . $transient; if ( ! in_array( $transient, $no_timeout ) ) { $transient_timeout = '_site_transient_timeout_' . $transient; $timeout = get_site_option( $transient_timeout ); if ( false !== $timeout && $timeout < time() ) { delete_site_option( $transient_option ); delete_site_option( $transient_timeout ); $value = false; } } if ( ! isset( $value ) ) $value = get_site_option( $transient_option ); } /** * 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. */ return apply_filters( 'site_transient_' . $transient, $value ); } |
関数
set_site_transient()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | /** * Set/update the value of a site transient. * * You do not need to serialize values, if the value needs to be serialize, then * it will be serialized before it is set. * * @since 2.9.0 * * @see set_transient() * * @param string $transient Transient name. Expected to not be SQL-escaped. Must be * 40 characters or fewer in length. * @param mixed $value Transient value. Expected to not be SQL-escaped. * @param int $expiration Optional. Time until expiration in seconds. Default 0. * @return bool False if value was not set and true if value was set. */ function set_site_transient( $transient, $value, $expiration = 0 ) { /** * 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. */ $value = apply_filters( 'pre_set_site_transient_' . $transient, $value ); $expiration = (int) $expiration; if ( wp_using_ext_object_cache() ) { $result = wp_cache_set( $transient, $value, 'site-transient', $expiration ); } else { $transient_timeout = '_site_transient_timeout_' . $transient; $option = '_site_transient_' . $transient; if ( false === get_site_option( $option ) ) { if ( $expiration ) add_site_option( $transient_timeout, time() + $expiration ); $result = add_site_option( $option, $value ); } else { if ( $expiration ) update_site_option( $transient_timeout, time() + $expiration ); $result = update_site_option( $option, $value ); } } if ( $result ) { /** * 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. */ do_action( 'set_site_transient_' . $transient, $value, $expiration ); /** * 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. */ do_action( 'setted_site_transient', $transient, $value, $expiration ); } return $result; } |