author | ymh <ymh.work@gmail.com> |
Tue, 27 Sep 2022 16:37:53 +0200 | |
changeset 19 | 3d72ae0968f4 |
parent 18 | be944660c56a |
child 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* Confirms that the activation key that is sent in an email after a user signs |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4 |
* up for a new site matches the key for that user and then displays confirmation. |
0 | 5 |
* |
6 |
* @package WordPress |
|
7 |
*/ |
|
8 |
||
9 |
define( 'WP_INSTALLING', true ); |
|
10 |
||
11 |
/** Sets up the WordPress Environment. */ |
|
16 | 12 |
require __DIR__ . '/wp-load.php'; |
0 | 13 |
|
16 | 14 |
require __DIR__ . '/wp-blog-header.php'; |
0 | 15 |
|
9 | 16 |
if ( ! is_multisite() ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
17 |
wp_redirect( wp_registration_url() ); |
0 | 18 |
die(); |
19 |
} |
|
20 |
||
9 | 21 |
$valid_error_codes = array( 'already_active', 'blog_taken' ); |
22 |
||
23 |
list( $activate_path ) = explode( '?', wp_unslash( $_SERVER['REQUEST_URI'] ) ); |
|
24 |
$activate_cookie = 'wp-activate-' . COOKIEHASH; |
|
25 |
||
26 |
$key = ''; |
|
27 |
$result = null; |
|
28 |
||
29 |
if ( isset( $_GET['key'] ) && isset( $_POST['key'] ) && $_GET['key'] !== $_POST['key'] ) { |
|
30 |
wp_die( __( 'A key value mismatch has been detected. Please follow the link provided in your activation email.' ), __( 'An error occurred during the activation' ), 400 ); |
|
31 |
} elseif ( ! empty( $_GET['key'] ) ) { |
|
32 |
$key = $_GET['key']; |
|
33 |
} elseif ( ! empty( $_POST['key'] ) ) { |
|
34 |
$key = $_POST['key']; |
|
35 |
} |
|
36 |
||
37 |
if ( $key ) { |
|
38 |
$redirect_url = remove_query_arg( 'key' ); |
|
39 |
||
16 | 40 |
if ( remove_query_arg( false ) !== $redirect_url ) { |
9 | 41 |
setcookie( $activate_cookie, $key, 0, $activate_path, COOKIE_DOMAIN, is_ssl(), true ); |
42 |
wp_safe_redirect( $redirect_url ); |
|
43 |
exit; |
|
44 |
} else { |
|
45 |
$result = wpmu_activate_signup( $key ); |
|
46 |
} |
|
47 |
} |
|
48 |
||
16 | 49 |
if ( null === $result && isset( $_COOKIE[ $activate_cookie ] ) ) { |
9 | 50 |
$key = $_COOKIE[ $activate_cookie ]; |
51 |
$result = wpmu_activate_signup( $key ); |
|
52 |
setcookie( $activate_cookie, ' ', time() - YEAR_IN_SECONDS, $activate_path, COOKIE_DOMAIN, is_ssl(), true ); |
|
53 |
} |
|
54 |
||
16 | 55 |
if ( null === $result || ( is_wp_error( $result ) && 'invalid_key' === $result->get_error_code() ) ) { |
9 | 56 |
status_header( 404 ); |
57 |
} elseif ( is_wp_error( $result ) ) { |
|
58 |
$error_code = $result->get_error_code(); |
|
59 |
||
16 | 60 |
if ( ! in_array( $error_code, $valid_error_codes, true ) ) { |
9 | 61 |
status_header( 400 ); |
62 |
} |
|
63 |
} |
|
64 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
nocache_headers(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
66 |
|
9 | 67 |
if ( is_object( $wp_object_cache ) ) { |
0 | 68 |
$wp_object_cache->cache_enabled = false; |
9 | 69 |
} |
0 | 70 |
|
16 | 71 |
// Fix for page title. |
0 | 72 |
$wp_query->is_404 = false; |
73 |
||
74 |
/** |
|
75 |
* Fires before the Site Activation page is loaded. |
|
76 |
* |
|
5 | 77 |
* @since 3.0.0 |
0 | 78 |
*/ |
79 |
do_action( 'activate_header' ); |
|
80 |
||
81 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
82 |
* Adds an action hook specific to this page. |
0 | 83 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
84 |
* Fires on {@see 'wp_head'}. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
85 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
86 |
* @since MU (3.0.0) |
0 | 87 |
*/ |
88 |
function do_activate_header() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
89 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
90 |
* Fires before the Site Activation page is loaded. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
91 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
92 |
* Fires on the {@see 'wp_head'} action. |
9 | 93 |
* |
94 |
* @since 3.0.0 |
|
95 |
*/ |
|
96 |
do_action( 'activate_wp_head' ); |
|
0 | 97 |
} |
98 |
add_action( 'wp_head', 'do_activate_header' ); |
|
99 |
||
100 |
/** |
|
101 |
* Loads styles specific to this page. |
|
102 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
103 |
* @since MU (3.0.0) |
0 | 104 |
*/ |
105 |
function wpmu_activate_stylesheet() { |
|
106 |
?> |
|
107 |
<style type="text/css"> |
|
108 |
form { margin-top: 2em; } |
|
109 |
#submit, #key { width: 90%; font-size: 24px; } |
|
110 |
#language { margin-top: .5em; } |
|
111 |
.error { background: #f66; } |
|
9 | 112 |
span.h3 { padding: 0 8px; font-size: 1.3em; font-weight: 600; } |
0 | 113 |
</style> |
114 |
<?php |
|
115 |
} |
|
116 |
add_action( 'wp_head', 'wpmu_activate_stylesheet' ); |
|
18 | 117 |
add_action( 'wp_head', 'wp_strict_cross_origin_referrer' ); |
118 |
add_filter( 'wp_robots', 'wp_robots_sensitive_page' ); |
|
0 | 119 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
120 |
get_header( 'wp-activate' ); |
16 | 121 |
|
122 |
$blog_details = get_blog_details(); |
|
0 | 123 |
?> |
124 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
125 |
<div id="signup-content" class="widecolumn"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
126 |
<div class="wp-activate-container"> |
9 | 127 |
<?php if ( ! $key ) { ?> |
0 | 128 |
|
9 | 129 |
<h2><?php _e( 'Activation Key Required' ); ?></h2> |
16 | 130 |
<form name="activateform" id="activateform" method="post" action="<?php echo network_site_url( $blog_details->path . 'wp-activate.php' ); ?>"> |
0 | 131 |
<p> |
9 | 132 |
<label for="key"><?php _e( 'Activation Key:' ); ?></label> |
133 |
<br /><input type="text" name="key" id="key" value="" size="50" /> |
|
0 | 134 |
</p> |
135 |
<p class="submit"> |
|
9 | 136 |
<input id="submit" type="submit" name="Submit" class="submit" value="<?php esc_attr_e( 'Activate' ); ?>" /> |
0 | 137 |
</p> |
138 |
</form> |
|
139 |
||
9 | 140 |
<?php |
141 |
} else { |
|
16 | 142 |
if ( is_wp_error( $result ) && in_array( $result->get_error_code(), $valid_error_codes, true ) ) { |
9 | 143 |
$signup = $result->get_error_data(); |
144 |
?> |
|
145 |
<h2><?php _e( 'Your account is now active!' ); ?></h2> |
|
146 |
<?php |
|
147 |
echo '<p class="lead-in">'; |
|
16 | 148 |
if ( '' === $signup->domain . $signup->path ) { |
9 | 149 |
printf( |
16 | 150 |
/* translators: 1: Login URL, 2: Username, 3: User email address, 4: Lost password URL. */ |
9 | 151 |
__( 'Your account has been activated. You may now <a href="%1$s">log in</a> to the site using your chosen username of “%2$s”. Please check your email inbox at %3$s for your password and login instructions. If you do not receive an email, please check your junk or spam folder. If you still do not receive an email within an hour, you can <a href="%4$s">reset your password</a>.' ), |
16 | 152 |
network_site_url( $blog_details->path . 'wp-login.php', 'login' ), |
9 | 153 |
$signup->user_login, |
154 |
$signup->user_email, |
|
155 |
wp_lostpassword_url() |
|
156 |
); |
|
0 | 157 |
} else { |
9 | 158 |
printf( |
16 | 159 |
/* translators: 1: Site URL, 2: Username, 3: User email address, 4: Lost password URL. */ |
9 | 160 |
__( 'Your site at %1$s is active. You may now log in to your site using your chosen username of “%2$s”. Please check your email inbox at %3$s for your password and login instructions. If you do not receive an email, please check your junk or spam folder. If you still do not receive an email within an hour, you can <a href="%4$s">reset your password</a>.' ), |
16 | 161 |
sprintf( '<a href="http://%1$s%2$s">%1$s%2$s</a>', $signup->domain, $blog_details->path ), |
9 | 162 |
$signup->user_login, |
163 |
$signup->user_email, |
|
164 |
wp_lostpassword_url() |
|
165 |
); |
|
166 |
} |
|
167 |
echo '</p>'; |
|
16 | 168 |
} elseif ( null === $result || is_wp_error( $result ) ) { |
9 | 169 |
?> |
170 |
<h2><?php _e( 'An error occurred during the activation' ); ?></h2> |
|
171 |
<?php if ( is_wp_error( $result ) ) : ?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
172 |
<p><?php echo $result->get_error_message(); ?></p> |
9 | 173 |
<?php endif; ?> |
174 |
<?php |
|
0 | 175 |
} else { |
9 | 176 |
$url = isset( $result['blog_id'] ) ? get_home_url( (int) $result['blog_id'] ) : ''; |
5 | 177 |
$user = get_userdata( (int) $result['user_id'] ); |
0 | 178 |
?> |
9 | 179 |
<h2><?php _e( 'Your account is now active!' ); ?></h2> |
0 | 180 |
|
181 |
<div id="signup-welcome"> |
|
9 | 182 |
<p><span class="h3"><?php _e( 'Username:' ); ?></span> <?php echo $user->user_login; ?></p> |
183 |
<p><span class="h3"><?php _e( 'Password:' ); ?></span> <?php echo $result['password']; ?></p> |
|
0 | 184 |
</div> |
185 |
||
9 | 186 |
<?php |
16 | 187 |
if ( $url && network_home_url( '', 'http' ) !== $url ) : |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
188 |
switch_to_blog( (int) $result['blog_id'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
189 |
$login_url = wp_login_url(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
190 |
restore_current_blog(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
191 |
?> |
9 | 192 |
<p class="view"> |
193 |
<?php |
|
16 | 194 |
/* translators: 1: Site URL, 2: Login URL. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
195 |
printf( __( 'Your account is now activated. <a href="%1$s">View your site</a> or <a href="%2$s">Log in</a>' ), $url, esc_url( $login_url ) ); |
9 | 196 |
?> |
197 |
</p> |
|
198 |
<?php else : ?> |
|
199 |
<p class="view"> |
|
200 |
<?php |
|
16 | 201 |
printf( |
202 |
/* translators: 1: Login URL, 2: Network home URL. */ |
|
203 |
__( 'Your account is now activated. <a href="%1$s">Log in</a> or go back to the <a href="%2$s">homepage</a>.' ), |
|
204 |
network_site_url( $blog_details->path . 'wp-login.php', 'login' ), |
|
205 |
network_home_url( $blog_details->path ) |
|
206 |
); |
|
9 | 207 |
?> |
208 |
</p> |
|
209 |
<?php |
|
210 |
endif; |
|
0 | 211 |
} |
212 |
} |
|
213 |
?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
214 |
</div> |
0 | 215 |
</div> |
216 |
<script type="text/javascript"> |
|
217 |
var key_input = document.getElementById('key'); |
|
218 |
key_input && key_input.focus(); |
|
219 |
</script> |
|
9 | 220 |
<?php |
221 |
get_footer( 'wp-activate' ); |