@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | namespace Subway; |
| 21 | 21 | |
| 22 | 22 | if (! defined('ABSPATH') ) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /** |
@@ -36,105 +36,105 @@ discard block |
||
| 36 | 36 | final class PageRedirect |
| 37 | 37 | { |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Redirects pages into our login page. |
|
| 41 | - * |
|
| 42 | - * @return void. |
|
| 43 | - */ |
|
| 44 | - public static function index() |
|
| 45 | - { |
|
| 46 | - |
|
| 47 | - // Only execute for non logged in users. |
|
| 48 | - if (is_user_logged_in() ) { |
|
| 49 | - return; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - $queried_id = get_queried_object_id(); |
|
| 53 | - |
|
| 54 | - $current_post = get_post(absint($queried_id)); |
|
| 55 | - |
|
| 56 | - $login_page_id = absint(get_option('subway_login_page')); |
|
| 57 | - |
|
| 58 | - $excluded_page = Options::getPublicPostsIdentifiers(); |
|
| 59 | - |
|
| 60 | - // Already escaped inside 'subway_get_redirect_page_url'. |
|
| 61 | - $redirect_page = Options::getRedirectPageUrl(); // WPCS XSS OK. |
|
| 62 | - |
|
| 63 | - // Turn off if is in 'wc-ajax' (woocommerce) |
|
| 64 | - if ( function_exists( 'is_ajax') ) { |
|
| 65 | - if ( is_ajax() ) { |
|
| 66 | - return; |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - // Same for normal ajax requests. |
|
| 71 | - if ( is_admin() && defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
| 72 | - return; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - // Exit if site is public. |
|
| 76 | - if (Options::isPublicSite() ) { |
|
| 77 | - return; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - // Check if redirect page is empty or not. |
|
| 81 | - if (empty($redirect_page) ) { |
|
| 82 | - return; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - // Check if buddypress activate page. |
|
| 86 | - if (function_exists('bp_is_activation_page') ) { |
|
| 87 | - if (bp_is_activation_page() ) { |
|
| 88 | - return; |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - // Check if buddypress registration page. |
|
| 93 | - if (function_exists('bp_is_register_page') ) { |
|
| 94 | - if (bp_is_register_page() ) { |
|
| 95 | - return; |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - // Assign 0 value to empty $post->ID to prevent exception. |
|
| 100 | - // This applies to custom WordPress pages such as BP Members Page and Groups. |
|
| 101 | - if (empty($current_post) ) { |
|
| 102 | - $current_post = new \stdclass; |
|
| 103 | - $current_post->ID = 0; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - $current_page_id = absint($current_post->ID); |
|
| 107 | - |
|
| 108 | - // Check if $current_page_id && $selected_blog_id is equal to each other. |
|
| 109 | - // Get the page ID instead of global $post->ID that the query returns. |
|
| 110 | - // The ID of the first post object inside the loop is not correct. |
|
| 111 | - $blog_id = absint(get_option('page_for_posts')); |
|
| 112 | - |
|
| 113 | - if (is_home() ) { |
|
| 114 | - if ($blog_id === $login_page_id ) { |
|
| 115 | - $current_page_id = $blog_id; |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - // Only execute the script for non-loggedin visitors. |
|
| 120 | - if (! is_user_logged_in() ) { |
|
| 121 | - |
|
| 122 | - if ($current_page_id !== $login_page_id ) { |
|
| 123 | - |
|
| 124 | - if (! in_array($current_page_id, $excluded_page, true) ) { |
|
| 125 | - |
|
| 126 | - wp_safe_redirect( |
|
| 127 | - add_query_arg( |
|
| 128 | - array( '_redirected' => 'yes' ), |
|
| 129 | - $redirect_page |
|
| 130 | - ) |
|
| 131 | - ); |
|
| 132 | - |
|
| 133 | - Helpers::close(); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - } |
|
| 39 | + /** |
|
| 40 | + * Redirects pages into our login page. |
|
| 41 | + * |
|
| 42 | + * @return void. |
|
| 43 | + */ |
|
| 44 | + public static function index() |
|
| 45 | + { |
|
| 46 | + |
|
| 47 | + // Only execute for non logged in users. |
|
| 48 | + if (is_user_logged_in() ) { |
|
| 49 | + return; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + $queried_id = get_queried_object_id(); |
|
| 53 | + |
|
| 54 | + $current_post = get_post(absint($queried_id)); |
|
| 55 | + |
|
| 56 | + $login_page_id = absint(get_option('subway_login_page')); |
|
| 57 | + |
|
| 58 | + $excluded_page = Options::getPublicPostsIdentifiers(); |
|
| 59 | + |
|
| 60 | + // Already escaped inside 'subway_get_redirect_page_url'. |
|
| 61 | + $redirect_page = Options::getRedirectPageUrl(); // WPCS XSS OK. |
|
| 62 | + |
|
| 63 | + // Turn off if is in 'wc-ajax' (woocommerce) |
|
| 64 | + if ( function_exists( 'is_ajax') ) { |
|
| 65 | + if ( is_ajax() ) { |
|
| 66 | + return; |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + // Same for normal ajax requests. |
|
| 71 | + if ( is_admin() && defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
| 72 | + return; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + // Exit if site is public. |
|
| 76 | + if (Options::isPublicSite() ) { |
|
| 77 | + return; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + // Check if redirect page is empty or not. |
|
| 81 | + if (empty($redirect_page) ) { |
|
| 82 | + return; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + // Check if buddypress activate page. |
|
| 86 | + if (function_exists('bp_is_activation_page') ) { |
|
| 87 | + if (bp_is_activation_page() ) { |
|
| 88 | + return; |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + // Check if buddypress registration page. |
|
| 93 | + if (function_exists('bp_is_register_page') ) { |
|
| 94 | + if (bp_is_register_page() ) { |
|
| 95 | + return; |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + // Assign 0 value to empty $post->ID to prevent exception. |
|
| 100 | + // This applies to custom WordPress pages such as BP Members Page and Groups. |
|
| 101 | + if (empty($current_post) ) { |
|
| 102 | + $current_post = new \stdclass; |
|
| 103 | + $current_post->ID = 0; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + $current_page_id = absint($current_post->ID); |
|
| 107 | + |
|
| 108 | + // Check if $current_page_id && $selected_blog_id is equal to each other. |
|
| 109 | + // Get the page ID instead of global $post->ID that the query returns. |
|
| 110 | + // The ID of the first post object inside the loop is not correct. |
|
| 111 | + $blog_id = absint(get_option('page_for_posts')); |
|
| 112 | + |
|
| 113 | + if (is_home() ) { |
|
| 114 | + if ($blog_id === $login_page_id ) { |
|
| 115 | + $current_page_id = $blog_id; |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + // Only execute the script for non-loggedin visitors. |
|
| 120 | + if (! is_user_logged_in() ) { |
|
| 121 | + |
|
| 122 | + if ($current_page_id !== $login_page_id ) { |
|
| 123 | + |
|
| 124 | + if (! in_array($current_page_id, $excluded_page, true) ) { |
|
| 125 | + |
|
| 126 | + wp_safe_redirect( |
|
| 127 | + add_query_arg( |
|
| 128 | + array( '_redirected' => 'yes' ), |
|
| 129 | + $redirect_page |
|
| 130 | + ) |
|
| 131 | + ); |
|
| 132 | + |
|
| 133 | + Helpers::close(); |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | 139 | } |
| 140 | 140 | |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | namespace Subway; |
| 21 | 21 | |
| 22 | -if (! defined('ABSPATH') ) { |
|
| 22 | +if ( ! defined('ABSPATH')) { |
|
| 23 | 23 | return; |
| 24 | 24 | } |
| 25 | 25 | |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | { |
| 46 | 46 | |
| 47 | 47 | // Only execute for non logged in users. |
| 48 | - if (is_user_logged_in() ) { |
|
| 48 | + if (is_user_logged_in()) { |
|
| 49 | 49 | return; |
| 50 | 50 | } |
| 51 | 51 | |
@@ -61,44 +61,44 @@ discard block |
||
| 61 | 61 | $redirect_page = Options::getRedirectPageUrl(); // WPCS XSS OK. |
| 62 | 62 | |
| 63 | 63 | // Turn off if is in 'wc-ajax' (woocommerce) |
| 64 | - if ( function_exists( 'is_ajax') ) { |
|
| 65 | - if ( is_ajax() ) { |
|
| 64 | + if (function_exists('is_ajax')) { |
|
| 65 | + if (is_ajax()) { |
|
| 66 | 66 | return; |
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | // Same for normal ajax requests. |
| 71 | - if ( is_admin() && defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
| 71 | + if (is_admin() && defined('DOING_AJAX') && DOING_AJAX) { |
|
| 72 | 72 | return; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | // Exit if site is public. |
| 76 | - if (Options::isPublicSite() ) { |
|
| 76 | + if (Options::isPublicSite()) { |
|
| 77 | 77 | return; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | // Check if redirect page is empty or not. |
| 81 | - if (empty($redirect_page) ) { |
|
| 81 | + if (empty($redirect_page)) { |
|
| 82 | 82 | return; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | // Check if buddypress activate page. |
| 86 | - if (function_exists('bp_is_activation_page') ) { |
|
| 87 | - if (bp_is_activation_page() ) { |
|
| 86 | + if (function_exists('bp_is_activation_page')) { |
|
| 87 | + if (bp_is_activation_page()) { |
|
| 88 | 88 | return; |
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | // Check if buddypress registration page. |
| 93 | - if (function_exists('bp_is_register_page') ) { |
|
| 94 | - if (bp_is_register_page() ) { |
|
| 93 | + if (function_exists('bp_is_register_page')) { |
|
| 94 | + if (bp_is_register_page()) { |
|
| 95 | 95 | return; |
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | // Assign 0 value to empty $post->ID to prevent exception. |
| 100 | 100 | // This applies to custom WordPress pages such as BP Members Page and Groups. |
| 101 | - if (empty($current_post) ) { |
|
| 101 | + if (empty($current_post)) { |
|
| 102 | 102 | $current_post = new \stdclass; |
| 103 | 103 | $current_post->ID = 0; |
| 104 | 104 | } |
@@ -110,22 +110,22 @@ discard block |
||
| 110 | 110 | // The ID of the first post object inside the loop is not correct. |
| 111 | 111 | $blog_id = absint(get_option('page_for_posts')); |
| 112 | 112 | |
| 113 | - if (is_home() ) { |
|
| 114 | - if ($blog_id === $login_page_id ) { |
|
| 113 | + if (is_home()) { |
|
| 114 | + if ($blog_id === $login_page_id) { |
|
| 115 | 115 | $current_page_id = $blog_id; |
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | // Only execute the script for non-loggedin visitors. |
| 120 | - if (! is_user_logged_in() ) { |
|
| 120 | + if ( ! is_user_logged_in()) { |
|
| 121 | 121 | |
| 122 | - if ($current_page_id !== $login_page_id ) { |
|
| 122 | + if ($current_page_id !== $login_page_id) { |
|
| 123 | 123 | |
| 124 | - if (! in_array($current_page_id, $excluded_page, true) ) { |
|
| 124 | + if ( ! in_array($current_page_id, $excluded_page, true)) { |
|
| 125 | 125 | |
| 126 | 126 | wp_safe_redirect( |
| 127 | 127 | add_query_arg( |
| 128 | - array( '_redirected' => 'yes' ), |
|
| 128 | + array('_redirected' => 'yes'), |
|
| 129 | 129 | $redirect_page |
| 130 | 130 | ) |
| 131 | 131 | ); |