wp-signup.php 29 KB

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