暫無描述

wp-signup.php 31KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019
  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 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. * See wpmu_validate_blog_signup() for details.
  205. */
  206. function validate_blog_form() {
  207. $user = '';
  208. if ( is_user_logged_in() ) {
  209. $user = wp_get_current_user();
  210. }
  211. return wpmu_validate_blog_signup( $_POST['blogname'], $_POST['blog_title'], $user );
  212. }
  213. /**
  214. * Displays the fields for the new user account registration form.
  215. *
  216. * @since MU (3.0.0)
  217. *
  218. * @param string $user_name The entered username.
  219. * @param string $user_email The entered email address.
  220. * @param WP_Error|string $errors A WP_Error object containing existing errors. Defaults to empty string.
  221. */
  222. function show_user_form( $user_name = '', $user_email = '', $errors = '' ) {
  223. if ( ! is_wp_error( $errors ) ) {
  224. $errors = new WP_Error();
  225. }
  226. // Username.
  227. echo '<label for="user_name">' . __( 'Username:' ) . '</label>';
  228. $errmsg = $errors->get_error_message( 'user_name' );
  229. if ( $errmsg ) {
  230. echo '<p class="error">' . $errmsg . '</p>';
  231. }
  232. echo '<input name="user_name" type="text" id="user_name" value="' . esc_attr( $user_name ) . '" autocapitalize="none" autocorrect="off" maxlength="60" /><br />';
  233. _e( '(Must be at least 4 characters, letters and numbers only.)' );
  234. ?>
  235. <label for="user_email"><?php _e( 'Email&nbsp;Address:' ); ?></label>
  236. <?php
  237. $errmsg = $errors->get_error_message( 'user_email' );
  238. if ( $errmsg ) {
  239. ?>
  240. <p class="error"><?php echo $errmsg; ?></p>
  241. <?php } ?>
  242. <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.)' ); ?>
  243. <?php
  244. $errmsg = $errors->get_error_message( 'generic' );
  245. if ( $errmsg ) {
  246. echo '<p class="error">' . $errmsg . '</p>';
  247. }
  248. /**
  249. * Fires at the end of the new user account registration form.
  250. *
  251. * @since 3.0.0
  252. *
  253. * @param WP_Error $errors A WP_Error object containing 'user_name' or 'user_email' errors.
  254. */
  255. do_action( 'signup_extra_fields', $errors );
  256. }
  257. /**
  258. * Validate user signup name and email
  259. *
  260. * @since MU (3.0.0)
  261. *
  262. * @return array Contains username, email, and error messages.
  263. * See wpmu_validate_user_signup() for details.
  264. */
  265. function validate_user_form() {
  266. return wpmu_validate_user_signup( $_POST['user_name'], $_POST['user_email'] );
  267. }
  268. /**
  269. * Allow returning users to sign up for another site
  270. *
  271. * @since MU (3.0.0)
  272. *
  273. * @param string $blogname The new site name
  274. * @param string $blog_title The new site title.
  275. * @param WP_Error|string $errors A WP_Error object containing existing errors. Defaults to empty string.
  276. */
  277. function signup_another_blog( $blogname = '', $blog_title = '', $errors = '' ) {
  278. $current_user = wp_get_current_user();
  279. if ( ! is_wp_error( $errors ) ) {
  280. $errors = new WP_Error();
  281. }
  282. $signup_defaults = array(
  283. 'blogname' => $blogname,
  284. 'blog_title' => $blog_title,
  285. 'errors' => $errors,
  286. );
  287. /**
  288. * Filters the default site sign-up variables.
  289. *
  290. * @since 3.0.0
  291. *
  292. * @param array $signup_defaults {
  293. * An array of default site sign-up variables.
  294. *
  295. * @type string $blogname The site blogname.
  296. * @type string $blog_title The site title.
  297. * @type WP_Error $errors A WP_Error object possibly containing 'blogname' or 'blog_title' errors.
  298. * }
  299. */
  300. $filtered_results = apply_filters( 'signup_another_blog_init', $signup_defaults );
  301. $blogname = $filtered_results['blogname'];
  302. $blog_title = $filtered_results['blog_title'];
  303. $errors = $filtered_results['errors'];
  304. /* translators: %s: Network title. */
  305. echo '<h2>' . sprintf( __( 'Get <em>another</em> %s site in seconds' ), get_network()->site_name ) . '</h2>';
  306. if ( $errors->has_errors() ) {
  307. echo '<p>' . __( 'There was a problem, please correct the form below and try again.' ) . '</p>';
  308. }
  309. ?>
  310. <p>
  311. <?php
  312. printf(
  313. /* translators: %s: Current user's display name. */
  314. __( '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!' ),
  315. $current_user->display_name
  316. );
  317. ?>
  318. </p>
  319. <?php
  320. $blogs = get_blogs_of_user( $current_user->ID );
  321. if ( ! empty( $blogs ) ) {
  322. ?>
  323. <p><?php _e( 'Sites you are already a member of:' ); ?></p>
  324. <ul>
  325. <?php
  326. foreach ( $blogs as $blog ) {
  327. $home_url = get_home_url( $blog->userblog_id );
  328. echo '<li><a href="' . esc_url( $home_url ) . '">' . $home_url . '</a></li>';
  329. }
  330. ?>
  331. </ul>
  332. <?php } ?>
  333. <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>
  334. <form id="setupform" method="post" action="wp-signup.php">
  335. <input type="hidden" name="stage" value="gimmeanotherblog" />
  336. <?php
  337. /**
  338. * Hidden sign-up form fields output when creating another site or user.
  339. *
  340. * @since MU (3.0.0)
  341. *
  342. * @param string $context A string describing the steps of the sign-up process. The value can be
  343. * 'create-another-site', 'validate-user', or 'validate-site'.
  344. */
  345. do_action( 'signup_hidden_fields', 'create-another-site' );
  346. ?>
  347. <?php show_blog_form( $blogname, $blog_title, $errors ); ?>
  348. <p class="submit"><input type="submit" name="submit" class="submit" value="<?php esc_attr_e( 'Create Site' ); ?>" /></p>
  349. </form>
  350. <?php
  351. }
  352. /**
  353. * Validate a new site signup for an existing user.
  354. *
  355. * @global string $blogname The new site's subdomain or directory name.
  356. * @global string $blog_title The new site's title.
  357. * @global WP_Error $errors Existing errors in the global scope.
  358. * @global string $domain The new site's domain.
  359. * @global string $path The new site's path.
  360. *
  361. * @since MU (3.0.0)
  362. *
  363. * @return null|bool True if site signup was validated, false if error.
  364. * The function halts all execution if the user is not logged in.
  365. */
  366. function validate_another_blog_signup() {
  367. global $blogname, $blog_title, $errors, $domain, $path;
  368. $current_user = wp_get_current_user();
  369. if ( ! is_user_logged_in() ) {
  370. die();
  371. }
  372. $result = validate_blog_form();
  373. // Extracted values set/overwrite globals.
  374. $domain = $result['domain'];
  375. $path = $result['path'];
  376. $blogname = $result['blogname'];
  377. $blog_title = $result['blog_title'];
  378. $errors = $result['errors'];
  379. if ( $errors->has_errors() ) {
  380. signup_another_blog( $blogname, $blog_title, $errors );
  381. return false;
  382. }
  383. $public = (int) $_POST['blog_public'];
  384. $blog_meta_defaults = array(
  385. 'lang_id' => 1,
  386. 'public' => $public,
  387. );
  388. // Handle the language setting for the new site.
  389. if ( ! empty( $_POST['WPLANG'] ) ) {
  390. $languages = signup_get_available_languages();
  391. if ( in_array( $_POST['WPLANG'], $languages, true ) ) {
  392. $language = wp_unslash( sanitize_text_field( $_POST['WPLANG'] ) );
  393. if ( $language ) {
  394. $blog_meta_defaults['WPLANG'] = $language;
  395. }
  396. }
  397. }
  398. /**
  399. * Filters the new site meta variables.
  400. *
  401. * Use the {@see 'add_signup_meta'} filter instead.
  402. *
  403. * @since MU (3.0.0)
  404. * @deprecated 3.0.0 Use the {@see 'add_signup_meta'} filter instead.
  405. *
  406. * @param array $blog_meta_defaults An array of default blog meta variables.
  407. */
  408. $meta_defaults = apply_filters_deprecated( 'signup_create_blog_meta', array( $blog_meta_defaults ), '3.0.0', 'add_signup_meta' );
  409. /**
  410. * Filters the new default site meta variables.
  411. *
  412. * @since 3.0.0
  413. *
  414. * @param array $meta {
  415. * An array of default site meta variables.
  416. *
  417. * @type int $lang_id The language ID.
  418. * @type int $blog_public Whether search engines should be discouraged from indexing the site. 1 for true, 0 for false.
  419. * }
  420. */
  421. $meta = apply_filters( 'add_signup_meta', $meta_defaults );
  422. $blog_id = wpmu_create_blog( $domain, $path, $blog_title, $current_user->ID, $meta, get_current_network_id() );
  423. if ( is_wp_error( $blog_id ) ) {
  424. return false;
  425. }
  426. confirm_another_blog_signup( $domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta, $blog_id );
  427. return true;
  428. }
  429. /**
  430. * Confirm a new site signup.
  431. *
  432. * @since MU (3.0.0)
  433. * @since 4.4.0 Added the `$blog_id` parameter.
  434. *
  435. * @param string $domain The domain URL.
  436. * @param string $path The site root path.
  437. * @param string $blog_title The site title.
  438. * @param string $user_name The username.
  439. * @param string $user_email The user's email address.
  440. * @param array $meta Any additional meta from the {@see 'add_signup_meta'} filter in validate_blog_signup().
  441. * @param int $blog_id The site ID.
  442. */
  443. function confirm_another_blog_signup( $domain, $path, $blog_title, $user_name, $user_email = '', $meta = array(), $blog_id = 0 ) {
  444. if ( $blog_id ) {
  445. switch_to_blog( $blog_id );
  446. $home_url = home_url( '/' );
  447. $login_url = wp_login_url();
  448. restore_current_blog();
  449. } else {
  450. $home_url = 'http://' . $domain . $path;
  451. $login_url = 'http://' . $domain . $path . 'wp-login.php';
  452. }
  453. $site = sprintf(
  454. '<a href="%1$s">%2$s</a>',
  455. esc_url( $home_url ),
  456. $blog_title
  457. );
  458. ?>
  459. <h2>
  460. <?php
  461. /* translators: %s: Site title. */
  462. printf( __( 'The site %s is yours.' ), $site );
  463. ?>
  464. </h2>
  465. <p>
  466. <?php
  467. printf(
  468. /* translators: 1: Link to new site, 2: Login URL, 3: Username. */
  469. __( '%1$s is your new site. <a href="%2$s">Log in</a> as &#8220;%3$s&#8221; using your existing password.' ),
  470. sprintf(
  471. '<a href="%s">%s</a>',
  472. esc_url( $home_url ),
  473. untrailingslashit( $domain . $path )
  474. ),
  475. esc_url( $login_url ),
  476. $user_name
  477. );
  478. ?>
  479. </p>
  480. <?php
  481. /**
  482. * Fires when the site or user sign-up process is complete.
  483. *
  484. * @since 3.0.0
  485. */
  486. do_action( 'signup_finished' );
  487. }
  488. /**
  489. * Shows a form for a visitor to sign up for a new user account.
  490. *
  491. * @since MU (3.0.0)
  492. *
  493. * @param string $user_name The username.
  494. * @param string $user_email The user's email.
  495. * @param WP_Error|string $errors A WP_Error object containing existing errors. Defaults to empty string.
  496. */
  497. function signup_user( $user_name = '', $user_email = '', $errors = '' ) {
  498. global $active_signup;
  499. if ( ! is_wp_error( $errors ) ) {
  500. $errors = new WP_Error();
  501. }
  502. $signup_for = isset( $_POST['signup_for'] ) ? esc_html( $_POST['signup_for'] ) : 'blog';
  503. $signup_user_defaults = array(
  504. 'user_name' => $user_name,
  505. 'user_email' => $user_email,
  506. 'errors' => $errors,
  507. );
  508. /**
  509. * Filters the default user variables used on the user sign-up form.
  510. *
  511. * @since 3.0.0
  512. *
  513. * @param array $signup_user_defaults {
  514. * An array of default user variables.
  515. *
  516. * @type string $user_name The user username.
  517. * @type string $user_email The user email address.
  518. * @type WP_Error $errors A WP_Error object with possible errors relevant to the sign-up user.
  519. * }
  520. */
  521. $filtered_results = apply_filters( 'signup_user_init', $signup_user_defaults );
  522. $user_name = $filtered_results['user_name'];
  523. $user_email = $filtered_results['user_email'];
  524. $errors = $filtered_results['errors'];
  525. ?>
  526. <h2>
  527. <?php
  528. /* translators: %s: Name of the network. */
  529. printf( __( 'Get your own %s account in seconds' ), get_network()->site_name );
  530. ?>
  531. </h2>
  532. <form id="setupform" method="post" action="wp-signup.php" novalidate="novalidate">
  533. <input type="hidden" name="stage" value="validate-user-signup" />
  534. <?php
  535. /** This action is documented in wp-signup.php */
  536. do_action( 'signup_hidden_fields', 'validate-user' );
  537. ?>
  538. <?php show_user_form( $user_name, $user_email, $errors ); ?>
  539. <p>
  540. <?php if ( 'blog' === $active_signup ) { ?>
  541. <input id="signupblog" type="hidden" name="signup_for" value="blog" />
  542. <?php } elseif ( 'user' === $active_signup ) { ?>
  543. <input id="signupblog" type="hidden" name="signup_for" value="user" />
  544. <?php } else { ?>
  545. <input id="signupblog" type="radio" name="signup_for" value="blog" <?php checked( $signup_for, 'blog' ); ?> />
  546. <label class="checkbox" for="signupblog"><?php _e( 'Gimme a site!' ); ?></label>
  547. <br />
  548. <input id="signupuser" type="radio" name="signup_for" value="user" <?php checked( $signup_for, 'user' ); ?> />
  549. <label class="checkbox" for="signupuser"><?php _e( 'Just a username, please.' ); ?></label>
  550. <?php } ?>
  551. </p>
  552. <p class="submit"><input type="submit" name="submit" class="submit" value="<?php esc_attr_e( 'Next' ); ?>" /></p>
  553. </form>
  554. <?php
  555. }
  556. /**
  557. * Validate the new user signup
  558. *
  559. * @since MU (3.0.0)
  560. *
  561. * @return bool True if new user signup was validated, false if error
  562. */
  563. function validate_user_signup() {
  564. $result = validate_user_form();
  565. $user_name = $result['user_name'];
  566. $user_email = $result['user_email'];
  567. $errors = $result['errors'];
  568. if ( $errors->has_errors() ) {
  569. signup_user( $user_name, $user_email, $errors );
  570. return false;
  571. }
  572. if ( 'blog' === $_POST['signup_for'] ) {
  573. signup_blog( $user_name, $user_email );
  574. return false;
  575. }
  576. /** This filter is documented in wp-signup.php */
  577. wpmu_signup_user( $user_name, $user_email, apply_filters( 'add_signup_meta', array() ) );
  578. confirm_user_signup( $user_name, $user_email );
  579. return true;
  580. }
  581. /**
  582. * New user signup confirmation
  583. *
  584. * @since MU (3.0.0)
  585. *
  586. * @param string $user_name The username
  587. * @param string $user_email The user's email address
  588. */
  589. function confirm_user_signup( $user_name, $user_email ) {
  590. ?>
  591. <h2>
  592. <?php
  593. /* translators: %s: Username. */
  594. printf( __( '%s is your new username' ), $user_name )
  595. ?>
  596. </h2>
  597. <p><?php _e( 'But, before you can start using your new username, <strong>you must activate it</strong>.' ); ?></p>
  598. <p>
  599. <?php
  600. /* translators: %s: Email address. */
  601. printf( __( 'Check your inbox at %s and click the link given.' ), '<strong>' . $user_email . '</strong>' );
  602. ?>
  603. </p>
  604. <p><?php _e( 'If you do not activate your username within two days, you will have to sign up again.' ); ?></p>
  605. <?php
  606. /** This action is documented in wp-signup.php */
  607. do_action( 'signup_finished' );
  608. }
  609. /**
  610. * Shows a form for a user or visitor to sign up for a new site.
  611. *
  612. * @since MU (3.0.0)
  613. *
  614. * @param string $user_name The username.
  615. * @param string $user_email The user's email address.
  616. * @param string $blogname The site name.
  617. * @param string $blog_title The site title.
  618. * @param WP_Error|string $errors A WP_Error object containing existing errors. Defaults to empty string.
  619. */
  620. function signup_blog( $user_name = '', $user_email = '', $blogname = '', $blog_title = '', $errors = '' ) {
  621. if ( ! is_wp_error( $errors ) ) {
  622. $errors = new WP_Error();
  623. }
  624. $signup_blog_defaults = array(
  625. 'user_name' => $user_name,
  626. 'user_email' => $user_email,
  627. 'blogname' => $blogname,
  628. 'blog_title' => $blog_title,
  629. 'errors' => $errors,
  630. );
  631. /**
  632. * Filters the default site creation variables for the site sign-up form.
  633. *
  634. * @since 3.0.0
  635. *
  636. * @param array $signup_blog_defaults {
  637. * An array of default site creation variables.
  638. *
  639. * @type string $user_name The user username.
  640. * @type string $user_email The user email address.
  641. * @type string $blogname The blogname.
  642. * @type string $blog_title The title of the site.
  643. * @type WP_Error $errors A WP_Error object with possible errors relevant to new site creation variables.
  644. * }
  645. */
  646. $filtered_results = apply_filters( 'signup_blog_init', $signup_blog_defaults );
  647. $user_name = $filtered_results['user_name'];
  648. $user_email = $filtered_results['user_email'];
  649. $blogname = $filtered_results['blogname'];
  650. $blog_title = $filtered_results['blog_title'];
  651. $errors = $filtered_results['errors'];
  652. if ( empty( $blogname ) ) {
  653. $blogname = $user_name;
  654. }
  655. ?>
  656. <form id="setupform" method="post" action="wp-signup.php">
  657. <input type="hidden" name="stage" value="validate-blog-signup" />
  658. <input type="hidden" name="user_name" value="<?php echo esc_attr( $user_name ); ?>" />
  659. <input type="hidden" name="user_email" value="<?php echo esc_attr( $user_email ); ?>" />
  660. <?php
  661. /** This action is documented in wp-signup.php */
  662. do_action( 'signup_hidden_fields', 'validate-site' );
  663. ?>
  664. <?php show_blog_form( $blogname, $blog_title, $errors ); ?>
  665. <p class="submit"><input type="submit" name="submit" class="submit" value="<?php esc_attr_e( 'Signup' ); ?>" /></p>
  666. </form>
  667. <?php
  668. }
  669. /**
  670. * Validate new site signup
  671. *
  672. * @since MU (3.0.0)
  673. *
  674. * @return bool True if the site signup was validated, false if error
  675. */
  676. function validate_blog_signup() {
  677. // Re-validate user info.
  678. $user_result = wpmu_validate_user_signup( $_POST['user_name'], $_POST['user_email'] );
  679. $user_name = $user_result['user_name'];
  680. $user_email = $user_result['user_email'];
  681. $user_errors = $user_result['errors'];
  682. if ( $user_errors->has_errors() ) {
  683. signup_user( $user_name, $user_email, $user_errors );
  684. return false;
  685. }
  686. $result = wpmu_validate_blog_signup( $_POST['blogname'], $_POST['blog_title'] );
  687. $domain = $result['domain'];
  688. $path = $result['path'];
  689. $blogname = $result['blogname'];
  690. $blog_title = $result['blog_title'];
  691. $errors = $result['errors'];
  692. if ( $errors->has_errors() ) {
  693. signup_blog( $user_name, $user_email, $blogname, $blog_title, $errors );
  694. return false;
  695. }
  696. $public = (int) $_POST['blog_public'];
  697. $signup_meta = array(
  698. 'lang_id' => 1,
  699. 'public' => $public,
  700. );
  701. // Handle the language setting for the new site.
  702. if ( ! empty( $_POST['WPLANG'] ) ) {
  703. $languages = signup_get_available_languages();
  704. if ( in_array( $_POST['WPLANG'], $languages, true ) ) {
  705. $language = wp_unslash( sanitize_text_field( $_POST['WPLANG'] ) );
  706. if ( $language ) {
  707. $signup_meta['WPLANG'] = $language;
  708. }
  709. }
  710. }
  711. /** This filter is documented in wp-signup.php */
  712. $meta = apply_filters( 'add_signup_meta', $signup_meta );
  713. wpmu_signup_blog( $domain, $path, $blog_title, $user_name, $user_email, $meta );
  714. confirm_blog_signup( $domain, $path, $blog_title, $user_name, $user_email, $meta );
  715. return true;
  716. }
  717. /**
  718. * Shows a message confirming that the new site has been registered and is awaiting activation.
  719. *
  720. * @since MU (3.0.0)
  721. *
  722. * @param string $domain The domain or subdomain of the site.
  723. * @param string $path The path of the site.
  724. * @param string $blog_title The title of the new site.
  725. * @param string $user_name The user's username.
  726. * @param string $user_email The user's email address.
  727. * @param array $meta Any additional meta from the {@see 'add_signup_meta'} filter in validate_blog_signup().
  728. */
  729. function confirm_blog_signup( $domain, $path, $blog_title, $user_name = '', $user_email = '', $meta = array() ) {
  730. ?>
  731. <h2>
  732. <?php
  733. /* translators: %s: Site address. */
  734. printf( __( 'Congratulations! Your new site, %s, is almost ready.' ), "<a href='http://{$domain}{$path}'>{$blog_title}</a>" )
  735. ?>
  736. </h2>
  737. <p><?php _e( 'But, before you can start using your site, <strong>you must activate it</strong>.' ); ?></p>
  738. <p>
  739. <?php
  740. /* translators: %s: Email address. */
  741. printf( __( 'Check your inbox at %s and click the link given.' ), '<strong>' . $user_email . '</strong>' );
  742. ?>
  743. </p>
  744. <p><?php _e( 'If you do not activate your site within two days, you will have to sign up again.' ); ?></p>
  745. <h2><?php _e( 'Still waiting for your email?' ); ?></h2>
  746. <p>
  747. <?php _e( 'If you haven&#8217;t received your email yet, there are a number of things you can do:' ); ?>
  748. <ul id="noemail-tips">
  749. <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>
  750. <li><p><?php _e( 'Check the junk or spam folder of your email client. Sometime emails wind up there by mistake.' ); ?></p></li>
  751. <li>
  752. <?php
  753. /* translators: %s: Email address. */
  754. printf( __( 'Have you entered your email correctly? You have entered %s, if it&#8217;s incorrect, you will not receive your email.' ), $user_email );
  755. ?>
  756. </li>
  757. </ul>
  758. </p>
  759. <?php
  760. /** This action is documented in wp-signup.php */
  761. do_action( 'signup_finished' );
  762. }
  763. /**
  764. * Retrieves languages available during the site/user signup process.
  765. *
  766. * @since 4.4.0
  767. *
  768. * @see get_available_languages()
  769. *
  770. * @return string[] Array of available language codes. Language codes are formed by
  771. * stripping the .mo extension from the language file names.
  772. */
  773. function signup_get_available_languages() {
  774. /**
  775. * Filters the list of available languages for front-end site signups.
  776. *
  777. * Passing an empty array to this hook will disable output of the setting on the
  778. * signup form, and the default language will be used when creating the site.
  779. *
  780. * Languages not already installed will be stripped.
  781. *
  782. * @since 4.4.0
  783. *
  784. * @param string[] $languages Array of available language codes. Language codes are formed by
  785. * stripping the .mo extension from the language file names.
  786. */
  787. $languages = (array) apply_filters( 'signup_get_available_languages', get_available_languages() );
  788. /*
  789. * Strip any non-installed languages and return.
  790. *
  791. * Re-call get_available_languages() here in case a language pack was installed
  792. * in a callback hooked to the 'signup_get_available_languages' filter before this point.
  793. */
  794. return array_intersect_assoc( $languages, get_available_languages() );
  795. }
  796. // Main.
  797. $active_signup = get_site_option( 'registration', 'none' );
  798. /**
  799. * Filters the type of site sign-up.
  800. *
  801. * @since 3.0.0
  802. *
  803. * @param string $active_signup String that returns registration type. The value can be
  804. * 'all', 'none', 'blog', or 'user'.
  805. */
  806. $active_signup = apply_filters( 'wpmu_active_signup', $active_signup );
  807. if ( current_user_can( 'manage_network' ) ) {
  808. echo '<div class="mu_alert">';
  809. _e( 'Greetings Network Administrator!' );
  810. echo ' ';
  811. switch ( $active_signup ) {
  812. case 'none':
  813. _e( 'The network currently disallows registrations.' );
  814. break;
  815. case 'blog':
  816. _e( 'The network currently allows site registrations.' );
  817. break;
  818. case 'user':
  819. _e( 'The network currently allows user registrations.' );
  820. break;
  821. default:
  822. _e( 'The network currently allows both site and user registrations.' );
  823. break;
  824. }
  825. echo ' ';
  826. /* translators: %s: URL to Network Settings screen. */
  827. printf( __( 'To change or disable registration go to your <a href="%s">Options page</a>.' ), esc_url( network_admin_url( 'settings.php' ) ) );
  828. echo '</div>';
  829. }
  830. $newblogname = isset( $_GET['new'] ) ? strtolower( preg_replace( '/^-|-$|[^-a-zA-Z0-9]/', '', $_GET['new'] ) ) : null;
  831. $current_user = wp_get_current_user();
  832. if ( 'none' === $active_signup ) {
  833. _e( 'Registration has been disabled.' );
  834. } elseif ( 'blog' === $active_signup && ! is_user_logged_in() ) {
  835. $login_url = wp_login_url( network_site_url( 'wp-signup.php' ) );
  836. /* translators: %s: Login URL. */
  837. printf( __( 'You must first <a href="%s">log in</a>, and then you can create a new site.' ), $login_url );
  838. } else {
  839. $stage = isset( $_POST['stage'] ) ? $_POST['stage'] : 'default';
  840. switch ( $stage ) {
  841. case 'validate-user-signup':
  842. if ( 'all' === $active_signup
  843. || ( 'blog' === $_POST['signup_for'] && 'blog' === $active_signup )
  844. || ( 'user' === $_POST['signup_for'] && 'user' === $active_signup )
  845. ) {
  846. validate_user_signup();
  847. } else {
  848. _e( 'User registration has been disabled.' );
  849. }
  850. break;
  851. case 'validate-blog-signup':
  852. if ( 'all' === $active_signup || 'blog' === $active_signup ) {
  853. validate_blog_signup();
  854. } else {
  855. _e( 'Site registration has been disabled.' );
  856. }
  857. break;
  858. case 'gimmeanotherblog':
  859. validate_another_blog_signup();
  860. break;
  861. case 'default':
  862. default:
  863. $user_email = isset( $_POST['user_email'] ) ? $_POST['user_email'] : '';
  864. /**
  865. * Fires when the site sign-up form is sent.
  866. *
  867. * @since 3.0.0
  868. */
  869. do_action( 'preprocess_signup_form' );
  870. if ( is_user_logged_in() && ( 'all' === $active_signup || 'blog' === $active_signup ) ) {
  871. signup_another_blog( $newblogname );
  872. } elseif ( ! is_user_logged_in() && ( 'all' === $active_signup || 'user' === $active_signup ) ) {
  873. signup_user( $newblogname, $user_email );
  874. } elseif ( ! is_user_logged_in() && ( 'blog' === $active_signup ) ) {
  875. _e( 'Sorry, new registrations are not allowed at this time.' );
  876. } else {
  877. _e( 'You are logged in already. No need to register again!' );
  878. }
  879. if ( $newblogname ) {
  880. $newblog = get_blogaddress_by_name( $newblogname );
  881. if ( 'blog' === $active_signup || 'all' === $active_signup ) {
  882. printf(
  883. /* translators: %s: Site address. */
  884. '<p>' . __( 'The site you were looking for, %s, does not exist, but you can create it now!' ) . '</p>',
  885. '<strong>' . $newblog . '</strong>'
  886. );
  887. } else {
  888. printf(
  889. /* translators: %s: Site address. */
  890. '<p>' . __( 'The site you were looking for, %s, does not exist.' ) . '</p>',
  891. '<strong>' . $newblog . '</strong>'
  892. );
  893. }
  894. }
  895. break;
  896. }
  897. }
  898. ?>
  899. </div>
  900. </div>
  901. <?php
  902. /**
  903. * Fires after the sign-up forms, before wp_footer.
  904. *
  905. * @since 3.0.0
  906. */
  907. do_action( 'after_signup_form' );
  908. ?>
  909. <?php
  910. get_footer( 'wp-signup' );