Site icon WP Smith

How to Write a Simple update_ms_option() Function for WordPress Multisite

For WordPress Multisite, I needed a function that worked like update_option(). So here's a simple one I wrote.

[php]function update_ms_option($blogID, $option_name, $option_value) {
global $wpdb;

$wpdb->query( $wpdb->prepare( "
INSERT INTO `".DB_NAME."`.`".$wpdb->get_blog_prefix($blogID)."options`
(
`option_id` ,
`blog_id` ,
`option_name` ,
`option_value` ,
`autoload`
)
VALUES (NULL, '0', '%s', '%s', 'yes')
ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = '%s', `autoload` = VALUES(`autoload`)",
array($option_name, $option_value, $option_value) ) );
[/php]