The delete_blog_option() WordPress PHP function removes a specific option by its name for a given blog ID. It is used to delete an option from the options table of a specific blog in a multisite environment. This function prevents the removal of certain WordPress options that are protected.
To use the delete_blog_option() function, you’ll need to provide the blog ID and the name of the option you wish to delete.
delete_blog_option( $id, $option );
- $id (int): This is the ID of the blog. You can also use null to refer to the current blog.
- $option (string): This is the name of the option to remove. It’s expected to not be SQL-escaped.
See WordPress Developer Resources: delete_blog_option()
This function is available from WordPress version 3.0.0. As of the latest version, it is not deprecated.
Delete ‘sample_option’ from the current blog
This code will delete the ‘sample_option’ from the options table of the current blog.
// Delete the 'sample_option' from the current blog delete_blog_option( null, 'sample_option' );
Delete ‘another_option’ from a blog with ID 3
This code will delete ‘another_option’ from the blog with ID 3.
// Delete the 'another_option' from blog with ID 3 delete_blog_option( 3, 'another_option' );
Attempt to delete a protected option
This code will attempt to delete ‘admin_email’, which is a protected option. The function will not remove it.
// Attempt to delete 'admin_email' from the current blog delete_blog_option( null, 'admin_email' );
Delete an option that does not exist
This code will attempt to delete ‘non_existing_option’. As this option does not exist, the function will simply do nothing.
// Attempt to delete 'non_existing_option' from the current blog delete_blog_option( null, 'non_existing_option' );
Delete an option from an non-existing blog
This code will attempt to delete ‘sample_option’ from a blog with ID 9999. If this blog does not exist, the function will simply do nothing.
// Attempt to delete 'sample_option' from a non-existing blog delete_blog_option( 9999, 'sample_option' );