WordPress函数文档delete_option()
删除wp_option表中的选项/值对 描述 译文 这是一种从选项数据库表中删除某一有名称的选项/值对的安全方…
删除wp_option表中的选项/值对
描述
译文
这是一种从选项数据库表中删除某一有名称的选项/值对的安全方法。
原文
A safe way of removing a named option/value pair from the options database table.
用法
<?php delete_option( $option ); ?>
参数
$option
(string) (必填) Name of the option to be deleted. A list of valid default options can be found at the Option Reference.
默认值: None
历史
添加于 版本: 1.2.0
源文件
delete_option() 函数的代码位于 wp-includes/option.php
.
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
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
/**
* Removes option by name. Prevents removal of protected WordPress options.
*
* @since 1.2.0
*
* @global wpdb $wpdb
*
* @param string $option Name of option to remove. Expected to not be SQL-escaped.
* @return bool True, if option is successfully deleted. False on failure.
*/
function delete_option( $option ) {
global $wpdb;
$option = trim( $option );
if ( empty( $option ) )
return false;
wp_protect_special_option( $option );
// Get the ID, if no ID then return
$row = $wpdb->get_row( $wpdb->prepare( “SELECT autoload FROM $wpdb->options WHERE option_name = %s”, $option ) );
if ( is_null( $row ) )
return false;
/**
* Fires immediately before an option is deleted.
*
* @since 2.9.0
*
* @param string $option Name of the option to delete.
*/
do_action( ‘delete_option’, $option );
$result = $wpdb->delete( $wpdb->options, array( ‘option_name’ => $option ) );
if ( ! defined( ‘WP_INSTALLING’ ) ) {
if ( ‘yes’ == $row->autoload ) {
$alloptions = wp_load_alloptions();
if ( is_array( $alloptions ) && isset( $alloptions[$option] ) ) {
unset( $alloptions[$option] );
wp_cache_set( ‘alloptions’, $alloptions, ‘options’ );
}
} else {
wp_cache_delete( $option, ‘options’ );
}
}
if ( $result ) {
/**
* Fires after a specific option has been deleted.
*
* The dynamic portion of the hook name, `$option`, refers to the option name.
*
* @since 3.0.0
*
* @param string $option Name of the deleted option.
*/
do_action( “delete_option_$option”, $option );
/**
* Fires after an option has been deleted.
*
* @since 2.9.0
*
* @param string $option Name of the deleted option.
*/
do_action( ‘deleted_option’, $option );
return true;
}
return false;
}
|
相关
- Options API
- add_option()
- add_blog_option()
- add_site_option()
- delete_option()
- delete_blog_option()
- delete_site_option()
- form_option()
- get_option()
- get_blog_option()
- get_site_option()
- get_site_url()
- get_user_option()
- update_option()
- update_blog_option()
- update_site_option()
- update_user_option()
- wp_load_alloptions()
- 原文:http://codex.wordpress.org/Function_Reference/delete_option
类别:WordPress函数文档、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
评论功能已经关闭!