Açıklama Yok

wp-signup.php 31KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  1. <?php
  2. /** Sets up the WordPress Environment. */
  3. require __DIR__ . '/wp-load.php';
  4. add_filter( 'wp_robots', 'wp_robots_no_robots' );
  5. require __DIR__ . '/wp-blog-header.php';
  6. nocache_headers();
  7. if ( is_array( get_site_option( 'illegal_names' ) ) && isset( $_GET['new'] ) && in_array( $_GET['new'], get_site_option( 'illegal_names' ), true ) ) {
  8. wp_redirect( network_home_url() );
  9. die();
  10. }
  11. /**
  12. * Prints signup_header via wp_head.
  13. *
  14. * @since MU (3.0.0)
  15. */
  16. function do_signup_header() {
  17. /**
  18. * Fires within the head section of the site sign-up screen.
  19. *
  20. * @since 3.0.0
  21. */
  22. do_action( 'signup_header' );
  23. }
  24. add_action( 'wp_head', 'do_signup_header' );
  25. if ( ! is_multisite() ) {
  26. wp_redirect( wp_registration_url() );
  27. die();
  28. }
  29. if ( ! is_main_site() ) {
  30. wp_redirect( network_site_url( 'wp-signup.php' ) );
  31. die();
  32. }
  33. // Fix for page title.
  34. $wp_query->is_404 = false;
  35. /**
  36. * Fires before the Site Sign-up page is loaded.
  37. *
  38. * @since 4.4.0
  39. */
  40. do_action( 'before_signup_header' );
  41. /**
  42. * Prints styles for front-end Multisite Sign-up pages.
  43. *
  44. * @since MU (3.0.0)
  45. */
  46. function wpmu_signup_stylesheet() {
  47. ?>
  48. <style type="text/css">
  49. .mu_register { width: 90%; margin:0 auto; }
  50. .mu_register form { margin-top: 2em; }
  51. .mu_register .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 Sign-up 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" autocomplete="off" /><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" autocomplete="off" /><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 ) . '" autocomplete="off" />';
  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. * Validates the new site sign-up.
  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" autocomplete="username" /><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" autocomplete="email" /><br /><?php _e( 'Your registration email is sent 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. * Validates user sign-up 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. * Shows a form for 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 are 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. * Validates a new site sign-up for an existing user.
  354. *
  355. * @since MU (3.0.0)
  356. *
  357. * @global string $blogname The new site's subdomain or directory name.
  358. * @global string $blog_title The new site's title.
  359. * @global WP_Error $errors Existing errors in the global scope.
  360. * @global string $domain The new site's domain.
  361. * @global string $path The new site's path.
  362. *
  363. * @return null|bool True if site signup was validated, false on 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. * Shows a message confirming that the new site has been created.
  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. * @global string $active_signup String that returns registration type. The value can be
  494. * 'all', 'none', 'blog', or 'user'.
  495. *
  496. * @param string $user_name The username.
  497. * @param string $user_email The user's email.
  498. * @param WP_Error|string $errors A WP_Error object containing existing errors. Defaults to empty string.
  499. */
  500. function signup_user( $user_name = '', $user_email = '', $errors = '' ) {
  501. global $active_signup;
  502. if ( ! is_wp_error( $errors ) ) {
  503. $errors = new WP_Error();
  504. }
  505. $signup_for = isset( $_POST['signup_for'] ) ? esc_html( $_POST['signup_for'] ) : 'blog';
  506. $signup_user_defaults = array(
  507. 'user_name' => $user_name,
  508. 'user_email' => $user_email,
  509. 'errors' => $errors,
  510. );
  511. /**
  512. * Filters the default user variables used on the user sign-up form.
  513. *
  514. * @since 3.0.0
  515. *
  516. * @param array $signup_user_defaults {
  517. * An array of default user variables.
  518. *
  519. * @type string $user_name The user username.
  520. * @type string $user_email The user email address.
  521. * @type WP_Error $errors A WP_Error object with possible errors relevant to the sign-up user.
  522. * }
  523. */
  524. $filtered_results = apply_filters( 'signup_user_init', $signup_user_defaults );
  525. $user_name = $filtered_results['user_name'];
  526. $user_email = $filtered_results['user_email'];
  527. $errors = $filtered_results['errors'];
  528. ?>
  529. <h2>
  530. <?php
  531. /* translators: %s: Name of the network. */
  532. printf( __( 'Get your own %s account in seconds' ), get_network()->site_name );
  533. ?>
  534. </h2>
  535. <form id="setupform" method="post" action="wp-signup.php" novalidate="novalidate">
  536. <input type="hidden" name="stage" value="validate-user-signup" />
  537. <?php
  538. /** This action is documented in wp-signup.php */
  539. do_action( 'signup_hidden_fields', 'validate-user' );
  540. ?>
  541. <?php show_user_form( $user_name, $user_email, $errors ); ?>
  542. <p>
  543. <?php if ( 'blog' === $active_signup ) { ?>
  544. <input id="signupblog" type="hidden" name="signup_for" value="blog" />
  545. <?php } elseif ( 'user' === $active_signup ) { ?>
  546. <input id="signupblog" type="hidden" name="signup_for" value="user" />
  547. <?php } else { ?>
  548. <input id="signupblog" type="radio" name="signup_for" value="blog" <?php checked( $signup_for, 'blog' ); ?> />
  549. <label class="checkbox" for="signupblog"><?php _e( 'Gimme a site!' ); ?></label>
  550. <br />
  551. <input id="signupuser" type="radio" name="signup_for" value="user" <?php checked( $signup_for, 'user' ); ?> />
  552. <label class="checkbox" for="signupuser"><?php _e( 'Just a username, please.' ); ?></label>
  553. <?php } ?>
  554. </p>
  555. <p class="submit"><input type="submit" name="submit" class="submit" value="<?php esc_attr_e( 'Next' ); ?>" /></p>
  556. </form>
  557. <?php
  558. }
  559. /**
  560. * Validates the new user sign-up.
  561. *
  562. * @since MU (3.0.0)
  563. *
  564. * @return bool True if new user sign-up was validated, false on error.
  565. */
  566. function validate_user_signup() {
  567. $result = validate_user_form();
  568. $user_name = $result['user_name'];
  569. $user_email = $result['user_email'];
  570. $errors = $result['errors'];
  571. if ( $errors->has_errors() ) {
  572. signup_user( $user_name, $user_email, $errors );
  573. return false;
  574. }
  575. if ( 'blog' === $_POST['signup_for'] ) {
  576. signup_blog( $user_name, $user_email );
  577. return false;
  578. }
  579. /** This filter is documented in wp-signup.php */
  580. wpmu_signup_user( $user_name, $user_email, apply_filters( 'add_signup_meta', array() ) );
  581. confirm_user_signup( $user_name, $user_email );
  582. return true;
  583. }
  584. /**
  585. * Shows a message confirming that the new user has been registered and is awaiting activation.
  586. *
  587. * @since MU (3.0.0)
  588. *
  589. * @param string $user_name The username.
  590. * @param string $user_email The user's email address.
  591. */
  592. function confirm_user_signup( $user_name, $user_email ) {
  593. ?>
  594. <h2>
  595. <?php
  596. /* translators: %s: Username. */
  597. printf( __( '%s is your new username' ), $user_name )
  598. ?>
  599. </h2>
  600. <p><?php _e( 'But, before you can start using your new username, <strong>you must activate it</strong>.' ); ?></p>
  601. <p>
  602. <?php
  603. /* translators: %s: Email address. */
  604. printf( __( 'Check your inbox at %s and click the link given.' ), '<strong>' . $user_email . '</strong>' );
  605. ?>
  606. </p>
  607. <p><?php _e( 'If you do not activate your username within two days, you will have to sign up again.' ); ?></p>
  608. <?php
  609. /** This action is documented in wp-signup.php */
  610. do_action( 'signup_finished' );
  611. }
  612. /**
  613. * Shows a form for a user or visitor to sign up for a new site.
  614. *
  615. * @since MU (3.0.0)
  616. *
  617. * @param string $user_name The username.
  618. * @param string $user_email The user's email address.
  619. * @param string $blogname The site name.
  620. * @param string $blog_title The site title.
  621. * @param WP_Error|string $errors A WP_Error object containing existing errors. Defaults to empty string.
  622. */
  623. function signup_blog( $user_name = '', $user_email = '', $blogname = '', $blog_title = '', $errors = '' ) {
  624. if ( ! is_wp_error( $errors ) ) {
  625. $errors = new WP_Error();
  626. }
  627. $signup_blog_defaults = array(
  628. 'user_name' => $user_name,
  629. 'user_email' => $user_email,
  630. 'blogname' => $blogname,
  631. 'blog_title' => $blog_title,
  632. 'errors' => $errors,
  633. );
  634. /**
  635. * Filters the default site creation variables for the site sign-up form.
  636. *
  637. * @since 3.0.0
  638. *
  639. * @param array $signup_blog_defaults {
  640. * An array of default site creation variables.
  641. *
  642. * @type string $user_name The user username.
  643. * @type string $user_email The user email address.
  644. * @type string $blogname The blogname.
  645. * @type string $blog_title The title of the site.
  646. * @type WP_Error $errors A WP_Error object with possible errors relevant to new site creation variables.
  647. * }
  648. */
  649. $filtered_results = apply_filters( 'signup_blog_init', $signup_blog_defaults );
  650. $user_name = $filtered_results['user_name'];
  651. $user_email = $filtered_results['user_email'];
  652. $blogname = $filtered_results['blogname'];
  653. $blog_title = $filtered_results['blog_title'];
  654. $errors = $filtered_results['errors'];
  655. if ( empty( $blogname ) ) {
  656. $blogname = $user_name;
  657. }
  658. ?>
  659. <form id="setupform" method="post" action="wp-signup.php">
  660. <input type="hidden" name="stage" value="validate-blog-signup" />
  661. <input type="hidden" name="user_name" value="<?php echo esc_attr( $user_name ); ?>" />
  662. <input type="hidden" name="user_email" value="<?php echo esc_attr( $user_email ); ?>" />
  663. <?php
  664. /** This action is documented in wp-signup.php */
  665. do_action( 'signup_hidden_fields', 'validate-site' );
  666. ?>
  667. <?php show_blog_form( $blogname, $blog_title, $errors ); ?>
  668. <p class="submit"><input type="submit" name="submit" class="submit" value="<?php esc_attr_e( 'Sign up' ); ?>" /></p>
  669. </form>
  670. <?php
  671. }
  672. /**
  673. * Validates new site signup.
  674. *
  675. * @since MU (3.0.0)
  676. *
  677. * @return bool True if the site sign-up was validated, false on error.
  678. */
  679. function validate_blog_signup() {
  680. // Re-validate user info.
  681. $user_result = wpmu_validate_user_signup( $_POST['user_name'], $_POST['user_email'] );
  682. $user_name = $user_result['user_name'];
  683. $user_email = $user_result['user_email'];
  684. $user_errors = $user_result['errors'];
  685. if ( $user_errors->has_errors() ) {
  686. signup_user( $user_name, $user_email, $user_errors );
  687. return false;
  688. }
  689. $result = wpmu_validate_blog_signup( $_POST['blogname'], $_POST['blog_title'] );
  690. $domain = $result['domain'];
  691. $path = $result['path'];
  692. $blogname = $result['blogname'];
  693. $blog_title = $result['blog_title'];
  694. $errors = $result['errors'];
  695. if ( $errors->has_errors() ) {
  696. signup_blog( $user_name, $user_email, $blogname, $blog_title, $errors );
  697. return false;
  698. }
  699. $public = (int) $_POST['blog_public'];
  700. $signup_meta = array(
  701. 'lang_id' => 1,
  702. 'public' => $public,
  703. );
  704. // Handle the language setting for the new site.
  705. if ( ! empty( $_POST['WPLANG'] ) ) {
  706. $languages = signup_get_available_languages();
  707. if ( in_array( $_POST['WPLANG'], $languages, true ) ) {
  708. $language = wp_unslash( sanitize_text_field( $_POST['WPLANG'] ) );
  709. if ( $language ) {
  710. $signup_meta['WPLANG'] = $language;
  711. }
  712. }
  713. }
  714. /** This filter is documented in wp-signup.php */
  715. $meta = apply_filters( 'add_signup_meta', $signup_meta );
  716. wpmu_signup_blog( $domain, $path, $blog_title, $user_name, $user_email, $meta );
  717. confirm_blog_signup( $domain, $path, $blog_title, $user_name, $user_email, $meta );
  718. return true;
  719. }
  720. /**
  721. * Shows a message confirming that the new site has been registered and is awaiting activation.
  722. *
  723. * @since MU (3.0.0)
  724. *
  725. * @param string $domain The domain or subdomain of the site.
  726. * @param string $path The path of the site.
  727. * @param string $blog_title The title of the new site.
  728. * @param string $user_name The user's username.
  729. * @param string $user_email The user's email address.
  730. * @param array $meta Any additional meta from the {@see 'add_signup_meta'} filter in validate_blog_signup().
  731. */
  732. function confirm_blog_signup( $domain, $path, $blog_title, $user_name = '', $user_email = '', $meta = array() ) {
  733. ?>
  734. <h2>
  735. <?php
  736. /* translators: %s: Site address. */
  737. printf( __( 'Congratulations! Your new site, %s, is almost ready.' ), "<a href='http://{$domain}{$path}'>{$blog_title}</a>" )
  738. ?>
  739. </h2>
  740. <p><?php _e( 'But, before you can start using your site, <strong>you must activate it</strong>.' ); ?></p>
  741. <p>
  742. <?php
  743. /* translators: %s: Email address. */
  744. printf( __( 'Check your inbox at %s and click the link given.' ), '<strong>' . $user_email . '</strong>' );
  745. ?>
  746. </p>
  747. <p><?php _e( 'If you do not activate your site within two days, you will have to sign up again.' ); ?></p>
  748. <h2><?php _e( 'Still waiting for your email?' ); ?></h2>
  749. <p>
  750. <?php _e( 'If you have not received your email yet, there are a number of things you can do:' ); ?>
  751. <ul id="noemail-tips">
  752. <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>
  753. <li><p><?php _e( 'Check the junk or spam folder of your email client. Sometime emails wind up there by mistake.' ); ?></p></li>
  754. <li>
  755. <?php
  756. /* translators: %s: Email address. */
  757. printf( __( 'Have you entered your email correctly? You have entered %s, if it&#8217;s incorrect, you will not receive your email.' ), $user_email );
  758. ?>
  759. </li>
  760. </ul>
  761. </p>
  762. <?php
  763. /** This action is documented in wp-signup.php */
  764. do_action( 'signup_finished' );
  765. }
  766. /**
  767. * Retrieves languages available during the site/user sign-up process.
  768. *
  769. * @since 4.4.0
  770. *
  771. * @see get_available_languages()
  772. *
  773. * @return string[] Array of available language codes. Language codes are formed by
  774. * stripping the .mo extension from the language file names.
  775. */
  776. function signup_get_available_languages() {
  777. /**
  778. * Filters the list of available languages for front-end site sign-ups.
  779. *
  780. * Passing an empty array to this hook will disable output of the setting on the
  781. * sign-up form, and the default language will be used when creating the site.
  782. *
  783. * Languages not already installed will be stripped.
  784. *
  785. * @since 4.4.0
  786. *
  787. * @param string[] $languages Array of available language codes. Language codes are formed by
  788. * stripping the .mo extension from the language file names.
  789. */
  790. $languages = (array) apply_filters( 'signup_get_available_languages', get_available_languages() );
  791. /*
  792. * Strip any non-installed languages and return.
  793. *
  794. * Re-call get_available_languages() here in case a language pack was installed
  795. * in a callback hooked to the 'signup_get_available_languages' filter before this point.
  796. */
  797. return array_intersect_assoc( $languages, get_available_languages() );
  798. }
  799. // Main.
  800. $active_signup = get_site_option( 'registration', 'none' );
  801. /**
  802. * Filters the type of site sign-up.
  803. *
  804. * @since 3.0.0
  805. *
  806. * @param string $active_signup String that returns registration type. The value can be
  807. * 'all', 'none', 'blog', or 'user'.
  808. */
  809. $active_signup = apply_filters( 'wpmu_active_signup', $active_signup );
  810. if ( current_user_can( 'manage_network' ) ) {
  811. echo '<div class="mu_alert">';
  812. _e( 'Greetings Network Administrator!' );
  813. echo ' ';
  814. switch ( $active_signup ) {
  815. case 'none':
  816. _e( 'The network currently disallows registrations.' );
  817. break;
  818. case 'blog':
  819. _e( 'The network currently allows site registrations.' );
  820. break;
  821. case 'user':
  822. _e( 'The network currently allows user registrations.' );
  823. break;
  824. default:
  825. _e( 'The network currently allows both site and user registrations.' );
  826. break;
  827. }
  828. echo ' ';
  829. /* translators: %s: URL to Network Settings screen. */
  830. printf( __( 'To change or disable registration go to your <a href="%s">Options page</a>.' ), esc_url( network_admin_url( 'settings.php' ) ) );
  831. echo '</div>';
  832. }
  833. $newblogname = isset( $_GET['new'] ) ? strtolower( preg_replace( '/^-|-$|[^-a-zA-Z0-9]/', '', $_GET['new'] ) ) : null;
  834. $current_user = wp_get_current_user();
  835. if ( 'none' === $active_signup ) {
  836. _e( 'Registration has been disabled.' );
  837. } elseif ( 'blog' === $active_signup && ! is_user_logged_in() ) {
  838. $login_url = wp_login_url( network_site_url( 'wp-signup.php' ) );
  839. /* translators: %s: Login URL. */
  840. printf( __( 'You must first <a href="%s">log in</a>, and then you can create a new site.' ), $login_url );
  841. } else {
  842. $stage = isset( $_POST['stage'] ) ? $_POST['stage'] : 'default';
  843. switch ( $stage ) {
  844. case 'validate-user-signup':
  845. if ( 'all' === $active_signup
  846. || ( 'blog' === $_POST['signup_for'] && 'blog' === $active_signup )
  847. || ( 'user' === $_POST['signup_for'] && 'user' === $active_signup )
  848. ) {
  849. validate_user_signup();
  850. } else {
  851. _e( 'User registration has been disabled.' );
  852. }
  853. break;
  854. case 'validate-blog-signup':
  855. if ( 'all' === $active_signup || 'blog' === $active_signup ) {
  856. validate_blog_signup();
  857. } else {
  858. _e( 'Site registration has been disabled.' );
  859. }
  860. break;
  861. case 'gimmeanotherblog':
  862. validate_another_blog_signup();
  863. break;
  864. case 'default':
  865. default:
  866. $user_email = isset( $_POST['user_email'] ) ? $_POST['user_email'] : '';
  867. /**
  868. * Fires when the site sign-up form is sent.
  869. *
  870. * @since 3.0.0
  871. */
  872. do_action( 'preprocess_signup_form' );
  873. if ( is_user_logged_in() && ( 'all' === $active_signup || 'blog' === $active_signup ) ) {
  874. signup_another_blog( $newblogname );
  875. } elseif ( ! is_user_logged_in() && ( 'all' === $active_signup || 'user' === $active_signup ) ) {
  876. signup_user( $newblogname, $user_email );
  877. } elseif ( ! is_user_logged_in() && ( 'blog' === $active_signup ) ) {
  878. _e( 'Sorry, new registrations are not allowed at this time.' );
  879. } else {
  880. _e( 'You are logged in already. No need to register again!' );
  881. }
  882. if ( $newblogname ) {
  883. $newblog = get_blogaddress_by_name( $newblogname );
  884. if ( 'blog' === $active_signup || 'all' === $active_signup ) {
  885. printf(
  886. /* translators: %s: Site address. */
  887. '<p>' . __( 'The site you were looking for, %s, does not exist, but you can create it now!' ) . '</p>',
  888. '<strong>' . $newblog . '</strong>'
  889. );
  890. } else {
  891. printf(
  892. /* translators: %s: Site address. */
  893. '<p>' . __( 'The site you were looking for, %s, does not exist.' ) . '</p>',
  894. '<strong>' . $newblog . '</strong>'
  895. );
  896. }
  897. }
  898. break;
  899. }
  900. }
  901. ?>
  902. </div>
  903. </div>
  904. <?php
  905. /**
  906. * Fires after the sign-up forms, before wp_footer.
  907. *
  908. * @since 3.0.0
  909. */
  910. do_action( 'after_signup_form' );
  911. ?>
  912. <?php
  913. get_footer( 'wp-signup' );