<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[35152] trunk/src/wp-signup.php: Introduce a language chooser to the site signup process on Multisite.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/35152">35152</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/35152","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>johnbillion</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-10-13 23:45:14 +0000 (Tue, 13 Oct 2015)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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 <a href="https://core.trac.wordpress.org/ticket/33844">#33844</a>
Props DrewAPicture, johnbillion</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpsignupphp">trunk/src/wp-signup.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpsignupphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-signup.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-signup.php 2015-10-13 22:11:36 UTC (rev 35151)
+++ trunk/src/wp-signup.php 2015-10-13 23:45:14 UTC (rev 35152)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -56,6 +56,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> .mu_register #user_email,
</span><span class="cx" style="display: block; padding: 0 10px"> .mu_register #blogname,
</span><span class="cx" style="display: block; padding: 0 10px"> .mu_register #user_name { width:100%; font-size: 24px; margin:5px 0; }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ .mu_register #site-language { display: block; }
</ins><span class="cx" style="display: block; padding: 0 10px"> .mu_register .prefix_address,
</span><span class="cx" style="display: block; padding: 0 10px"> .mu_register .suffix_address {font-size: 18px;display:inline; }
</span><span class="cx" style="display: block; padding: 0 10px"> .mu_register label { font-weight:700; font-size:15px; display:block; margin:10px 0; }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -121,6 +122,38 @@
</span><span class="cx" style="display: block; padding: 0 10px"> echo '<input name="blog_title" type="text" id="blog_title" value="'.esc_attr($blog_title).'" />';
</span><span class="cx" style="display: block; padding: 0 10px"> ?>
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <?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. ?>
+
</ins><span class="cx" style="display: block; padding: 0 10px"> <div id="privacy">
</span><span class="cx" style="display: block; padding: 0 10px"> <p class="privacy-intro">
</span><span class="cx" style="display: block; padding: 0 10px"> <label for="blog_public_on"><?php _e('Privacy:') ?></label>
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -330,6 +363,21 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'public' => $public
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // 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;
+ }
+ }
+
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Filter the new site meta variables.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -339,6 +387,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $blog_meta_defaults An array of default blog meta variables.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> $meta_defaults = apply_filters( 'signup_create_blog_meta', $blog_meta_defaults );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Filter the new default site meta variables.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -631,6 +680,21 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $public = (int) $_POST['blog_public'];
</span><span class="cx" style="display: block; padding: 0 10px"> $signup_meta = array ('lang_id' => 1, 'public' => $public);
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // 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;
+ }
+ }
+
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /** This filter is documented in wp-signup.php */
</span><span class="cx" style="display: block; padding: 0 10px"> $meta = apply_filters( 'add_signup_meta', $signup_meta );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -672,6 +736,39 @@
</span><span class="cx" style="display: block; padding: 0 10px"> do_action( 'signup_finished' );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/**
+ * 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() );
+}
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Main
</span><span class="cx" style="display: block; padding: 0 10px"> $active_signup = get_site_option( 'registration', 'none' );
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span></span></pre>
</div>
</div>
</body>
</html>