Changeset 1120

Show
Ignore:
Timestamp:
10/22/07 17:16:22 (1 year ago)
Author:
donncha
Message:

Remove primary_blog record for user after removed from blog.
Check for username and email when adding user.
Rework permission denied redirect code. props momo360modena, fixes #427

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wp-admin/menu.php

    r1069 r1120  
    151151uksort($menu, "strnatcasecmp"); // make it all pretty 
    152152 
    153 if (! user_can_access_admin_page()) { 
    154         global $wpdb; 
     153if ( !user_can_access_admin_page() ) { 
    155154        // find the blog of this user first 
    156         $primary_blog = $wpdb->get_var( "SELECT meta_value FROM {$wpdb->usermeta} WHERE user_id = '$user_ID' AND meta_key = 'primary_blog'" ); 
    157         if( $primary_blog ) { 
     155        $primary_blog = (int) get_usermeta( $user_ID, 'primary_blog' ); 
     156        if( $primary_blog != 0 ) { 
     157                global $wpdb; 
    158158                $newblog = $wpdb->get_row( "SELECT * FROM {$wpdb->blogs} WHERE blog_id = '{$primary_blog}'" ); 
    159159                if( $newblog != null ) { 
    160                         header( "Location: http://" . $newblog->domain . $newblog->path . "wp-admin/" ); 
    161                         exit; 
     160                        $blogs = get_blogs_of_user( $user_ID ); 
     161                        if ( empty($blogs) || $blogs == false ) { // If user haven't any blog 
     162                                update_usermeta( $user_ID, 'wp_1_capabilities', array('subscriber' => true)); // Add subscriber permission for first blog. 
     163                                wp_redirect( 'http://'.$current_site->domain . $current_site->path. 'wp-admin/' ); 
     164                                exit(); 
     165                        } 
     166 
     167                        foreach ( (array) $blogs as $blog ) { 
     168                                if ( $blog->userblog_id == $newblog->blog_id ) { 
     169                                        wp_redirect( 'http://'.$newblog->domain . $newblog->path . 'wp-admin/' ); 
     170                                        exit(); 
     171                                } 
     172                        } 
     173                         
     174                        $blog = $blogs[0]; // Take the first blog... 
     175                        wp_redirect( 'http://'.$blog->domain . $blog->path. 'wp-admin/' ); 
     176                        exit(); 
    162177                } 
    163178        } 
  • trunk/wp-admin/wpmu-edit.php

    r1110 r1120  
    187187                        reset( $_POST['blogusers'] ); 
    188188                        foreach ( (array) $_POST['blogusers'] as $key => $val ) { 
    189                                 $wpdb->query( "DELETE FROM " . $wpdb->usermeta . " WHERE meta_key = '" . $wpmuBaseTablePrefix . $id . "_capabilities' AND user_id = '" . $key . "'" ); 
     189                                delete_usermeta( $key, $wpmuBaseTablePrefix.$id.'_capabilities' ); 
     190                                delete_usermeta( $key, $wpmuBaseTablePrefix.$id.'_user_level' ); 
     191                                delete_usermeta( $key, 'primary_blog', $id ); // Delete primary blog if need. 
    190192                        } 
    191193                } 
     
    403405                if( is_array( $_POST['user'] ) == true ) { 
    404406                        $user = $_POST['user']; 
    405                         if ( empty($user['username']) || empty($user['email']) ) { 
     407                        if ( empty($user['username']) && empty($user['email']) ) { 
    406408                                wp_die( __("<p>Missing username and email.</p>") ); 
    407                         }                        
     409                        } elseif ( empty($user['username']) ) { 
     410                                wp_die( __("<p>Missing username.</p>") ); 
     411                        } elseif ( empty($user['email']) ) { 
     412                                wp_die( __("<p>Missing email.</p>") ); 
     413                        } 
     414                         
    408415                        $password = generate_random_password(); 
    409416                        $user_id = wpmu_create_user(wp_specialchars( strtolower( $user['username'] ) ), $password, wp_specialchars( $user['email'] ) );