WordPress.org

Plugin Directory

Changeset 498136


Ignore:
Timestamp:
01/31/12 19:26:52 (2 years ago)
Author:
ydubois
Message:

Bugfix in table structure and data replication

File:
1 edited

Legend:

Unmodified
Added
Removed
  • yd-wpmu-sitewide-options/trunk/yd-wpmu-sitewide-options.php

    r325631 r498136  
    33 * @package YD_WPMU-Sitewide-Options 
    44 * @author Yann Dubois 
    5  * @version 4.0.0 
     5 * @version 4.0.1 
    66 */ 
    77 
     
    1111 Description: Makes selected plugin settings network-wide. Change to a setting of your main blog can now be automatically replicated to all multisite blogs. Centralized management of your plugin options. 
    1212 Author: Yann Dubois 
    13  Version: 4.0.0 
     13 Version: 4.0.1 
    1414 Author URI: http://www.yann.com/ 
    1515 */ 
     
    8383 - Added feature to replicate custom database tables used by some plugins 
    8484 - Tested WP3.0.3 compatibility, updated doc 
     85 Revision 4.0.1 
     86 - Bugfix in table structure and data replication 
    8587  
    8688 TODO: 
     
    567569 
    568570function yd_wpmuso_display_dbtable( $table, $options, $i ) { 
    569     $tbl = 'ydtable_' . esc_attr( $table ); 
    570     $tbl2 = 'yddata_' . esc_attr( $table ); 
    571     $tbld = esc_attr( $table ); 
     571    //global $wpdb; 
     572    $table = esc_attr( $table ); 
     573    //$stripped_table = preg_replace( '/^' . $wpdb->prefix . '/', '', $table ); 
     574    $tbl = 'ydtable_' . $table; 
     575    $tbl2 = 'yddata_' . $table; 
     576    $tbld = $table; 
    572577    $opt_id = 'table_' . $table; 
    573578    $opt2_id = 'data_' . $table; 
     
    781786                        foreach( $blog_list as $blog ) { 
    782787                            if( $blog['blog_id'] == $master_blog_id ) continue; 
    783                             yd_wpmuso_create_table( $opt, $blog['blog_id'] ); 
     788                            yd_wpmuso_create_table( $opt, $blog['blog_id'], $master_blog_id ); 
    784789                        } 
    785790                    } 
     
    788793                        foreach( $blog_list as $blog ) { 
    789794                            if( $blog['blog_id'] == $master_blog_id ) continue; 
    790                             yd_wpmuso_replicate_data( $opt, $blog['blog_id'], true ); 
     795                            yd_wpmuso_replicate_data( $opt, $blog['blog_id'], true, $master_blog_id ); 
    791796                        } 
    792797                    } 
     
    855860        foreach( $options[$i]["selected_options"] as $opt ) { 
    856861            if( preg_match( '/^ydtable_/', $opt ) ) { 
    857                 yd_wpmuso_create_table( $opt, $blog_id ); 
     862                yd_wpmuso_create_table( $opt, $blog_id, $master_blog_id ); 
    858863            } elseif( preg_match( '/^yddata_/', $opt ) ) { 
    859                 yd_wpmuso_replicate_data( $opt, $blog_id, true ); 
     864                yd_wpmuso_replicate_data( $opt, $blog_id, true, $master_blog_id ); 
    860865            } else { 
    861866                //echo $opt . ': '; 
     
    883888add_action( 'wpmu_new_blog', 'yd_wpmuso_options_new_blog_action' ); 
    884889 
    885 function yd_wpmuso_create_table( $opt, $blog_id ) { 
     890function yd_wpmuso_create_table( $opt, $blog_id, $master_blog_id ) { 
    886891    global $wpdb; 
    887892    //echo $opt . '<br/>'; 
     
    893898    $sql = $res[0]["Create Table"]; 
    894899    //echo $sql . '<br/><br/>'; 
     900    // $wpdb->prefix must be caught in the context of the "master blog". 
     901    switch_to_blog( $master_blog_id ); 
    895902    $post = preg_replace( '/^' . $wpdb->prefix . '/i', '', $table ); 
     903    restore_current_blog(); 
    896904    switch_to_blog( $blog_id ); 
    897905    $sql = preg_replace( '/' . $table . '/i', $wpdb->prefix . $post, $sql ); 
     
    903911} 
    904912 
    905 function yd_wpmuso_replicate_data( $opt, $blog_id, $delete = false ) { 
     913function yd_wpmuso_replicate_data( $opt, $blog_id, $delete = false, $master_blog_id ) { 
    906914    global $wpdb; 
    907915    $table = preg_replace( '/^yddata_/', '', $opt ); 
    908916    //$query = "SELECT * FROM $table"; 
    909917    //$res = $wpdb->get_results( $query, ARRAY_A ); 
     918    // $wpdb->prefix must be caught in the context of the "master blog". 
     919    switch_to_blog( $master_blog_id ); 
    910920    $post = preg_replace( '/^' . $wpdb->prefix . '/i', '', $table ); 
     921    restore_current_blog(); 
    911922    switch_to_blog( $blog_id ); 
    912923    if( $delete ) { 
Note: See TracChangeset for help on using the changeset viewer.