Move add site form to site-new.php. see #15174

git-svn-id: https://develop.svn.wordpress.org/trunk@15886 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2010-10-21 13:49:49 +00:00
parent 238431b624
commit e93f819e09
4 changed files with 143 additions and 104 deletions

View File

@ -158,70 +158,6 @@ switch ( $_GET['action'] ) {
wp_redirect( add_query_arg( 'updated', 'true', network_admin_url( 'settings.php' ) ) );
exit();
break;
case 'addblog':
check_admin_referer( 'add-blog', '_wpnonce_add-blog' );
if ( ! current_user_can( 'manage_sites' ) )
wp_die( __( 'You do not have permission to access this page.' ) );
if ( is_array( $_POST['blog'] ) == false )
wp_die( __( 'Can’t create an empty site.' ) );
$blog = $_POST['blog'];
$domain = '';
if ( ! preg_match( '/(--)/', $blog['domain'] ) && preg_match( '|^([a-zA-Z0-9-])+$|', $blog['domain'] ) )
$domain = strtolower( $blog['domain'] );
// If not a subdomain install, make sure the domain isn't a reserved word
if ( ! is_subdomain_install() ) {
$subdirectory_reserved_names = apply_filters( 'subdirectory_reserved_names', array( 'page', 'comments', 'blog', 'files', 'feed' ) );
if ( in_array( $domain, $subdirectory_reserved_names ) )
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 ) ) );
}
$email = sanitize_email( $blog['email'] );
$title = $blog['title'];
if ( empty( $domain ) )
wp_die( __( 'Missing or invalid site address.' ) );
if ( empty( $email ) )
wp_die( __( 'Missing email address.' ) );
if ( !is_email( $email ) )
wp_die( __( 'Invalid email address.' ) );
if ( is_subdomain_install() ) {
$newdomain = $domain . '.' . preg_replace( '|^www\.|', '', $current_site->domain );
$path = $base;
} else {
$newdomain = $current_site->domain;
$path = $base . $domain . '/';
}
$password = 'N/A';
$user_id = email_exists($email);
if ( !$user_id ) { // Create a new user with a random password
$password = wp_generate_password();
$user_id = wpmu_create_user( $domain, $password, $email );
if ( false == $user_id )
wp_die( __( 'There was an error creating the user.' ) );
else
wp_new_user_notification( $user_id, $password );
}
$wpdb->hide_errors();
$id = wpmu_create_blog( $newdomain, $path, $title, $user_id , array( 'public' => 1 ), $current_site->id );
$wpdb->show_errors();
if ( !is_wp_error( $id ) ) {
if ( !is_super_admin( $user_id ) && !get_user_option( 'primary_blog', $user_id ) )
update_user_option( $user_id, 'primary_blog', $id, true );
$content_mail = sprintf( __( "New site created by %1s\n\nAddress: http://%2s\nName: %3s"), $current_user->user_login , $newdomain . $path, stripslashes( $title ) );
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' ) . '>' );
wpmu_welcome_notification( $id, $user_id, $password, $title, array( 'public' => 1 ) );
wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'add-blog' ), wp_get_referer() ) );
exit();
} else {
wp_die( $id->get_error_message() );
}
break;
case 'updateblog':
check_admin_referer( 'editblog' );

View File

@ -14,6 +14,10 @@ $menu[4] = array( '', 'read', 'separator1', '', 'wp-menu-separator' );
/* translators: Sites menu item */
$menu[5] = array(__('Sites'), 'manage_sites', 'sites.php', '', 'menu-top menu-icon-site', 'menu-site', 'div');
$submenu['sites.php'][5] = array( __('Sites'), 'manage_sites', 'sites.php' );
$submenu['sites.php'][10] = array( __('Add New'), 'manage_sites', 'site-new.php' );
$menu[10] = array(__('Users'), 'manage_network_users', 'users.php', '', 'menu-top menu-icon-users', 'menu-users', 'div');
$menu[15] = array(__('Themes'), 'manage_network_themes', 'themes.php', '', 'menu-top menu-icon-appearance', 'menu-appearance', 'div');

View File

