Skip to content

Commit 1811cb1

Browse files
authored
Add files via upload
1 parent dc39483 commit 1811cb1

5 files changed

Lines changed: 531 additions & 0 deletions

File tree

activate.php

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
<?php
2+
/**
3+
* Confirms that the activation key that is sent in an email after a user signs
4+
* up for a new site matches the key for that user and then displays confirmation.
5+
*
6+
* @package WordPress
7+
*/
8+
9+
define( 'WP_INSTALLING', true );
10+
11+
/** Sets up the WordPress Environment. */
12+
require __DIR__ . '/wp-load.php';
13+
14+
require __DIR__ . '/wp-blog-header.php';
15+
16+
if ( ! is_multisite() ) {
17+
wp_redirect( wp_registration_url() );
18+
die();
19+
}
20+
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+
40+
if ( remove_query_arg( false ) !== $redirect_url ) {
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+
49+
if ( null === $result && isset( $_COOKIE[ $activate_cookie ] ) ) {
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+
55+
if ( null === $result || ( is_wp_error( $result ) && 'invalid_key' === $result->get_error_code() ) ) {
56+
status_header( 404 );
57+
} elseif ( is_wp_error( $result ) ) {
58+
$error_code = $result->get_error_code();
59+
60+
if ( ! in_array( $error_code, $valid_error_codes, true ) ) {
61+
status_header( 400 );
62+
}
63+
}
64+
65+
nocache_headers();
66+
67+
if ( is_object( $wp_object_cache ) ) {
68+
$wp_object_cache->cache_enabled = false;
69+
}
70+
71+
// Fix for page title.
72+
$wp_query->is_404 = false;
73+
74+
/**
75+
* Fires before the Site Activation page is loaded.
76+
*
77+
* @since 3.0.0
78+
*/
79+
do_action( 'activate_header' );
80+
81+
/**
82+
* Adds an action hook specific to this page.
83+
*
84+
* Fires on {@see 'wp_head'}.
85+
*
86+
* @since MU (3.0.0)
87+
*/
88+
function do_activate_header() {
89+
/**
90+
* Fires within the `<head>` section of the Site Activation page.
91+
*
92+
* Fires on the {@see 'wp_head'} action.
93+
*
94+
* @since 3.0.0
95+
*/
96+
do_action( 'activate_wp_head' );
97+
}
98+
add_action( 'wp_head', 'do_activate_header' );
99+
100+
/**
101+
* Loads styles specific to this page.
102+
*
103+
* @since MU (3.0.0)
104+
*/
105+
function wpmu_activate_stylesheet() {
106+
?>
107+
<style type="text/css">
108+
.wp-activate-container { width: 90%; margin: 0 auto; }
109+
.wp-activate-container form { margin-top: 2em; }
110+
#submit, #key { width: 100%; font-size: 24px; box-sizing: border-box; }
111+
#language { margin-top: 0.5em; }
112+
.wp-activate-container .error { background: #f66; color: #333; }
113+
span.h3 { padding: 0 8px; font-size: 1.3em; font-weight: 600; }
114+
</style>
115+
<?php
116+
}
117+
add_action( 'wp_head', 'wpmu_activate_stylesheet' );
118+
add_action( 'wp_head', 'wp_strict_cross_origin_referrer' );
119+
add_filter( 'wp_robots', 'wp_robots_sensitive_page' );
120+
121+
get_header( 'wp-activate' );
122+
123+
$blog_details = get_site();
124+
?>
125+
126+
<div id="signup-content" class="widecolumn">
127+
<div class="wp-activate-container">
128+
<?php if ( ! $key ) { ?>
129+
130+
<h2><?php _e( 'Activation Key Required' ); ?></h2>
131+
<form name="activateform" id="activateform" method="post" action="<?php echo esc_url( network_site_url( $blog_details->path . 'wp-activate.php' ) ); ?>">
132+
<p>
133+
<label for="key"><?php _e( 'Activation Key:' ); ?></label>
134+
<br /><input type="text" name="key" id="key" value="" size="50" autofocus="autofocus" />
135+
</p>
136+
<p class="submit">
137+
<input id="submit" type="submit" name="Submit" class="submit" value="<?php esc_attr_e( 'Activate' ); ?>" />
138+
</p>
139+
</form>
140+
141+
<?php
142+
} else {
143+
if ( is_wp_error( $result ) && in_array( $result->get_error_code(), $valid_error_codes, true ) ) {
144+
$signup = $result->get_error_data();
145+
?>
146+
<h2><?php _e( 'Your account is now active!' ); ?></h2>
147+
<?php
148+
echo '<p class="lead-in">';
149+
if ( '' === $signup->domain . $signup->path ) {
150+
printf(
151+
/* translators: 1: Login URL, 2: Username, 3: User email address, 4: Lost password URL. */
152+
__( '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>.' ),
153+
esc_url( network_site_url( $blog_details->path . 'wp-login.php', 'login' ) ),
154+
esc_html( $signup->user_login ),
155+
esc_html( $signup->user_email ),
156+
esc_url( wp_lostpassword_url() )
157+
);
158+
} else {
159+
printf(
160+
/* translators: 1: Site URL, 2: Username, 3: User email address, 4: Lost password URL. */
161+
__( '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>.' ),
162+
sprintf( '<a href="http://%1$s">%1$s</a>', esc_url( $signup->domain . $blog_details->path ) ),
163+
esc_html( $signup->user_login ),
164+
esc_html( $signup->user_email ),
165+
esc_url( wp_lostpassword_url() )
166+
);
167+
}
168+
echo '</p>';
169+
} elseif ( null === $result || is_wp_error( $result ) ) {
170+
?>
171+
<h2><?php _e( 'An error occurred during the activation' ); ?></h2>
172+
<?php if ( is_wp_error( $result ) ) : ?>
173+
<p><?php echo esc_html( $result->get_error_message() ); ?></p>
174+
<?php endif; ?>
175+
<?php
176+
} else {
177+
$url = isset( $result['blog_id'] ) ? esc_url( get_home_url( (int) $result['blog_id'] ) ) : '';
178+
$user = get_userdata( (int) $result['user_id'] );
179+
?>
180+
<h2><?php _e( 'Your account is now active!' ); ?></h2>
181+
182+
<div id="signup-welcome">
183+
<p><span class="h3"><?php _e( 'Username:' ); ?></span> <?php echo esc_html( $user->user_login ); ?></p>
184+
<p><span class="h3"><?php _e( 'Password:' ); ?></span> <?php echo esc_html( $result['password'] ); ?></p>
185+
</div>
186+
187+
<?php
188+
if ( $url && network_home_url( '', 'http' ) !== $url ) :
189+
switch_to_blog( (int) $result['blog_id'] );
190+
$login_url = wp_login_url();
191+
restore_current_blog();
192+
?>
193+
<p class="view">
194+
<?php
195+
/* translators: 1: Site URL, 2: Login URL. */
196+
printf( __( 'Your account is now activated. <a href="%1$s">View your site</a> or <a href="%2$s">Log in</a>' ), esc_url( $url ), esc_url( $login_url ) );
197+
?>
198+
</p>
199+
<?php else : ?>
200+
<p class="view">
201+
<?php
202+
printf(
203+
/* translators: 1: Login URL, 2: Network home URL. */
204+
__( 'Your account is now activated. <a href="%1$s">Log in</a> or go back to the <a href="%2$s">homepage</a>.' ),
205+
esc_url( network_site_url( $blog_details->path . 'wp-login.php', 'login' ) ),
206+
esc_url( network_home_url( $blog_details->path ) )
207+
);
208+
?>
209+
</p>
210+
<?php
211+
endif;
212+
}
213+
}
214+
?>
215+
</div>
216+
</div>
217+
<?php
218+
get_footer( 'wp-activate' );

blog-header.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Loads the WordPress environment and template.
4+
*
5+
* @package WordPress
6+
*/
7+
8+
if ( ! isset( $wp_did_header ) ) {
9+
10+
$wp_did_header = true;
11+
12+
// Load the WordPress library.
13+
require_once __DIR__ . '/wp-load.php';
14+
15+
// Set up the WordPress query.
16+
wp();
17+
18+
// Load the theme template.
19+
require_once ABSPATH . WPINC . '/template-loader.php';
20+
21+
}

comments-post.php

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
/**
3+
* Handles Comment Post to WordPress and prevents duplicate comment posting.
4+
*
5+
* @package WordPress
6+
*/
7+
8+
if ( 'POST' !== $_SERVER['REQUEST_METHOD'] ) {
9+
$protocol = $_SERVER['SERVER_PROTOCOL'];
10+
if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0', 'HTTP/3' ), true ) ) {
11+
$protocol = 'HTTP/1.0';
12+
}
13+
14+
header( 'Allow: POST' );
15+
header( "$protocol 405 Method Not Allowed" );
16+
header( 'Content-Type: text/plain' );
17+
exit;
18+
}
19+
20+
/** Sets up the WordPress Environment. */
21+
require __DIR__ . '/wp-load.php';
22+
23+
nocache_headers();
24+
25+
$comment = wp_handle_comment_submission( wp_unslash( $_POST ) );
26+
if ( is_wp_error( $comment ) ) {
27+
$data = (int) $comment->get_error_data();
28+
if ( ! empty( $data ) ) {
29+
wp_die(
30+
'<p>' . $comment->get_error_message() . '</p>',
31+
__( 'Comment Submission Failure' ),
32+
array(
33+
'response' => $data,
34+
'back_link' => true,
35+
)
36+
);
37+
} else {
38+
exit;
39+
}
40+
}
41+
42+
$user = wp_get_current_user();
43+
$cookies_consent = ( isset( $_POST['wp-comment-cookies-consent'] ) );
44+
45+
/**
46+
* Fires after comment cookies are set.
47+
*
48+
* @since 3.4.0
49+
* @since 4.9.6 The `$cookies_consent` parameter was added.
50+
*
51+
* @param WP_Comment $comment Comment object.
52+
* @param WP_User $user Comment author's user object. The user may not exist.
53+
* @param bool $cookies_consent Comment author's consent to store cookies.
54+
*/
55+
do_action( 'set_comment_cookies', $comment, $user, $cookies_consent );
56+
57+
$location = empty( $_POST['redirect_to'] ) ? get_comment_link( $comment ) : $_POST['redirect_to'] . '#comment-' . $comment->comment_ID;
58+
59+
// If user didn't consent to cookies, add specific query arguments to display the awaiting moderation message.
60+
if ( ! $cookies_consent && 'unapproved' === wp_get_comment_status( $comment ) && ! empty( $comment->comment_author_email ) ) {
61+
$location = add_query_arg(
62+
array(
63+
'unapproved' => $comment->comment_ID,
64+
'moderation-hash' => wp_hash( $comment->comment_date_gmt ),
65+
),
66+
$location
67+
);
68+
}
69+
70+
/**
71+
* Filters the location URI to send the commenter after posting.
72+
*
73+
* @since 2.0.5
74+
*
75+
* @param string $location The 'redirect_to' URI sent via $_POST.
76+
* @param WP_Comment $comment Comment object.
77+
*/
78+
$location = apply_filters( 'comment_post_redirect', $location, $comment );
79+
80+
wp_safe_redirect( $location );
81+
exit;

0 commit comments

Comments
 (0)