update_site_option()
update_site_option( string $option, mixed $value ) 更新已为…
update_site_option( string $option, mixed $value )
更新已为当前网络添加的选项的值。
Updates the value of an option that was already added for the current network.
目录锚点:#说明#参数#源码#笔记
说明(Description)
另请参见更新网络选项()
参数(Parameters)
参数 | 类型 | 说明 |
---|---|---|
$option | (string) | 选项名称。不应为SQL转义。 |
$value | (mixed) | 选项值。不应为SQL转义。 |
源码(Source)
/** * Update the value of a site option that was already added. * * @since 2.8.0 * * @see update_option() * * @global wpdb $wpdb * * @param string $option Name of option. Expected to not be SQL-escaped. * @param mixed $value Option value. Expected to not be SQL-escaped. * @return bool False if value was not updated and true if value was updated. */ function update_site_option( $option, $value ) { global $wpdb; wp_protect_special_option( $option ); $old_value = get_site_option( $option ); /** * 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. */ $value = apply_filters( 'pre_update_site_option_' . $option, $value, $old_value ); if ( $value === $old_value ) return false; if ( false === $old_value ) return add_site_option( $option, $value ); $notoptions_key = "{$wpdb->siteid}:notoptions"; $notoptions = wp_cache_get( $notoptions_key, 'site-options' ); if ( is_array( $notoptions ) && isset( $notoptions[$option] ) ) { unset( $notoptions[$option] ); wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); } if ( !is_multisite() ) { $result = update_option( $option, $value ); } else { $value = sanitize_option( $option, $value ); $serialized_value = maybe_serialize( $value ); $result = $wpdb->update( $wpdb->sitemeta, array( 'meta_value' => $serialized_value ), array( 'site_id' => $wpdb->siteid, 'meta_key' => $option ) ); if ( $result ) { $cache_key = "{$wpdb->siteid}:$option"; wp_cache_set( $cache_key, $value, 'site-options' ); } } if ( $result ) { /** * 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. */ do_action( "update_site_option_{$option}", $option, $value, $old_value ); /** * 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. */ do_action( "update_site_option", $option, $value, $old_value ); return true; } return false; }
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
4.4.0 | wp-includes/option.php | 5 | 2 |
笔记(Notes)
从4.0开始,尽管该函数名为,但该值存储在网络的sitemata表中,而不是存储在站点的options表中。
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
还没有任何评论,赶紧来占个楼吧!