@ -0,0 +1,137 @@
<?php
/**
* Add Site Administration Screen
*
* @package WordPress
* @subpackage Administration
*/
/** Load WordPress Administration Bootstrap */
require_once('./admin.php');
if ( ! is_multisite() )
wp_die( __( 'Multisite support is not enabled.' ) );
if ( ! current_user_can('manage_sites') )
wp_die(__('You do not have sufficient permissions to add sites to this network.'));
if ( isset($_REQUEST['action']) && 'add-site' == $_REQUEST['action'] ) {
check_admin_referer( 'add-blog', '_wpnonce_add-blog' );
if ( ! current_user_can( 'manage_sites' ) )
wp_die( __( 'You do not have permission to access this page.' ) );
if ( is_array( $_POST['blog'] ) == false )
wp_die( __( 'Can&#8217;t create an empty site.' ) );
$blog = $_POST['blog'];
$domain = '';
if ( ! preg_match( '/(--)/', $blog['domain'] ) && preg_match( '|^([a-zA-Z0-9-])+$|', $blog['domain'] ) )
$domain = strtolower( $blog['domain'] );
// If not a subdomain install, make sure the domain isn't a reserved word
if ( ! is_subdomain_install() ) {
$subdirectory_reserved_names = apply_filters( 'subdirectory_reserved_names', array( 'page', 'comments', 'blog', 'files', 'feed' ) );
if ( in_array( $domain, $subdirectory_reserved_names ) )
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 ) ) );
}
$email = sanitize_email( $blog['email'] );
$title = $blog['title'];
if ( empty( $domain ) )
wp_die( __( 'Missing or invalid site address.' ) );
if ( empty( $email ) )
wp_die( __( 'Missing email address.' ) );
if ( !is_email( $email ) )
wp_die( __( 'Invalid email address.' ) );
if ( is_subdomain_install() ) {
$newdomain = $domain . '.' . preg_replace( '|^www\.|', '', $current_site->domain );
$path = $base;
} else {
$newdomain = $current_site->domain;
$path = $base . $domain . '/';
}
$password = 'N/A';
$user_id = email_exists($email);
if ( !$user_id ) { // Create a new user with a random password
$password = wp_generate_password();
$user_id = wpmu_create_user( $domain, $password, $email );
if ( false == $user_id )
wp_die( __( 'There was an error creating the user.' ) );
else
wp_new_user_notification( $user_id, $password );
}
$wpdb->hide_errors();
$id = wpmu_create_blog( $newdomain, $path, $title, $user_id , array( 'public' => 1 ), $current_site->id );
$wpdb->show_errors();
if ( !is_wp_error( $id ) ) {
if ( !is_super_admin( $user_id ) && !get_user_option( 'primary_blog', $user_id ) )
update_user_option( $user_id, 'primary_blog', $id, true );
$content_mail = sprintf( __( "New site created by %1s\n\nAddress: http://%2s\nName: %3s"), $current_user->user_login , $newdomain . $path, stripslashes( $title ) );
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' ) . '>' );
wpmu_welcome_notification( $id, $user_id, $password, $title, array( 'public' => 1 ) );
wp_redirect( add_query_arg( array('update' => 'added'), 'site-new.php' ) );
exit;
} else {
wp_die( $id->get_error_message() );
}
}
if ( isset($_GET['update']) ) {
$messages = array();
if ( 'added' == $_GET['update'] )
$messages[] = __('Site added.');
}
$title = __('Add New Site');
$parent_file = 'sites.php';
require('../admin-header.php');
?>
<div class="wrap">
<?php screen_icon(); ?>
<h2 id="add-new-site"><?php _e('Add New Site') ?></h2>
<?php
if ( ! empty( $messages ) ) {
foreach ( $messages as $msg )
echo '<div id="message" class="updated"><p>' . $msg . '</p></div>';
} ?>
<form method="post" action="<?php echo network_admin_url('site-new.php?action=add-site'); ?>">
<?php wp_nonce_field( 'add-blog', '_wpnonce_add-blog' ) ?>
<table class="form-table">
<tr class="form-field form-required">
<th scope="row"><?php _e( 'Site Address' ) ?></th>
<td>
<?php if ( is_subdomain_install() ) { ?>
<input name="blog[domain]" type="text" class="regular-text" title="<?php _e( 'Domain' ) ?>"/>.<?php echo preg_replace( '|^www\.|', '', $current_site->domain );?>
<?php } else {
echo $current_site->domain . $current_site->path ?><input name="blog[domain]" class="regular-text" type="text" title="<?php _e( 'Domain' ) ?>"/>
<?php }
echo '<p>' . __( 'Only the characters a-z and 0-9 recommended.' ) . '</p>';
?>
</td>
</tr>
<tr class="form-field form-required">
<th scope="row"><?php _e( 'Site Title' ) ?></th>
<td><input name="blog[title]" type="text" class="regular-text" title="<?php _e( 'Title' ) ?>"/></td>
</tr>
<tr class="form-field form-required">
<th scope="row"><?php _e( 'Admin Email' ) ?></th>
<td><input name="blog[email]" type="text" class="regular-text" title="<?php _e( 'Email' ) ?>"/></td>
</tr>
<tr class="form-field">
<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>
</tr>
</table>
<?php submit_button( __('Add Site'), 'primary', 'add-site' ); ?>
</form>
</div>
<?php
require('../admin-footer.php');
?>

