delete_option( string $option )
Removes option by name. Prevents removal of protected WordPress options.
描述
参数
$option
(string)
(Required)
Name of option to remove. Expected to not be SQL-escaped.
返回值
(bool) True, if option is successfully deleted. False on failure.
源代码
File: wp-includes/option.php
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;
}
更新日志
Version
描述
1.2.0
Introduced.
相关函数
Uses
wp-includes/load.php:
wp_installing()
wp-includes/cache.php:
wp_cache_set()
wp-includes/cache.php:
wp_cache_delete()
wp-includes/plugin.php:
do_action()
wp-includes/option.php:
wp_load_alloptions()
wp-includes/option.php:
delete_option
wp-includes/option.php:
delete_option_{$option}
wp-includes/option.php:
deleted_option
wp-includes/option.php:
wp_protect_special_option()
wp-includes/wp-db.php:
wpdb::get_row()
wp-includes/wp-db.php:
wpdb::delete()
wp-includes/wp-db.php:
wpdb::prepare()
Show 7 more uses
Hide more uses
Used By
wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php:
WP_REST_Settings_Controller::update_item()
wp-admin/includes/class-wp-upgrader.php:
WP_Upgrader::release_lock()
wp-includes/option.php:
delete_network_option()
wp-includes/taxonomy.php:
_wp_batch_split_terms()
wp-admin/includes/class-wp-site-icon.php:
WP_Site_Icon::delete_attachment_data()
wp-admin/includes/misc.php:
update_home_siteurl()
wp-admin/includes/schema.php:
populate_options()
wp-admin/includes/update-core.php:
update_core()
wp-includes/theme.php:
remove_theme_mods()
wp-includes/theme.php:
switch_theme()
wp-includes/theme.php:
get_theme_mods()
wp-includes/class-wp-theme.php:
WP_Theme::get_allowed_on_site()
wp-includes/taxonomy.php:
clean_term_cache()
wp-includes/option.php:
get_transient()
wp-includes/option.php:
set_transient()
wp-includes/option.php:
delete_transient()
wp-includes/post.php:
_reset_front_page_settings_for_post()
wp-includes/revision.php:
_wp_upgrade_revisions_of_post()
wp-includes/ms-functions.php:
maybe_add_existing_user_to_blog()
wp-includes/ms-blogs.php:
delete_blog_option()
Show 15 more used by
Hide more used by
User Contributed Notes
Skip to note content
You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note
Contributed by Codex
Delete a single option
This will delete ‘my_option’ from the options table within your MySQL database.