Changeset 12736 for trunk/wp-admin/ms-edit.php
- Timestamp:
- 01/15/2010 11:49:09 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/ms-edit.php
r12725 r12736 10 10 do_action('wpmuadminedit', ''); 11 11 12 if ( isset($_GET[ 'id' ]) ) {12 if ( isset($_GET[ 'id' ]) ) 13 13 $id = intval( $_GET[ 'id' ] ); 14 } elseif( isset($_POST[ 'id' ]) ) { 14 elseif ( isset($_POST[ 'id' ]) ) 15 15 $id = intval( $_POST[ 'id' ] ); 16 } 17 18 if( isset( $_POST['ref'] ) == false && !empty($_SERVER['HTTP_REFERER']) ) { 16 17 if ( isset( $_POST['ref'] ) == false && !empty($_SERVER['HTTP_REFERER']) ) 19 18 $_POST['ref'] = $_SERVER['HTTP_REFERER']; 20 } 21 22 switch( $_GET['action'] ) { 19 20 switch ( $_GET['action'] ) { 23 21 case "siteoptions": 24 22 check_admin_referer('siteoptions'); 25 if ( empty( $_POST ) )23 if ( empty( $_POST ) ) 26 24 wp_die( __("You probably need to go back to the <a href='ms-options.php'>options page</a>") ); 27 25 28 26 update_site_option( "WPLANG", $_POST['WPLANG'] ); 29 27 30 if ( is_email( $_POST['admin_email'] ) )28 if ( is_email( $_POST['admin_email'] ) ) 31 29 update_site_option( "admin_email", $_POST['admin_email'] ); 32 30 33 31 $illegal_names = split( ' ', $_POST['illegal_names'] ); 34 foreach ( (array) $illegal_names as $name ) {32 foreach ( (array) $illegal_names as $name ) { 35 33 $name = trim( $name ); 36 if ( $name != '' )34 if ( $name != '' ) 37 35 $names[] = trim( $name ); 38 36 } 39 37 update_site_option( "illegal_names", $names ); 40 38 41 if ( $_POST['limited_email_domains'] != '' ) {39 if ( $_POST['limited_email_domains'] != '' ) { 42 40 $limited_email_domains = str_replace( ' ', "\n", $_POST[ 'limited_email_domains' ] ); 43 41 $limited_email_domains = split( "\n", stripslashes( $limited_email_domains ) ); 44 foreach ( (array) $limited_email_domains as $domain ) {42 foreach ( (array) $limited_email_domains as $domain ) { 45 43 $limited_email[] = trim( $domain ); 46 44 } … … 50 48 } 51 49 52 if ( $_POST['banned_email_domains'] != '' ) {50 if ( $_POST['banned_email_domains'] != '' ) { 53 51 $banned_email_domains = split( "\n", stripslashes( $_POST[ 'banned_email_domains' ] ) ); 54 foreach ( (array) $banned_email_domains as $domain ) {52 foreach ( (array) $banned_email_domains as $domain ) { 55 53 $banned[] = trim( $domain ); 56 54 } … … 60 58 } 61 59 update_site_option( 'default_user_role', $_POST[ 'default_user_role' ] ); 62 if ( trim( $_POST[ 'dashboard_blog_orig' ] ) == '' )60 if ( trim( $_POST[ 'dashboard_blog_orig' ] ) == '' ) 63 61 $_POST[ 'dashboard_blog_orig' ] = $current_site->blog_id; 64 if ( trim( $_POST[ 'dashboard_blog' ] ) == '' ) {62 if ( trim( $_POST[ 'dashboard_blog' ] ) == '' ) { 65 63 $_POST[ 'dashboard_blog' ] = $current_site->blog_id; 66 64 $dashboard_blog_id = $current_site->blog_id; … … 85 83 } 86 84 } 87 if ( is_wp_error( $dashboard_blog_id ) ) {85 if ( is_wp_error( $dashboard_blog_id ) ) 88 86 wp_die( __( 'Problem creating dashboard blog: ' ) . $dashboard_blog_id->get_error_message() ); 89 } 90 if( $_POST[ 'dashboard_blog_orig' ] != $_POST[ 'dashboard_blog' ] ) { 87 if ( $_POST[ 'dashboard_blog_orig' ] != $_POST[ 'dashboard_blog' ] ) { 91 88 $users = get_users_of_blog( get_site_option( 'dashboard_blog' ) ); 92 89 $move_users = array(); 93 90 foreach ( (array)$users as $user ) { 94 if ( array_pop( array_keys( unserialize( $user->meta_value ) ) ) == 'subscriber' )91 if ( array_pop( array_keys( unserialize( $user->meta_value ) ) ) == 'subscriber' ) 95 92 $move_users[] = $user->user_id; 96 93 } … … 105 102 update_site_option( "dashboard_blog", $dashboard_blog_id ); 106 103 $options = array( 'registrationnotification', 'registration', 'add_new_users', 'menu_items', 'mu_media_buttons', 'upload_space_check_disabled', 'blog_upload_space', 'upload_filetypes', 'site_name', 'first_post', 'first_page', 'first_comment', 'first_comment_url', 'first_comment_author', 'welcome_email', 'welcome_user_email', 'fileupload_maxk', 'admin_notice_feed' ); 107 foreach ( $options as $option_name ) {104 foreach ( $options as $option_name ) { 108 105 $value = stripslashes_deep( $_POST[ $option_name ] ); 109 106 update_site_option( $option_name, $value ); … … 113 110 if ( is_array( $site_admins ) ) { 114 111 $mainblog_id = $wpdb->get_var( "SELECT blog_id FROM {$wpdb->blogs} WHERE domain='{$current_site->domain}' AND path='{$current_site->path}'" ); 115 if ( $mainblog_id ) {112 if ( $mainblog_id ) { 116 113 reset( $site_admins ); 117 foreach ( (array) $site_admins as $site_admin ) {114 foreach ( (array) $site_admins as $site_admin ) { 118 115 $uid = $wpdb->get_var( "SELECT ID FROM {$wpdb->users} WHERE user_login='{$site_admin}'" ); 119 if ( $uid )116 if ( $uid ) 120 117 add_user_to_blog( $mainblog_id, $uid, 'administrator' ); 121 118 } … … 133 130 check_admin_referer('add-blog'); 134 131 135 if ( is_array( $_POST[ 'blog' ] ) == false ) {132 if ( is_array( $_POST[ 'blog' ] ) == false ) 136 133 wp_die( "Can't create an empty blog." ); 137 }138 134 $blog = $_POST['blog']; 139 135 $domain = sanitize_user( str_replace( '/', '', $blog[ 'domain' ] ) ); … … 141 137 $title = $blog[ 'title' ]; 142 138 143 if ( empty($domain) || empty($email) )139 if ( empty($domain) || empty($email) ) 144 140 wp_die( __('Missing blog address or email address.') ); 145 if ( !is_email( $email ) )141 if ( !is_email( $email ) ) 146 142 wp_die( __('Invalid email address') ); 147 143 148 if ( is_subdomain_install() ) {144 if ( is_subdomain_install() ) { 149 145 $newdomain = $domain.".".$current_site->domain; 150 146 $path = $base; … … 156 152 $password = 'N/A'; 157 153 $user_id = email_exists($email); 158 if ( !$user_id ) { // Create a new user with a random password154 if ( !$user_id ) { // Create a new user with a random password 159 155 $password = wp_generate_password(); 160 156 $user_id = wpmu_create_user( $domain, $password, $email ); 161 if (false == $user_id) {157 if ( false == $user_id ) 162 158 wp_die( __('There was an error creating the user') ); 163 } else {159 else 164 160 wp_new_user_notification($user_id, $password); 165 }166 161 } 167 162 … … 169 164 $id = wpmu_create_blog($newdomain, $path, $title, $user_id , array( "public" => 1 ), $current_site->id); 170 165 $wpdb->show_errors(); 171 if ( !is_wp_error($id) ) {166 if ( !is_wp_error($id) ) { 172 167 $dashboard_blog = get_dashboard_blog(); 173 if ( get_user_option( 'primary_blog', $user_id ) == $dashboard_blog->blog_id )168 if ( get_user_option( 'primary_blog', $user_id ) == $dashboard_blog->blog_id ) 174 169 update_user_option( $user_id, 'primary_blog', $id, true ); 175 170 $content_mail = sprintf( __( "New blog created by %1s\n\nAddress: http://%2s\nName: %3s"), $current_user->user_login , $newdomain.$path, stripslashes( $title ) ); … … 185 180 case "updateblog": 186 181 check_admin_referer('editblog'); 187 if ( empty( $_POST ) )182 if ( empty( $_POST ) ) 188 183 wp_die( __('You probably need to go back to the <a href="ms-sites.php">sites page</a>') ); 189 184 190 185 // themes 191 if ( is_array( $_POST[ 'theme' ] ) ) {186 if ( is_array( $_POST[ 'theme' ] ) ) 192 187 $_POST[ 'option' ][ 'allowedthemes' ] = $_POST[ 'theme' ]; 193 } else {188 else 194 189 $_POST[ 'option' ][ 'allowedthemes' ] = ''; 195 }196 190 197 191 switch_to_blog( $id ); 198 if ( is_array( $_POST[ 'option' ] ) ) {192 if ( is_array( $_POST[ 'option' ] ) ) { 199 193 $c = 1; 200 194 $count = count( $_POST[ 'option' ] ); 201 195 foreach ( (array) $_POST['option'] as $key => $val ) { 202 if ( $key === 0 )196 if ( $key === 0 ) 203 197 continue; // Avoids "0 is a protected WP option and may not be modified" error when edit blog options 204 if ( $c == $count ) {198 if ( $c == $count ) 205 199 update_option( $key, $val ); 206 } else {200 else 207 201 update_option( $key, $val, false ); // no need to refresh blog details yet 208 }209 202 $c++; 210 203 } 211 204 } 212 205 213 if ( $_POST['update_home_url'] == 'update' ) {206 if ( $_POST['update_home_url'] == 'update' ) { 214 207 if( get_option( 'siteurl' ) != 'http://' . $_POST['blog']['domain'] . $_POST['blog']['path'] ) 215 208 update_option( 'siteurl', 'http://' . $_POST['blog']['domain'] . $_POST['blog']['path'] ); … … 239 232 $blog_prefix = $wpdb->get_blog_prefix( $id ); 240 233 // user roles 241 if ( is_array( $_POST[ 'role' ] ) == true ) {234 if ( is_array( $_POST[ 'role' ] ) == true ) { 242 235 $newroles = $_POST[ 'role' ]; 243 236 reset( $newroles ); … … 245 238 $role_len = strlen( $role ); 246 239 $existing_role = $wpdb->get_var( "SELECT meta_value FROM $wpdb->usermeta WHERE user_id = '$userid' AND meta_key = '" . $blog_prefix. "capabilities'" ); 247 if ( false == $existing_role ) {240 if ( false == $existing_role ) 248 241 $wpdb->query( "INSERT INTO " . $wpdb->usermeta . "( `umeta_id` , `user_id` , `meta_key` , `meta_value` ) VALUES ( NULL, '$userid', '" . $blog_prefix . "capabilities', 'a:1:{s:" . strlen( $role ) . ":\"" . $role . "\";b:1;}')" ); 249 } elseif( $existing_role != "a:1:{s:" . strlen( $role ) . ":\"" . $role . "\";b:1;}" ) {242 elseif ( $existing_role != "a:1:{s:" . strlen( $role ) . ":\"" . $role . "\";b:1;}" ) 250 243 $wpdb->query( "UPDATE $wpdb->usermeta SET meta_value = 'a:1:{s:" . strlen( $role ) . ":\"" . $role . "\";b:1;}' WHERE user_id = '$userid' AND meta_key = '" . $blog_prefix . "capabilities'" ); 251 }252 253 244 } 254 245 } … … 262 253 263 254 // change password 264 if ( is_array( $_POST[ 'user_password' ] ) ) {255 if ( is_array( $_POST[ 'user_password' ] ) ) { 265 256 reset( $_POST[ 'user_password' ] ); 266 257 $newroles = $_POST[ 'role' ]; … … 268 259 unset( $_POST[ 'role' ] ); 269 260 $_POST[ 'role' ] = $newroles[ $userid ]; 270 if ( $pass != '' ) {261 if ( $pass != '' ) { 271 262 $cap = $wpdb->get_var( "SELECT meta_value FROM {$wpdb->usermeta} WHERE user_id = '{$userid}' AND meta_key = '{$blog_prefix}capabilities' AND meta_value = 'a:0:{}'" ); 272 263 $userdata = get_userdata($userid); … … 275 266 $_POST[ 'rich_editing' ] = $userdata->rich_editing; 276 267 edit_user( $userid ); 277 if ( $cap == null )268 if ( $cap == null ) 278 269 $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE user_id = '{$userid}' AND meta_key = '{$blog_prefix}capabilities' AND meta_value = 'a:0:{}'" ); 279 270 } … … 284 275 285 276 // add user? 286 if ( $_POST[ 'newuser' ] != '' ) {277 if ( $_POST[ 'newuser' ] != '' ) { 287 278 $newuser = $_POST[ 'newuser' ]; 288 279 $userid = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->users . " WHERE user_login = %s", $newuser ) ); 289 if ( $userid ) {280 if ( $userid ) { 290 281 $user = $wpdb->get_var( "SELECT user_id FROM " . $wpdb->usermeta . " WHERE user_id='$userid' AND meta_key='wp_" . $id . "_capabilities'" ); 291 if ( $user == false )282 if ( $user == false ) 292 283 add_user_to_blog($id, $userid, $_POST[ 'new_role' ]); 293 284 } … … 300 291 case "deleteblog": 301 292 check_admin_referer('deleteblog'); 302 if ( $id != '0' && $id != $current_site->blog_id )293 if ( $id != '0' && $id != $current_site->blog_id ) 303 294 wpmu_delete_blog( $id, true ); 304 295 … … 310 301 check_admin_referer('allblogs'); 311 302 foreach ( (array) $_POST[ 'allblogs' ] as $key => $val ) { 312 if ( $val != '0' && $val != $current_site->blog_id ) {303 if ( $val != '0' && $val != $current_site->blog_id ) { 313 304 if ( isset($_POST['allblog_delete']) ) { 314 305 $blogfunction = 'all_delete'; … … 393 384 // Themes 394 385 case "updatethemes": 395 if ( is_array( $_POST['theme'] ) ) {386 if ( is_array( $_POST['theme'] ) ) { 396 387 $themes = get_themes(); 397 388 reset( $themes ); 398 foreach ( (array) $themes as $key => $theme ) {399 if ( $_POST['theme'][ wp_specialchars( $theme['Stylesheet'] ) ] == 'enabled' )389 foreach ( (array) $themes as $key => $theme ) { 390 if ( $_POST['theme'][ wp_specialchars( $theme['Stylesheet'] ) ] == 'enabled' ) 400 391 $allowed_themes[ wp_specialchars( $theme['Stylesheet'] ) ] = true; 401 392 } … … 410 401 $referrer = ( isset($_GET['ref']) ) ? stripslashes($_GET['ref']) : $_SERVER['HTTP_REFERER']; 411 402 $referrer = clean_url($referrer); 412 if ( !headers_sent() ){403 if ( !headers_sent() ) { 413 404 nocache_headers(); 414 405 header( 'Content-Type: text/html; charset=utf-8' ); … … 441 432 case "deleteuser": 442 433 check_admin_referer('deleteuser'); 443 if ( $id != '0' && $id != '1' )434 if ( $id != '0' && $id != '1' ) 444 435 wpmu_delete_user($id); 445 436 … … 455 446 confirm_delete_users( $_POST['allusers'] ); 456 447 echo '</div>'; 457 } elseif ( isset( $_POST[ 'alluser_transfer_delete' ] ) ) {458 if ( is_array( $_POST[ 'blog' ] ) && !empty( $_POST[ 'blog' ] ) ) {459 foreach ( $_POST[ 'blog' ] as $id => $users ) {460 foreach ( $users as $blogid => $user_id ) {448 } elseif ( isset( $_POST[ 'alluser_transfer_delete' ] ) ) { 449 if ( is_array( $_POST[ 'blog' ] ) && !empty( $_POST[ 'blog' ] ) ) { 450 foreach ( $_POST[ 'blog' ] as $id => $users ) { 451 foreach ( $users as $blogid => $user_id ) { 461 452 remove_user_from_blog( $id, $blogid, $user_id ); 462 453 } 463 454 } 464 455 } 465 if ( is_array( $_POST[ 'user' ] ) && !empty( $_POST[ 'user' ] ) )456 if ( is_array( $_POST[ 'user' ] ) && !empty( $_POST[ 'user' ] ) ) 466 457 foreach( $_POST[ 'user' ] as $id ) 467 458 wpmu_delete_user( $id ); … … 470 461 } else { 471 462 foreach ( (array) $_POST['allusers'] as $key => $val ) { 472 if ( $val == '' || $val == '0' ) {463 if ( $val == '' || $val == '0' ) 473 464 continue; 474 }475 465 $user = new WP_User( $val ); 476 if ( in_array( $user->user_login, get_site_option( 'site_admins', array( 'admin' ) ) ) ) {466 if ( in_array( $user->user_login, get_site_option( 'site_admins', array( 'admin' ) ) ) ) 477 467 wp_die( sprintf( __( 'Warning! User cannot be modified. The user %s is a site admnistrator.' ), $user->user_login ) ); 478 }479 468 if ( isset($_POST['alluser_spam']) ) { 480 469 $userfunction = 'all_spam'; … … 502 491 check_admin_referer('add-user'); 503 492 504 if ( is_array( $_POST[ 'user' ] ) == false ) {493 if ( is_array( $_POST[ 'user' ] ) == false ) 505 494 wp_die( __( "Cannot create an empty user." ) ); 506 }507 495 $user = $_POST['user']; 508 if ( empty($user['username']) && empty($user['email']) ) {496 if ( empty($user['username']) && empty($user['email']) ) 509 497 wp_die( __('Missing username and email.') ); 510 } elseif ( empty($user['username']) ) {498 elseif ( empty($user['username']) ) 511 499 wp_die( __('Missing username.') ); 512 } elseif ( empty($user['email']) ) {500 elseif ( empty($user['email']) ) 513 501 wp_die( __('Missing email.') ); 514 }515 502 516 503 $password = generate_random_password(); 517 504 $user_id = wpmu_create_user(wp_specialchars( strtolower( $user['username'] ) ), $password, wp_specialchars( $user['email'] ) ); 518 505 519 if ( false == $user_id ) {506 if ( false == $user_id ) 520 507 wp_die( __('Duplicated username or email address.') ); 521 } else {508 else 522 509 wp_new_user_notification($user_id, $password); 523 } 524 if ( get_site_option( 'dashboard_blog' ) == false ) {510 511 if ( get_site_option( 'dashboard_blog' ) == false ) 525 512 add_user_to_blog( $current_site->blog_id, $user_id, get_site_option( 'default_user_role', 'subscriber' ) ); 526 } else {513 else 527 514 add_user_to_blog( get_site_option( 'dashboard_blog' ), $user_id, get_site_option( 'default_user_role', 'subscriber' ) ); 528 }529 515 530 516 wp_redirect( add_query_arg( array('updated' => 'true', 'action' => 'add'), $_SERVER['HTTP_REFERER'] ) );
Note: See TracChangeset
for help on using the changeset viewer.