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