delete_option()

删除wp_option表中的选项/值对

描述

这是一种从选项数据库表中删除某一有名称的选项/值对的安全方法。

用法

<?php delete_option( $option ); ?>

参数

$option

(string) (必填) 要删除的选项的名称。可在选项参考中找到有效默认选项的列表。

默认值: None

历史

添加于 版本: 1.2.0

源文件

delete_option() 函数的代码位于 wp-includes/option.php.

/* ———————————-
* wordpress函数 星空站长网(xingkongweb.com)收集
* ———————————- */
/**
* 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()

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索