PageRenderTime 42ms CodeModel.GetById 6ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-signup.php

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