delete_option

The timeline below displays how wordpress function delete_option has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Removes an 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 the option to delete. Expected to not be SQL-escaped.
 * @return bool True if the option was deleted, false otherwise.
 */
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 ('yes' === $row->autoload) {
            $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');
        }
    }
    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;
}

WordPress Version: 5.9

/**
 * 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 the option to delete. Expected to not be SQL-escaped.
 * @return bool True if the option was deleted, false otherwise.
 */
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 ('yes' === $row->autoload) {
            $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');
        }
    }
    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;
}

WordPress Version: 5.5

/**
 * 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 the option to delete. Expected to not be SQL-escaped.
 * @return bool True if the option was deleted, false otherwise.
 */
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(true);
            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;
}

WordPress Version: 5.4

/**
 * 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(true);
            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;
}

WordPress Version: 3.1

/**
 * 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(true);
            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;
}

WordPress Version: 4.4

/**
 * 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;
}

WordPress Version: 4.3

/**
 * 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;
}

WordPress Version: 4.1

/**
 * Removes option by name. Prevents removal of protected WordPress options.
 *
 * @since 1.2.0
 *
 * @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;
}

WordPress Version: 3.9

/**
 * Removes option by name. Prevents removal of protected WordPress options.
 *
 * @since 1.2.0
 *
 * @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;
}

WordPress Version: 3.7

/**
 * Removes option by name. Prevents removal of protected WordPress options.
 *
 * @package WordPress
 * @subpackage Option
 * @since 1.2.0
 *
 * @uses do_action() Calls 'delete_option' hook before option is deleted.
 * @uses do_action() Calls 'deleted_option' and 'delete_option_$option' hooks on success.
 *
 * @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;
    }
    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) {
        do_action("delete_option_{$option}", $option);
        do_action('deleted_option', $option);
        return true;
    }
    return false;
}