WordPressを読む 11-4 /blog/wp-includes/option.php 4
2014/11/29
目次
/blog/wp-includes/option.php 4
読込元 : /blog/wp-includes/functions.php 1
関数
set_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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | /** * Set/update the value of a transient. * * You do not need to serialize values. If the value needs to be serialized, then * it will be serialized before it is set. * * @since 2.8.0 * * @param string $transient Transient name. Expected to not be SQL-escaped. Must be * 45 characters or fewer in length. * @param mixed $value Transient value. Must be serializable if non-scalar. * 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_transient( $transient, $value, $expiration = 0 ) { /** * 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. */ $value = apply_filters( 'pre_set_transient_' . $transient, $value ); $expiration = (int) $expiration; if ( wp_using_ext_object_cache() ) { $result = wp_cache_set( $transient, $value, 'transient', $expiration ); } else { $transient_timeout = '_transient_timeout_' . $transient; $transient = '_transient_' . $transient; if ( false === get_option( $transient ) ) { $autoload = 'yes'; if ( $expiration ) { $autoload = 'no'; add_option( $transient_timeout, time() + $expiration, '', 'no' ); } $result = add_option( $transient, $value, '', $autoload ); } else { // If expiration is requested, but the transient has no timeout option, // delete, then re-create transient rather than update. $update = true; if ( $expiration ) { if ( false === get_option( $transient_timeout ) ) { delete_option( $transient ); add_option( $transient_timeout, time() + $expiration, '', 'no' ); $result = add_option( $transient, $value, '', 'no' ); $update = false; } else { update_option( $transient_timeout, time() + $expiration ); } } if ( $update ) { $result = update_option( $transient, $value ); } } } if ( $result ) { /** * 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. */ do_action( 'set_transient_' . $transient, $value, $expiration ); /** * 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. */ do_action( 'setted_transient', $transient, $value, $expiration ); } return $result; } |
関数
wp_user_settings()
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 | /** * Saves and restores user interface settings stored in a cookie. * * Checks if the current user-settings cookie is updated and stores it. When no * cookie exists (different browser used), adds the last saved cookie restoring * the settings. * * @since 2.7.0 */ function wp_user_settings() { if ( ! is_admin() || defined( 'DOING_AJAX' ) ) { return; } if ( ! $user_id = get_current_user_id() ) { return; } if ( is_super_admin() && ! is_user_member_of_blog() ) { return; } $settings = (string) get_user_option( 'user-settings', $user_id ); if ( isset( $_COOKIE['wp-settings-' . $user_id] ) ) { $cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-' . $user_id] ); // No change or both empty if ( $cookie == $settings ) return; $last_saved = (int) get_user_option( 'user-settings-time', $user_id ); $current = isset( $_COOKIE['wp-settings-time-' . $user_id]) ? preg_replace( '/[^0-9]/', '', $_COOKIE['wp-settings-time-' . $user_id] ) : 0; // The cookie is newer than the saved value. Update the user_option and leave the cookie as-is if ( $current > $last_saved ) { update_user_option( $user_id, 'user-settings', $cookie, false ); update_user_option( $user_id, 'user-settings-time', time() - 5, false ); return; } } // The cookie is not set in the current browser or the saved value is newer. $secure = ( 'https' === parse_url( site_url(), PHP_URL_SCHEME ) ); setcookie( 'wp-settings-' . $user_id, $settings, time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure ); setcookie( 'wp-settings-time-' . $user_id, time(), time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure ); $_COOKIE['wp-settings-' . $user_id] = $settings; } |
関数
get_user_setting()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | /** * Retrieve user interface setting value based on setting name. * * @since 2.7.0 * * @param string $name The name of the setting. * @param string $default Optional default value to return when $name is not set. * @return mixed the last saved user setting or the default value/false if it doesn't exist. */ function get_user_setting( $name, $default = false ) { $all_user_settings = get_all_user_settings(); return isset( $all_user_settings[$name] ) ? $all_user_settings[$name] : $default; } |
関数
set_user_setting()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | /** * Add or update user interface setting. * * Both $name and $value can contain only ASCII letters, numbers and underscores. * This function has to be used before any output has started as it calls setcookie(). * * @since 2.8.0 * * @param string $name The name of the setting. * @param string $value The value for the setting. * @return bool true if set successfully/false if not. */ function set_user_setting( $name, $value ) { if ( headers_sent() ) { return false; } $all_user_settings = get_all_user_settings(); $all_user_settings[$name] = $value; return wp_set_all_user_settings( $all_user_settings ); } |
関数
delete_user_setting()
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 | /** * Delete user interface settings. * * Deleting settings would reset them to the defaults. * This function has to be used before any output has started as it calls setcookie(). * * @since 2.7.0 * * @param mixed $names The name or array of names of the setting to be deleted. * @return bool true if deleted successfully/false if not. */ function delete_user_setting( $names ) { if ( headers_sent() ) { return false; } $all_user_settings = get_all_user_settings(); $names = (array) $names; $deleted = false; foreach ( $names as $name ) { if ( isset( $all_user_settings[$name] ) ) { unset( $all_user_settings[$name] ); $deleted = true; } } if ( $deleted ) { return wp_set_all_user_settings( $all_user_settings ); } return false; } |