delete_option()删除选项

功能:

delete_option()函数的功能是删除wp_options表中指定的一条数据。

<?php delete_option( $option ); ?>

参数:

$option
(string) (必选的) 要删除的选项表记录名称
默认: 无

返回值:

(boolean)
如果成功删除记录就返回True,删除失败或者记录不存在就返回false

所在位置:

delete_option() 函数包含在 wp-includes/option.php 中。

源码:

delete_option()函数源码

/** * Removes option by name. Prevents removal of protected WordPress options. * * @since 1.2.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @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 ( ! 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; }

示例:

<?php if(delete_option(“ooask_survey”)){ //将ooask_survey表中选项名为ooask_survey的记录删除,成功就返回true echo “删除成功”; } ?>

相关函数:

add_option()
get_option()
update_option()

(完)

人已赞赏
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索