/wp-signup.php

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