delete_option( string $option )

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


Description Description


Parameters Parameters

$option

(string) (Required) Name of option to remove. Expected to not be SQL-escaped.


Top ↑

Return Return

(bool) True, if option is successfully deleted. False on failure.


Top ↑

Source Source

File: wp-includes/option.php

548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
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;
}

Top ↑

Changelog Changelog

Changelog
Version Description
1.2.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

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