-
Notifications
You must be signed in to change notification settings - Fork 0
/
preview.php
34 lines (28 loc) · 836 Bytes
/
preview.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
// Load CP.
require_once('../../../wp-load.php');
/*
Here we don't check for nonces because this link is intended
to be accessed directly.
*/
// Delete the cookie if there is no key.
if (!isset($_REQUEST['preview'])) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
if (isset($_COOKIE['selective_preview'])) {
setcookie('selective_preview', '', time() - 3600);
}
exit;
}
// Sanitize the value of the cookie and prepare.
$key = preg_replace('/[^0-9]/', '', sanitize_key(wp_unslash($_REQUEST['preview']))); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$url = parse_url(site_url()); // phpcs:ignore WordPress.WP.AlternativeFunctions.parse_url_parse_url
// Place the cookie
setcookie(
'selective_preview',
$key,
0,
'/',
$url['host'],
true,
true
);
wp_safe_redirect(site_url());