| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | Plugin Name: Test insert_blog() bug |
|---|
| 4 | Description: Activate this plugin to test the insert_blog() bug here http://core.trac.wordpress.org/ticket/23400 |
|---|
| 5 | Plugin URI: http://core.trac.wordpress.org/ticket/23400 |
|---|
| 6 | Author: David Mårtensson |
|---|
| 7 | Version: 1.0 |
|---|
| 8 | Author URI: http://www.feedmeastraycat.net/ |
|---|
| 9 | */ |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | add_action('init', '_init'); |
|---|
| 13 | add_action('refresh_blog_details', '_refresh_blog_details', 10, 1); |
|---|
| 14 | |
|---|
| 15 | function _init() { |
|---|
| 16 | |
|---|
| 17 | if ( MULTISITE && isset($_GET['action']) && $_GET['action'] == "testbug" ) { |
|---|
| 18 | |
|---|
| 19 | global $current_site; |
|---|
| 20 | |
|---|
| 21 | $domain = "test-".date("YmdHis"); |
|---|
| 22 | $name = "Test ".date("Y-m-d H:i:s"); |
|---|
| 23 | |
|---|
| 24 | if ( is_subdomain_install() ) { |
|---|
| 25 | $newdomain = $domain . '.' . preg_replace( '|^www\.|', '', $current_site->domain ); |
|---|
| 26 | $path = $current_site->path; |
|---|
| 27 | } else { |
|---|
| 28 | $newdomain = $current_site->domain; |
|---|
| 29 | $path = $current_site->path . $domain . '/'; |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | $blog_id = wpmu_create_blog( $newdomain, $path, $name, 0 ); |
|---|
| 33 | |
|---|
| 34 | if ( is_int($blog_id) ) { |
|---|
| 35 | echo "Created blog id: ".$blog_id."<br>"; |
|---|
| 36 | } |
|---|
| 37 | else { |
|---|
| 38 | echo "Error:<br>"; |
|---|
| 39 | var_dump($blog_id); |
|---|
| 40 | } |
|---|
| 41 | die; |
|---|
| 42 | |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | function _refresh_blog_details( $blog_id ) { |
|---|
| 48 | |
|---|
| 49 | $current_blog_id = get_current_blog_id(); |
|---|
| 50 | if ($current_blog_id != 1) { |
|---|
| 51 | switch_to_blog(1); |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | global $wpdb; |
|---|
| 55 | $truncate = $wpdb->query( $wpdb->prepare('TRUNCATE TABLE `'.$wpdb->posts.'`') ); |
|---|
| 56 | if ($truncate) { |
|---|
| 57 | $set_autoincrement = $wpdb->query( $wpdb->prepare('ALTER TABLE `'.$wpdb->posts.'` AUTO_INCREMENT = 100') ); |
|---|
| 58 | if ($set_autoincrement) { |
|---|
| 59 | wp_insert_post(array( |
|---|
| 60 | 'post_title' => 'Hello World '.date('H:i'), |
|---|
| 61 | 'post_content' => 'Hello World!' |
|---|
| 62 | )); |
|---|
| 63 | } |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | if ($current_blog_id != 1) { |
|---|
| 67 | switch_to_blog($current_blog_id); |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | } |
|---|