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

来自站长百科
跳转至: 导航、​ 搜索
无编辑摘要
无编辑摘要
 
第1行: 第1行:
== 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.
使用函数[[WordPress:Function_Reference/update_option|update_option]]将指定的选项/选项值更新到选项数据库表格。在插入声明之前,option_name 参数值与 %%%$wpdb->escape%%%都逸出了
 
使用函数[[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.
 


合理地使用选项,建议使用[[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]]。
合理地使用选项,建议使用[[WordPress:Function_Reference/get_option|get_option]],如果测试为true,然后使用[[WordPress:Function_Reference/update_option|update_option]]。如果[[WordPress:Function_Reference/get_option|get_option]]返回false,那么应该使用[[WordPress:Function Reference/add option|add_option]]。[[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]]函数。
注意[[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 ==
== 用法 ==
== 用法 ==
%%%<?php update_option('option_name', 'newvalue'); ?>%%%


%%%<?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并且将自动载入设置为无。
更新参数值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
$option_name = 'myhack_extraction_length' ;  
$option_name = 'myhack_extraction_length' ;  
第54行: 第26行:
?>%%%
?>%%%


== 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|将要更新的选项的名称。可以在[[WordPress:Option Reference|选项参考]]中找到需要更新的有效的默认选项的列表。}}
{{Parameter|option_name|string|将要更新的选项的名称。可以在[[WordPress:Option Reference|选项参考]]中找到需要更新的有效的默认选项的列表。}}
{{Parameter|newvalue|string|The NEW value for this option name.}}


{{Parameter|newvalue|string|这个选项名的新的参数值。}}
{{Parameter|newvalue|string|这个选项名的新的参数值。}}

2008年7月28日 (一) 11:19的最新版本

描述[ ]

使用函数update_option将指定的选项/选项值更新到选项数据库表格。在插入声明之前,option_name 参数值与 %%%$wpdb->escape%%%都逸出了

合理地使用选项,建议使用get_option,如果测试为true,然后使用update_option。如果get_option返回false,那么应该使用add_optionupdate_option function.

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

用法[ ]

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

例子[ ]

更新参数值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);
 }

?>%%%

参数[ ]