Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/ms-edit.php

    r15470 r16847  
    1010require_once( './admin.php' );
    1111
    12 if ( ! is_multisite() )
    13     wp_die( __( 'Multisite support is not enabled.' ) );
    14 
    15 if ( empty( $_GET['action'] ) )
    16     wp_redirect( admin_url( 'ms-admin.php' ) );
    17 
    18 do_action( 'wpmuadminedit' , '');
    19 
    20 if ( isset( $_GET['id' ]) )
    21     $id = intval( $_GET['id'] );
    22 elseif ( isset( $_POST['id'] ) )
    23     $id = intval( $_POST['id'] );
    24 
    25 switch ( $_GET['action'] ) {
    26     case 'siteoptions':
    27         check_admin_referer( 'siteoptions' );
    28         if ( ! current_user_can( 'manage_network_options' ) )
    29             wp_die( __( 'You do not have permission to access this page.' ) );
    30 
    31         if ( empty( $_POST ) )
    32             wp_die( sprintf( __( 'You probably need to go back to the <a href="%s">options page</a>.', esc_url( admin_url( 'ms-options.php' ) ) ) ) );
    33 
    34         if ( isset($_POST['WPLANG']) && ( '' === $_POST['WPLANG'] || in_array( $_POST['WPLANG'], get_available_languages() ) ) )
    35             update_site_option( 'WPLANG', $_POST['WPLANG'] );
    36 
    37         if ( is_email( $_POST['admin_email'] ) )
    38             update_site_option( 'admin_email', $_POST['admin_email'] );
    39 
    40         $illegal_names = split( ' ', $_POST['illegal_names'] );
    41         foreach ( (array) $illegal_names as $name ) {
    42             $name = trim( $name );
    43             if ( $name != '' )
    44                 $names[] = trim( $name );
    45         }
    46         update_site_option( 'illegal_names', $names );
    47 
    48         if ( $_POST['limited_email_domains'] != '' ) {
    49             $limited_email_domains = str_replace( ' ', "\n", $_POST['limited_email_domains'] );
    50             $limited_email_domains = split( "\n", stripslashes( $limited_email_domains ) );
    51             $limited_email = array();
    52             foreach ( (array) $limited_email_domains as $domain ) {
    53                     $domain = trim( $domain );
    54                 if ( ! preg_match( '/(--|\.\.)/', $domain ) && preg_match( '|^([a-zA-Z0-9-\.])+$|', $domain ) )
    55                     $limited_email[] = trim( $domain );
    56             }
    57             update_site_option( 'limited_email_domains', $limited_email );
    58         } else {
    59             update_site_option( 'limited_email_domains', '' );
    60         }
    61 
    62         if ( $_POST['banned_email_domains'] != '' ) {
    63             $banned_email_domains = split( "\n", stripslashes( $_POST['banned_email_domains'] ) );
    64             $banned = array();
    65             foreach ( (array) $banned_email_domains as $domain ) {
    66                 $domain = trim( $domain );
    67                 if ( ! preg_match( '/(--|\.\.)/', $domain ) && preg_match( '|^([a-zA-Z0-9-\.])+$|', $domain ) )
    68                     $banned[] = trim( $domain );
    69             }
    70             update_site_option( 'banned_email_domains', $banned );
    71         } else {
    72             update_site_option( 'banned_email_domains', '' );
    73         }
    74         update_site_option( 'default_user_role', $_POST['default_user_role'] );
    75         if ( trim( $_POST['dashboard_blog_orig'] ) == '' )
    76             $_POST['dashboard_blog_orig'] = $current_site->blog_id;
    77         if ( trim( $_POST['dashboard_blog'] ) == '' ) {
    78             $_POST['dashboard_blog'] = $current_site->blog_id;
    79             $dashboard_blog_id = $current_site->blog_id;
    80         } elseif ( ! preg_match( '/(--|\.)/', $_POST['dashboard_blog'] ) && preg_match( '|^([a-zA-Z0-9-\.])+$|', $_POST['dashboard_blog'] ) ) {
    81             $dashboard_blog = $_POST['dashboard_blog'];
    82             $blog_details = get_blog_details( $dashboard_blog );
    83             if ( false === $blog_details ) {
    84                 if ( is_numeric( $dashboard_blog ) )
    85                     wp_die( __( 'A dashboard site referenced by ID must already exist' ) );
    86                 if ( is_subdomain_install() ) {
    87                     $domain = $dashboard_blog . '.' . $current_site->domain;
    88                     $path = $current_site->path;
    89                 } else {
    90                     $domain = $current_site->domain;
    91                     $path = trailingslashit( $current_site->path . $dashboard_blog );
    92                 }
    93                 $wpdb->hide_errors();
    94                 $dashboard_blog_id = wpmu_create_blog( $domain, $path, __( 'My Dashboard' ), $current_user->id , array( 'public' => 0 ), $current_site->id );
    95                 $wpdb->show_errors();
    96             } else {
    97                 $dashboard_blog_id = $blog_details->blog_id;
    98             }
    99         }
    100         if ( is_wp_error( $dashboard_blog_id ) )
    101             wp_die( __( 'Problem creating dashboard site: ' ) . $dashboard_blog_id->get_error_message() );
    102         if ( $_POST['dashboard_blog_orig'] != $_POST['dashboard_blog'] ) {
    103             $users = get_users_of_blog( get_site_option( 'dashboard_blog' ) );
    104             $move_users = array();
    105             foreach ( (array)$users as $user ) {
    106                 $user_meta_value = unserialize( $user->meta_value );
    107                 if ( is_array( $user_meta_value ) && array_pop( $var_by_ref = array_keys( $user_meta_value ) ) == 'subscriber' )
    108                     $move_users[] = $user->user_id;
    109             }
    110             if ( false == empty( $move_users ) ) {
    111                 foreach ( (array)$move_users as $user_id ) {
    112                     remove_user_from_blog($user_id, get_site_option( 'dashboard_blog' ) );
    113                     add_user_to_blog( $dashboard_blog_id, $user_id, get_site_option( 'default_user_role', 'subscriber' ) );
    114                     update_user_meta( $user_id, 'primary_blog', $dashboard_blog_id );
    115                 }
    116             }
    117         }
    118         update_site_option( 'dashboard_blog', $dashboard_blog_id );
    119 
    120         $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', 'global_terms_enabled' );
    121         $checked_options = array( 'mu_media_buttons' => array(), 'menu_items' => array(), 'registrationnotification' => 'no', 'upload_space_check_disabled' => 1, 'add_new_users' => 0 );
    122         foreach ( $checked_options as $option_name => $option_unchecked_value ) {
    123             if ( ! isset( $_POST[$option_name] ) )
    124                 $_POST[$option_name] = $option_unchecked_value;
    125         }
    126         foreach ( $options as $option_name ) {
    127             if ( ! isset($_POST[$option_name]) )
    128                 continue;
    129             $value = stripslashes_deep( $_POST[$option_name] );
    130             update_site_option( $option_name, $value );
    131         }
    132 
    133         // Update more options here
    134         do_action( 'update_wpmu_options' );
    135 
    136         wp_redirect( add_query_arg( 'updated', 'true', admin_url( 'ms-options.php' ) ) );
    137         exit();
    138     break;
    139     case 'addblog':
    140         check_admin_referer( 'add-blog', '_wpnonce_add-blog' );
    141 
    142         if ( ! current_user_can( 'manage_sites' ) )
    143             wp_die( __( 'You do not have permission to access this page.' ) );
    144 
    145         if ( is_array( $_POST['blog'] ) == false )
    146             wp_die(  __( 'Can&#8217;t create an empty site.' ) );
    147         $blog = $_POST['blog'];
    148         $domain = '';
    149         if ( ! preg_match( '/(--)/', $blog['domain'] ) && preg_match( '|^([a-zA-Z0-9-])+$|', $blog['domain'] ) )
    150             $domain = strtolower( $blog['domain'] );
    151 
    152         // If not a subdomain install, make sure the domain isn't a reserved word
    153         if ( ! is_subdomain_install() ) {
    154             $subdirectory_reserved_names = apply_filters( 'subdirectory_reserved_names', array( 'page', 'comments', 'blog', 'files', 'feed' ) );
    155             if ( in_array( $domain, $subdirectory_reserved_names ) )
    156                 wp_die( sprintf( __('The following words are reserved for use by WordPress functions and cannot be used as blog names: <code>%s</code>' ), implode( '</code>, <code>', $subdirectory_reserved_names ) ) );
    157         }
    158 
    159         $email = sanitize_email( $blog['email'] );
    160         $title = $blog['title'];
    161 
    162         if ( empty( $domain ) )
    163             wp_die( __( 'Missing or invalid site address.' ) );
    164         if ( empty( $email ) )
    165             wp_die( __( 'Missing email address.' ) );
    166         if ( !is_email( $email ) )
    167             wp_die( __( 'Invalid email address.' ) );
    168 
    169         if ( is_subdomain_install() ) {
    170             $newdomain = $domain . '.' . preg_replace( '|^www\.|', '', $current_site->domain );
    171             $path = $base;
    172         } else {
    173             $newdomain = $current_site->domain;
    174             $path = $base . $domain . '/';
    175         }
    176 
    177         $password = 'N/A';
    178         $user_id = email_exists($email);
    179         if ( !$user_id ) { // Create a new user with a random password
    180             $password = wp_generate_password();
    181             $user_id = wpmu_create_user( $domain, $password, $email );
    182             if ( false == $user_id )
    183                 wp_die( __( 'There was an error creating the user.' ) );
    184             else
    185                 wp_new_user_notification( $user_id, $password );
    186         }
    187 
    188         $wpdb->hide_errors();
    189         $id = wpmu_create_blog( $newdomain, $path, $title, $user_id , array( 'public' => 1 ), $current_site->id );
    190         $wpdb->show_errors();
    191         if ( !is_wp_error( $id ) ) {
    192             $dashboard_blog = get_dashboard_blog();
    193             if ( !is_super_admin( $user_id ) && get_user_option( 'primary_blog', $user_id ) == $dashboard_blog->blog_id )
    194                 update_user_option( $user_id, 'primary_blog', $id, true );
    195             $content_mail = sprintf( __( "New site created by %1s\n\nAddress: http://%2s\nName: %3s"), $current_user->user_login , $newdomain . $path, stripslashes( $title ) );
    196             wp_mail( get_site_option('admin_email'),  sprintf( __( '[%s] New Site Created' ), $current_site->site_name ), $content_mail, 'From: "Site Admin" <' . get_site_option( 'admin_email' ) . '>' );
    197             wpmu_welcome_notification( $id, $user_id, $password, $title, array( 'public' => 1 ) );
    198             wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'add-blog' ), wp_get_referer() ) );
    199             exit();
    200         } else {
    201             wp_die( $id->get_error_message() );
    202         }
    203     break;
    204 
    205     case 'updateblog':
    206         check_admin_referer( 'editblog' );
    207         if ( ! current_user_can( 'manage_sites' ) )
    208             wp_die( __( 'You do not have permission to access this page.' ) );
    209 
    210         if ( empty( $_POST ) )
    211             wp_die( sprintf( __( 'You probably need to go back to the <a href="%s">sites page</a>', esc_url( admin_url( 'ms-sites.php' ) ) ) ) );
    212 
    213         switch_to_blog( $id );
    214 
    215         // themes
    216         $allowedthemes = array();
    217         if ( isset($_POST['theme']) && is_array( $_POST['theme'] ) ) {
    218             foreach ( $_POST['theme'] as $theme => $val ) {
    219                 if ( 'on' == $val )
    220                     $allowedthemes[$theme] = true;
    221             }
    222         }
    223         update_option( 'allowedthemes',  $allowedthemes );
    224 
    225         // options
    226         if ( is_array( $_POST['option'] ) ) {
    227             $c = 1;
    228             $count = count( $_POST['option'] );
    229             $skip_options = array( 'allowedthemes' ); // Don't update these options since they are handled elsewhere in the form.
    230             foreach ( (array) $_POST['option'] as $key => $val ) {
    231                 if ( $key === 0 || is_array( $val ) || in_array($key, $skip_options) )
    232                     continue; // Avoids "0 is a protected WP option and may not be modified" error when edit blog options
    233                 if ( $c == $count )
    234                     update_option( $key, stripslashes( $val ) );
    235                 else
    236                     update_option( $key, stripslashes( $val ), false ); // no need to refresh blog details yet
    237                 $c++;
    238             }
    239         }
    240 
    241         // home and siteurl
    242         if ( isset( $_POST['update_home_url'] ) && $_POST['update_home_url'] == 'update' ) {
    243             $blog_address = get_blogaddress_by_domain( $_POST['blog']['domain'], $_POST['blog']['path'] );
    244             if ( get_option( 'siteurl' ) !=  $blog_address )
    245                 update_option( 'siteurl', $blog_address );
    246 
    247             if ( get_option( 'home' ) != $blog_address )
    248                 update_option( 'home', $blog_address );
    249         }
    250 
    251         // rewrite rules can't be flushed during switch to blog
    252         delete_option( 'rewrite_rules' );
    253 
    254         // update blogs table
    255         $blog_data = stripslashes_deep( $_POST['blog'] );
    256         update_blog_details( $id, $blog_data );
    257 
    258         // get blog prefix
    259         $blog_prefix = $wpdb->get_blog_prefix( $id );
    260 
    261         // user roles
    262         if ( isset( $_POST['role'] ) && is_array( $_POST['role'] ) == true ) {
    263             $newroles = $_POST['role'];
    264 
    265             reset( $newroles );
    266             foreach ( (array) $newroles as $userid => $role ) {
    267                 $user = new WP_User( $userid );
    268                 if ( empty( $user->ID ) )
    269                     continue;
    270                 $user->for_blog( $id );
    271                 $user->set_role( $role );
    272             }
    273         }
    274 
    275         // remove user
    276         if ( isset( $_POST['blogusers'] ) && is_array( $_POST['blogusers'] ) ) {
    277             reset( $_POST['blogusers'] );
    278             foreach ( (array) $_POST['blogusers'] as $key => $val )
    279                 remove_user_from_blog( $key, $id );
    280         }
    281 
    282         // change password
    283         if ( isset( $_POST['user_password'] ) && is_array( $_POST['user_password'] ) ) {
    284             reset( $_POST['user_password'] );
    285             $newroles = $_POST['role'];
    286             foreach ( (array) $_POST['user_password'] as $userid => $pass ) {
    287                 unset( $_POST['role'] );
    288                 $_POST['role'] = $newroles[ $userid ];
    289                 if ( $pass != '' ) {
    290                     $cap = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM {$wpdb->usermeta} WHERE user_id = %d AND meta_key = '{$blog_prefix}capabilities' AND meta_value = 'a:0:{}'", $userid ) );
    291                     $userdata = get_userdata($userid);
    292                     $_POST['pass1'] = $_POST['pass2'] = $pass;
    293                     $_POST['email'] = $userdata->user_email;
    294                     $_POST['rich_editing'] = $userdata->rich_editing;
    295                     edit_user( $userid );
    296                     if ( $cap == null )
    297                         $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->usermeta} WHERE user_id = %d AND meta_key = '{$blog_prefix}capabilities' AND meta_value = 'a:0:{}'", $userid ) );
    298                 }
    299             }
    300             unset( $_POST['role'] );
    301             $_POST['role'] = $newroles;
    302         }
    303 
    304         // add user
    305         if ( !empty( $_POST['newuser'] ) ) {
    306             $newuser = $_POST['newuser'];
    307             $userid = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->users . " WHERE user_login = %s", $newuser ) );
    308             if ( $userid ) {
    309                 $user = $wpdb->get_var( "SELECT user_id FROM " . $wpdb->usermeta . " WHERE user_id='$userid' AND meta_key='{$blog_prefix}capabilities'" );
    310                 if ( $user == false )
    311                     add_user_to_blog( $id, $userid, $_POST['new_role'] );
    312             }
    313         }
    314         do_action( 'wpmu_update_blog_options' );
    315         restore_current_blog();
    316         wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'editblog', 'id' => $id ), wp_get_referer() ) );
    317     break;
    318 
    319     case 'deleteblog':
    320         check_admin_referer('deleteblog');
    321         if ( ! current_user_can( 'manage_sites' ) )
    322             wp_die( __( 'You do not have permission to access this page.' ) );
    323 
    324         if ( $id != '0' && $id != $current_site->blog_id )
    325             wpmu_delete_blog( $id, true );
    326 
    327         wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'delete' ), wp_get_referer() ) );
    328         exit();
    329     break;
    330 
    331     case 'allblogs':
    332         if ( isset( $_POST['doaction']) || isset($_POST['doaction2'] ) ) {
    333             check_admin_referer( 'bulk-ms-sites', '_wpnonce_bulk-ms-sites' );
    334 
    335             if ( ! current_user_can( 'manage_sites' ) )
    336                 wp_die( __( 'You do not have permission to access this page.' ) );
    337 
    338             if ( $_GET['action'] != -1 || $_POST['action2'] != -1 )
    339                 $doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
    340 
    341 
    342             foreach ( (array) $_POST['allblogs'] as $key => $val ) {
    343                 if ( $val != '0' && $val != $current_site->blog_id ) {
    344                     switch ( $doaction ) {
    345                         case 'delete':
    346                             $blogfunction = 'all_delete';
    347                             wpmu_delete_blog( $val, true );
    348                         break;
    349 
    350                         case 'spam':
    351                             $blogfunction = 'all_spam';
    352                             update_blog_status( $val, 'spam', '1', 0 );
    353                             set_time_limit( 60 );
    354                         break;
    355 
    356                         case 'notspam':
    357                             $blogfunction = 'all_notspam';
    358                             update_blog_status( $val, 'spam', '0', 0 );
    359                             set_time_limit( 60 );
    360                         break;
    361                     }
    362                 } else {
    363                     wp_die( __( 'You are not allowed to change the current site.' ) );
    364                 }
    365             }
    366 
    367             wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $blogfunction ), wp_get_referer() ) );
    368             exit();
    369         } else {
    370             wp_redirect( admin_url( 'ms-sites.php' ) );
    371         }
    372     break;
    373 
    374     case 'archiveblog':
    375         check_admin_referer( 'archiveblog' );
    376         if ( ! current_user_can( 'manage_sites' ) )
    377             wp_die( __( 'You do not have permission to access this page.' ) );
    378 
    379         update_blog_status( $id, 'archived', '1' );
    380         do_action( 'archive_blog', $id );
    381         wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'archive' ), wp_get_referer() ) );
    382         exit();
    383     break;
    384 
    385     case 'unarchiveblog':
    386         check_admin_referer( 'unarchiveblog' );
    387         if ( ! current_user_can( 'manage_sites' ) )
    388             wp_die( __( 'You do not have permission to access this page.' ) );
    389 
    390         do_action( 'unarchive_blog', $id );
    391         update_blog_status( $id, 'archived', '0' );
    392         wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'unarchive' ), wp_get_referer() ) );
    393         exit();
    394     break;
    395 
    396     case 'activateblog':
    397         check_admin_referer( 'activateblog' );
    398         if ( ! current_user_can( 'manage_sites' ) )
    399             wp_die( __( 'You do not have permission to access this page.' ) );
    400 
    401         update_blog_status( $id, 'deleted', '0' );
    402         do_action( 'activate_blog', $id );
    403         wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'activate' ), wp_get_referer() ) );
    404         exit();
    405     break;
    406 
    407     case 'deactivateblog':
    408         check_admin_referer( 'deactivateblog' );
    409         if ( ! current_user_can( 'manage_sites' ) )
    410             wp_die( __( 'You do not have permission to access this page.' ) );
    411 
    412         do_action( 'deactivate_blog', $id );
    413         update_blog_status( $id, 'deleted', '1' );
    414         wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'deactivate' ), wp_get_referer() ) );
    415         exit();
    416     break;
    417 
    418     case 'unspamblog':
    419         check_admin_referer( 'unspamblog' );
    420         if ( ! current_user_can( 'manage_sites' ) )
    421             wp_die( __( 'You do not have permission to access this page.' ) );
    422 
    423         update_blog_status( $id, 'spam', '0' );
    424         wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'unspam' ), wp_get_referer() ) );
    425         exit();
    426     break;
    427 
    428     case 'spamblog':
    429         check_admin_referer( 'spamblog' );
    430         if ( ! current_user_can( 'manage_sites' ) )
    431             wp_die( __( 'You do not have permission to access this page.' ) );
    432 
    433         update_blog_status( $id, 'spam', '1' );
    434         wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'spam' ), wp_get_referer() ) );
    435         exit();
    436     break;
    437 
    438     // Themes
    439     case 'updatethemes':
    440     if ( ! current_user_can( 'manage_network_themes' ) )
    441         wp_die( __( 'You do not have permission to access this page.' ) );
    442 
    443         if ( is_array( $_POST['theme'] ) ) {
    444             $themes = get_themes();
    445             reset( $themes );
    446             $allowed_themes = array();
    447             foreach ( (array) $themes as $key => $theme ) {
    448                 if ( $_POST['theme'][ esc_html( $theme['Stylesheet'] ) ] == 'enabled' )
    449                     $allowed_themes[ esc_html( $theme['Stylesheet'] ) ] = true;
    450             }
    451             update_site_option( 'allowedthemes', $allowed_themes );
    452         }
    453         wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'themes' ),  wp_get_referer() ) );
    454         exit();
    455     break;
    456 
    457     // Common
    458     case 'confirm':
    459         if ( !headers_sent() ) {
    460             nocache_headers();
    461             header( 'Content-Type: text/html; charset=utf-8' );
    462         }
    463         if ( $current_site->blog_id == $id )
    464             wp_die( __( 'You are not allowed to change the current site.' ) );
    465         ?>
    466         <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    467         <html xmlns="http://www.w3.org/1999/xhtml" <?php if ( function_exists( 'language_attributes' ) ) language_attributes(); ?>>
    468             <head>
    469                 <title><?php _e( 'WordPress &rsaquo; Confirm your action' ); ?></title>
    470 
    471                 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    472                 <?php
    473                 wp_admin_css( 'install', true );
    474                 wp_admin_css( 'ie', true );
    475                 ?>
    476             </head>
    477             <body>
    478                 <h1 id="logo"><img alt="WordPress" src="<?php echo esc_attr( admin_url( 'images/wordpress-logo.png' ) ); ?>" /></h1>
    479                 <form action="ms-edit.php?action=<?php echo esc_attr( $_GET['action2'] ) ?>" method="post">
    480                     <input type="hidden" name="action" value="<?php echo esc_attr( $_GET['action2'] ) ?>" />
    481                     <input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />
    482                     <input type="hidden" name="_wp_http_referer" value="<?php echo esc_attr( wp_get_referer() ); ?>" />
    483                     <?php wp_nonce_field( $_GET['action2'], '_wpnonce', false ); ?>
    484                     <p><?php echo esc_html( stripslashes( $_GET['msg'] ) ); ?></p>
    485                     <p class="submit"><input class="button" type="submit" value="<?php _e( 'Confirm' ); ?>" /></p>
    486                 </form>
    487             </body>
    488         </html>
    489         <?php
    490     break;
    491 
    492     // Users
    493     case 'deleteuser':
    494         if ( ! current_user_can( 'manage_network_users' ) )
    495             wp_die( __( 'You do not have permission to access this page.' ) );
    496 
    497         check_admin_referer( 'deleteuser' );
    498 
    499         if ( $id != '0' && $id != '1' ) {
    500             $_POST['allusers'] = array( $id ); // confirm_delete_users() can only handle with arrays
    501             $title = __( 'Users' );
    502             $parent_file = 'ms-admin.php';
    503             require_once( 'admin-header.php' );
    504             echo '<div class="wrap">';
    505             confirm_delete_users( $_POST['allusers'] );
    506             echo '</div>';
    507             require_once( 'admin-footer.php' );
    508             exit();
    509         } else {
    510             wp_redirect( admin_url( 'ms-users.php' ) );
    511         }
    512     break;
    513 
    514     case 'allusers':
    515         if ( ! current_user_can( 'manage_network_users' ) )
    516             wp_die( __( 'You do not have permission to access this page.' ) );
    517 
    518         if ( isset( $_POST['doaction']) || isset($_POST['doaction2'] ) ) {
    519             check_admin_referer( 'bulk-ms-users', '_wpnonce_bulk-ms-users' );
    520 
    521             if ( $_GET['action'] != -1 || $_POST['action2'] != -1 )
    522                 $doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
    523 
    524             foreach ( (array) $_POST['allusers'] as $key => $val ) {
    525                 if ( !empty( $val ) ) {
    526                     switch ( $doaction ) {
    527                         case 'delete':
    528                             $title = __( 'Users' );
    529                             $parent_file = 'ms-admin.php';
    530                             require_once( 'admin-header.php' );
    531                             echo '<div class="wrap">';
    532                             confirm_delete_users( $_POST['allusers'] );
    533                             echo '</div>';
    534                             require_once( 'admin-footer.php' );
    535                             exit();
    536                         break;
    537 
    538                         case 'spam':
    539                             $user = new WP_User( $val );
    540                             if ( in_array( $user->user_login, get_super_admins() ) )
    541                                 wp_die( sprintf( __( 'Warning! User cannot be modified. The user %s is a network administrator.' ), esc_html( $user->user_login ) ) );
    542 
    543                             $userfunction = 'all_spam';
    544                             $blogs = get_blogs_of_user( $val, true );
    545                             foreach ( (array) $blogs as $key => $details ) {
    546                                 if ( $details->userblog_id != $current_site->blog_id ) // main blog not a spam !
    547                                     update_blog_status( $details->userblog_id, 'spam', '1' );
    548                             }
    549                             update_user_status( $val, 'spam', '1', 1 );
    550                         break;
    551 
    552                         case 'notspam':
    553                             $userfunction = 'all_notspam';
    554                             $blogs = get_blogs_of_user( $val, true );
    555                             foreach ( (array) $blogs as $key => $details )
    556                                 update_blog_status( $details->userblog_id, 'spam', '0' );
    557 
    558                             update_user_status( $val, 'spam', '0', 1 );
    559                         break;
    560                     }
    561                 }
    562             }
    563 
    564             wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $userfunction ), wp_get_referer() ) );
    565             exit();
    566         } else {
    567             wp_redirect( admin_url( 'ms-users.php' ) );
    568         }
    569     break;
    570 
    571     case 'dodelete':
    572         check_admin_referer( 'ms-users-delete' );
    573         if ( ! current_user_can( 'manage_network_users' ) )
    574             wp_die( __( 'You do not have permission to access this page.' ) );
    575 
    576         if ( ! empty( $_POST['blog'] ) && is_array( $_POST['blog'] ) ) {
    577             foreach ( $_POST['blog'] as $id => $users ) {
    578                 foreach ( $users as $blogid => $user_id ) {
    579                     if ( ! empty( $_POST['delete'] ) && 'reassign' == $_POST['delete'][$blogid][$id] )
    580                         remove_user_from_blog( $id, $blogid, $user_id );
    581                     else
    582                         remove_user_from_blog( $id, $blogid );
    583                 }
    584             }
    585         }
    586         $i = 0;
    587         if ( is_array( $_POST['user'] ) && ! empty( $_POST['user'] ) )
    588             foreach( $_POST['user'] as $id ) {
    589                 wpmu_delete_user( $id );
    590                 $i++;
    591             }
    592 
    593         if ( $i == 1 )
    594             $deletefunction = 'delete';
    595         else
    596             $deletefunction = 'all_delete';
    597 
    598         wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $deletefunction ), admin_url( 'ms-users.php' ) ) );
    599     break;
    600 
    601     case 'adduser':
    602         check_admin_referer( 'add-user', '_wpnonce_add-user' );
    603         if ( ! current_user_can( 'manage_network_users' ) )
    604             wp_die( __( 'You do not have permission to access this page.' ) );
    605 
    606         if ( is_array( $_POST['user'] ) == false )
    607             wp_die( __( 'Cannot create an empty user.' ) );
    608         $user = $_POST['user'];
    609         if ( empty($user['username']) && empty($user['email']) )
    610             wp_die( __( 'Missing username and email.' ) );
    611         elseif ( empty($user['username']) )
    612             wp_die( __( 'Missing username.' ) );
    613         elseif ( empty($user['email']) )
    614             wp_die( __( 'Missing email.' ) );
    615 
    616         $password = wp_generate_password();
    617         $user_id = wpmu_create_user( esc_html( strtolower( $user['username'] ) ), $password, esc_html( $user['email'] ) );
    618 
    619         if ( false == $user_id )
    620             wp_die( __( 'Duplicated username or email address.' ) );
    621         else
    622             wp_new_user_notification( $user_id, $password );
    623 
    624         if ( get_site_option( 'dashboard_blog' ) == false )
    625             add_user_to_blog( $current_site->blog_id, $user_id, get_site_option( 'default_user_role', 'subscriber' ) );
    626         else
    627             add_user_to_blog( get_site_option( 'dashboard_blog' ), $user_id, get_site_option( 'default_user_role', 'subscriber' ) );
    628 
    629         wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'add' ), wp_get_referer() ) );
    630         exit();
    631     break;
    632 
    633     default:
    634         wp_redirect( admin_url( 'ms-admin.php' ) );
    635     break;
    636 }
     12wp_redirect( network_admin_url() );
     13exit;
    63714?>
Note: See TracChangeset for help on using the changeset viewer.