delete_option

Removes option by name.

Description

delete_option( (string) $option ); 

Prevents removal of protected WordPress options.

Parameters (1)

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

Usage

  1. if ( !function_exists( 'delete_option' ) ) { 
  2. require_once ABSPATH . WPINC . '/option.php'; 
  3.  
  4. // Name of option to remove. Expected to not be SQL-escaped. 
  5. $option = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = delete_option($option); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/option.php  
  1. function delete_option( $option ) { 
  2. global $wpdb; 
  3.  
  4. $option = trim( $option ); 
  5. if ( empty( $option ) ) 
  6. return false; 
  7.  
  8.  
  9. // Get the ID, if no ID then return 
  10. $row = $wpdb->get_row( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ); 
  11. if ( is_null( $row ) ) 
  12. return false; 
  13.  
  14. /** 
  15. * Fires immediately before an option is deleted. 
  16. * @since 2.9.0 
  17. * @param string $option Name of the option to delete. 
  18. */ 
  19. do_action( 'delete_option', $option ); 
  20.  
  21. $result = $wpdb->delete( $wpdb->options, array( 'option_name' => $option ) ); 
  22. if ( ! wp_installing() ) { 
  23. if ( 'yes' == $row->autoload ) { 
  24. $alloptions = wp_load_alloptions(); 
  25. if ( is_array( $alloptions ) && isset( $alloptions[$option] ) ) { 
  26. unset( $alloptions[$option] ); 
  27. wp_cache_set( 'alloptions', $alloptions, 'options' ); 
  28. } else { 
  29. wp_cache_delete( $option, 'options' ); 
  30. if ( $result ) { 
  31.  
  32. /** 
  33. * Fires after a specific option has been deleted. 
  34. * The dynamic portion of the hook name, `$option`, refers to the option name. 
  35. * @since 3.0.0 
  36. * @param string $option Name of the deleted option. 
  37. */ 
  38. do_action( "delete_option_{$option}", $option ); 
  39.  
  40. /** 
  41. * Fires after an option has been deleted. 
  42. * @since 2.9.0 
  43. * @param string $option Name of the deleted option. 
  44. */ 
  45. do_action( 'deleted_option', $option ); 
  46. return true; 
  47. return false;