summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2008-11-24 13:09:33 +0000
committerdonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2008-11-24 13:09:33 +0000
commit23f67568a169dd05954b92d198923850709baae3 (patch)
tree5ed395f861f5a82cf76132885892cfc5d25a43ef
parent3a5eefe78060c39d6f9a633703feb8d4378a41fd (diff)
downloadwordpress-mu-23f67568a169dd05954b92d198923850709baae3.tar.gz
wordpress-mu-23f67568a169dd05954b92d198923850709baae3.tar.xz
wordpress-mu-23f67568a169dd05954b92d198923850709baae3.zip
Fixes from Trunk
git-svn-id: http://svn.automattic.com/wordpress-mu/branches/2.6@1541 7be80a69-a1ef-0310-a953-fb0f7c49ff36
-rw-r--r--wp-includes/wpmu-functions.php71
1 files changed, 55 insertions, 16 deletions
diff --git a/wp-includes/wpmu-functions.php b/wp-includes/wpmu-functions.php
index ff004b8..9a3f6ec 100644
--- a/wp-includes/wpmu-functions.php
+++ b/wp-includes/wpmu-functions.php
@@ -83,9 +83,9 @@ function get_admin_users_for_domain( $sitedomain = '', $path = '' ) {
} else {
$site_id = $wpdb->get_var( $wpdb->prepare("SELECT id FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path) );
}
-
+
if( $site_id != false ) {
- return $wpdb->get_results( $wpdb->prepare("SELECT u.ID, u.user_login, u.user_pass FROM $wpdb->users AS u, $wpdb->sitemeta AS sm WHERE sm.meta_key = 'admin_user_id' AND u.ID = %d AND sm.site_id = %d", $wpdb->sitemeta.'.meta_value', $site_id), ARRAY_A );
+ return $wpdb->get_results( $wpdb->prepare("SELECT u.ID, u.user_login, u.user_pass FROM $wpdb->users AS u, $wpdb->sitemeta AS sm WHERE sm.meta_key = 'admin_user_id' AND u.ID = sm.meta_value AND sm.site_id = %d", $site_id), ARRAY_A );
}
return false;
}
@@ -132,7 +132,7 @@ function get_blog_details( $id, $getall = true ) {
return $details;
}
- $details = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE blog_id = %d", $id) ); // get_blog_details ?
+ $details = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE blog_id = %d /* get_blog_details */", $id) );
if ( !$details ) {
wp_cache_set( $id . $all, -1, 'blog-details' );
return false;
@@ -415,8 +415,7 @@ function get_blogs_of_user( $id, $all = false ) {
$blogs = $match = array();
foreach ( (array) $user as $key => $value ) {
- if ( strstr( $key, '_capabilities') && strstr( $key, $wpdb->base_prefix) ) {
- preg_match('/' . $wpdb->base_prefix . '(\d+)_capabilities/', $key, $match);
+ if ( false !== strpos( $key, '_capabilities') && 0 === strpos( $key, $wpdb->base_prefix ) && preg_match( '/' . $wpdb->base_prefix . '(\d+)_capabilities/', $key, $match ) ) {
$blog = get_blog_details( $match[1] );
if ( $blog && isset( $blog->domain ) && ( $all == true || $all == false && ( $blog->archived == 0 && $blog->spam == 0 && $blog->deleted == 0 ) ) ) {
$blogs[$match[1]]->userblog_id = $match[1];
@@ -445,6 +444,8 @@ function get_active_blog_for_user( $user_id ) { // get an active blog for user -
$ret = false;
if( is_array( $blogs ) && count( $blogs ) > 0 ) {
foreach( (array) $blogs as $blog_id => $blog ) {
+ if ( $blog->site_id != $wpdb->siteid )
+ continue;
$details = get_blog_details( $blog_id );
if( is_object( $details ) && $details->archived == 0 && $details->spam == 0 && $details->deleted == 0 ) {
$ret = $blog;
@@ -649,7 +650,8 @@ function add_user_to_blog( $blog_id, $user_id, $role ) {
return true;
}
-function remove_user_from_blog($user_id, $blog_id = '') {
+function remove_user_from_blog($user_id, $blog_id = '', $reassign = '') {
+ global $wpdb;
switch_to_blog($blog_id);
$user_id = (int) $user_id;
do_action('remove_user_from_blog', $user_id, $blog_id);
@@ -681,6 +683,12 @@ function remove_user_from_blog($user_id, $blog_id = '') {
update_usermeta($user_id, 'source_domain', '');
}
+ if( $reassign != '' ) {
+ $reassign = (int) $reassign;
+ $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_author = %d WHERE post_author = %d", $reassign, $user_id) );
+ $wpdb->query( $wpdb->prepare("UPDATE $wpdb->links SET link_owner = %d WHERE link_owner = %d", $reassign, $user_id) );
+ }
+
restore_current_blog();
}
@@ -721,6 +729,30 @@ function get_blog_permalink( $blog_id, $post_id ) {
return $link;
}
+function get_blog_id_from_url( $domain, $path = '/' ) {
+ global $wpdb;
+
+ $domain = strtolower( $wpdb->escape( $domain ) );
+ $path = strtolower( $wpdb->escape( $path ) );
+ $id = wp_cache_get( md5( $domain . $path ), 'blog-id-cache' );
+
+ if( $id == -1 ) { // blog does not exist
+ return 0;
+ } elseif( $id ) {
+ return (int)$id;
+ }
+
+ $id = $wpdb->get_var( "SELECT blog_id FROM $wpdb->blogs WHERE domain = '$domain' and path = '$path' /* get_blog_id_from_url */" );
+
+ if ( !$id ) {
+ wp_cache_set( md5( $domain . $path ), -1, 'blog-id-cache' );
+ return false;
+ }
+ wp_cache_set( md5( $domain . $path ), $id, 'blog-id-cache' );
+
+ return $id;
+}
+
// wpmu admin functions
function wpmu_admin_do_redirect( $url = '' ) {
@@ -729,7 +761,7 @@ function wpmu_admin_do_redirect( $url = '' ) {
$ref = $_GET['ref'];
if ( isset( $_POST['ref'] ) )
$ref = $_POST['ref'];
-
+
if( $ref ) {
$ref = wpmu_admin_redirect_add_updated_param( $ref );
wp_redirect( $ref );
@@ -814,7 +846,7 @@ function is_email_address_unsafe( $user_email ) {
strstr( $banned_domain, '/' ) &&
preg_match( $banned_domain, $email_domain )
)
- )
+ )
return true;
}
}
@@ -1082,9 +1114,9 @@ function wpmu_signup_user_notification($user, $user_email, $key, $meta = '') {
$admin_email = 'support@' . $_SERVER['SERVER_NAME'];
$from_name = get_site_option( "site_name" ) == '' ? 'WordPress' : wp_specialchars( get_site_option( "site_name" ) );
$message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
- $message = sprintf(__("To activate your user, please click the following link:\n\n%s\n\nAfter you activate, you will receive *another email* with your login.\n\n"), clean_url("http://{$current_site->domain}{$current_site->path}wp-activate.php?key=$key") );
+ $message = sprintf(__( apply_filters( 'wpmu_signup_user_notification_email', "To activate your user, please click the following link:\n\n%s\n\nAfter you activate, you will receive *another email* with your login.\n\n" ) ), clean_url("http://{$current_site->domain}{$current_site->path}wp-activate.php?key=$key") );
// TODO: Don't hard code activation link.
- $subject = sprintf(__('Activate %s'), $user);
+ $subject = sprintf(__( apply_filters( 'wpmu_signup_user_notification_subject', 'Activate %s' )), $user);
wp_mail($user_email, $subject, $message, $message_headers);
return true;
}
@@ -1295,13 +1327,13 @@ function insert_blog($domain, $path, $site_id) {
// Install an empty blog. wpdb should already be switched.
function install_blog($blog_id, $blog_title = '') {
global $wpdb, $table_prefix, $wp_roles;
-
+ $wpdb->suppress_errors();
+
// Cast for security
$blog_id = (int) $blog_id;
require_once( ABSPATH . 'wp-admin/includes/upgrade.php');
-
- $wpdb->suppress_errors();
+
if ( $wpdb->get_results("SELECT ID FROM $wpdb->posts") )
die(__('<h1>Already Installed</h1><p>You appear to have already installed WordPress. To reinstall please clear your old database tables first.</p>') . '</body></html>');
$wpdb->suppress_errors( false);
@@ -1313,7 +1345,7 @@ function install_blog($blog_id, $blog_title = '') {
populate_options();
populate_roles();
$wp_roles->_init();
-
+
// fix url.
update_option('siteurl', $url);
update_option('home', $url);
@@ -1344,8 +1376,6 @@ function install_blog($blog_id, $blog_title = '') {
$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE meta_key = %s", $table_prefix.'user_level') );
$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE meta_key = %s", $table_prefix.'capabilities') );
- wp_cache_delete('notoptions', 'options');
- wp_cache_delete('alloptions', 'options');
$wpdb->suppress_errors( false );
}
@@ -1994,4 +2024,13 @@ function add_existing_user_to_blog() {
}
}
}
+
+function add_new_user_to_blog( $user_id, $email, $meta ) {
+ if( $meta[ 'add_to_blog' ] ) {
+ $blog_id = $meta[ 'add_to_blog' ];
+ $role = $meta[ 'new_role' ];
+ add_user_to_blog( $blog_id, $user_id, $role );
+ }
+}
+add_action( 'wpmu_activate_user', $user_id, $email, $meta );
?>