Skip to:
Content

bbPress.org


Ignore:
Timestamp:
04/28/2012 10:55:53 PM (13 years ago)
Author:
johnjamesjacoby
Message:

Allow user favorites and subscriptions to work per site on multisite installations. Props isaacchapman. Fixes #1818.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-admin/bbp-tools.php

    r3811 r3856  
    723723    $statement = __( 'Removing trashed topics from user favorites… %s', 'bbpress' );
    724724    $result    = __( 'Failed!', 'bbpress' );
    725 
    726     $users = $wpdb->get_results( "SELECT `user_id`, `meta_value` AS `favorites` FROM `$wpdb->usermeta` WHERE `meta_key` = '_bbp_favorites';" );
     725    $key       = bbp_get_favorites_key();
     726    $users     = $wpdb->get_results( "SELECT `user_id`, `meta_value` AS `favorites` FROM `{$wpdb->usermeta}` WHERE `meta_key` = '{$key}';" );
     727
    727728    if ( is_wp_error( $users ) )
    728729        return array( 1, sprintf( $statement, $result ) );
    729730
    730     $topics = $wpdb->get_col( "SELECT `ID` FROM `$wpdb->posts` WHERE `post_type` = '" . bbp_get_topic_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "';" );
     731    $topics = $wpdb->get_col( "SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_type` = '" . bbp_get_topic_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "';" );
    731732
    732733    if ( is_wp_error( $topics ) )
     
    743744
    744745        $favorites = join( ',', $favorites );
    745         $values[] = "('$user->user_id', '_bbp_favorites', '$favorites')";
     746        $values[] = "('{$user->user_id}', '{$key}, '{$favorites}')";
    746747    }
    747748
     
    751752    }
    752753
    753     $sql_delete = "DELETE FROM `$wpdb->usermeta` WHERE `meta_key` = '_bbp_favorites';";
     754    $sql_delete = "DELETE FROM `{$wpdb->usermeta}` WHERE `meta_key` = '{$key}';";
    754755    if ( is_wp_error( $wpdb->query( $sql_delete ) ) )
    755756        return array( 4, sprintf( $statement, $result ) );
     
    782783    $statement = __( 'Removing trashed topics from user subscriptions… %s', 'bbpress' );
    783784    $result    = __( 'Failed!', 'bbpress' );
    784 
    785     $users = $wpdb->get_results( "SELECT `user_id`, `meta_value` AS `subscriptions` FROM `$wpdb->usermeta` WHERE `meta_key` = '_bbp_subscriptions';" );
     785    $key       = bbp_get_subscriptions_key();
     786    $users     = $wpdb->get_results( "SELECT `user_id`, `meta_value` AS `subscriptions` FROM `{$wpdb->usermeta}` WHERE `meta_key` = '{$key}';" );
     787
    786788    if ( is_wp_error( $users ) )
    787789        return array( 1, sprintf( $statement, $result ) );
    788790
    789     $topics = $wpdb->get_col( "SELECT `ID` FROM `$wpdb->posts` WHERE `post_type` = '" . bbp_get_topic_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "';" );
     791    $topics = $wpdb->get_col( "SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_type` = '" . bbp_get_topic_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "';" );
    790792    if ( is_wp_error( $topics ) )
    791793        return array( 2, sprintf( $statement, $result ) );
     
    801803
    802804        $subscriptions = join( ',', $subscriptions );
    803         $values[] = "('$user->user_id', '_bbp_subscriptions', '$subscriptions')";
     805        $values[] = "('{$user->user_id}', '{$key}', '{$subscriptions}')";
    804806    }
    805807
     
    809811    }
    810812
    811     $sql_delete = "DELETE FROM `$wpdb->usermeta` WHERE `meta_key` = '_bbp_subscriptions';";
     813    $sql_delete = "DELETE FROM `{$wpdb->usermeta}` WHERE `meta_key` = '{$key}';";
    812814    if ( is_wp_error( $wpdb->query( $sql_delete ) ) )
    813815        return array( 4, sprintf( $statement, $result ) );
     
    816818    foreach ( $values as $chunk ) {
    817819        $chunk = "\n" . join( ",\n", $chunk );
    818         $sql_insert = "INSERT INTO `$wpdb->usermeta` (`user_id`, `meta_key`, `meta_value`) VALUES $chunk;";
     820        $sql_insert = "INSERT INTO `{$wpdb->usermeta}` (`user_id`, `meta_key`, `meta_value`) VALUES $chunk;";
    819821        if ( is_wp_error( $wpdb->query( $sql_insert ) ) )
    820822            return array( 5, sprintf( $statement, $result ) );
Note: See TracChangeset for help on using the changeset viewer.