| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * WordPress Signup Page 4 * 5 * Handles the user registration and site creation process for multisite installations. 6 * 7 * @package WordPress 8 */ 9 10 /** Sets up the WordPress Environment. */ 11 require __DIR__ . '/wp-load.php'; 12 13 add_filter( 'wp_robots', 'wp_robots_no_robots' ); 14 15 require __DIR__ . '/wp-blog-header.php'; 16 17 nocache_headers(); 18 19 if ( is_array( get_site_option( 'illegal_names' ) ) && isset( $_GET['new'] ) && in_array( $_GET['new'], get_site_option( 'illegal_names' ), true ) ) { 20 wp_redirect( network_home_url() ); 21 die(); 22 } 23 24 /** 25 * Prints signup_header via wp_head. 26 * 27 * @since MU (3.0.0) 28 */ 29 function do_signup_header() { 30 /** 31 * Fires within the head section of the site sign-up screen. 32 * 33 * @since 3.0.0 34 */ 35 do_action( 'signup_header' ); 36 } 37 add_action( 'wp_head', 'do_signup_header' ); 38 39 if ( ! is_multisite() ) { 40 wp_redirect( wp_registration_url() ); 41 die(); 42 } 43 44 if ( ! is_main_site() ) { 45 wp_redirect( network_site_url( 'wp-signup.php' ) ); 46 die(); 47 } 48 49 // Fix for page title. 50 $wp_query->is_404 = false; 51 52 /** 53 * Fires before the Site Sign-up page is loaded. 54 * 55 * @since 4.4.0 56 */ 57 do_action( 'before_signup_header' ); 58 59 /** 60 * Prints styles for front-end Multisite Sign-up pages. 61 * 62 * @since MU (3.0.0) 63 */ 64 function wpmu_signup_stylesheet() { 65 ?> 66 <style> 67 .mu_register { width: 90%; margin: 0 auto; text-align: start; padding: 24px; box-sizing: border-box; } 68 .mu_register p { font-size: 18px; } 69 .mu_register form { margin: 24px 0; } 70 .mu_register fieldset, 71 .mu_register legend { margin: 0; padding: 0; border: none; } 72 .mu_register .error { padding: 10px; color: #333; background: #ffebe8; border: 1px solid #c00; } 73 .mu_register input[type="submit"], 74 .mu_register #blog_title, 75 .mu_register #user_email, 76 .mu_register #blogname, 77 .mu_register #user_name { width: 100%; font-size: 24px; margin: 5px 0; box-sizing: border-box; } 78 .mu_register input[type="email"], 79 .mu_register #user_name { direction: ltr; } 80 .mu_register #site-language { display: block; } 81 .mu_register .prefix_address, 82 .mu_register .suffix_address { font-size: 18px; display: inline-block; direction: ltr; } 83 .mu_register label, 84 .mu_register legend, 85 .mu_register .label-heading { font-weight: 600; font-size: 15px; display: block; margin: 10px 0; } 86 .mu_register legend + p, 87 .mu_register input + p { margin-top: 0; } 88 .mu_register label.checkbox { display: inline; } 89 .mu_register .mu_alert { font-weight: 600; padding: 10px; color: #333; background: #ffffe0; border: 1px solid #e6db55; } 90 .mu_register .mu_alert a { color: inherit; text-decoration: underline; } 91 .mu_register .signup-options .wp-signup-radio-button { display: block; } 92 .mu_register .privacy-intro .wp-signup-radio-button { margin-right: 0.5em; } 93 .rtl .mu_register .wp-signup-blogname { direction: ltr; text-align: right; } 94 </style> 95 <?php 96 } 97 add_action( 'wp_head', 'wpmu_signup_stylesheet' ); 98 99 get_header( 'wp-signup' ); 100 101 /** 102 * Fires before the site Sign-up form. 103 * 104 * @since 3.0.0 105 */ 106 do_action( 'before_signup_form' ); 107 ?> 108 <div id="signup-content" class="widecolumn"> 109 <div class="mu_register wp-signup-container" role="main"> 110 <?php 111 /** 112 * Generates and displays the Sign-up and Create Site forms. 113 * 114 * @since MU (3.0.0) 115 * 116 * @param string $blogname The new site name. 117 * @param string $blog_title The new site title. 118 * @param WP_Error|string $errors A WP_Error object containing existing errors. Defaults to empty string. 119 */ 120 function show_blog_form( $blogname = '', $blog_title = '', $errors = '' ) { 121 if ( ! is_wp_error( $errors ) ) { 122 $errors = new WP_Error(); 123 } 124 125 $current_network = get_network(); 126 // Site name. 127 if ( ! is_subdomain_install() ) { 128 echo '<label for="blogname">' . __( 'Site Name (subdirectory only):' ) . '</label>'; 129 } else { 130 echo '<label for="blogname">' . __( 'Site Domain (subdomain only):' ) . '</label>'; 131 } 132 133 $errmsg_blogname = $errors->get_error_message( 'blogname' ); 134 $errmsg_blogname_aria = ''; 135 if ( $errmsg_blogname ) { 136 $errmsg_blogname_aria = 'wp-signup-blogname-error '; 137 echo '<p class="error" id="wp-signup-blogname-error">' . $errmsg_blogname . '</p>'; 138 } 139 140 if ( ! is_subdomain_install() ) { 141 echo '<div class="wp-signup-blogname"><span class="prefix_address" id="prefix-address">' . $current_network->domain . $current_network->path . '</span><input name="blogname" type="text" id="blogname" value="' . esc_attr( $blogname ) . '" maxlength="60" autocomplete="off" required="required" aria-describedby="' . $errmsg_blogname_aria . 'prefix-address" /></div>'; 142 } else { 143 $site_domain = preg_replace( '|^www\.|', '', $current_network->domain ); 144 echo '<div class="wp-signup-blogname"><input name="blogname" type="text" id="blogname" value="' . esc_attr( $blogname ) . '" maxlength="60" autocomplete="off" required="required" aria-describedby="' . $errmsg_blogname_aria . 'suffix-address" /><span class="suffix_address" id="suffix-address">.' . esc_html( $site_domain ) . '</span></div>'; 145 } 146 147 if ( ! is_user_logged_in() ) { 148 if ( ! is_subdomain_install() ) { 149 $site = $current_network->domain . $current_network->path . __( 'sitename' ); 150 } else { 151 $site = __( 'domain' ) . '.' . $site_domain . $current_network->path; 152 } 153 154 printf( 155 '<p>(<strong>%s</strong>) %s</p>', 156 /* translators: %s: Site address. */ 157 sprintf( __( 'Your address will be %s.' ), $site ), 158 __( 'Must be at least 4 characters, letters and numbers only. It cannot be changed, so choose carefully!' ) 159 ); 160 } 161 162 // Site Title. 163 ?> 164 <label for="blog_title"><?php _e( 'Site Title:' ); ?></label> 165 <?php 166 $errmsg_blog_title = $errors->get_error_message( 'blog_title' ); 167 $errmsg_blog_title_aria = ''; 168 if ( $errmsg_blog_title ) { 169 $errmsg_blog_title_aria = ' aria-describedby="wp-signup-blog-title-error"'; 170 echo '<p class="error" id="wp-signup-blog-title-error">' . $errmsg_blog_title . '</p>'; 171 } 172 echo '<input name="blog_title" type="text" id="blog_title" value="' . esc_attr( $blog_title ) . '" required="required" autocomplete="off"' . $errmsg_blog_title_aria . ' />'; 173 ?> 174 175 <?php 176 // Site Language. 177 $languages = signup_get_available_languages(); 178 179 if ( ! empty( $languages ) ) : 180 ?> 181 <p> 182 <label for="site-language"><?php _e( 'Site Language:' ); ?></label> 183 <?php 184 // Network default. 185 $lang = get_site_option( 'WPLANG' ); 186 187 if ( isset( $_POST['WPLANG'] ) ) { 188 $lang = $_POST['WPLANG']; 189 } 190 191 // Use US English if the default isn't available. 192 if ( ! in_array( $lang, $languages, true ) ) { 193 $lang = ''; 194 } 195 196 wp_dropdown_languages( 197 array( 198 'name' => 'WPLANG', 199 'id' => 'site-language', 200 'selected' => $lang, 201 'languages' => $languages, 202 'show_available_translations' => false, 203 ) 204 ); 205 ?> 206 </p> 207 <?php 208 endif; // Languages. 209 210 $blog_public_on_checked = ''; 211 $blog_public_off_checked = ''; 212 if ( isset( $_POST['blog_public'] ) && '0' === $_POST['blog_public'] ) { 213 $blog_public_off_checked = 'checked="checked"'; 214 } else { 215 $blog_public_on_checked = 'checked="checked"'; 216 } 217 ?> 218 219 <div id="privacy"> 220 <fieldset class="privacy-intro"> 221 <legend> 222 <span class="label-heading"><?php _e( 'Privacy:' ); ?></span> 223 <?php _e( 'Allow search engines to index this site.' ); ?> 224 </legend> 225 <p class="wp-signup-radio-buttons"> 226 <span class="wp-signup-radio-button"> 227 <input type="radio" id="blog_public_on" name="blog_public" value="1" <?php echo $blog_public_on_checked; ?> /> 228 <label class="checkbox" for="blog_public_on"><?php _e( 'Yes' ); ?></label> 229 </span> 230 <span class="wp-signup-radio-button"> 231 <input type="radio" id="blog_public_off" name="blog_public" value="0" <?php echo $blog_public_off_checked; ?> /> 232 <label class="checkbox" for="blog_public_off"><?php _e( 'No' ); ?></label> 233 </span> 234 </p> 235 </fieldset> 236 </div> 237 238 <?php 239 /** 240 * Fires after the site sign-up form. 241 * 242 * @since 3.0.0 243 * 244 * @param WP_Error $errors A WP_Error object possibly containing 'blogname' or 'blog_title' errors. 245 */ 246 do_action( 'signup_blogform', $errors ); 247 } 248 249 /** 250 * Validates the new site sign-up. 251 * 252 * @since MU (3.0.0) 253 * 254 * @return array Contains the new site data and error messages. 255 * See wpmu_validate_blog_signup() for details. 256 */ 257 function validate_blog_form() { 258 $user = ''; 259 if ( is_user_logged_in() ) { 260 $user = wp_get_current_user(); 261 } 262 263 return wpmu_validate_blog_signup( $_POST['blogname'], $_POST['blog_title'], $user ); 264 } 265 266 /** 267 * Displays the fields for the new user account registration form. 268 * 269 * @since MU (3.0.0) 270 * 271 * @param string $user_name The entered username. 272 * @param string $user_email The entered email address. 273 * @param WP_Error|string $errors A WP_Error object containing existing errors. Defaults to empty string. 274 */ 275 function show_user_form( $user_name = '', $user_email = '', $errors = '' ) { 276 if ( ! is_wp_error( $errors ) ) { 277 $errors = new WP_Error(); 278 } 279 280 // Username. 281 echo '<label for="user_name">' . __( 'Username:' ) . '</label>'; 282 $errmsg_username = $errors->get_error_message( 'user_name' ); 283 $errmsg_username_aria = ''; 284 if ( $errmsg_username ) { 285 $errmsg_username_aria = 'wp-signup-username-error '; 286 echo '<p class="error" id="wp-signup-username-error">' . $errmsg_username . '</p>'; 287 } 288 ?> 289 <input name="user_name" type="text" id="user_name" value="<?php echo esc_attr( $user_name ); ?>" autocapitalize="none" autocorrect="off" maxlength="60" autocomplete="username" required="required" aria-describedby="<?php echo $errmsg_username_aria; ?>wp-signup-username-description" /> 290 <p id="wp-signup-username-description"><?php _e( '(Must be at least 4 characters, lowercase letters and numbers only.)' ); ?></p> 291 292 <?php 293 // Email address. 294 echo '<label for="user_email">' . __( 'Email Address:' ) . '</label>'; 295 $errmsg_email = $errors->get_error_message( 'user_email' ); 296 $errmsg_email_aria = ''; 297 if ( $errmsg_email ) { 298 $errmsg_email_aria = 'wp-signup-email-error '; 299 echo '<p class="error" id="wp-signup-email-error">' . $errmsg_email . '</p>'; 300 } 301 ?> 302 <input name="user_email" type="email" id="user_email" value="<?php echo esc_attr( $user_email ); ?>" maxlength="200" autocomplete="email" required="required" aria-describedby="<?php echo $errmsg_email_aria; ?>wp-signup-email-description" /> 303 <p id="wp-signup-email-description"><?php _e( 'Your registration email is sent to this address. (Double-check your email address before continuing.)' ); ?></p> 304 305 <?php 306 // Extra fields. 307 $errmsg_generic = $errors->get_error_message( 'generic' ); 308 if ( $errmsg_generic ) { 309 echo '<p class="error" id="wp-signup-generic-error">' . $errmsg_generic . '</p>'; 310 } 311 /** 312 * Fires at the end of the new user account registration form. 313 * 314 * @since 3.0.0 315 * 316 * @param WP_Error $errors A WP_Error object containing 'user_name' or 'user_email' errors. 317 */ 318 do_action( 'signup_extra_fields', $errors ); 319 } 320 321 /** 322 * Validates user sign-up name and email. 323 * 324 * @since MU (3.0.0) 325 * 326 * @return array Contains username, email, and error messages. 327 * See wpmu_validate_user_signup() for details. 328 */ 329 function validate_user_form() { 330 return wpmu_validate_user_signup( $_POST['user_name'], $_POST['user_email'] ); 331 } 332 333 /** 334 * Shows a form for returning users to sign up for another site. 335 * 336 * @since MU (3.0.0) 337 * 338 * @param string $blogname The new site name 339 * @param string $blog_title The new site title. 340 * @param WP_Error|string $errors A WP_Error object containing existing errors. Defaults to empty string. 341 */ 342 function signup_another_blog( $blogname = '', $blog_title = '', $errors = '' ) { 343 $current_user = wp_get_current_user(); 344 345 if ( ! is_wp_error( $errors ) ) { 346 $errors = new WP_Error(); 347 } 348 349 $signup_defaults = array( 350 'blogname' => $blogname, 351 'blog_title' => $blog_title, 352 'errors' => $errors, 353 ); 354 355 /** 356 * Filters the default site sign-up variables. 357 * 358 * @since 3.0.0 359 * 360 * @param array $signup_defaults { 361 * An array of default site sign-up variables. 362 * 363 * @type string $blogname The site blogname. 364 * @type string $blog_title The site title. 365 * @type WP_Error $errors A WP_Error object possibly containing 'blogname' or 'blog_title' errors. 366 * } 367 */ 368 $filtered_results = apply_filters( 'signup_another_blog_init', $signup_defaults ); 369 370 $blogname = $filtered_results['blogname']; 371 $blog_title = $filtered_results['blog_title']; 372 $errors = $filtered_results['errors']; 373 374 /* translators: %s: Network title. */ 375 echo '<h2>' . sprintf( __( 'Get <em>another</em> %s site in seconds' ), get_network()->site_name ) . '</h2>'; 376 377 if ( $errors->has_errors() ) { 378 echo '<p>' . __( 'There was a problem, please correct the form below and try again.' ) . '</p>'; 379 } 380 ?> 381 <p> 382 <?php 383 printf( 384 /* translators: %s: Current user's display name. */ 385 __( '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!' ), 386 $current_user->display_name 387 ); 388 ?> 389 </p> 390 391 <?php 392 $blogs = get_blogs_of_user( $current_user->ID ); 393 if ( ! empty( $blogs ) ) { 394 ?> 395 396 <p><?php _e( 'Sites you are already a member of:' ); ?></p> 397 <ul> 398 <?php 399 foreach ( $blogs as $blog ) { 400 $home_url = get_home_url( $blog->userblog_id ); 401 echo '<li><a href="' . esc_url( $home_url ) . '">' . $home_url . '</a></li>'; 402 } 403 ?> 404 </ul> 405 <?php } ?> 406 407 <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> 408 <form id="setupform" method="post" action="wp-signup.php"> 409 <input type="hidden" name="stage" value="gimmeanotherblog" /> 410 <?php 411 /** 412 * Fires when hidden sign-up form fields output when creating another site or user. 413 * 414 * @since MU (3.0.0) 415 * 416 * @param string $context A string describing the steps of the sign-up process. The value can be 417 * 'create-another-site', 'validate-user', or 'validate-site'. 418 */ 419 do_action( 'signup_hidden_fields', 'create-another-site' ); 420 ?> 421 <?php show_blog_form( $blogname, $blog_title, $errors ); ?> 422 <p class="submit"><input type="submit" name="submit" class="submit" value="<?php esc_attr_e( 'Create Site' ); ?>" /></p> 423 </form> 424 <?php 425 } 426 427 /** 428 * Validates a new site sign-up for an existing user. 429 * 430 * @since MU (3.0.0) 431 * 432 * @global string $blogname The new site's subdomain or directory name. 433 * @global string $blog_title The new site's title. 434 * @global WP_Error $errors Existing errors in the global scope. 435 * @global string $domain The new site's domain. 436 * @global string $path The new site's path. 437 * 438 * @return null|bool True if site signup was validated, false on error. 439 * The function halts all execution if the user is not logged in. 440 */ 441 function validate_another_blog_signup() { 442 global $blogname, $blog_title, $errors, $domain, $path; 443 $current_user = wp_get_current_user(); 444 if ( ! is_user_logged_in() ) { 445 die(); 446 } 447 448 $result = validate_blog_form(); 449 450 // Extracted values set/overwrite globals. 451 $domain = $result['domain']; 452 $path = $result['path']; 453 $blogname = $result['blogname']; 454 $blog_title = $result['blog_title']; 455 $errors = $result['errors']; 456 457 if ( $errors->has_errors() ) { 458 signup_another_blog( $blogname, $blog_title, $errors ); 459 return false; 460 } 461 462 $public = (int) $_POST['blog_public']; 463 464 $blog_meta_defaults = array( 465 'lang_id' => 1, 466 'public' => $public, 467 ); 468 469 // Handle the language setting for the new site. 470 if ( ! empty( $_POST['WPLANG'] ) ) { 471 472 $languages = signup_get_available_languages(); 473 474 if ( in_array( $_POST['WPLANG'], $languages, true ) ) { 475 $language = wp_unslash( sanitize_text_field( $_POST['WPLANG'] ) ); 476 477 if ( $language ) { 478 $blog_meta_defaults['WPLANG'] = $language; 479 } 480 } 481 } 482 483 /** 484 * Filters the new site meta variables. 485 * 486 * Use the {@see 'add_signup_meta'} filter instead. 487 * 488 * @since MU (3.0.0) 489 * @deprecated 3.0.0 Use the {@see 'add_signup_meta'} filter instead. 490 * 491 * @param array $blog_meta_defaults An array of default blog meta variables. 492 */ 493 $meta_defaults = apply_filters_deprecated( 'signup_create_blog_meta', array( $blog_meta_defaults ), '3.0.0', 'add_signup_meta' ); 494 495 /** 496 * Filters the new default site meta variables. 497 * 498 * @since 3.0.0 499 * 500 * @param array $meta { 501 * An array of default site meta variables. 502 * 503 * @type int $lang_id The language ID. 504 * @type int $blog_public Whether search engines should be discouraged from indexing the site. 1 for true, 0 for false. 505 * } 506 */ 507 $meta = apply_filters( 'add_signup_meta', $meta_defaults ); 508 509 $blog_id = wpmu_create_blog( $domain, $path, $blog_title, $current_user->ID, $meta, get_current_network_id() ); 510 511 if ( is_wp_error( $blog_id ) ) { 512 return false; 513 } 514 515 confirm_another_blog_signup( $domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta, $blog_id ); 516 return true; 517 } 518 519 /** 520 * Shows a message confirming that the new site has been created. 521 * 522 * @since MU (3.0.0) 523 * @since 4.4.0 Added the `$blog_id` parameter. 524 * 525 * @param string $domain The domain URL. 526 * @param string $path The site root path. 527 * @param string $blog_title The site title. 528 * @param string $user_name The username. 529 * @param string $user_email The user's email address. 530 * @param array $meta Any additional meta from the {@see 'add_signup_meta'} filter in validate_blog_signup(). 531 * @param int $blog_id The site ID. 532 */ 533 function confirm_another_blog_signup( $domain, $path, $blog_title, $user_name, $user_email = '', $meta = array(), $blog_id = 0 ) { 534 535 if ( $blog_id ) { 536 switch_to_blog( $blog_id ); 537 $home_url = home_url( '/' ); 538 $login_url = wp_login_url(); 539 restore_current_blog(); 540 } else { 541 $home_url = 'http://' . $domain . $path; 542 $login_url = 'http://' . $domain . $path . 'wp-login.php'; 543 } 544 545 $site = sprintf( 546 '<a href="%1$s">%2$s</a>', 547 esc_url( $home_url ), 548 $blog_title 549 ); 550 551 ?> 552 <h2> 553 <?php 554 /* translators: %s: Site title. */ 555 printf( __( 'The site %s is yours.' ), $site ); 556 ?> 557 </h2> 558 <p> 559 <?php 560 printf( 561 /* translators: 1: Link to new site, 2: Login URL, 3: Username. */ 562 __( '%1$s is your new site. <a href="%2$s">Log in</a> as “%3$s” using your existing password.' ), 563 sprintf( 564 '<a href="%s">%s</a>', 565 esc_url( $home_url ), 566 untrailingslashit( $domain . $path ) 567 ), 568 esc_url( $login_url ), 569 $user_name 570 ); 571 ?> 572 </p> 573 <?php 574 /** 575 * Fires when the site or user sign-up process is complete. 576 * 577 * @since 3.0.0 578 */ 579 do_action( 'signup_finished' ); 580 } 581 582 /** 583 * Shows a form for a visitor to sign up for a new user account. 584 * 585 * @since MU (3.0.0) 586 * 587 * @global string $active_signup String that returns registration type. The value can be 588 * 'all', 'none', 'blog', or 'user'. 589 * 590 * @param string $user_name The username. 591 * @param string $user_email The user's email. 592 * @param WP_Error|string $errors A WP_Error object containing existing errors. Defaults to empty string. 593 */ 594 function signup_user( $user_name = '', $user_email = '', $errors = '' ) { 595 global $active_signup; 596 597 if ( ! is_wp_error( $errors ) ) { 598 $errors = new WP_Error(); 599 } 600 601 $signup_for = isset( $_POST['signup_for'] ) ? esc_html( $_POST['signup_for'] ) : 'blog'; 602 603 $signup_user_defaults = array( 604 'user_name' => $user_name, 605 'user_email' => $user_email, 606 'errors' => $errors, 607 ); 608 609 /** 610 * Filters the default user variables used on the user sign-up form. 611 * 612 * @since 3.0.0 613 * 614 * @param array $signup_user_defaults { 615 * An array of default user variables. 616 * 617 * @type string $user_name The user username. 618 * @type string $user_email The user email address. 619 * @type WP_Error $errors A WP_Error object with possible errors relevant to the sign-up user. 620 * } 621 */ 622 $filtered_results = apply_filters( 'signup_user_init', $signup_user_defaults ); 623 $user_name = $filtered_results['user_name']; 624 $user_email = $filtered_results['user_email']; 625 $errors = $filtered_results['errors']; 626 627 ?> 628 629 <h2> 630 <?php 631 /* translators: %s: Name of the network. */ 632 printf( __( 'Get your own %s account in seconds' ), get_network()->site_name ); 633 ?> 634 </h2> 635 <form id="setupform" method="post" action="wp-signup.php" novalidate="novalidate"> 636 <input type="hidden" name="stage" value="validate-user-signup" /> 637 <?php 638 /** This action is documented in wp-signup.php */ 639 do_action( 'signup_hidden_fields', 'validate-user' ); 640 ?> 641 <?php show_user_form( $user_name, $user_email, $errors ); ?> 642 643 <?php if ( 'blog' === $active_signup ) : ?> 644 <input id="signupblog" type="hidden" name="signup_for" value="blog" /> 645 <?php elseif ( 'user' === $active_signup ) : ?> 646 <input id="signupblog" type="hidden" name="signup_for" value="user" /> 647 <?php else : ?> 648 <fieldset class="signup-options"> 649 <legend><?php _e( 'Create a site or only a username:' ); ?></legend> 650 <p class="wp-signup-radio-buttons"> 651 <span class="wp-signup-radio-button"> 652 <input id="signupblog" type="radio" name="signup_for" value="blog" <?php checked( $signup_for, 'blog' ); ?> /> 653 <label class="checkbox" for="signupblog"><?php _e( 'Gimme a site!' ); ?></label> 654 </span> 655 <span class="wp-signup-radio-button"> 656 <input id="signupuser" type="radio" name="signup_for" value="user" <?php checked( $signup_for, 'user' ); ?> /> 657 <label class="checkbox" for="signupuser"><?php _e( 'Just a username, please.' ); ?></label> 658 </span> 659 </p> 660 </fieldset> 661 <?php endif; ?> 662 663 <p class="submit"><input type="submit" name="submit" class="submit" value="<?php esc_attr_e( 'Next' ); ?>" /></p> 664 </form> 665 <?php 666 } 667 668 /** 669 * Validates the new user sign-up. 670 * 671 * @since MU (3.0.0) 672 * 673 * @return bool True if new user sign-up was validated, false on error. 674 */ 675 function validate_user_signup() { 676 $result = validate_user_form(); 677 $user_name = $result['user_name']; 678 $user_email = $result['user_email']; 679 $errors = $result['errors']; 680 681 if ( $errors->has_errors() ) { 682 signup_user( $user_name, $user_email, $errors ); 683 return false; 684 } 685 686 if ( 'blog' === $_POST['signup_for'] ) { 687 signup_blog( $user_name, $user_email ); 688 return false; 689 } 690 691 /** This filter is documented in wp-signup.php */ 692 wpmu_signup_user( $user_name, $user_email, apply_filters( 'add_signup_meta', array() ) ); 693 694 confirm_user_signup( $user_name, $user_email ); 695 return true; 696 } 697 698 /** 699 * Shows a message confirming that the new user has been registered and is awaiting activation. 700 * 701 * @since MU (3.0.0) 702 * 703 * @param string $user_name The username. 704 * @param string $user_email The user's email address. 705 */ 706 function confirm_user_signup( $user_name, $user_email ) { 707 ?> 708 <h2> 709 <?php 710 /* translators: %s: Username. */ 711 printf( __( '%s is your new username' ), $user_name ) 712 ?> 713 </h2> 714 <p><?php _e( 'But, before you can start using your new username, <strong>you must activate it</strong>.' ); ?></p> 715 <p> 716 <?php 717 /* translators: %s: The user email address. */ 718 printf( __( 'Check your inbox at %s and click on the given link.' ), '<strong>' . $user_email . '</strong>' ); 719 ?> 720 </p> 721 <p><?php _e( 'If you do not activate your username within two days, you will have to sign up again.' ); ?></p> 722 <?php 723 /** This action is documented in wp-signup.php */ 724 do_action( 'signup_finished' ); 725 } 726 727 /** 728 * Shows a form for a user or visitor to sign up for a new site. 729 * 730 * @since MU (3.0.0) 731 * 732 * @param string $user_name The username. 733 * @param string $user_email The user's email address. 734 * @param string $blogname The site name. 735 * @param string $blog_title The site title. 736 * @param WP_Error|string $errors A WP_Error object containing existing errors. Defaults to empty string. 737 */ 738 function signup_blog( $user_name = '', $user_email = '', $blogname = '', $blog_title = '', $errors = '' ) { 739 if ( ! is_wp_error( $errors ) ) { 740 $errors = new WP_Error(); 741 } 742 743 $signup_blog_defaults = array( 744 'user_name' => $user_name, 745 'user_email' => $user_email, 746 'blogname' => $blogname, 747 'blog_title' => $blog_title, 748 'errors' => $errors, 749 ); 750 751 /** 752 * Filters the default site creation variables for the site sign-up form. 753 * 754 * @since 3.0.0 755 * 756 * @param array $signup_blog_defaults { 757 * An array of default site creation variables. 758 * 759 * @type string $user_name The user username. 760 * @type string $user_email The user email address. 761 * @type string $blogname The blogname. 762 * @type string $blog_title The title of the site. 763 * @type WP_Error $errors A WP_Error object with possible errors relevant to new site creation variables. 764 * } 765 */ 766 $filtered_results = apply_filters( 'signup_blog_init', $signup_blog_defaults ); 767 768 $user_name = $filtered_results['user_name']; 769 $user_email = $filtered_results['user_email']; 770 $blogname = $filtered_results['blogname']; 771 $blog_title = $filtered_results['blog_title']; 772 $errors = $filtered_results['errors']; 773 774 if ( empty( $blogname ) ) { 775 $blogname = $user_name; 776 } 777 ?> 778 <form id="setupform" method="post" action="wp-signup.php"> 779 <input type="hidden" name="stage" value="validate-blog-signup" /> 780 <input type="hidden" name="user_name" value="<?php echo esc_attr( $user_name ); ?>" /> 781 <input type="hidden" name="user_email" value="<?php echo esc_attr( $user_email ); ?>" /> 782 <?php 783 /** This action is documented in wp-signup.php */ 784 do_action( 'signup_hidden_fields', 'validate-site' ); 785 ?> 786 <?php show_blog_form( $blogname, $blog_title, $errors ); ?> 787 <p class="submit"><input type="submit" name="submit" class="submit" value="<?php esc_attr_e( 'Sign up' ); ?>" /></p> 788 </form> 789 <?php 790 } 791 792 /** 793 * Validates new site signup. 794 * 795 * @since MU (3.0.0) 796 * 797 * @return bool True if the site sign-up was validated, false on error. 798 */ 799 function validate_blog_signup() { 800 // Re-validate user info. 801 $user_result = wpmu_validate_user_signup( $_POST['user_name'], $_POST['user_email'] ); 802 $user_name = $user_result['user_name']; 803 $user_email = $user_result['user_email']; 804 $user_errors = $user_result['errors']; 805 806 if ( $user_errors->has_errors() ) { 807 signup_user( $user_name, $user_email, $user_errors ); 808 return false; 809 } 810 811 $result = wpmu_validate_blog_signup( $_POST['blogname'], $_POST['blog_title'] ); 812 $domain = $result['domain']; 813 $path = $result['path']; 814 $blogname = $result['blogname']; 815 $blog_title = $result['blog_title']; 816 $errors = $result['errors']; 817 818 if ( $errors->has_errors() ) { 819 signup_blog( $user_name, $user_email, $blogname, $blog_title, $errors ); 820 return false; 821 } 822 823 $public = (int) $_POST['blog_public']; 824 $signup_meta = array( 825 'lang_id' => 1, 826 'public' => $public, 827 ); 828 829 // Handle the language setting for the new site. 830 if ( ! empty( $_POST['WPLANG'] ) ) { 831 832 $languages = signup_get_available_languages(); 833 834 if ( in_array( $_POST['WPLANG'], $languages, true ) ) { 835 $language = wp_unslash( sanitize_text_field( $_POST['WPLANG'] ) ); 836 837 if ( $language ) { 838 $signup_meta['WPLANG'] = $language; 839 } 840 } 841 } 842 843 /** This filter is documented in wp-signup.php */ 844 $meta = apply_filters( 'add_signup_meta', $signup_meta ); 845 846 wpmu_signup_blog( $domain, $path, $blog_title, $user_name, $user_email, $meta ); 847 confirm_blog_signup( $domain, $path, $blog_title, $user_name, $user_email, $meta ); 848 return true; 849 } 850 851 /** 852 * Shows a message confirming that the new site has been registered and is awaiting activation. 853 * 854 * @since MU (3.0.0) 855 * 856 * @param string $domain The domain or subdomain of the site. 857 * @param string $path The path of the site. 858 * @param string $blog_title The title of the new site. 859 * @param string $user_name The user's username. 860 * @param string $user_email The user's email address. 861 * @param array $meta Any additional meta from the {@see 'add_signup_meta'} filter in validate_blog_signup(). 862 */ 863 function confirm_blog_signup( $domain, $path, $blog_title, $user_name = '', $user_email = '', $meta = array() ) { 864 ?> 865 <h2> 866 <?php 867 /* translators: %s: Site address. */ 868 printf( __( 'Congratulations! Your new site, %s, is almost ready.' ), "<a href='http://{$domain}{$path}'>{$blog_title}</a>" ) 869 ?> 870 </h2> 871 872 <p><?php _e( 'But, before you can start using your site, <strong>you must activate it</strong>.' ); ?></p> 873 <p> 874 <?php 875 /* translators: %s: The user email address. */ 876 printf( __( 'Check your inbox at %s and click on the given link.' ), '<strong>' . $user_email . '</strong>' ); 877 ?> 878 </p> 879 <p><?php _e( 'If you do not activate your site within two days, you will have to sign up again.' ); ?></p> 880 <h2><?php _e( 'Still waiting for your email?' ); ?></h2> 881 <p><?php _e( 'If you have not received your email yet, there are a number of things you can do:' ); ?></p> 882 <ul id="noemail-tips"> 883 <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> 884 <li><p><?php _e( 'Check the junk or spam folder of your email client. Sometime emails wind up there by mistake.' ); ?></p></li> 885 <li> 886 <?php 887 /* translators: %s: Email address. */ 888 printf( __( 'Have you entered your email correctly? You have entered %s, if it’s incorrect, you will not receive your email.' ), $user_email ); 889 ?> 890 </li> 891 </ul> 892 <?php 893 /** This action is documented in wp-signup.php */ 894 do_action( 'signup_finished' ); 895 } 896 897 /** 898 * Retrieves languages available during the site/user sign-up process. 899 * 900 * @since 4.4.0 901 * 902 * @see get_available_languages() 903 * 904 * @return string[] Array of available language codes. Language codes are formed by 905 * stripping the .mo extension from the language file names. 906 */ 907 function signup_get_available_languages() { 908 /** 909 * Filters the list of available languages for front-end site sign-ups. 910 * 911 * Passing an empty array to this hook will disable output of the setting on the 912 * sign-up form, and the default language will be used when creating the site. 913 * 914 * Languages not already installed will be stripped. 915 * 916 * @since 4.4.0 917 * 918 * @param string[] $languages Array of available language codes. Language codes are formed by 919 * stripping the .mo extension from the language file names. 920 */ 921 $languages = (array) apply_filters( 'signup_get_available_languages', get_available_languages() ); 922 923 /* 924 * Strip any non-installed languages and return. 925 * 926 * Re-call get_available_languages() here in case a language pack was installed 927 * in a callback hooked to the 'signup_get_available_languages' filter before this point. 928 */ 929 return array_intersect_assoc( $languages, get_available_languages() ); 930 } 931 932 // Main. 933 $active_signup = get_site_option( 'registration', 'none' ); 934 935 /** 936 * Filters the type of site sign-up. 937 * 938 * @since 3.0.0 939 * 940 * @param string $active_signup String that returns registration type. The value can be 941 * 'all', 'none', 'blog', or 'user'. 942 */ 943 $active_signup = apply_filters( 'wpmu_active_signup', $active_signup ); 944 945 if ( current_user_can( 'manage_network' ) ) { 946 echo '<div class="mu_alert">'; 947 _e( 'Greetings Network Administrator!' ); 948 echo ' '; 949 950 switch ( $active_signup ) { 951 case 'none': 952 _e( 'The network currently disallows registrations.' ); 953 break; 954 case 'blog': 955 _e( 'The network currently allows site registrations.' ); 956 break; 957 case 'user': 958 _e( 'The network currently allows user registrations.' ); 959 break; 960 default: 961 _e( 'The network currently allows both site and user registrations.' ); 962 break; 963 } 964 965 echo ' '; 966 967 /* translators: %s: URL to Network Settings screen. */ 968 printf( __( 'To change or disable registration go to your <a href="%s">Options page</a>.' ), esc_url( network_admin_url( 'settings.php' ) ) ); 969 echo '</div>'; 970 } 971 972 $newblogname = isset( $_GET['new'] ) ? strtolower( preg_replace( '/^-|-$|[^-a-zA-Z0-9]/', '', $_GET['new'] ) ) : null; 973 974 $current_user = wp_get_current_user(); 975 if ( 'none' === $active_signup ) { 976 _e( 'Registration has been disabled.' ); 977 } elseif ( 'blog' === $active_signup && ! is_user_logged_in() ) { 978 $login_url = wp_login_url( network_site_url( 'wp-signup.php' ) ); 979 /* translators: %s: Login URL. */ 980 printf( __( 'You must first <a href="%s">log in</a>, and then you can create a new site.' ), $login_url ); 981 } else { 982 $stage = $_POST['stage'] ?? 'default'; 983 switch ( $stage ) { 984 case 'validate-user-signup': 985 if ( 'all' === $active_signup 986 || ( 'blog' === $_POST['signup_for'] && 'blog' === $active_signup ) 987 || ( 'user' === $_POST['signup_for'] && 'user' === $active_signup ) 988 ) { 989 validate_user_signup(); 990 } else { 991 _e( 'User registration has been disabled.' ); 992 } 993 break; 994 case 'validate-blog-signup': 995 if ( 'all' === $active_signup || 'blog' === $active_signup ) { 996 validate_blog_signup(); 997 } else { 998 _e( 'Site registration has been disabled.' ); 999 } 1000 break; 1001 case 'gimmeanotherblog': 1002 validate_another_blog_signup(); 1003 break; 1004 case 'default': 1005 default: 1006 $user_email = $_POST['user_email'] ?? ''; 1007 /** 1008 * Fires when the site sign-up form is sent. 1009 * 1010 * @since 3.0.0 1011 */ 1012 do_action( 'preprocess_signup_form' ); 1013 if ( is_user_logged_in() && ( 'all' === $active_signup || 'blog' === $active_signup ) ) { 1014 signup_another_blog( $newblogname ); 1015 } elseif ( ! is_user_logged_in() && ( 'all' === $active_signup || 'user' === $active_signup ) ) { 1016 signup_user( $newblogname, $user_email ); 1017 } elseif ( ! is_user_logged_in() && ( 'blog' === $active_signup ) ) { 1018 _e( 'Sorry, new registrations are not allowed at this time.' ); 1019 } else { 1020 _e( 'You are logged in already. No need to register again!' ); 1021 } 1022 1023 if ( $newblogname ) { 1024 $newblog = get_blogaddress_by_name( $newblogname ); 1025 1026 if ( 'blog' === $active_signup || 'all' === $active_signup ) { 1027 printf( 1028 /* translators: %s: Site address. */ 1029 '<p>' . __( 'The site you were looking for, %s, does not exist, but you can create it now!' ) . '</p>', 1030 '<strong>' . $newblog . '</strong>' 1031 ); 1032 } else { 1033 printf( 1034 /* translators: %s: Site address. */ 1035 '<p>' . __( 'The site you were looking for, %s, does not exist.' ) . '</p>', 1036 '<strong>' . $newblog . '</strong>' 1037 ); 1038 } 1039 } 1040 break; 1041 } 1042 } 1043 ?> 1044 </div> 1045 </div> 1046 <?php 1047 /** 1048 * Fires after the sign-up forms, before wp_footer. 1049 * 1050 * @since 3.0.0 1051 */ 1052 do_action( 'after_signup_form' ); 1053 ?> 1054 1055 <?php 1056 get_footer( 'wp-signup' );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Sat Apr 18 08:20:10 2026 | Cross-referenced by PHPXref |