WordPress: Function Reference/update option:修订间差异

来自站长百科
跳转至: 导航、​ 搜索
(新页面: == Description == Use the function update_option to update a named option/value pair to the options database table. The option_name value i...)
 
无编辑摘要
第1行: 第1行:
== Description ==
== Description ==
== 描述==


Use the function [[WordPress:Function_Reference/update_option|update_option]] to update a named option/value pair to the options database table. The option_name value is escaped with %%%$wpdb->escape%%% before the INSERT statement.
Use the function [[WordPress:Function_Reference/update_option|update_option]] to update a named option/value pair to the options database table. The option_name value is escaped with %%%$wpdb->escape%%% before the INSERT statement.
使用函数[[WordPress:Function_Reference/update_option|update_option]]将指定的选项/选项值更新到选项数据库表格。在插入声明之前,option_name value is escaped with %%%$wpdb->escape%%%。


Proper use of this function suggests using [[WordPress:Function_Reference/get_option|get_option]] to retrieve the option and if tested for true, then use [[WordPress:Function_Reference/update_option|update_option]].  If [[WordPress:Function_Reference/get_option|get_option]] returns false, then [[WordPress:Function Reference/add option|add_option]] should be used instead.
Proper use of this function suggests using [[WordPress:Function_Reference/get_option|get_option]] to retrieve the option and if tested for true, then use [[WordPress:Function_Reference/update_option|update_option]].  If [[WordPress:Function_Reference/get_option|get_option]] returns false, then [[WordPress:Function Reference/add option|add_option]] should be used instead.
合理地使用选项,建议使用[[WordPress:Function_Reference/get_option|get_option]]得到选项,如果测试为真的,然后使用[[WordPress:Function_Reference/update_option|update_option]]。如果[[WordPress:Function_Reference/get_option|get_option]]返回错误的,那么应该使用[[WordPress:Function Reference/add option|add_option]]。


Note that [[WordPress:Function_Reference/update_option|update_option]] cannot be used to change whether an option is to be loaded (or not loaded) by <tt>wp_load_alloptions</tt>.  In that case, a [[WordPress:Function_Reference/delete_option|delete_option]] should be followed by use of the [[WordPress:Function_Reference/update_option|update_option]] function.
Note that [[WordPress:Function_Reference/update_option|update_option]] cannot be used to change whether an option is to be loaded (or not loaded) by <tt>wp_load_alloptions</tt>.  In that case, a [[WordPress:Function_Reference/delete_option|delete_option]] should be followed by use of the [[WordPress:Function_Reference/update_option|update_option]] function.
    
    
注意[[WordPress:Function_Reference/update_option|update_option]]可以用来更改选项是否通过<tt>wp_load_alloptions</tt>载入(或者没有载入)。在这种情况下,[[WordPress:Function_Reference/delete_option|delete_option]]应该在接着使用[[WordPress:Function_Reference/update_option|update_option]]函数。
== Usage ==
== Usage ==
== 用法 ==
%%%<?php update_option('option_name', 'newvalue'); ?>%%%
%%%<?php update_option('option_name', 'newvalue'); ?>%%%
%%%<?php update_option('option_name', 'newvalue'); ?>%%%


== Example ==
== Example ==
== 例子 ==
Update the option name myhack_extraction_length with the value 255.  If the option does not exist then use add_option and set autoload to no.
Update the option name myhack_extraction_length with the value 255.  If the option does not exist then use add_option and set autoload to no.
更新参数值255的选项名myhack_extraction_length。如果这个选项不存在,使用add_option并且将自动载入设置为无。
%%%<?php
$option_name = 'myhack_extraction_length' ;
$newvalue = '255' ;
  if ( get_option($option_name) ) {
    update_option($option_name, $newvalue);
  } else {
    $deprecated=' ';
    $autoload='no';
    add_option($option_name, $newvalue, $deprecated, $autoload);
  }
?>%%%


%%%<?php
%%%<?php
第26行: 第55行:


== Parameters ==
== Parameters ==
== 参数 ==
{{Parameter|option_name|string|Name of the option to update. A list of valid default options to update can be found at the [[WordPress:Option Reference]].}}
{{Parameter|option_name|string|Name of the option to update. A list of valid default options to update can be found at the [[WordPress:Option Reference]].}}
{{Parameter|option_name|string|将要更新的选项的名称。可以在[[WordPress:Option Reference|选项参考]]中找到需要更新的有效的默认选项的列表。}}
{{Parameter|newvalue|string|The NEW value for this option name.}}
{{Parameter|newvalue|string|The NEW value for this option name.}}
{{Parameter|newvalue|string|这个选项名的新的参数值。}}

2008年7月22日 (二) 13:28的版本

Description

描述

Use the function update_option to update a named option/value pair to the options database table. The option_name value is escaped with %%%$wpdb->escape%%% before the INSERT statement.

使用函数update_option将指定的选项/选项值更新到选项数据库表格。在插入声明之前,option_name value is escaped with %%%$wpdb->escape%%%。

Proper use of this function suggests using get_option to retrieve the option and if tested for true, then use update_option. If get_option returns false, then add_option should be used instead.


合理地使用选项,建议使用get_option得到选项,如果测试为真的,然后使用update_option。如果get_option返回错误的,那么应该使用add_option

Note that update_option cannot be used to change whether an option is to be loaded (or not loaded) by wp_load_alloptions. In that case, a delete_option should be followed by use of the update_option function.

注意update_option可以用来更改选项是否通过wp_load_alloptions载入(或者没有载入)。在这种情况下,delete_option应该在接着使用update_option函数。

Usage

用法

%%%<?php update_option('option_name', 'newvalue'); ?>%%%

%%%<?php update_option('option_name', 'newvalue'); ?>%%%

Example

例子

Update the option name myhack_extraction_length with the value 255. If the option does not exist then use add_option and set autoload to no.

更新参数值255的选项名myhack_extraction_length。如果这个选项不存在,使用add_option并且将自动载入设置为无。

%%%<?php $option_name = 'myhack_extraction_length' ; $newvalue = '255' ;

 if ( get_option($option_name) ) {
   update_option($option_name, $newvalue);
 } else {
   $deprecated=' ';
   $autoload='no';
   add_option($option_name, $newvalue, $deprecated, $autoload);
 }

?>%%%


%%%<?php $option_name = 'myhack_extraction_length' ; $newvalue = '255' ;

 if ( get_option($option_name) ) {
   update_option($option_name, $newvalue);
 } else {
   $deprecated=' ';
   $autoload='no';
   add_option($option_name, $newvalue, $deprecated, $autoload);
 }

?>%%%

Parameters

参数