My requirement is to add couple of custom fields in the add/edit a site forms without touching the WordPress core. I tried to copy the site-new.php from /wp-admin/network and paste it into my custom plugin but it fails due to many dependencies. I dont think so it is good exercise to copy and paste the whole network folder inside the plugin.
I also tried to callout this hook but instead of override, it just show me the fields underneath of the form. I guess I need to add hook when users submit the form. but couldn't find the hook that I need to callout to save additional fields data in DB.
add_action('network_site_new_form', array($this, 'add_extra_new_site_fields'));
Added this function
function add_extra_new_site_fields()
{
?>
<form method="post" action="<?php echo network_admin_url( 'site-new.php?action=add-site' ); ?>" novalidate="novalidate">
<?php wp_nonce_field( 'add-blog', '_wpnonce_add-blog' ); ?>
<table class="form-table" role="presentation">
<tr class="form-field form-required">
<th scope="row"><label for="site-address"><?php _e( 'Site s Address (URL)' ); ?> <span class="required">*</span></label></th>
<td>
<?php if ( is_subdomain_install() ) { ?>
<input name="blog[domain]" type="text" class="regular-text" 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>
<?php
} else {
echo get_network()->domain . get_network()->path
?>
<input name="blog[domain]" type="text" class="regular-text" id="site-address" aria-describedby="site-address-desc" autocapitalize="none" autocorrect="off" required />
<?php
}
echo '<p class="description" id="site-address-desc">' . __( 'Only lowercase letters (a-z), numbers, and hyphens are allowed.' ) . '</p>';
?>
</td>
</tr>
<tr class="form-field form-required">
<th scope="row"><label for="site-title"><?php _e( 'Site Title' ); ?> <span class="required">*</span></label></th>
<td><input name="blog[title]" type="text" class="regular-text" id="site-title" required /></td>
</tr>
<?php
$languages = get_available_languages();
$translations = wp_get_available_translations();
if ( ! empty( $languages ) || ! empty( $translations ) ) :
?>
<tr class="form-field form-required">
<th scope="row"><label for="site-language"><?php _e( 'Site Language' ); ?></label></th>
<td>
<?php
// Network default.
$lang = get_site_option( 'WPLANG' );
// Use English if the default isn't available.
if ( ! in_array( $lang, $languages ) ) {
$lang = '';
}
wp_dropdown_languages(
array(
'name' => 'WPLANG',
'id' => 'site-language',
'selected' => $lang,
'languages' => $languages,
'translations' => $translations,
//'show_available_translations' => current_user_can( 'install_languages' ) && wp_can_install_language_pack(),
)
);
?>
</td>
</tr>
<?php endif; // Languages. ?>
<tr class="form-field form-required">
<th scope="row"><label for="admin-email"><?php _e( 'Admin Email' ); ?> <span class="required">*</span></label></th>
<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>
</tr>
<tr class="form-field">
<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>
</tr>
<tr class="form-field form-required">
<th scope="row"><label for="admin-email"><?php _e( 'Account ID' ); ?> <span class="required">*</span></label></th>
<td><input name="blog[account_id]" type="input" class="regular-text" id="admin-account_id" required /></td>
</tr>
</table>
<?php
/**
* Fires at the end of the new site form in network admin.
*
* @since 4.5.0
*/
//do_action( 'network_site_new_form' );
submit_button( __( 'Add Site' ), 'primary', 'add-site' );
?>
</form>
<?php
}
give me your suggestions.