View File

@ -30,7 +30,7 @@ if ( isset( $_REQUEST['action'] ) && 'editblog' == $_REQUEST['action'] ) {
);
} else {
add_contextual_help($current_screen,
'<p>' . __('Add New takes you farther down on this same page. You can search for a site by Name, ID number, or IP address. Screen Options allows you to choose how many sites to display on one page.') . '</p>' .
'<p>' . __('Add New takes you to the Add New Site screen. You can search for a site by Name, ID number, or IP address. Screen Options allows you to choose how many sites to display on one page.') . '</p>' .
'<p>' . __('This is the main table of all sites on this network. Switch between list and excerpt views by using the icons above the right side of the table.') . '</p>' .
'<p>' . __('Hovering over each site reveals seven options (three for the primary site):') . '</p>' .
'<ul><li>' . __('An Edit link to a separate Edit Site screen.') . '</li>' .
@ -40,7 +40,6 @@ if ( isset( $_REQUEST['action'] ) && 'editblog' == $_REQUEST['action'] ) {
'<li>' . __('Visit to go to the frontend site live.') . '</li></ul>' .
'<p>' . __('The site ID is used internally, and is not shown on the front end of the site or to users/viewers.') . '</p>' .
'<p>' . __('Clicking on bold settings can re-sort this table. The upper right icons switch between list and excerpt views.') . '</p>' .
'<p>' . __("Clicking on Add Site, after filling out the address, title, and admin's email address, adds the site instantly to the network and this table. You may want to then click on the action link to edit options for that site.") . '</p>' .
'<p>' . __('If the admin email for the new site does not exist in the database, a new user will also be created.') . '</p>' .
'<p><strong>' . __('For more information:') . '</strong></p>' .
'<p>' . __('<a href="http://codex.wordpress.org/Super_Admin_Sites_SubPanel" target="_blank">Documentation on Sites</a>') . '</p>' .
@ -65,9 +64,6 @@ if ( isset( $_REQUEST['updated'] ) && $_REQUEST['updated'] == 'true' && ! empty(
case 'delete':
$msg = __( 'Site deleted.' );
break;
case 'add-blog':
$msg = __( 'Site added.' );
break;
case 'archive':
$msg = __( 'Site archived.' );
break;
@ -355,7 +351,7 @@ switch ( $action ) {
<?php screen_icon('index'); ?>
<h2><?php _e('Sites') ?>
<?php echo $msg; ?>
<a href="#form-add-site" class="button add-new-h2"><?php echo esc_html_x( 'Add New', 'sites' ); ?></a>
<a href="<?php echo network_admin_url('site-new.php'); ?>" class="button add-new-h2"><?php echo esc_html_x( 'Add New', 'sites' ); ?></a>
<?php if ( isset( $_REQUEST['s'] ) && $_REQUEST['s'] ) {
printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( $s ) );
} ?>
@ -378,40 +374,6 @@ switch ( $action ) {
<?php $wp_list_table->display(); ?>
</form>
</div>
<div id="form-add-site" class="wrap">
<h3><?php _e( 'Add Site' ) ?></h3>
<form method="post" action="edit.php?action=addblog">
<?php wp_nonce_field( 'add-blog', '_wpnonce_add-blog' ) ?>
<table class="form-table">
<tr class="form-field form-required">
<th scope="row"><?php _e( 'Site Address' ) ?></th>
<td>
<?php if ( is_subdomain_install() ) { ?>
<input name="blog[domain]" type="text" class="regular-text" title="<?php _e( 'Domain' ) ?>"/>.<?php echo preg_replace( '|^www\.|', '', $current_site->domain );?>
<?php } else {
echo $current_site->domain . $current_site->path ?><input name="blog[domain]" class="regular-text" type="text" title="<?php _e( 'Domain' ) ?>"/>
<?php }
echo '<p>' . __( 'Only the characters a-z and 0-9 recommended.' ) . '</p>';
?>
</td>
</tr>
<tr class="form-field form-required">
<th scope="row"><?php _e( 'Site Title' ) ?></th>
<td><input name="blog[title]" type="text" class="regular-text" title="<?php _e( 'Title' ) ?>"/></td>
</tr>
<tr class="form-field form-required">
<th scope="row"><?php _e( 'Admin Email' ) ?></th>
<td><input name="blog[email]" type="text" class="regular-text" title="<?php _e( 'Email' ) ?>"/></td>
</tr>
<tr class="form-field">
<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>
</tr>
</table>
<p class="submit">
<input class="button" type="submit" name="go" value="<?php esc_attr_e( 'Add Site' ) ?>" /></p>
</form>
</div>
<?php
break;
} // end switch( $action )