diff --git a/wp-activate.php b/wp-activate.php index bfd562076c..f70a800153 100644 --- a/wp-activate.php +++ b/wp-activate.php @@ -18,6 +18,48 @@ if ( !is_multisite() ) { die(); } +$valid_error_codes = array( 'already_active', 'blog_taken' ); + +list( $activate_path ) = explode( '?', wp_unslash( $_SERVER['REQUEST_URI'] ) ); +$activate_cookie = 'wp-activate-' . COOKIEHASH; + +$key = ''; +$result = null; + +if ( ! empty( $_GET['key'] ) ) { + $key = $_GET['key']; +} elseif ( ! empty( $_POST['key'] ) ) { + $key = $_POST['key']; +} + +if ( $key ) { + $redirect_url = remove_query_arg( 'key' ); + + if ( $redirect_url !== remove_query_arg( false ) ) { + setcookie( $activate_cookie, $key, 0, $activate_path, COOKIE_DOMAIN, is_ssl(), true ); + wp_safe_redirect( $redirect_url ); + exit; + } else { + $result = wpmu_activate_signup( $key ); + } +} + +if ( $result === null && isset( $_COOKIE[ $activate_cookie ] ) ) { + $key = $_COOKIE[ $activate_cookie ]; + $result = wpmu_activate_signup( $key ); + setcookie( $activate_cookie, ' ', time() - YEAR_IN_SECONDS, $activate_path, COOKIE_DOMAIN, is_ssl(), true ); +} + +if ( $result === null || ( is_wp_error( $result ) && 'invalid_key' === $result->get_error_code() ) ) { + status_header( 404 ); +} elseif ( is_wp_error( $result ) ) { + $error_code = $result->get_error_code(); + + if ( ! in_array( $error_code, $valid_error_codes ) ) { + status_header( 400 ); + } +} + if ( is_object( $wp_object_cache ) ) $wp_object_cache->cache_enabled = false; @@ -63,13 +105,14 @@ function wpmu_activate_stylesheet() {