[wp-trac] [WordPress Trac] #16964: New function network_delete_option($option) to help keep option clutter to a minimum
WordPress Trac
wp-trac at lists.automattic.com
Thu Mar 24 23:03:33 UTC 2011
#16964: New function network_delete_option($option) to help keep option clutter to
a minimum
--------------------------+-------------------------------------
Reporter: philipwalton | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Multisite | Version:
Severity: normal | Keywords: needs-testing has-patch
--------------------------+-------------------------------------
When I create uninstall.php files for plugins I always delete the options
I created using `delete_option()`. However, recently I realized that if
anyone is using my plugins on a multisite installation, `delete_option()`
would only delete that option from the options table of the main site; not
any of the subsites.
I believe a function should be created to make removing options as easy as
possible, so I created a function called `network_delete_option()`.
The patch I've included is to the ms-functions.php file. Perhaps it is
more appropriate somewhere else, but I just want to get the discussion
started.
Here is the code:
{{{
/**
* Deletes the option from all options tables
*
* @uses delete_option()
*
* @param mixed $options a string or array of strings which correspond to
the option names to be deleted
*/
function network_delete_option( $options ) {
// convert an option passed as a single string to an array
if ( is_string( $options ) ) {
$options = array( $options );
}
if ( is_multisite() ) {
global $wpdb;
$blogs = $wpdb->get_results( "SELECT blog_id FROM
{$wpdb->blogs}", ARRAY_A );
if ( $blogs ) {
// loop through each subsite ( blog )
foreach( $blogs as $blog ) {
switch_to_blog( $blog['blog_id'] );
foreach( $options as $option ) {
delete_option( $option );
}
}
}
} else {
// loop through each subsite ( blog )
foreach( $options as $option ) {
delete_option( $option );
}
}
}
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/16964>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list