Skip to content

Commit 7a7e1ad

Browse files
committed
Multisite: Improve messaging for previously activated users.
Ensure activation of a site is not attempted multiple times and users are shown the correct message if they follow the link a second time. Merges [44021] to the 4.9 branch. git-svn-id: https://develop.svn.wordpress.org/branches/4.9@44024 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 1775941 commit 7a7e1ad

File tree

3 files changed

+94
-36
lines changed

3 files changed

+94
-36
lines changed

src/wp-activate.php

Lines changed: 75 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,48 @@
1818
die();
1919
}
2020

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 ( ! empty( $_GET['key'] ) ) {
30+
$key = $_GET['key'];
31+
} elseif ( ! empty( $_POST['key'] ) ) {
32+
$key = $_POST['key'];
33+
}
34+
35+
if ( $key ) {
36+
$redirect_url = remove_query_arg( 'key' );
37+
38+
if ( $redirect_url !== remove_query_arg( false ) ) {
39+
setcookie( $activate_cookie, $key, 0, $activate_path, COOKIE_DOMAIN, is_ssl(), true );
40+
wp_safe_redirect( $redirect_url );
41+
exit;
42+
} else {
43+
$result = wpmu_activate_signup( $key );
44+
}
45+
}
46+
47+
if ( $result === null && isset( $_COOKIE[ $activate_cookie ] ) ) {
48+
$key = $_COOKIE[ $activate_cookie ];
49+
$result = wpmu_activate_signup( $key );
50+
setcookie( $activate_cookie, ' ', time() - YEAR_IN_SECONDS, $activate_path, COOKIE_DOMAIN, is_ssl(), true );
51+
}
52+
53+
if ( $result === null || ( is_wp_error( $result ) && 'invalid_key' === $result->get_error_code() ) ) {
54+
status_header( 404 );
55+
} elseif ( is_wp_error( $result ) ) {
56+
$error_code = $result->get_error_code();
57+
58+
if ( ! in_array( $error_code, $valid_error_codes ) ) {
59+
status_header( 400 );
60+
}
61+
}
62+
2163
nocache_headers();
2264

2365
if ( is_object( $wp_object_cache ) )
@@ -69,13 +111,14 @@ function wpmu_activate_stylesheet() {
69111
<?php
70112
}
71113
add_action( 'wp_head', 'wpmu_activate_stylesheet' );
114+
add_action( 'wp_head', 'wp_sensitive_page_meta' );
72115

73116
get_header( 'wp-activate' );
74117
?>
75118

