Edit File by line
/home/barbar84/public_h.../wp-admin/network
File: site-new.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Add Site Administration Screen
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Multisite
[5] Fix | Delete
* @since 3.1.0
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
/** Load WordPress Administration Bootstrap */
[9] Fix | Delete
require_once __DIR__ . '/admin.php';
[10] Fix | Delete
[11] Fix | Delete
/** WordPress Translation Installation API */
[12] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/translation-install.php';
[13] Fix | Delete
[14] Fix | Delete
if ( ! current_user_can( 'create_sites' ) ) {
[15] Fix | Delete
wp_die( __( 'Sorry, you are not allowed to add sites to this network.' ) );
[16] Fix | Delete
}
[17] Fix | Delete
[18] Fix | Delete
get_current_screen()->add_help_tab(
[19] Fix | Delete
array(
[20] Fix | Delete
'id' => 'overview',
[21] Fix | Delete
'title' => __( 'Overview' ),
[22] Fix | Delete
'content' =>
[23] Fix | Delete
'<p>' . __( 'This screen is for Super Admins to add new sites to the network. This is not affected by the registration settings.' ) . '</p>' .
[24] Fix | Delete
'<p>' . __( 'If the admin email for the new site does not exist in the database, a new user will also be created.' ) . '</p>',
[25] Fix | Delete
)
[26] Fix | Delete
);
[27] Fix | Delete
[28] Fix | Delete
get_current_screen()->set_help_sidebar(
[29] Fix | Delete
'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
[30] Fix | Delete
'<p>' . __( '<a href="https://wordpress.org/support/article/network-admin-sites-screen/">Documentation on Site Management</a>' ) . '</p>' .
[31] Fix | Delete
'<p>' . __( '<a href="https://wordpress.org/support/forum/multisite/">Support Forums</a>' ) . '</p>'
[32] Fix | Delete
);
[33] Fix | Delete
[34] Fix | Delete
if ( isset( $_REQUEST['action'] ) && 'add-site' === $_REQUEST['action'] ) {
[35] Fix | Delete
check_admin_referer( 'add-blog', '_wpnonce_add-blog' );
[36] Fix | Delete
[37] Fix | Delete
if ( ! is_array( $_POST['blog'] ) ) {
[38] Fix | Delete
wp_die( __( 'Can&#8217;t create an empty site.' ) );
[39] Fix | Delete
}
[40] Fix | Delete
[41] Fix | Delete
$blog = $_POST['blog'];
[42] Fix | Delete
$domain = '';
[43] Fix | Delete
[44] Fix | Delete
$blog['domain'] = trim( $blog['domain'] );
[45] Fix | Delete
if ( preg_match( '|^([a-zA-Z0-9-])+$|', $blog['domain'] ) ) {
[46] Fix | Delete
$domain = strtolower( $blog['domain'] );
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
// If not a subdomain installation, make sure the domain isn't a reserved word.
[50] Fix | Delete
if ( ! is_subdomain_install() ) {
[51] Fix | Delete
$subdirectory_reserved_names = get_subdirectory_reserved_names();
[52] Fix | Delete
[53] Fix | Delete
if ( in_array( $domain, $subdirectory_reserved_names, true ) ) {
[54] Fix | Delete
wp_die(
[55] Fix | Delete
sprintf(
[56] Fix | Delete
/* translators: %s: Reserved names list. */
[57] Fix | Delete
__( 'The following words are reserved for use by WordPress functions and cannot be used as blog names: %s' ),
[58] Fix | Delete
'<code>' . implode( '</code>, <code>', $subdirectory_reserved_names ) . '</code>'
[59] Fix | Delete
)
[60] Fix | Delete
);
[61] Fix | Delete
}
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
$title = $blog['title'];
[65] Fix | Delete
[66] Fix | Delete
$meta = array(
[67] Fix | Delete
'public' => 1,
[68] Fix | Delete
);
[69] Fix | Delete
[70] Fix | Delete
// Handle translation installation for the new site.
[71] Fix | Delete
if ( isset( $_POST['WPLANG'] ) ) {
[72] Fix | Delete
if ( '' === $_POST['WPLANG'] ) {
[73] Fix | Delete
$meta['WPLANG'] = ''; // en_US
[74] Fix | Delete
} elseif ( in_array( $_POST['WPLANG'], get_available_languages(), true ) ) {
[75] Fix | Delete
$meta['WPLANG'] = $_POST['WPLANG'];
[76] Fix | Delete
} elseif ( current_user_can( 'install_languages' ) && wp_can_install_language_pack() ) {
[77] Fix | Delete
$language = wp_download_language_pack( wp_unslash( $_POST['WPLANG'] ) );
[78] Fix | Delete
if ( $language ) {
[79] Fix | Delete
$meta['WPLANG'] = $language;
[80] Fix | Delete
}
[81] Fix | Delete
}
[82] Fix | Delete
}
[83] Fix | Delete
[84] Fix | Delete
if ( empty( $domain ) ) {
[85] Fix | Delete
wp_die( __( 'Missing or invalid site address.' ) );
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
if ( isset( $blog['email'] ) && '' === trim( $blog['email'] ) ) {
[89] Fix | Delete
wp_die( __( 'Missing email address.' ) );
[90] Fix | Delete
}
[91] Fix | Delete
[92] Fix | Delete
$email = sanitize_email( $blog['email'] );
[93] Fix | Delete
if ( ! is_email( $email ) ) {
[94] Fix | Delete
wp_die( __( 'Invalid email address.' ) );
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
if ( is_subdomain_install() ) {
[98] Fix | Delete
$newdomain = $domain . '.' . preg_replace( '|^www\.|', '', get_network()->domain );
[99] Fix | Delete
$path = get_network()->path;
[100] Fix | Delete
} else {
[101] Fix | Delete
$newdomain = get_network()->domain;
[102] Fix | Delete
$path = get_network()->path . $domain . '/';
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
$password = 'N/A';
[106] Fix | Delete
$user_id = email_exists( $email );
[107] Fix | Delete
if ( ! $user_id ) { // Create a new user with a random password.
[108] Fix | Delete
/**
[109] Fix | Delete
* Fires immediately before a new user is created via the network site-new.php page.
[110] Fix | Delete
*
[111] Fix | Delete
* @since 4.5.0
[112] Fix | Delete
*
[113] Fix | Delete
* @param string $email Email of the non-existent user.
[114] Fix | Delete
*/
[115] Fix | Delete
do_action( 'pre_network_site_new_created_user', $email );
[116] Fix | Delete
[117] Fix | Delete
$user_id = username_exists( $domain );
[118] Fix | Delete
if ( $user_id ) {
[119] Fix | Delete
wp_die( __( 'The domain or path entered conflicts with an existing username.' ) );
[120] Fix | Delete
}
[121] Fix | Delete
$password = wp_generate_password( 12, false );
[122] Fix | Delete
$user_id = wpmu_create_user( $domain, $password, $email );
[123] Fix | Delete
if ( false === $user_id ) {
[124] Fix | Delete
wp_die( __( 'There was an error creating the user.' ) );
[125] Fix | Delete
}
[126] Fix | Delete
[127] Fix | Delete
/**
[128] Fix | Delete
* Fires after a new user has been created via the network site-new.php page.
[129] Fix | Delete
*
[130] Fix | Delete
* @since 4.4.0
[131] Fix | Delete
*
[132] Fix | Delete
* @param int $user_id ID of the newly created user.
[133] Fix | Delete
*/
[134] Fix | Delete
do_action( 'network_site_new_created_user', $user_id );
[135] Fix | Delete
}
[136] Fix | Delete
[137] Fix | Delete
$wpdb->hide_errors();
[138] Fix | Delete
$id = wpmu_create_blog( $newdomain, $path, $title, $user_id, $meta, get_current_network_id() );
[139] Fix | Delete
$wpdb->show_errors();
[140] Fix | Delete
[141] Fix | Delete
if ( ! is_wp_error( $id ) ) {
[142] Fix | Delete
if ( ! is_super_admin( $user_id ) && ! get_user_option( 'primary_blog', $user_id ) ) {
[143] Fix | Delete
update_user_option( $user_id, 'primary_blog', $id, true );
[144] Fix | Delete
}
[145] Fix | Delete
[146] Fix | Delete
wpmu_new_site_admin_notification( $id, $user_id );
[147] Fix | Delete
wpmu_welcome_notification( $id, $user_id, $password, $title, array( 'public' => 1 ) );
[148] Fix | Delete
wp_redirect(
[149] Fix | Delete
add_query_arg(
[150] Fix | Delete
array(
[151] Fix | Delete
'update' => 'added',
[152] Fix | Delete
'id' => $id,
[153] Fix | Delete
),
[154] Fix | Delete
'site-new.php'
[155] Fix | Delete
)
[156] Fix | Delete
);
[157] Fix | Delete
exit;
[158] Fix | Delete
} else {
[159] Fix | Delete
wp_die( $id->get_error_message() );
[160] Fix | Delete
}
[161] Fix | Delete
}
[162] Fix | Delete
[163] Fix | Delete
if ( isset( $_GET['update'] ) ) {
[164] Fix | Delete
$messages = array();
[165] Fix | Delete
if ( 'added' === $_GET['update'] ) {
[166] Fix | Delete
$messages[] = sprintf(
[167] Fix | Delete
/* translators: 1: Dashboard URL, 2: Network admin edit URL. */
[168] Fix | Delete
__( 'Site added. <a href="%1$s">Visit Dashboard</a> or <a href="%2$s">Edit Site</a>' ),
[169] Fix | Delete
esc_url( get_admin_url( absint( $_GET['id'] ) ) ),
[170] Fix | Delete
network_admin_url( 'site-info.php?id=' . absint( $_GET['id'] ) )
[171] Fix | Delete
);
[172] Fix | Delete
}
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
$title = __( 'Add New Site' );
[176] Fix | Delete
$parent_file = 'sites.php';
[177] Fix | Delete
[178] Fix | Delete
wp_enqueue_script( 'user-suggest' );
[179] Fix | Delete
[180] Fix | Delete
require_once ABSPATH . 'wp-admin/admin-header.php';
[181] Fix | Delete
[182] Fix | Delete
?>
[183] Fix | Delete
[184] Fix | Delete
<div class="wrap">
[185] Fix | Delete
<h1 id="add-new-site"><?php _e( 'Add New Site' ); ?></h1>
[186] Fix | Delete
<?php
[187] Fix | Delete
if ( ! empty( $messages ) ) {
[188] Fix | Delete
foreach ( $messages as $msg ) {
[189] Fix | Delete
echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
[190] Fix | Delete
}
[191] Fix | Delete
}
[192] Fix | Delete
?>
[193] Fix | Delete
<p>
[194] Fix | Delete
<?php
[195] Fix | Delete
printf(
[196] Fix | Delete
/* translators: %s: Asterisk symbol (*). */
[197] Fix | Delete
__( 'Required fields are marked %s' ),
[198] Fix | Delete
'<span class="required">*</span>'
[199] Fix | Delete
);
[200] Fix | Delete
?>
[201] Fix | Delete
</p>
[202] Fix | Delete
<form method="post" action="<?php echo network_admin_url( 'site-new.php?action=add-site' ); ?>" novalidate="novalidate">
[203] Fix | Delete
<?php wp_nonce_field( 'add-blog', '_wpnonce_add-blog' ); ?>
[204] Fix | Delete
<table class="form-table" role="presentation">
[205] Fix | Delete
<tr class="form-field form-required">
[206] Fix | Delete
<th scope="row"><label for="site-address"><?php _e( 'Site Address (URL)' ); ?> <span class="required">*</span></label></th>
[207] Fix | Delete
<td>
[208] Fix | Delete
<?php if ( is_subdomain_install() ) { ?>
[209] Fix | Delete
<input name="blog[domain]" type="text" class="regular-text ltr" id="site-address" aria-describedby="site-address-desc" autocapitalize="none" autocorrect="off" required /><span class="no-break">.<?php echo preg_replace( '|^www\.|', '', get_network()->domain ); ?></span>
[210] Fix | Delete
<?php
[211] Fix | Delete
} else {
[212] Fix | Delete
echo get_network()->domain . get_network()->path
[213] Fix | Delete
?>
[214] Fix | Delete
<input name="blog[domain]" type="text" class="regular-text ltr" id="site-address" aria-describedby="site-address-desc" autocapitalize="none" autocorrect="off" required />
[215] Fix | Delete
<?php
[216] Fix | Delete
}
[217] Fix | Delete
echo '<p class="description" id="site-address-desc">' . __( 'Only lowercase letters (a-z), numbers, and hyphens are allowed.' ) . '</p>';
[218] Fix | Delete
?>
[219] Fix | Delete
</td>
[220] Fix | Delete
</tr>
[221] Fix | Delete
<tr class="form-field form-required">
[222] Fix | Delete
<th scope="row"><label for="site-title"><?php _e( 'Site Title' ); ?> <span class="required">*</span></label></th>
[223] Fix | Delete
<td><input name="blog[title]" type="text" class="regular-text" id="site-title" required /></td>
[224] Fix | Delete
</tr>
[225] Fix | Delete
<?php
[226] Fix | Delete
$languages = get_available_languages();
[227] Fix | Delete
$translations = wp_get_available_translations();
[228] Fix | Delete
if ( ! empty( $languages ) || ! empty( $translations ) ) :
[229] Fix | Delete
?>
[230] Fix | Delete
<tr class="form-field form-required">
[231] Fix | Delete
<th scope="row"><label for="site-language"><?php _e( 'Site Language' ); ?></label></th>
[232] Fix | Delete
<td>
[233] Fix | Delete
<?php
[234] Fix | Delete
// Network default.
[235] Fix | Delete
$lang = get_site_option( 'WPLANG' );
[236] Fix | Delete
[237] Fix | Delete
// Use English if the default isn't available.
[238] Fix | Delete
if ( ! in_array( $lang, $languages, true ) ) {
[239] Fix | Delete
$lang = '';
[240] Fix | Delete
}
[241] Fix | Delete
[242] Fix | Delete
wp_dropdown_languages(
[243] Fix | Delete
array(
[244] Fix | Delete
'name' => 'WPLANG',
[245] Fix | Delete
'id' => 'site-language',
[246] Fix | Delete
'selected' => $lang,
[247] Fix | Delete
'languages' => $languages,
[248] Fix | Delete
'translations' => $translations,
[249] Fix | Delete
'show_available_translations' => current_user_can( 'install_languages' ) && wp_can_install_language_pack(),
[250] Fix | Delete
)
[251] Fix | Delete
);
[252] Fix | Delete
?>
[253] Fix | Delete
</td>
[254] Fix | Delete
</tr>
[255] Fix | Delete
<?php endif; // Languages. ?>
[256] Fix | Delete
<tr class="form-field form-required">
[257] Fix | Delete
<th scope="row"><label for="admin-email"><?php _e( 'Admin Email' ); ?> <span class="required">*</span></label></th>
[258] Fix | Delete
<td><input name="blog[email]" type="email" class="regular-text wp-suggest-user" id="admin-email" data-autocomplete-type="search" data-autocomplete-field="user_email" aria-describedby="site-admin-email" required /></td>
[259] Fix | Delete
</tr>
[260] Fix | Delete
<tr class="form-field">
[261] Fix | Delete
<td colspan="2" class="td-full"><p id="site-admin-email"><?php _e( 'A new user will be created if the above email address is not in the database.' ); ?><br /><?php _e( 'The username and a link to set the password will be mailed to this email address.' ); ?></p></td>
[262] Fix | Delete
</tr>
[263] Fix | Delete
</table>
[264] Fix | Delete
[265] Fix | Delete
<?php
[266] Fix | Delete
/**
[267] Fix | Delete
* Fires at the end of the new site form in network admin.
[268] Fix | Delete
*
[269] Fix | Delete
* @since 4.5.0
[270] Fix | Delete
*/
[271] Fix | Delete
do_action( 'network_site_new_form' );
[272] Fix | Delete
[273] Fix | Delete
submit_button( __( 'Add Site' ), 'primary', 'add-site' );
[274] Fix | Delete
?>
[275] Fix | Delete
</form>
[276] Fix | Delete
</div>
[277] Fix | Delete
<?php
[278] Fix | Delete
require_once ABSPATH . 'wp-admin/admin-footer.php';
[279] Fix | Delete
[280] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function