]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/network/site-new.php
Wordpress 3.1.1-scripts
[autoinstalls/wordpress.git] / wp-admin / network / site-new.php
1 <?php
2 /**
3  * Add Site Administration Screen
4  *
5  * @package WordPress
6  * @subpackage Multisite
7  * @since 3.1.0
8  */
9
10 /** Load WordPress Administration Bootstrap */
11 require_once( './admin.php' );
12
13 if ( ! is_multisite() )
14         wp_die( __( 'Multisite support is not enabled.' ) );
15
16 if ( ! current_user_can( 'manage_sites' ) )
17         wp_die( __( 'You do not have sufficient permissions to add sites to this network.' ) );
18
19 add_contextual_help($current_screen,
20         '<p>' . __('This screen is for Super Admins to add new sites to the network. This is not affected by the registration settings.') . '</p>' .
21         '<p>' . __('If the admin email for the new site does not exist in the database, a new user will also be created.') . '</p>' .
22         '<p><strong>' . __('For more information:') . '</strong></p>' .
23         '<p>' . __('<a href="http://codex.wordpress.org/Network_Admin_Sites_Screens" target="_blank">Documentation on Site Management</a>') . '</p>' .
24         '<p>' . __('<a href="http://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>'
25 );
26
27 if ( isset($_REQUEST['action']) && 'add-site' == $_REQUEST['action'] ) {
28         check_admin_referer( 'add-blog', '_wpnonce_add-blog' );
29
30         if ( ! current_user_can( 'manage_sites' ) )
31                 wp_die( __( 'You do not have permission to access this page.' ) );
32
33         if ( ! is_array( $_POST['blog'] ) )
34                 wp_die( __( 'Can&#8217;t create an empty site.' ) );
35         $blog = $_POST['blog'];
36         $domain = '';
37         if ( ! preg_match( '/(--)/', $blog['domain'] ) && preg_match( '|^([a-zA-Z0-9-])+$|', $blog['domain'] ) )
38                 $domain = strtolower( $blog['domain'] );
39
40         // If not a subdomain install, make sure the domain isn't a reserved word
41         if ( ! is_subdomain_install() ) {
42                 $subdirectory_reserved_names = apply_filters( 'subdirectory_reserved_names', array( 'page', 'comments', 'blog', 'files', 'feed' ) );
43                 if ( in_array( $domain, $subdirectory_reserved_names ) )
44                         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 ) ) );
45         }
46
47         $email = sanitize_email( $blog['email'] );
48         $title = $blog['title'];
49
50         if ( empty( $domain ) )
51                 wp_die( __( 'Missing or invalid site address.' ) );
52         if ( empty( $email ) )
53                 wp_die( __( 'Missing email address.' ) );
54         if ( !is_email( $email ) )
55                 wp_die( __( 'Invalid email address.' ) );
56
57         if ( is_subdomain_install() ) {
58                 $newdomain = $domain . '.' . preg_replace( '|^www\.|', '', $current_site->domain );
59                 $path = $base;
60         } else {
61                 $newdomain = $current_site->domain;
62                 $path = $base . $domain . '/';
63         }
64
65         $password = 'N/A';
66         $user_id = email_exists($email);
67         if ( !$user_id ) { // Create a new user with a random password
68                 $password = wp_generate_password( 12, false );
69                 $user_id = wpmu_create_user( $domain, $password, $email );
70                 if ( false == $user_id )
71                         wp_die( __( 'There was an error creating the user.' ) );
72                 else
73                         wp_new_user_notification( $user_id, $password );
74         }
75
76         $wpdb->hide_errors();
77         $id = wpmu_create_blog( $newdomain, $path, $title, $user_id , array( 'public' => 1 ), $current_site->id );
78         $wpdb->show_errors();
79         if ( !is_wp_error( $id ) ) {
80                 if ( !is_super_admin( $user_id ) && !get_user_option( 'primary_blog', $user_id ) )
81                         update_user_option( $user_id, 'primary_blog', $id, true );
82                 $content_mail = sprintf( __( "New site created by %1s\n\nAddress: http://%2s\nName: %3s"), $current_user->user_login , $newdomain . $path, stripslashes( $title ) );
83                 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' ) . '>' );
84                 wpmu_welcome_notification( $id, $user_id, $password, $title, array( 'public' => 1 ) );
85                 wp_redirect( add_query_arg( array('update' => 'added'), 'site-new.php' ) );
86                 exit;
87         } else {
88                 wp_die( $id->get_error_message() );
89         }
90 }
91
92 if ( isset($_GET['update']) ) {
93         $messages = array();
94         if ( 'added' == $_GET['update'] )
95                 $messages[] = __('Site added.');
96 }
97
98 $title = __('Add New Site');
99 $parent_file = 'sites.php';
100
101 require('../admin-header.php');
102
103 ?>
104
105 <div class="wrap">
106 <?php screen_icon('ms-admin'); ?>
107 <h2 id="add-new-site"><?php _e('Add New Site') ?></h2>
108 <?php
109 if ( ! empty( $messages ) ) {
110         foreach ( $messages as $msg )
111                 echo '<div id="message" class="updated"><p>' . $msg . '</p></div>';
112 } ?>
113 <form method="post" action="<?php echo network_admin_url('site-new.php?action=add-site'); ?>">
114 <?php wp_nonce_field( 'add-blog', '_wpnonce_add-blog' ) ?>
115         <table class="form-table">
116                 <tr class="form-field form-required">
117                         <th scope="row"><?php _e( 'Site Address' ) ?></th>
118                         <td>
119                         <?php if ( is_subdomain_install() ) { ?>
120                                 <input name="blog[domain]" type="text" class="regular-text" title="<?php _e( 'Domain' ) ?>"/>.<?php echo preg_replace( '|^www\.|', '', $current_site->domain );?>
121                         <?php } else {
122                                 echo $current_site->domain . $current_site->path ?><input name="blog[domain]" class="regular-text" type="text" title="<?php _e( 'Domain' ) ?>"/>
123                         <?php }
124                         echo '<p>' . __( 'Only the characters a-z and 0-9 recommended.' ) . '</p>';
125                         ?>
126                         </td>
127                 </tr>
128                 <tr class="form-field form-required">
129                         <th scope="row"><?php _e( 'Site Title' ) ?></th>
130                         <td><input name="blog[title]" type="text" class="regular-text" title="<?php _e( 'Title' ) ?>"/></td>
131                 </tr>
132                 <tr class="form-field form-required">
133                         <th scope="row"><?php _e( 'Admin Email' ) ?></th>
134                         <td><input name="blog[email]" type="text" class="regular-text" title="<?php _e( 'Email' ) ?>"/></td>
135                 </tr>
136                 <tr class="form-field">
137                         <td colspan="2"><?php _e( 'A new user will be created if the above email address is not in the database.' ) ?><br /><?php _e( 'The username and password will be mailed to this email address.' ) ?></td>
138                 </tr>
139         </table>
140         <?php submit_button( __('Add Site'), 'primary', 'add-site' ); ?>
141         </form>
142 </div>
143 <?php
144 require('../admin-footer.php');
145 ?>