delete_option

Definition:
function delete_option( $option ) {}

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

Parameters

  • string $option: Name of option to remove. Expected to not be SQL-escaped.

Return values

returns:True, if option is successfully deleted. False on failure.

Defined actions

  • delete_option
    do_action( 'delete_option', $option );
  • delete_option_$option
    do_action( "delete_option_$option", $option );
  • deleted_option
    do_action( 'deleted_option', $option );

Source code

function delete_option( $option ) {

	global $wpdb;



	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->query( $wpdb->prepare( "DELETE FROM $wpdb->options WHERE option_name = %s", $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;

}

802

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: