3 * Add Site Administration Screen
6 * @subpackage Multisite
10 /** Load WordPress Administration Bootstrap */
11 require_once( './admin.php' );
13 if ( ! is_multisite() )
14 wp_die( __( 'Multisite support is not enabled.' ) );
16 if ( ! current_user_can( 'manage_sites' ) )
17 wp_die( __( 'You do not have sufficient permissions to add sites to this network.' ) );
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>'
27 if ( isset($_REQUEST['action']) && 'add-site' == $_REQUEST['action'] ) {
28 check_admin_referer( 'add-blog', '_wpnonce_add-blog' );
30 if ( ! current_user_can( 'manage_sites' ) )
31 wp_die( __( 'You do not have permission to access this page.' ) );
33 if ( ! is_array( $_POST['blog'] ) )
34 wp_die( __( 'Can’t create an empty site.' ) );
35 $blog = $_POST['blog'];
37 if ( ! preg_match( '/(--)/', $blog['domain'] ) && preg_match( '|^([a-zA-Z0-9-])+$|', $blog['domain'] ) )
38 $domain = strtolower( $blog['domain'] );
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 ) ) );
47 $email = sanitize_email( $blog['email'] );
48 $title = $blog['title'];
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.' ) );
57 if ( is_subdomain_install() ) {
58 $newdomain = $domain . '.' . preg_replace( '|^www\.|', '', $current_site->domain );
61 $newdomain = $current_site->domain;
62 $path = $base . $domain . '/';
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.' ) );
73 wp_new_user_notification( $user_id, $password );
77 $id = wpmu_create_blog( $newdomain, $path, $title, $user_id , array( 'public' => 1 ), $current_site->id );
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' ) );
88 wp_die( $id->get_error_message() );
92 if ( isset($_GET['update']) ) {
94 if ( 'added' == $_GET['update'] )
95 $messages[] = __('Site added.');
98 $title = __('Add New Site');
99 $parent_file = 'sites.php';
101 require('../admin-header.php');
106 <?php screen_icon('ms-admin'); ?>
107 <h2 id="add-new-site"><?php _e('Add New Site') ?></h2>
109 if ( ! empty( $messages ) ) {
110 foreach ( $messages as $msg )
111 echo '<div id="message" class="updated"><p>' . $msg . '</p></div>';
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>
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 );?>
122 echo $current_site->domain . $current_site->path ?><input name="blog[domain]" class="regular-text" type="text" title="<?php _e( 'Domain' ) ?>"/>
124 echo '<p>' . __( 'Only the characters a-z and 0-9 recommended.' ) . '</p>';
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>
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>
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>
140 <?php submit_button( __('Add Site'), 'primary', 'add-site' ); ?>
144 require('../admin-footer.php');