| Conditions | 14 |
| Paths | 102 |
| Total Lines | 81 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 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 | // 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 | // Exit if site is public. |
||
| 64 | if (Options::isPublicSite() ) { |
||
| 65 | return; |
||
| 66 | } |
||
| 67 | |||
| 68 | // Check if redirect page is empty or not. |
||
| 69 | if (empty($redirect_page) ) { |
||
| 70 | return; |
||
| 71 | } |
||
| 72 | |||
| 73 | // Check if buddypress activate page. |
||
| 74 | if (function_exists('bp_is_activation_page') ) { |
||
| 75 | if (bp_is_activation_page() ) { |
||
| 76 | return; |
||
| 77 | } |
||
| 78 | } |
||
| 79 | |||
| 80 | // Check if buddypress registration page. |
||
| 81 | if (function_exists('bp_is_register_page') ) { |
||
| 82 | if (bp_is_register_page() ) { |
||
| 83 | return; |
||
| 84 | } |
||
| 85 | } |
||
| 86 | |||
| 87 | // Assign 0 value to empty $post->ID to prevent exception. |
||
| 88 | // This applies to custom WordPress pages such as BP Members Page and Groups. |
||
| 89 | if (empty($current_post) ) { |
||
| 90 | $current_post = new \stdclass; |
||
| 91 | $current_post->ID = 0; |
||
| 92 | } |
||
| 93 | |||
| 94 | $current_page_id = absint($current_post->ID); |
||
| 95 | |||
| 96 | // Check if $current_page_id && $selected_blog_id is equal to each other. |
||
| 97 | // Get the page ID instead of global $post->ID that the query returns. |
||
| 98 | // The ID of the first post object inside the loop is not correct. |
||
| 99 | $blog_id = absint(get_option('page_for_posts')); |
||
| 100 | |||
| 101 | if (is_home() ) { |
||
| 102 | if ($blog_id === $login_page_id ) { |
||
| 103 | $current_page_id = $blog_id; |
||
| 104 | } |
||
| 105 | } |
||
| 106 | |||
| 107 | // Only execute the script for non-loggedin visitors. |
||
| 108 | if (! is_user_logged_in() ) { |
||
| 109 | |||
| 110 | if ($current_page_id !== $login_page_id ) { |
||
| 111 | |||
| 129 |
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.