wp-signup.php 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046
  1. <?php
  2. /** Sets up the WordPress Environment. */
  3. require __DIR__ . '/wp-load.php';
  4. add_filter( 'wp_robots', 'wp_robots_no_robots' );
  5. require __DIR__ . '/wp-blog-header.php';
  6. nocache_headers();
  7. if ( is_array( get_site_option( 'illegal_names' ) ) && isset( $_GET['new'] ) && in_array( $_GET['new'], get_site_option( 'illegal_names' ), true ) ) {
  8. wp_redirect( network_home_url() );
  9. die();
  10. }
  11. /**
  12. * Prints signup_header via wp_head.
  13. *
  14. * @since MU (3.0.0)
  15. */
  16. function do_signup_header() {
  17. /**
  18. * Fires within the head section of the site sign-up screen.
  19. *
  20. * @since 3.0.0
  21. */
  22. do_action( 'signup_header' );
  23. }
  24. add_action( 'wp_head', 'do_signup_header' );
  25. if ( ! is_multisite() ) {
  26. wp_redirect( wp_registration_url() );
  27. die();
  28. }
  29. if ( ! is_main_site() ) {
  30. wp_redirect( network_site_url( 'wp-signup.php' ) );
  31. die();
  32. }
  33. // Fix for page title.
  34. $wp_query->is_404 = false;
  35. /**
  36. * Fires before the Site Sign-up page is loaded.
  37. *
  38. * @since 4.4.0
  39. */
  40. do_action( 'before_signup_header' );
  41. /**
  42. * Prints styles for front-end Multisite Sign-up pages.
  43. *
  44. * @since MU (3.0.0)
  45. */
  46. function wpmu_signup_stylesheet() {
  47. ?>
  48. <style type="text/css">
  49. .mu_register { width: 90%; margin: 0 auto; }
  50. .mu_register form { margin-top: 2em; }
  51. .mu_register fieldset,
  52. .mu_register legend { margin: 0; padding: 0; border: none; }
  53. .mu_register .error { font-weight: 600; padding: 10px; color: #333; background: #ffebe8; border: 1px solid #c00; }
  54. .mu_register input[type="submit"],
  55. .mu_register #blog_title,
  56. .mu_register #user_email,
  57. .mu_register #blogname,
  58. .mu_register #user_name { width: 100%; font-size: 24px; margin: 5px 0; box-sizing: border-box; }
  59. .mu_register #site-language { display: block; }
  60. .mu_register .prefix_address,
  61. .mu_register .suffix_address { font-size: 18px; display: inline-block; direction: ltr; }
  62. .mu_register label,
  63. .mu_register legend,
  64. .mu_register .label-heading { font-weight: 600; font-size: 15px; display: block; margin: 10px 0; }
  65. .mu_register legend + p,
  66. .mu_register input + p { margin-top: 0; }
  67. .mu_register label.checkbox { display: inline; }
  68. .mu_register .mu_alert { font-weight: 600; padding: 10px; color: #333; background: #ffffe0; border: 1px solid #e6db55; }
  69. .mu_register .mu_alert a { color: inherit; text-decoration: underline; }
  70. .mu_register .signup-options .wp-signup-radio-button { display: block; }
  71. .mu_register .privacy-intro .wp-signup-radio-button { margin-right: 0.5em; }
  72. .rtl .mu_register .wp-signup-blogname { direction: ltr; text-align: right; }
  73. </style>
  74. <?php
  75. }
  76. add_action( 'wp_head', 'wpmu_signup_stylesheet' );
  77. get_header( 'wp-signup' );
  78. /**
  79. * Fires before the site Sign-up form.
  80. *
  81. * @since 3.0.0
  82. */
  83. do_action( 'before_signup_form' );
  84. ?>
  85. <div id="signup-content" class="widecolumn">
  86. <div class="mu_register wp-signup-container" role="main">
  87. <?php
  88. /**
  89. * Generates and displays the Sign-up and Create Site forms.
  90. *
  91. * @since MU (3.0.0)
  92. *
  93. * @param string $blogname The new site name.
  94. * @param string $blog_title The new site title.
  95. * @param WP_Error|string $errors A WP_Error object containing existing errors. Defaults to empty string.
  96. */
  97. function show_blog_form( $blogname = '', $blog_title = '', $errors = '' ) {
  98. if ( ! is_wp_error( $errors ) ) {
  99. $errors = new WP_Error();
  100. }
  101. $current_network = get_network();
  102. // Blog name.
  103. if ( ! is_subdomain_install() ) {
  104. echo '<label for="blogname">' . __( 'Site Name (subdirectory only):' ) . '</label>';
  105. } else {
  106. echo '<label for="blogname">' . __( 'Site Domain (subdomain only):' ) . '</label>';
  107. }
  108. $errmsg_blogname = $errors->get_error_message( 'blogname' );
  109. $errmsg_blogname_aria = '';
  110. if ( $errmsg_blogname ) {
  111. $errmsg_blogname_aria = 'wp-signup-blogname-error ';
  112. echo '<p class="error" id="wp-signup-blogname-error">' . $errmsg_blogname . '</p>';
  113. }
  114. if ( ! is_subdomain_install() ) {
  115. echo '<div class="wp-signup-blogname"><span class="prefix_address" id="prefix-address">' . $current_network->domain . $current_network->path . '</span><input name="blogname" type="text" id="blogname" value="' . esc_attr( $blogname ) . '" maxlength="60" autocomplete="off" required="required" aria-describedby="' . $errmsg_blogname_aria . 'prefix-address" /></div>';
  116. } else {
  117. $site_domain = preg_replace( '|^www\.|', '', $current_network->domain );
  118. echo '<div class="wp-signup-blogname"><input name="blogname" type="text" id="blogname" value="' . esc_attr( $blogname ) . '" maxlength="60" autocomplete="off" required="required" aria-describedby="' . $errmsg_blogname_aria . 'suffix-address" /><span class="suffix_address" id="suffix-address">.' . esc_html( $site_domain ) . '</span></div>';
  119. }
  120. if ( ! is_user_logged_in() ) {
  121. if ( ! is_subdomain_install() ) {
  122. $site = $current_network->domain . $current_network->path . __( 'sitename' );
  123. } else {
  124. $site = __( 'domain' ) . '.' . $site_domain . $current_network->path;
  125. }
  126. printf(
  127. '<p>(<strong>%s</strong>) %s</p>',
  128. /* translators: %s: Site address. */
  129. sprintf( __( 'Your address will be %s.' ), $site ),
  130. __( 'Must be at least 4 characters, letters and numbers only. It cannot be changed, so choose carefully!' )
  131. );
  132. }
  133. // Site Title.
  134. ?>
  135. <label for="blog_title"><?php _e( 'Site Title:' ); ?></label>
  136. <?php
  137. $errmsg_blog_title = $errors->get_error_message( 'blog_title' );
  138. $errmsg_blog_title_aria = '';
  139. if ( $errmsg_blog_title ) {
  140. $errmsg_blog_title_aria = ' aria-describedby="wp-signup-blog-title-error"';
  141. echo '<p class="error" id="wp-signup-blog-title-error">' . $errmsg_blog_title . '</p>';
  142. }
  143. echo '<input name="blog_title" type="text" id="blog_title" value="' . esc_attr( $blog_title ) . '" required="required" autocomplete="off"' . $errmsg_blog_title_aria . ' />';
  144. ?>
  145. <?php
  146. // Site Language.
  147. $languages = signup_get_available_languages();
  148. if ( ! empty( $languages ) ) :
  149. ?>
  150. <p>
  151. <label for="site-language"><?php _e( 'Site Language:' ); ?></label>
  152. <?php
  153. // Network default.
  154. $lang = get_site_option( 'WPLANG' );
  155. if ( isset( $_POST['WPLANG'] ) ) {
  156. $lang = $_POST['WPLANG'];
  157. }
  158. // Use US English if the default isn't available.
  159. if ( ! in_array( $lang, $languages, true ) ) {
  160. $lang = '';
  161. }
  162. wp_dropdown_languages(
  163. array(
  164. 'name' => 'WPLANG',
  165. 'id' => 'site-language',
  166. 'selected' => $lang,
  167. 'languages' => $languages,
  168. 'show_available_translations' => false,
  169. )
  170. );
  171. ?>
  172. </p>
  173. <?php
  174. endif; // Languages.
  175. $blog_public_on_checked = '';
  176. $blog_public_off_checked = '';
  177. if ( isset( $_POST['blog_public'] ) && '0' === $_POST['blog_public'] ) {
  178. $blog_public_off_checked = 'checked="checked"';
  179. } else {
  180. $blog_public_on_checked = 'checked="checked"';
  181. }
  182. ?>
  183. <div id="privacy">
  184. <fieldset class="privacy-intro">
  185. <legend>
  186. <span class="label-heading"><?php _e( 'Privacy:' ); ?></span>
  187. <?php _e( 'Allow search engines to index this site.' ); ?>
  188. </legend>
  189. <p class="wp-signup-radio-buttons">
  190. <span class="wp-signup-radio-button">
  191. <input type="radio" id="blog_public_on" name="blog_public" value="1" <?php echo $blog_public_on_checked; ?> />
  192. <label class="checkbox" for="blog_public_on"><?php _e( 'Yes' ); ?></label>
  193. </span>
  194. <span class="wp-signup-radio-button">
  195. <input type="radio" id="blog_public_off" name="blog_public" value="0" <?php echo $blog_public_off_checked; ?> />
  196. <label class="checkbox" for="blog_public_off"><?php _e( 'No' ); ?></label>
  197. </span>
  198. </p>
  199. </fieldset>
  200. </div>
  201. <?php
  202. /**
  203. * Fires after the site sign-up form.
  204. *
  205. * @since 3.0.0
  206. *
  207. * @param WP_Error $errors A WP_Error object possibly containing 'blogname' or 'blog_title' errors.
  208. */
  209. do_action( 'signup_blogform', $errors );
  210. }
  211. /**
  212. * Validates the new site sign-up.
  213. *
  214. * @since MU (3.0.0)
  215. *
  216. * @return array Contains the new site data and error messages.
  217. * See wpmu_validate_blog_signup() for details.
  218. */
  219. function validate_blog_form() {
  220. $user = '';
  221. if ( is_user_logged_in() ) {
  222. $user = wp_get_current_user();
  223. }
  224. return wpmu_validate_blog_signup( $_POST['blogname'], $_POST['blog_title'], $user );
  225. }
  226. /**
  227. * Displays the fields for the new user account registration form.
  228. *
  229. * @since MU (3.0.0)
  230. *
  231. * @param string $user_name The entered username.
  232. * @param string $user_email The entered email address.
  233. * @param WP_Error|string $errors A WP_Error object containing existing errors. Defaults to empty string.
  234. */
  235. function show_user_form( $user_name = '', $user_email = '', $errors = '' ) {
  236. if ( ! is_wp_error( $errors ) ) {
  237. $errors = new WP_Error();
  238. }
  239. // Username.
  240. echo '<label for="user_name">' . __( 'Username:' ) . '</label>';
  241. $errmsg_username = $errors->get_error_message( 'user_name' );
  242. $errmsg_username_aria = '';
  243. if ( $errmsg_username ) {
  244. $errmsg_username_aria = 'wp-signup-username-error ';
  245. echo '<p class="error" id="wp-signup-username-error">' . $errmsg_username . '</p>';
  246. }
  247. ?>
  248. <input name="user_name" type="text" id="user_name" value="<?php echo esc_attr( $user_name ); ?>" autocapitalize="none" autocorrect="off" maxlength="60" autocomplete="username" required="required" aria-describedby="<?php echo $errmsg_username_aria; ?>wp-signup-username-description" />
  249. <p id="wp-signup-username-description"><?php _e( '(Must be at least 4 characters, lowercase letters and numbers only.)' ); ?></p>
  250. <?php
  251. // Email address.
  252. echo '<label for="user_email">' . __( 'Email&nbsp;Address:' ) . '</label>';
  253. $errmsg_email = $errors->get_error_message( 'user_email' );
  254. $errmsg_email_aria = '';
  255. if ( $errmsg_email ) {
  256. $errmsg_email_aria = 'wp-signup-email-error ';
  257. echo '<p class="error" id="wp-signup-email-error">' . $errmsg_email . '</p>';
  258. }
  259. ?>
  260. <input name="user_email" type="email" id="user_email" value="<?php echo esc_attr( $user_email ); ?>" maxlength="200" autocomplete="email" required="required" aria-describedby="<?php echo $errmsg_email_aria; ?>wp-signup-email-description" />
  261. <p id="wp-signup-email-description"><?php _e( 'Your registration email is sent to this address. (Double-check your email address before continuing.)' ); ?></p>
  262. <?php
  263. // Extra fields.
  264. $errmsg_generic = $errors->get_error_message( 'generic' );
  265. if ( $errmsg_generic ) {
  266. echo '<p class="error" id="wp-signup-generic-error">' . $errmsg_generic . '</p>';
  267. }
  268. /**
  269. * Fires at the end of the new user account registration form.
  270. *
  271. * @since 3.0.0
  272. *
  273. * @param WP_Error $errors A WP_Error object containing 'user_name' or 'user_email' errors.
  274. */
  275. do_action( 'signup_extra_fields', $errors );
  276. }
  277. /**
  278. * Validates user sign-up name and email.
  279. *
  280. * @since MU (3.0.0)
  281. *
  282. * @return array Contains username, email, and error messages.
  283. * See wpmu_validate_user_signup() for details.
  284. */
  285. function validate_user_form() {
  286. return wpmu_validate_user_signup( $_POST['user_name'], $_POST['user_email'] );
  287. }
  288. /**
  289. * Shows a form for returning users to sign up for another site.
  290. *
  291. * @since MU (3.0.0)
  292. *
  293. * @param string $blogname The new site name
  294. * @param string $blog_title The new site title.
  295. * @param WP_Error|string $errors A WP_Error object containing existing errors. Defaults to empty string.
  296. */
  297. function signup_another_blog( $blogname = '', $blog_title = '', $errors = '' ) {
  298. $current_user = wp_get_current_user();
  299. if ( ! is_wp_error( $errors ) ) {
  300. $errors = new WP_Error();
  301. }
  302. $signup_defaults = array(
  303. 'blogname' => $blogname,
  304. 'blog_title' => $blog_title,
  305. 'errors' => $errors,
  306. );
  307. /**
  308. * Filters the default site sign-up variables.
  309. *
  310. * @since 3.0.0
  311. *
  312. * @param array $signup_defaults {
  313. * An array of default site sign-up variables.
  314. *
  315. * @type string $blogname The site blogname.
  316. * @type string $blog_title The site title.
  317. * @type WP_Error $errors A WP_Error object possibly containing 'blogname' or 'blog_title' errors.
  318. * }
  319. */
  320. $filtered_results = apply_filters( 'signup_another_blog_init', $signup_defaults );
  321. $blogname = $filtered_results['blogname'];
  322. $blog_title = $filtered_results['blog_title'];
  323. $errors = $filtered_results['errors'];
  324. /* translators: %s: Network title. */
  325. echo '<h2>' . sprintf( __( 'Get <em>another</em> %s site in seconds' ), get_network()->site_name ) . '</h2>';
  326. if ( $errors->has_errors() ) {
  327. echo '<p>' . __( 'There was a problem, please correct the form below and try again.' ) . '</p>';
  328. }
  329. ?>
  330. <p>
  331. <?php
  332. printf(
  333. /* translators: %s: Current user's display name. */
  334. __( 'Welcome back, %s. By filling out the form below, you can <strong>add another site to your account</strong>. There is no limit to the number of sites you can have, so create to your heart&#8217;s content, but write responsibly!' ),
  335. $current_user->display_name
  336. );
  337. ?>
  338. </p>
  339. <?php
  340. $blogs = get_blogs_of_user( $current_user->ID );
  341. if ( ! empty( $blogs ) ) {
  342. ?>
  343. <p><?php _e( 'Sites you are already a member of:' ); ?></p>
  344. <ul>
  345. <?php
  346. foreach ( $blogs as $blog ) {
  347. $home_url = get_home_url( $blog->userblog_id );
  348. echo '<li><a href="' . esc_url( $home_url ) . '">' . $home_url . '</a></li>';
  349. }
  350. ?>
  351. </ul>
  352. <?php } ?>
  353. <p><?php _e( 'If you are not going to use a great site domain, leave it for a new user. Now have at it!' ); ?></p>
  354. <form id="setupform" method="post" action="wp-signup.php">
  355. <input type="hidden" name="stage" value="gimmeanotherblog" />
  356. <?php
  357. /**
  358. * Hidden sign-up form fields output when creating another site or user.
  359. *
  360. * @since MU (3.0.0)
  361. *
  362. * @param string $context A string describing the steps of the sign-up process. The value can be
  363. * 'create-another-site', 'validate-user', or 'validate-site'.
  364. */
  365. do_action( 'signup_hidden_fields', 'create-another-site' );
  366. ?>
  367. <?php show_blog_form( $blogname, $blog_title, $errors ); ?>
  368. <p class="submit"><input type="submit" name="submit" class="submit" value="<?php esc_attr_e( 'Create Site' ); ?>" /></p>
  369. </form>
  370. <?php
  371. }
  372. /**
  373. * Validates a new site sign-up for an existing user.
  374. *
  375. * @since MU (3.0.0)
  376. *
  377. * @global string $blogname The new site's subdomain or directory name.
  378. * @global string $blog_title The new site's title.
  379. * @global WP_Error $errors Existing errors in the global scope.
  380. * @global string $domain The new site's domain.
  381. * @global string $path The new site's path.
  382. *
  383. * @return null|bool True if site signup was validated, false on error.
  384. * The function halts all execution if the user is not logged in.
  385. */
  386. function validate_another_blog_signup() {
  387. global $blogname, $blog_title, $errors, $domain, $path;
  388. $current_user = wp_get_current_user();
  389. if ( ! is_user_logged_in() ) {
  390. die();
  391. }
  392. $result = validate_blog_form();
  393. // Extracted values set/overwrite globals.
  394. $domain = $result['domain'];
  395. $path = $result['path'];
  396. $blogname = $result['blogname'];
  397. $blog_title = $result['blog_title'];
  398. $errors = $result['errors'];
  399. if ( $errors->has_errors() ) {
  400. signup_another_blog( $blogname, $blog_title, $errors );
  401. return false;
  402. }
  403. $public = (int) $_POST['blog_public'];
  404. $blog_meta_defaults = array(
  405. 'lang_id' => 1,
  406. 'public' => $public,
  407. );
  408. // Handle the language setting for the new site.
  409. if ( ! empty( $_POST['WPLANG'] ) ) {
  410. $languages = signup_get_available_languages();
  411. if ( in_array( $_POST['WPLANG'], $languages, true ) ) {
  412. $language = wp_unslash( sanitize_text_field( $_POST['WPLANG'] ) );
  413. if ( $language ) {
  414. $blog_meta_defaults['WPLANG'] = $language;
  415. }
  416. }
  417. }
  418. /**
  419. * Filters the new site meta variables.
  420. *
  421. * Use the {@see 'add_signup_meta'} filter instead.
  422. *
  423. * @since MU (3.0.0)
  424. * @deprecated 3.0.0 Use the {@see 'add_signup_meta'} filter instead.
  425. *
  426. * @param array $blog_meta_defaults An array of default blog meta variables.
  427. */
  428. $meta_defaults = apply_filters_deprecated( 'signup_create_blog_meta', array( $blog_meta_defaults ), '3.0.0', 'add_signup_meta' );
  429. /**
  430. * Filters the new default site meta variables.
  431. *
  432. * @since 3.0.0
  433. *
  434. * @param array $meta {
  435. * An array of default site meta variables.
  436. *
  437. * @type int $lang_id The language ID.
  438. * @type int $blog_public Whether search engines should be discouraged from indexing the site. 1 for true, 0 for false.
  439. * }
  440. */
  441. $meta = apply_filters( 'add_signup_meta', $meta_defaults );
  442. $blog_id = wpmu_create_blog( $domain, $path, $blog_title, $current_user->ID, $meta, get_current_network_id() );
  443. if ( is_wp_error( $blog_id ) ) {
  444. return false;
  445. }
  446. confirm_another_blog_signup( $domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta, $blog_id );
  447. return true;
  448. }
  449. /**
  450. * Shows a message confirming that the new site has been created.
  451. *
  452. * @since MU (3.0.0)
  453. * @since 4.4.0 Added the `$blog_id` parameter.
  454. *
  455. * @param string $domain The domain URL.
  456. * @param string $path The site root path.
  457. * @param string $blog_title The site title.
  458. * @param string $user_name The username.
  459. * @param string $user_email The user's email address.
  460. * @param array $meta Any additional meta from the {@see 'add_signup_meta'} filter in validate_blog_signup().
  461. * @param int $blog_id The site ID.
  462. */
  463. function confirm_another_blog_signup( $domain, $path, $blog_title, $user_name, $user_email = '', $meta = array(), $blog_id = 0 ) {
  464. if ( $blog_id ) {
  465. switch_to_blog( $blog_id );
  466. $home_url = home_url( '/' );
  467. $login_url = wp_login_url();
  468. restore_current_blog();
  469. } else {
  470. $home_url = 'http://' . $domain . $path;
  471. $login_url = 'http://' . $domain . $path . 'wp-login.php';
  472. }
  473. $site = sprintf(
  474. '<a href="%1$s">%2$s</a>',
  475. esc_url( $home_url ),
  476. $blog_title
  477. );
  478. ?>
  479. <h2>
  480. <?php
  481. /* translators: %s: Site title. */
  482. printf( __( 'The site %s is yours.' ), $site );
  483. ?>
  484. </h2>
  485. <p>
  486. <?php
  487. printf(
  488. /* translators: 1: Link to new site, 2: Login URL, 3: Username. */
  489. __( '%1$s is your new site. <a href="%2$s">Log in</a> as &#8220;%3$s&#8221; using your existing password.' ),
  490. sprintf(
  491. '<a href="%s">%s</a>',
  492. esc_url( $home_url ),
  493. untrailingslashit( $domain . $path )
  494. ),
  495. esc_url( $login_url ),
  496. $user_name
  497. );
  498. ?>
  499. </p>
  500. <?php
  501. /**
  502. * Fires when the site or user sign-up process is complete.
  503. *
  504. * @since 3.0.0
  505. */
  506. do_action( 'signup_finished' );
  507. }
  508. /**
  509. * Shows a form for a visitor to sign up for a new user account.
  510. *
  511. * @since MU (3.0.0)
  512. *
  513. * @global string $active_signup String that returns registration type. The value can be
  514. * 'all', 'none', 'blog', or 'user'.
  515. *
  516. * @param string $user_name The username.
  517. * @param string $user_email The user's email.
  518. * @param WP_Error|string $errors A WP_Error object containing existing errors. Defaults to empty string.
  519. */
  520. function signup_user( $user_name = '', $user_email = '', $errors = '' ) {
  521. global $active_signup;
  522. if ( ! is_wp_error( $errors ) ) {
  523. $errors = new WP_Error();
  524. }
  525. $signup_for = isset( $_POST['signup_for'] ) ? esc_html( $_POST['signup_for'] ) : 'blog';
  526. $signup_user_defaults = array(
  527. 'user_name' => $user_name,
  528. 'user_email' => $user_email,
  529. 'errors' => $errors,
  530. );
  531. /**
  532. * Filters the default user variables used on the user sign-up form.
  533. *
  534. * @since 3.0.0
  535. *
  536. * @param array $signup_user_defaults {
  537. * An array of default user variables.
  538. *
  539. * @type string $user_name The user username.
  540. * @type string $user_email The user email address.
  541. * @type WP_Error $errors A WP_Error object with possible errors relevant to the sign-up user.
  542. * }
  543. */
  544. $filtered_results = apply_filters( 'signup_user_init', $signup_user_defaults );
  545. $user_name = $filtered_results['user_name'];
  546. $user_email = $filtered_results['user_email'];
  547. $errors = $filtered_results['errors'];
  548. ?>
  549. <h2>
  550. <?php
  551. /* translators: %s: Name of the network. */
  552. printf( __( 'Get your own %s account in seconds' ), get_network()->site_name );
  553. ?>
  554. </h2>
  555. <form id="setupform" method="post" action="wp-signup.php" novalidate="novalidate">
  556. <input type="hidden" name="stage" value="validate-user-signup" />
  557. <?php
  558. /** This action is documented in wp-signup.php */
  559. do_action( 'signup_hidden_fields', 'validate-user' );
  560. ?>
  561. <?php show_user_form( $user_name, $user_email, $errors ); ?>
  562. <?php if ( 'blog' === $active_signup ) : ?>
  563. <input id="signupblog" type="hidden" name="signup_for" value="blog" />
  564. <?php elseif ( 'user' === $active_signup ) : ?>
  565. <input id="signupblog" type="hidden" name="signup_for" value="user" />
  566. <?php else : ?>
  567. <fieldset class="signup-options">
  568. <legend><?php _e( 'Create a site or only a username:' ); ?></legend>
  569. <p class="wp-signup-radio-buttons">
  570. <span class="wp-signup-radio-button">
  571. <input id="signupblog" type="radio" name="signup_for" value="blog" <?php checked( $signup_for, 'blog' ); ?> />
  572. <label class="checkbox" for="signupblog"><?php _e( 'Gimme a site!' ); ?></label>
  573. </span>
  574. <span class="wp-signup-radio-button">
  575. <input id="signupuser" type="radio" name="signup_for" value="user" <?php checked( $signup_for, 'user' ); ?> />
  576. <label class="checkbox" for="signupuser"><?php _e( 'Just a username, please.' ); ?></label>
  577. </span>
  578. </p>
  579. </fieldset>
  580. <?php endif; ?>
  581. <p class="submit"><input type="submit" name="submit" class="submit" value="<?php esc_attr_e( 'Next' ); ?>" /></p>
  582. </form>
  583. <?php
  584. }
  585. /**
  586. * Validates the new user sign-up.
  587. *
  588. * @since MU (3.0.0)
  589. *
  590. * @return bool True if new user sign-up was validated, false on error.
  591. */
  592. function validate_user_signup() {
  593. $result = validate_user_form();
  594. $user_name = $result['user_name'];
  595. $user_email = $result['user_email'];
  596. $errors = $result['errors'];
  597. if ( $errors->has_errors() ) {
  598. signup_user( $user_name, $user_email, $errors );
  599. return false;
  600. }
  601. if ( 'blog' === $_POST['signup_for'] ) {
  602. signup_blog( $user_name, $user_email );
  603. return false;
  604. }
  605. /** This filter is documented in wp-signup.php */
  606. wpmu_signup_user( $user_name, $user_email, apply_filters( 'add_signup_meta', array() ) );
  607. confirm_user_signup( $user_name, $user_email );
  608. return true;
  609. }
  610. /**
  611. * Shows a message confirming that the new user has been registered and is awaiting activation.
  612. *
  613. * @since MU (3.0.0)
  614. *
  615. * @param string $user_name The username.
  616. * @param string $user_email The user's email address.
  617. */
  618. function confirm_user_signup( $user_name, $user_email ) {
  619. ?>
  620. <h2>
  621. <?php
  622. /* translators: %s: Username. */
  623. printf( __( '%s is your new username' ), $user_name )
  624. ?>
  625. </h2>
  626. <p><?php _e( 'But, before you can start using your new username, <strong>you must activate it</strong>.' ); ?></p>
  627. <p>
  628. <?php
  629. /* translators: %s: Email address. */
  630. printf( __( 'Check your inbox at %s and click the link given.' ), '<strong>' . $user_email . '</strong>' );
  631. ?>
  632. </p>
  633. <p><?php _e( 'If you do not activate your username within two days, you will have to sign up again.' ); ?></p>
  634. <?php
  635. /** This action is documented in wp-signup.php */
  636. do_action( 'signup_finished' );
  637. }
  638. /**
  639. * Shows a form for a user or visitor to sign up for a new site.
  640. *
  641. * @since MU (3.0.0)
  642. *
  643. * @param string $user_name The username.
  644. * @param string $user_email The user's email address.
  645. * @param string $blogname The site name.
  646. * @param string $blog_title The site title.
  647. * @param WP_Error|string $errors A WP_Error object containing existing errors. Defaults to empty string.
  648. */
  649. function signup_blog( $user_name = '', $user_email = '', $blogname = '', $blog_title = '', $errors = '' ) {
  650. if ( ! is_wp_error( $errors ) ) {
  651. $errors = new WP_Error();
  652. }
  653. $signup_blog_defaults = array(
  654. 'user_name' => $user_name,
  655. 'user_email' => $user_email,
  656. 'blogname' => $blogname,
  657. 'blog_title' => $blog_title,
  658. 'errors' => $errors,
  659. );
  660. /**
  661. * Filters the default site creation variables for the site sign-up form.
  662. *
  663. * @since 3.0.0
  664. *
  665. * @param array $signup_blog_defaults {
  666. * An array of default site creation variables.
  667. *
  668. * @type string $user_name The user username.
  669. * @type string $user_email The user email address.
  670. * @type string $blogname The blogname.
  671. * @type string $blog_title The title of the site.
  672. * @type WP_Error $errors A WP_Error object with possible errors relevant to new site creation variables.
  673. * }
  674. */
  675. $filtered_results = apply_filters( 'signup_blog_init', $signup_blog_defaults );
  676. $user_name = $filtered_results['user_name'];
  677. $user_email = $filtered_results['user_email'];
  678. $blogname = $filtered_results['blogname'];
  679. $blog_title = $filtered_results['blog_title'];
  680. $errors = $filtered_results['errors'];
  681. if ( empty( $blogname ) ) {
  682. $blogname = $user_name;
  683. }
  684. ?>
  685. <form id="setupform" method="post" action="wp-signup.php">
  686. <input type="hidden" name="stage" value="validate-blog-signup" />
  687. <input type="hidden" name="user_name" value="<?php echo esc_attr( $user_name ); ?>" />
  688. <input type="hidden" name="user_email" value="<?php echo esc_attr( $user_email ); ?>" />
  689. <?php
  690. /** This action is documented in wp-signup.php */
  691. do_action( 'signup_hidden_fields', 'validate-site' );
  692. ?>
  693. <?php show_blog_form( $blogname, $blog_title, $errors ); ?>
  694. <p class="submit"><input type="submit" name="submit" class="submit" value="<?php esc_attr_e( 'Sign up' ); ?>" /></p>
  695. </form>
  696. <?php
  697. }
  698. /**
  699. * Validates new site signup.
  700. *
  701. * @since MU (3.0.0)
  702. *
  703. * @return bool True if the site sign-up was validated, false on error.
  704. */
  705. function validate_blog_signup() {
  706. // Re-validate user info.
  707. $user_result = wpmu_validate_user_signup( $_POST['user_name'], $_POST['user_email'] );
  708. $user_name = $user_result['user_name'];
  709. $user_email = $user_result['user_email'];
  710. $user_errors = $user_result['errors'];
  711. if ( $user_errors->has_errors() ) {
  712. signup_user( $user_name, $user_email, $user_errors );
  713. return false;
  714. }
  715. $result = wpmu_validate_blog_signup( $_POST['blogname'], $_POST['blog_title'] );
  716. $domain = $result['domain'];
  717. $path = $result['path'];
  718. $blogname = $result['blogname'];
  719. $blog_title = $result['blog_title'];
  720. $errors = $result['errors'];
  721. if ( $errors->has_errors() ) {
  722. signup_blog( $user_name, $user_email, $blogname, $blog_title, $errors );
  723. return false;
  724. }
  725. $public = (int) $_POST['blog_public'];
  726. $signup_meta = array(
  727. 'lang_id' => 1,
  728. 'public' => $public,
  729. );
  730. // Handle the language setting for the new site.
  731. if ( ! empty( $_POST['WPLANG'] ) ) {
  732. $languages = signup_get_available_languages();
  733. if ( in_array( $_POST['WPLANG'], $languages, true ) ) {
  734. $language = wp_unslash( sanitize_text_field( $_POST['WPLANG'] ) );
  735. if ( $language ) {
  736. $signup_meta['WPLANG'] = $language;
  737. }
  738. }
  739. }
  740. /** This filter is documented in wp-signup.php */
  741. $meta = apply_filters( 'add_signup_meta', $signup_meta );
  742. wpmu_signup_blog( $domain, $path, $blog_title, $user_name, $user_email, $meta );
  743. confirm_blog_signup( $domain, $path, $blog_title, $user_name, $user_email, $meta );
  744. return true;
  745. }
  746. /**
  747. * Shows a message confirming that the new site has been registered and is awaiting activation.
  748. *
  749. * @since MU (3.0.0)
  750. *
  751. * @param string $domain The domain or subdomain of the site.
  752. * @param string $path The path of the site.
  753. * @param string $blog_title The title of the new site.
  754. * @param string $user_name The user's username.
  755. * @param string $user_email The user's email address.
  756. * @param array $meta Any additional meta from the {@see 'add_signup_meta'} filter in validate_blog_signup().
  757. */
  758. function confirm_blog_signup( $domain, $path, $blog_title, $user_name = '', $user_email = '', $meta = array() ) {
  759. ?>
  760. <h2>
  761. <?php
  762. /* translators: %s: Site address. */
  763. printf( __( 'Congratulations! Your new site, %s, is almost ready.' ), "<a href='http://{$domain}{$path}'>{$blog_title}</a>" )
  764. ?>
  765. </h2>
  766. <p><?php _e( 'But, before you can start using your site, <strong>you must activate it</strong>.' ); ?></p>
  767. <p>
  768. <?php
  769. /* translators: %s: Email address. */
  770. printf( __( 'Check your inbox at %s and click the link given.' ), '<strong>' . $user_email . '</strong>' );
  771. ?>
  772. </p>
  773. <p><?php _e( 'If you do not activate your site within two days, you will have to sign up again.' ); ?></p>
  774. <h2><?php _e( 'Still waiting for your email?' ); ?></h2>
  775. <p><?php _e( 'If you have not received your email yet, there are a number of things you can do:' ); ?></p>
  776. <ul id="noemail-tips">
  777. <li><p><strong><?php _e( 'Wait a little longer. Sometimes delivery of email can be delayed by processes outside of our control.' ); ?></strong></p></li>
  778. <li><p><?php _e( 'Check the junk or spam folder of your email client. Sometime emails wind up there by mistake.' ); ?></p></li>
  779. <li>
  780. <?php
  781. /* translators: %s: Email address. */
  782. printf( __( 'Have you entered your email correctly? You have entered %s, if it&#8217;s incorrect, you will not receive your email.' ), $user_email );
  783. ?>
  784. </li>
  785. </ul>
  786. <?php
  787. /** This action is documented in wp-signup.php */
  788. do_action( 'signup_finished' );
  789. }
  790. /**
  791. * Retrieves languages available during the site/user sign-up process.
  792. *
  793. * @since 4.4.0
  794. *
  795. * @see get_available_languages()
  796. *
  797. * @return string[] Array of available language codes. Language codes are formed by
  798. * stripping the .mo extension from the language file names.
  799. */
  800. function signup_get_available_languages() {
  801. /**
  802. * Filters the list of available languages for front-end site sign-ups.
  803. *
  804. * Passing an empty array to this hook will disable output of the setting on the
  805. * sign-up form, and the default language will be used when creating the site.
  806. *
  807. * Languages not already installed will be stripped.
  808. *
  809. * @since 4.4.0
  810. *
  811. * @param string[] $languages Array of available language codes. Language codes are formed by
  812. * stripping the .mo extension from the language file names.
  813. */
  814. $languages = (array) apply_filters( 'signup_get_available_languages', get_available_languages() );
  815. /*
  816. * Strip any non-installed languages and return.
  817. *
  818. * Re-call get_available_languages() here in case a language pack was installed
  819. * in a callback hooked to the 'signup_get_available_languages' filter before this point.
  820. */
  821. return array_intersect_assoc( $languages, get_available_languages() );
  822. }
  823. // Main.
  824. $active_signup = get_site_option( 'registration', 'none' );
  825. /**
  826. * Filters the type of site sign-up.
  827. *
  828. * @since 3.0.0
  829. *
  830. * @param string $active_signup String that returns registration type. The value can be
  831. * 'all', 'none', 'blog', or 'user'.
  832. */
  833. $active_signup = apply_filters( 'wpmu_active_signup', $active_signup );
  834. if ( current_user_can( 'manage_network' ) ) {
  835. echo '<div class="mu_alert">';
  836. _e( 'Greetings Network Administrator!' );
  837. echo ' ';
  838. switch ( $active_signup ) {
  839. case 'none':
  840. _e( 'The network currently disallows registrations.' );
  841. break;
  842. case 'blog':
  843. _e( 'The network currently allows site registrations.' );
  844. break;
  845. case 'user':
  846. _e( 'The network currently allows user registrations.' );
  847. break;
  848. default:
  849. _e( 'The network currently allows both site and user registrations.' );
  850. break;
  851. }
  852. echo ' ';
  853. /* translators: %s: URL to Network Settings screen. */
  854. printf( __( 'To change or disable registration go to your <a href="%s">Options page</a>.' ), esc_url( network_admin_url( 'settings.php' ) ) );
  855. echo '</div>';
  856. }
  857. $newblogname = isset( $_GET['new'] ) ? strtolower( preg_replace( '/^-|-$|[^-a-zA-Z0-9]/', '', $_GET['new'] ) ) : null;
  858. $current_user = wp_get_current_user();
  859. if ( 'none' === $active_signup ) {
  860. _e( 'Registration has been disabled.' );
  861. } elseif ( 'blog' === $active_signup && ! is_user_logged_in() ) {
  862. $login_url = wp_login_url( network_site_url( 'wp-signup.php' ) );
  863. /* translators: %s: Login URL. */
  864. printf( __( 'You must first <a href="%s">log in</a>, and then you can create a new site.' ), $login_url );
  865. } else {
  866. $stage = isset( $_POST['stage'] ) ? $_POST['stage'] : 'default';
  867. switch ( $stage ) {
  868. case 'validate-user-signup':
  869. if ( 'all' === $active_signup
  870. || ( 'blog' === $_POST['signup_for'] && 'blog' === $active_signup )
  871. || ( 'user' === $_POST['signup_for'] && 'user' === $active_signup )
  872. ) {
  873. validate_user_signup();
  874. } else {
  875. _e( 'User registration has been disabled.' );
  876. }
  877. break;
  878. case 'validate-blog-signup':
  879. if ( 'all' === $active_signup || 'blog' === $active_signup ) {
  880. validate_blog_signup();
  881. } else {
  882. _e( 'Site registration has been disabled.' );
  883. }
  884. break;
  885. case 'gimmeanotherblog':
  886. validate_another_blog_signup();
  887. break;
  888. case 'default':
  889. default:
  890. $user_email = isset( $_POST['user_email'] ) ? $_POST['user_email'] : '';
  891. /**
  892. * Fires when the site sign-up form is sent.
  893. *
  894. * @since 3.0.0
  895. */
  896. do_action( 'preprocess_signup_form' );
  897. if ( is_user_logged_in() && ( 'all' === $active_signup || 'blog' === $active_signup ) ) {
  898. signup_another_blog( $newblogname );
  899. } elseif ( ! is_user_logged_in() && ( 'all' === $active_signup || 'user' === $active_signup ) ) {
  900. signup_user( $newblogname, $user_email );
  901. } elseif ( ! is_user_logged_in() && ( 'blog' === $active_signup ) ) {
  902. _e( 'Sorry, new registrations are not allowed at this time.' );
  903. } else {
  904. _e( 'You are logged in already. No need to register again!' );
  905. }
  906. if ( $newblogname ) {
  907. $newblog = get_blogaddress_by_name( $newblogname );
  908. if ( 'blog' === $active_signup || 'all' === $active_signup ) {
  909. printf(
  910. /* translators: %s: Site address. */
  911. '<p>' . __( 'The site you were looking for, %s, does not exist, but you can create it now!' ) . '</p>',
  912. '<strong>' . $newblog . '</strong>'
  913. );
  914. } else {
  915. printf(
  916. /* translators: %s: Site address. */
  917. '<p>' . __( 'The site you were looking for, %s, does not exist.' ) . '</p>',
  918. '<strong>' . $newblog . '</strong>'
  919. );
  920. }
  921. }
  922. break;
  923. }
  924. }
  925. ?>
  926. </div>
  927. </div>
  928. <?php
  929. /**
  930. * Fires after the sign-up forms, before wp_footer.
  931. *
  932. * @since 3.0.0
  933. */
  934. do_action( 'after_signup_form' );
  935. ?>
  936. <?php
  937. get_footer( 'wp-signup' );