Introduce a language chooser to the site signup process on Multisite.

If your Multisite installation is one of the relatively few that allows new sites to be registered, either by existing users or by new visitors to your site, a 'Site Language' dropdown menu will now be presented if your network has additional languages installed. This option defaults to the value of the 'Default Language' setting on the Network Admin Settings screen, and is restricted to currently installed languages.

The languages available in this setting can be controlled via the `signup_get_available_languages` filter. To disable it completely, return an empty array.

Fixes #33844
Props DrewAPicture, johnbillion

Built from https://develop.svn.wordpress.org/trunk@35152


git-svn-id: http://core.svn.wordpress.org/trunk@35118 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
John Blackbourn 2015-10-13 23:46:25 +00:00
parent 87aa982824
commit 8dd677a09f
2 changed files with 98 additions and 1 deletions

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.4-alpha-35151'; $wp_version = '4.4-alpha-35152';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

View File

@ -56,6 +56,7 @@ function wpmu_signup_stylesheet() {
.mu_register #user_email, .mu_register #user_email,
.mu_register #blogname, .mu_register #blogname,
.mu_register #user_name { width:100%; font-size: 24px; margin:5px 0; } .mu_register #user_name { width:100%; font-size: 24px; margin:5px 0; }
.mu_register #site-language { display: block; }
.mu_register .prefix_address, .mu_register .prefix_address,
.mu_register .suffix_address {font-size: 18px;display:inline; } .mu_register .suffix_address {font-size: 18px;display:inline; }
.mu_register label { font-weight:700; font-size:15px; display:block; margin:10px 0; } .mu_register label { font-weight:700; font-size:15px; display:block; margin:10px 0; }
@ -121,6 +122,38 @@ function show_blog_form( $blogname = '', $blog_title = '', $errors = '' ) {
echo '<input name="blog_title" type="text" id="blog_title" value="'.esc_attr($blog_title).'" />'; echo '<input name="blog_title" type="text" id="blog_title" value="'.esc_attr($blog_title).'" />';
?> ?>
<?php
// Site Language.
$languages = signup_get_available_languages();
if ( ! empty( $languages ) ) :
?>
<p>
<label for="site-language"><?php _e( 'Site Language:' ); ?></label>
<?php
// Network default.
$lang = get_site_option( 'WPLANG' );
if ( isset( $_POST['WPLANG'] ) ) {
$lang = $_POST['WPLANG'];
}
// Use US 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,
'show_available_translations' => false,
) );
?>
</p>
<?php endif; // Languages. ?>
<div id="privacy"> <div id="privacy">
<p class="privacy-intro"> <p class="privacy-intro">
<label for="blog_public_on"><?php _e('Privacy:') ?></label> <label for="blog_public_on"><?php _e('Privacy:') ?></label>
@ -330,6 +363,21 @@ function validate_another_blog_signup() {
'public' => $public 'public' => $public
); );
// Handle the language setting for the new site.
if ( ! empty( $_POST['WPLANG'] ) ) {
$languages = signup_get_available_languages();
if ( in_array( $_POST['WPLANG'], $languages ) ) {
$language = wp_unslash( sanitize_text_field( $_POST['WPLANG'] ) );
if ( $language ) {
$blog_meta_defaults['WPLANG'] = $language;
}
}
}
/** /**
* Filter the new site meta variables. * Filter the new site meta variables.
* *
@ -339,6 +387,7 @@ function validate_another_blog_signup() {
* @param array $blog_meta_defaults An array of default blog meta variables. * @param array $blog_meta_defaults An array of default blog meta variables.
*/ */
$meta_defaults = apply_filters( 'signup_create_blog_meta', $blog_meta_defaults ); $meta_defaults = apply_filters( 'signup_create_blog_meta', $blog_meta_defaults );
/** /**
* Filter the new default site meta variables. * Filter the new default site meta variables.
* *
@ -631,6 +680,21 @@ function validate_blog_signup() {
$public = (int) $_POST['blog_public']; $public = (int) $_POST['blog_public'];
$signup_meta = array ('lang_id' => 1, 'public' => $public); $signup_meta = array ('lang_id' => 1, 'public' => $public);
// Handle the language setting for the new site.
if ( ! empty( $_POST['WPLANG'] ) ) {
$languages = signup_get_available_languages();
if ( in_array( $_POST['WPLANG'], $languages ) ) {
$language = wp_unslash( sanitize_text_field( $_POST['WPLANG'] ) );
if ( $language ) {
$signup_meta['WPLANG'] = $language;
}
}
}
/** This filter is documented in wp-signup.php */ /** This filter is documented in wp-signup.php */
$meta = apply_filters( 'add_signup_meta', $signup_meta ); $meta = apply_filters( 'add_signup_meta', $signup_meta );
@ -672,6 +736,39 @@ function confirm_blog_signup( $domain, $path, $blog_title, $user_name = '', $use
do_action( 'signup_finished' ); do_action( 'signup_finished' );
} }
/**
* Retrieves languages available during the site/user signup process.
*
* @since 4.4.0
*
* @see get_available_languages()
*
* @return array List of available languages.
*/
function signup_get_available_languages() {
/**
* Filter the list of available languages for front-end site signups.
*
* Passing an empty array to this hook will disable output of the setting on the
* signup form, and the default language will be used when creating the site.
*
* Languages not already installed will be stripped.
*
* @since 4.4.0
*
* @param array $available_languages Available languages.
*/
$languages = (array) apply_filters( 'signup_get_available_languages', get_available_languages() );
/*
* Strip any non-installed languages and return.
*
* Re-call get_available_languages() here in case a language pack was installed
* in a callback hooked to the 'signup_get_available_languages' filter before this point.
*/
return array_intersect_assoc( $languages, get_available_languages() );
}
// Main // Main
$active_signup = get_site_option( 'registration', 'none' ); $active_signup = get_site_option( 'registration', 'none' );
/** /**