1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Subway WordPress Plugin Package. |
4
|
|
|
* |
5
|
|
|
* (c) Joseph Gabito <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* PHP Version 5.4 |
11
|
|
|
* |
12
|
|
|
* @category Subway\Page\Redirect |
13
|
|
|
* @package Subway |
14
|
|
|
* @author Joseph G. <[email protected]> |
15
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
16
|
|
|
* @version GIT:github.com/codehaiku/subway |
17
|
|
|
* @link github.com/codehaiku/subway The Plugin Repository |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace Subway; |
21
|
|
|
|
22
|
|
|
if (! defined('ABSPATH') ) { |
23
|
|
|
return; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Subway Option Methods. |
28
|
|
|
* |
29
|
|
|
* @category Subway\Page\Redirect |
30
|
|
|
* @package Subway |
31
|
|
|
* @author Joseph G. <[email protected]> |
32
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
33
|
|
|
* @link github.com/codehaiku/subway The Plugin Repository |
34
|
|
|
* @since 1.0 |
35
|
|
|
*/ |
36
|
|
|
final class PageRedirect |
37
|
|
|
{ |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Redirects pages into our login page. |
41
|
|
|
* |
42
|
|
|
* @return void. |
|
|
|
|
43
|
|
|
*/ |
44
|
|
|
public static function index() |
45
|
|
|
{ |
46
|
|
|
|
47
|
|
|
// Additional filter for custom pages, taxonomy, links, parameterized urls, etc. |
48
|
|
|
// Callback function/method must return true (boolean) to disable redirect. |
49
|
|
|
$should_exit = apply_filters( 'subway/classes/subway-page-redirect/index/before-page-redirect', false ); |
50
|
|
|
|
51
|
|
|
if ( $should_exit ) { |
52
|
|
|
return; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
// Only execute for non logged in users. |
56
|
|
|
if (is_user_logged_in() ) { |
57
|
|
|
return; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$is_private = false; |
61
|
|
|
|
62
|
|
|
$queried_id = get_queried_object_id(); |
63
|
|
|
|
64
|
|
|
$current_post = get_post(absint($queried_id)); |
65
|
|
|
|
66
|
|
|
$login_page_id = absint(get_option('subway_login_page')); |
67
|
|
|
|
68
|
|
|
$excluded_page = Options::getPublicPostsIdentifiers(); |
69
|
|
|
|
70
|
|
|
// Already escaped inside 'subway_get_redirect_page_url'. |
71
|
|
|
$redirect_page = Options::getRedirectPageUrl(); // WPCS XSS OK. |
72
|
|
|
|
73
|
|
|
if ( !empty( $current_post ) ) { |
74
|
|
|
$is_private = Metabox::isPostPrivate( $current_post->ID ); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
// do_action( 'subway/classes/subway-page-redirect/index/before_page_redirect' ); |
78
|
|
|
|
79
|
|
|
// Turn off if is in 'wc-ajax' (woocommerce) |
80
|
|
|
if ( function_exists( 'is_ajax') ) { |
81
|
|
|
if ( is_ajax() ) { |
82
|
|
|
return; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
// Same for normal ajax requests. |
87
|
|
|
if ( is_admin() && defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
88
|
|
|
return; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
// Exit if site is public. |
92
|
|
|
if ( Options::isPublicSite() ) { |
93
|
|
|
return; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
// Check if redirect page is empty or not. |
97
|
|
|
if ( empty( $redirect_page ) ) { |
98
|
|
|
return; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
// Check if buddypress activate page. |
102
|
|
|
if (function_exists('bp_is_activation_page') ) { |
103
|
|
|
if (bp_is_activation_page() ) { |
104
|
|
|
return; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
// Check if buddypress registration page. |
109
|
|
|
if (function_exists('bp_is_register_page') ) { |
110
|
|
|
if (bp_is_register_page() ) { |
111
|
|
|
return; |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
// Assign 0 value to empty $post->ID to prevent exception. |
116
|
|
|
// This applies to custom WordPress pages such as BP Members Page and Groups. |
117
|
|
|
if (empty($current_post) ) { |
118
|
|
|
$current_post = new \stdclass; |
119
|
|
|
$current_post->ID = 0; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
$current_page_id = absint($current_post->ID); |
123
|
|
|
|
124
|
|
|
// Check if $current_page_id && $selected_blog_id is equal to each other. |
125
|
|
|
// Get the page ID instead of global $post->ID that the query returns. |
126
|
|
|
// The ID of the first post object inside the loop is not correct. |
127
|
|
|
$blog_id = absint(get_option('page_for_posts')); |
128
|
|
|
|
129
|
|
|
if (is_home() ) { |
130
|
|
|
if ($blog_id === $login_page_id ) { |
131
|
|
|
$current_page_id = $blog_id; |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
// Only execute the script for non-loggedin visitors. |
136
|
|
|
if ( ! is_user_logged_in() ) { |
137
|
|
|
|
138
|
|
|
if ($current_page_id !== $login_page_id ) { |
139
|
|
|
|
140
|
|
|
if ( ! in_array( $current_page_id, $excluded_page, true ) || in_array( $current_page_id, $excluded_page, true ) && true === $is_private ) { |
141
|
|
|
|
142
|
|
|
wp_safe_redirect( |
143
|
|
|
add_query_arg( |
144
|
|
|
array( '_redirected' => 'yes' ), |
145
|
|
|
$redirect_page |
146
|
|
|
) |
147
|
|
|
); |
148
|
|
|
|
149
|
|
|
Helpers::close(); |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
} |
156
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.