From 8dd677a09ffc9a679088abbcd63bbd91995ef718 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Tue, 13 Oct 2015 23:46:25 +0000 Subject: [PATCH] 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 --- wp-includes/version.php | 2 +- wp-signup.php | 97 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 1 deletion(-) diff --git a/wp-includes/version.php b/wp-includes/version.php index 2f3f813dd2..5a4a9ebbaa 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @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. diff --git a/wp-signup.php b/wp-signup.php index 01dfdf6791..314421713e 100644 --- a/wp-signup.php +++ b/wp-signup.php @@ -56,6 +56,7 @@ function wpmu_signup_stylesheet() { .mu_register #user_email, .mu_register #blogname, .mu_register #user_name { width:100%; font-size: 24px; margin:5px 0; } + .mu_register #site-language { display: block; } .mu_register .prefix_address, .mu_register .suffix_address {font-size: 18px;display:inline; } .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 ''; ?> + +

+ + 'WPLANG', + 'id' => 'site-language', + 'selected' => $lang, + 'languages' => $languages, + 'show_available_translations' => false, + ) ); + ?> +

+ +

@@ -330,6 +363,21 @@ function validate_another_blog_signup() { '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. * @@ -339,6 +387,7 @@ function validate_another_blog_signup() { * @param array $blog_meta_defaults An array of default blog meta variables. */ $meta_defaults = apply_filters( 'signup_create_blog_meta', $blog_meta_defaults ); + /** * Filter the new default site meta variables. * @@ -631,6 +680,21 @@ function validate_blog_signup() { $public = (int) $_POST['blog_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 */ $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' ); } +/** + * 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 $active_signup = get_site_option( 'registration', 'none' ); /**