76119
<div id="signup-content" class="widecolumn">
77120
<div class="wp-activate-container">
78-
<?php if ( empty($_GET['key']) && empty($_POST['key']) ) { ?>
121+
<?php if ( ! $key ) { ?>
79122

80123
<h2><?php _e('Activation Key Required') ?></h2>
81124
<form name="activateform" id="activateform" method="post" action="<?php echo network_site_url('wp-activate.php'); ?>">
@@ -89,42 +132,39 @@ function wpmu_activate_stylesheet() {
89132
</form>
90133

91134
<?php } else {
92-
93-
$key = !empty($_GET['key']) ? $_GET['key'] : $_POST['key'];
94-
$result = wpmu_activate_signup( $key );
95-
if ( is_wp_error($result) ) {
96-
if ( 'already_active' == $result->get_error_code() || 'blog_taken' == $result->get_error_code() ) {
97-
$signup = $result->get_error_data();
98-
?>
99-
<h2><?php _e('Your account is now active!'); ?></h2>
100-
<?php
101-
echo '<p class="lead-in">';
102-
if ( $signup->domain . $signup->path == '' ) {
103-
printf(
104-
/* translators: 1: login URL, 2: username, 3: user email, 4: lost password URL */
105-
__( 'Your account has been activated. You may now <a href="%1$s">log in</a> to the site using your chosen username of &#8220;%2$s&#8221;. 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>.' ),
106-
network_site_url( 'wp-login.php', 'login' ),
107-
$signup->user_login,
108-
$signup->user_email,
109-
wp_lostpassword_url()
110-
);
111-
} else {
112-
printf(
113-
/* translators: 1: site URL, 2: username, 3: user email, 4: lost password URL */
114-
__( 'Your site at %1$s is active. You may now log in to your site using your chosen username of &#8220;%2$s&#8221;. 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>.' ),
115-
sprintf( '<a href="http://%1$s">%1$s</a>', $signup->domain ),
116-
$signup->user_login,
117-
$signup->user_email,
118-
wp_lostpassword_url()
119-
);
120-
}
121-
echo '</p>';
135+
if ( is_wp_error( $result ) && in_array( $result->get_error_code(), $valid_error_codes ) ) {
136+
$signup = $result->get_error_data();
137+
?>
138+
<h2><?php _e( 'Your account is now active!' ); ?></h2>
139+
<?php
140+
echo '<p class="lead-in">';
141+
if ( $signup->domain . $signup->path == '' ) {
142+
printf(
143+
/* translators: 1: login URL, 2: username, 3: user email, 4: lost password URL */
144+
__( 'Your account has been activated. You may now <a href="%1$s">log in</a> to the site using your chosen username of &#8220;%2$s&#8221;. 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>.' ),
145+
network_site_url( 'wp-login.php', 'login' ),
146+
$signup->user_login,
147+
$signup->user_email,
148+
wp_lostpassword_url()
149+
);
122150
} else {
123-
?>
124-
<h2><?php _e( 'An error occurred during the activation' ); ?></h2>
125-
<p><?php echo $result->get_error_message(); ?></p>
126-
<?php
151+
printf(
152+
/* translators: 1: site URL, 2: username, 3: user email, 4: lost password URL */
153+
__( 'Your site at %1$s is active. You may now log in to your site using your chosen username of &#8220;%2$s&#8221;. 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>.' ),
154+
sprintf( '<a href="http://%1$s">%1$s</a>', $signup->domain ),
155+
$signup->user_login,
156+
$signup->user_email,
157+
wp_lostpassword_url()
158+
);
127159
}
160+
echo '</p>';
161+
} elseif ( $result === null || is_wp_error( $result ) ) {
162+
?>
163+
<h2><?php _e( 'An error occurred during the activation' ); ?></h2>
164+
<?php if ( is_wp_error( $result ) ) : ?>
165+
<p><?php echo $result->get_error_message(); ?></p>
166+
<?php endif; ?>
167+
<?php
128168
} else {
129169
$url = isset( $result['blog_id'] ) ? get_home_url( (int) $result['blog_id'] ) : '';
130170
$user = get_userdata( (int) $result['user_id'] );

src/wp-includes/general-template.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2812,6 +2812,24 @@ function wp_no_robots() {
28122812
echo "<meta name='robots' content='noindex,follow' />\n";
28132813
}
28142814

2815+
/**
2816+
* Display a noindex,noarchive meta tag and referrer origin-when-cross-origin meta tag.
2817+
*
2818+
* Outputs a noindex,noarchive meta tag that tells web robots not to index or cache the page content.
2819+
* Outputs a referrer origin-when-cross-origin meta tag that tells the browser not to send the full
2820+
* url as a referrer to other sites when cross-origin assets are loaded.
2821+
*
2822+
* Typical usage is as a wp_head callback. add_action( 'wp_head', 'wp_sensitive_page_meta' );
2823+
*
2824+
* @since 5.0.0
2825+
*/
2826+
function wp_sensitive_page_meta() {
2827+
?>
2828+
<meta name='robots' content='noindex,noarchive' />
2829+
<meta name='referrer' content='strict-origin-when-cross-origin' />
2830+
<?php
2831+
}
2832+
28152833
/**
28162834
* Display site icon meta tags.
28172835
*

src/wp-login.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function login_header( $title = 'Log In', $message = '', $wp_error = null ) {
3434
global $error, $interim_login, $action;
3535

3636
// Don't index any of these forms
37-
add_action( 'login_head', 'wp_no_robots' );
37+
add_action( 'login_head', 'wp_sensitive_page_meta' );
3838

3939
add_action( 'login_head', 'wp_login_viewport_meta' );
4040

0 commit comments

Comments
 (0)