Skip to content

Commit 73e9316

Browse files
authored
headless redirect duplicate code (#300)
1 parent 47256b7 commit 73e9316

File tree

1 file changed

+1
-54
lines changed

1 file changed

+1
-54
lines changed

wordpress/wp-content/themes/headless/setup/helpers/headless-redirect.php

+1-54
Original file line numberDiff line numberDiff line change
@@ -46,58 +46,5 @@ function headless_redirect() {
4646
$redirect = $headless_domain . $path;
4747
}
4848

49-
// if a 404 quickly fail and send to headless domain to handle
50-
// if we don't, WP will return info on a post we don't want (e.g. the most recent post)
51-
if (is_404()) {
52-
$redirect = $headless_domain . $path;
53-
return $redirect;
54-
}
55-
56-
// check if preview and user has edit ability.
57-
// if so, redirect to preview path
58-
if (is_preview()) {
59-
if (current_user_can('edit_posts')) {
60-
$revisions = wp_get_post_revisions($id, [
61-
'posts_per_page' => 1,
62-
'fields' => 'ids',
63-
'check_enabled' => false,
64-
]);
65-
66-
$auth_code = wpe_headless_generate_authentication_code(wp_get_current_user());
67-
68-
$preview_id = is_array($revisions) && !empty($revisions) ? array_values($revisions)[0] : null;
69-
70-
$redirect =
71-
$headless_domain .
72-
'/api/preview/?code=' .
73-
rawurlencode($auth_code) .
74-
'&id=' .
75-
$id .
76-
'&preview_id=' .
77-
$preview_id;
78-
return $redirect;
79-
}
80-
}
81-
82-
// else do standard redirect tree
83-
if ($slug) {
84-
if (current_user_can('edit_posts')) {
85-
$auth_code = wpe_headless_generate_authentication_code(wp_get_current_user());
86-
$redirect =
87-
$headless_domain . '/api/preview/?code=' . rawurlencode($auth_code) . '&slug=' . $slug . '&id=' . $id;
88-
} else {
89-
$redirect = $headless_domain . $slug;
90-
}
91-
} else {
92-
$path = $_SERVER['REQUEST_URI'];
93-
if (current_user_can('edit_posts')) {
94-
$auth_code = wpe_headless_generate_authentication_code(wp_get_current_user());
95-
$redirect =
96-
$headless_domain . '/api/preview/?code=' . rawurlencode($auth_code) . '&path=' . $path . '&id=' . $id;
97-
} else {
98-
$redirect = $headless_domain . $path;
99-
}
100-
}
101-
10249
return $redirect;
103-
}
50+
}

0 commit comments

Comments
 (0)