wp-signup.php 29 KB

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