Created
March 27, 2012 11:47
-
-
Save bolstad/2215239 to your computer and use it in GitHub Desktop.
bulk timezone changer for wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo "memory use: " . memory_get_usage() . "\n"; | |
$configdir = __FILE__; | |
$configdir = preg_replace('|wp-content\/.*|','',$configdir); | |
$configdir .= 'wp-load.php'; | |
error_reporting(E_ALL); | |
ini_set('display_errors','On'); | |
ini_set('display_startup_errors','On'); | |
// set some required variables if running from cli | |
if (empty($_SERVER['HTTP_HOST'])) | |
{ | |
$_SERVER["SERVER_NAME"] = "localhost"; | |
$_SERVER["HTTP_HOST"] = '127.0.0.1'; | |
$_SERVER["SERVER_PROTOCOL"] = 'HTTP/1.1'; | |
$_SERVER["HTTP_USER_AGENT"] = "fake agent"; | |
$_SERVER["HTTP_ACCEPT"] = "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,text/css,*/*;q=0.1"; | |
} | |
echo "Loading: $configdir\n"; | |
if (file_exists($configdir)) | |
include("$configdir"); | |
else | |
die ("Can not load $configdir\n"); | |
if (function_exists('switch_to_blog')) | |
{ | |
global $wpdb; | |
$blogs = $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs ORDER BY blog_id DESC LIMIT %d,5", $c ) ); | |
foreach( $blogs as $blog ) { | |
if( $blog != $tags_blog_id ) { | |
$details = get_blog_details( $blog ); | |
print_r($details); | |
switch_to_blog($details->blog_id); | |
if ( get_option( 'timezone_string' ) != 'Europe/Stockholm' ) { | |
update_option( 'timezone_string', 'Europe/Stockholm' ); | |
} else { | |
$deprecated = ' '; | |
$autoload = 'yes'; | |
add_option( 'timezone_string', 'Europe/Stockholm', $deprecated, $autoload ); | |
} | |
if ( get_option( 'gmt_offset' ) != '' ) { | |
update_option( 'gmt_offset', '' ); | |
} else { | |
$deprecated = ' '; | |
$autoload = 'yes'; | |
add_option( 'gmt_offset', '', $deprecated, $autoload ); | |
} | |
} | |
$c++; | |
} | |
} | |
echo "memory use: " . memory_get_usage() . "\n"; | |
echo "Done!"; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment