[フレーム] Skip to content
WordPress.org
Get WordPress
WordPress.org

WordPress Developer Resources

delete_option()

Home Reference Functions delete_option()

delete_option( string $option ): bool

Removes an option by name. Prevents removal of protected WordPress options.

Parameters

$optionstringrequired
Name of the option to delete. Expected to not be SQL-escaped.

Return

bool True if the option was deleted, false otherwise.

Source

function delete_option( $option ) {
	global $wpdb;
	if ( is_scalar( $option ) ) {
		$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 ( in_array( $row->autoload, wp_autoload_values_to_autoload(), true ) ) {
			$alloptions = wp_load_alloptions( true );
			if ( is_array( $alloptions ) && isset( $alloptions[ $option ] ) ) {
				unset( $alloptions[ $option ] );
				wp_cache_set( 'alloptions', $alloptions, 'options' );
			}
		} else {
			wp_cache_delete( $option, 'options' );
		}
		$notoptions = wp_cache_get( 'notoptions', 'options' );
		if ( ! is_array( $notoptions ) ) {
			$notoptions = array();
		}
		$notoptions[ $option ] = true;
		wp_cache_set( 'notoptions', $notoptions, '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;
}

View all references View on Trac View on GitHub

Hooks

do_action( ‘deleted_option’, string $option )

Fires after an option has been deleted.

do_action( ‘delete_option’, string $option )

Fires immediately before an option is deleted.

do_action( “delete_option_{$option}”, string $option )

Fires after a specific option has been deleted.

UsesDescription
wp_autoload_values_to_autoload() wp-includes/option.php

Returns the values that trigger autoloading from the options table.

wp_installing() wp-includes/load.php

Checks or sets whether WordPress is in “installation” mode.

wp_cache_set() wp-includes/cache.php

Saves the data to the cache.

wp_cache_delete() wp-includes/cache.php

Removes the cache contents matching key and group.

wp_load_alloptions() wp-includes/option.php

Loads and caches all autoloaded options, if available or all options.

wp_protect_special_option() wp-includes/option.php

Protects WordPress special option from being modified.

wpdb::get_row() wp-includes/class-wpdb.php

Retrieves one row from the database.

wpdb::delete() wp-includes/class-wpdb.php

Deletes a row in the table.

wp_cache_get() wp-includes/cache.php

Retrieves the cache contents from the cache by key and group.

do_action() wp-includes/plugin.php

Calls the callback functions that have been added to an action hook.

wpdb::prepare() wp-includes/class-wpdb.php

Prepares a SQL query for safe execution.

Show 6 more Show less
Used byDescription
wp_update_https_migration_required() wp-includes/https-migration.php

Updates the ‘https_migration_required’ option if needed when the given URL has been updated from HTTP to HTTPS.

_wp_batch_update_comment_type() wp-includes/comment.php

Updates the comment type for a batch of comments.

WP_Recovery_Mode_Email_Service::clear_rate_limit() wp-includes/class-wp-recovery-mode-email-service.php

Clears the rate limit, allowing a new recovery mode email to be sent immediately.

WP_Paused_Extensions_Storage::delete() wp-includes/class-wp-paused-extensions-storage.php

Forgets a previously recorded extension error.

WP_Paused_Extensions_Storage::delete_all() wp-includes/class-wp-paused-extensions-storage.php

Remove all paused extensions.

clean_taxonomy_cache() wp-includes/taxonomy.php

Cleans the caches for a taxonomy.

_wp_menus_changed() wp-includes/nav-menu.php

Handles menu config after theme change.

WP_REST_Settings_Controller::update_item() wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php

Updates settings for the settings object.

WP_Upgrader::release_lock() wp-admin/includes/class-wp-upgrader.php

Releases an upgrader lock.

delete_network_option() wp-includes/option.php

Removes a network option by name.

_wp_batch_split_terms() wp-includes/taxonomy.php

Splits a batch of shared taxonomy terms.

WP_Site_Icon::delete_attachment_data() wp-admin/includes/class-wp-site-icon.php

Deletes the Site Icon when the image file is deleted.

update_home_siteurl() wp-admin/includes/misc.php

Flushes rewrite rules if siteurl, home or page_on_front changed.

populate_options() wp-admin/includes/schema.php

Create WordPress options and set the default values.

update_core() wp-admin/includes/update-core.php

Upgrades the core of WordPress.

_delete_attachment_theme_mod() wp-includes/theme.php

Checks an attachment being deleted to see if it’s a header or background image.

remove_theme_mods() wp-includes/theme.php

Removes theme modifications option for the active theme.

switch_theme() wp-includes/theme.php

Switches the theme.

get_theme_mods() wp-includes/theme.php

Retrieves all theme modifications.

WP_Theme::get_allowed_on_site() wp-includes/class-wp-theme.php

Returns array of stylesheet names of themes allowed on the site.

get_transient() wp-includes/option.php

Retrieves the value of a transient.

set_transient() wp-includes/option.php

Sets/updates the value of a transient.

delete_transient() wp-includes/option.php

Deletes a transient.

_wp_upgrade_revisions_of_post() wp-includes/revision.php

Upgrades the revisions author, adds the current post as a revision and sets the revisions version to 1.

maybe_add_existing_user_to_blog() wp-includes/ms-functions.php

Adds a new user to a blog by visiting /newbloguser/{key}/.

delete_blog_option() wp-includes/ms-blogs.php

Removes an option by name for a given blog ID. Prevents removal of protected WordPress options.

WP_Widget::get_settings() wp-includes/class-wp-widget.php

Retrieves the settings for all instances of the widget class.

Show 22 more Show less

Changelog

VersionDescription
1.2.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.

AltStyle によって変換されたページ (->オリジナル) /