WordPressを読む 11-5 /blog/wp-includes/option.php 5
2014/11/29
目次
/blog/wp-includes/option.php 5
読込元 : /blog/wp-includes/functions.php 1
関数
get_all_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 | /** * Retrieve all user interface settings. * * @since 2.7.0 * * @return array the last saved user settings or empty array. */ function get_all_user_settings() { global $_updated_user_settings; if ( ! $user_id = get_current_user_id() ) { return array(); } if ( isset( $_updated_user_settings ) && is_array( $_updated_user_settings ) ) { return $_updated_user_settings; } $user_settings = array(); if ( isset( $_COOKIE['wp-settings-' . $user_id] ) ) { $cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-' . $user_id] ); if ( strpos( $cookie, '=' ) ) { // '=' cannot be 1st char parse_str( $cookie, $user_settings ); } } else { $option = get_user_option( 'user-settings', $user_id ); if ( $option && is_string( $option ) ) { parse_str( $option, $user_settings ); } } $_updated_user_settings = $user_settings; return $user_settings; } |
関数
wp_set_all_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 | /** * Private. Set all user interface settings. * * @since 2.8.0 * * @param array $user_settings * @return bool */ function wp_set_all_user_settings( $user_settings ) { global $_updated_user_settings; if ( ! $user_id = get_current_user_id() ) { return false; } if ( is_super_admin() && ! is_user_member_of_blog() ) { return; } $settings = ''; foreach ( $user_settings as $name => $value ) { $_name = preg_replace( '/[^A-Za-z0-9_]+/', '', $name ); $_value = preg_replace( '/[^A-Za-z0-9_]+/', '', $value ); if ( ! empty( $_name ) ) { $settings .= $_name . '=' . $_value . '&'; } } $settings = rtrim( $settings, '&' ); parse_str( $settings, $_updated_user_settings ); update_user_option( $user_id, 'user-settings', $settings, false ); update_user_option( $user_id, 'user-settings-time', time(), false ); return true; } |
関数
delete_all_user_settings()
1 2 3 4 5 6 7 8 9 10 11 12 13 | /** * Delete the user settings of the current user. * * @since 2.7.0 */ function delete_all_user_settings() { if ( ! $user_id = get_current_user_id() ) { return; } update_user_option( $user_id, 'user-settings', '', false ); setcookie( 'wp-settings-' . $user_id, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH ); } |
関数
get_site_option()
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 90 91 92 | /** * Retrieve site option value based on name of option. * * @since 2.8.0 * * @see get_option() * * @param string $option Name of option to retrieve. Expected to not be SQL-escaped. * @param mixed $default Optional value to return if option doesn't exist. Default false. * @param bool $use_cache Whether to use cache. Multisite only. Default true. * @return mixed Value set for the option. */ function get_site_option( $option, $default = false, $use_cache = true ) { global $wpdb; /** * 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. */ $pre = apply_filters( 'pre_site_option_' . $option, false ); if ( false !== $pre ) return $pre; // prevent non-existent options from triggering multiple queries $notoptions_key = "{$wpdb->siteid}:notoptions"; $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); 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. */ return apply_filters( 'default_site_option_' . $option, $default ); } if ( ! is_multisite() ) { /** This filter is documented in wp-includes/option.php */ $default = apply_filters( 'default_site_option_' . $option, $default ); $value = get_option($option, $default); } else { $cache_key = "{$wpdb->siteid}:$option"; if ( $use_cache ) $value = wp_cache_get($cache_key, 'site-options'); if ( !isset($value) || (false === $value) ) { $row = $wpdb->get_row( $wpdb->prepare("SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $wpdb->siteid ) ); // Has to be get_row instead of get_var because of funkiness with 0, false, null values if ( is_object( $row ) ) { $value = $row->meta_value; $value = maybe_unserialize( $value ); wp_cache_set( $cache_key, $value, 'site-options' ); } else { $notoptions[$option] = true; wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); /** This filter is documented in wp-includes/option.php */ $value = apply_filters( 'default_site_option_' . $option, $default ); } } } /** * 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. */ return apply_filters( 'site_option_' . $option, $value ); } |