Exemple #1
0
/**
 * Redirects all the pages except for few selected pages inside
 * the reading settings
 *
 * (Front-end General)
 *
 * @return void
 */
function subway_redirect_to_login()
{
    global $post;
    $post_copy =& $post;
    $login_page_id = intval(get_option('subway_login_page'));
    $excluded_page = subway_get_excluded_page_id_collection();
    // Already escaped inside 'subway_get_redirect_page_url'.
    $redirect_page = subway_get_redirect_page_url();
    // Check if redirect page is empty or not.
    if (empty($redirect_page)) {
        return;
    }
    // Check if buddypress activate page.
    if (function_exists('bp_is_activation_page')) {
        if (bp_is_activation_page()) {
            return;
        }
    }
    // Check if buddypress registration page.
    if (function_exists('bp_is_register_page')) {
        if (bp_is_register_page()) {
            return;
        }
    }
    // In case their is no post ID assign a 0 value to
    // $post->ID. This pages applies to custom WordPress pages
    // like BuddyPress Members and Groups.
    if (empty($post_copy)) {
        $post_copy = new stdclass();
        $post_copy->ID = 0;
    }
    // Check if current page is locked down or not.
    $current_page_id = intval($post_copy->ID);
    // Check if $current_page_id && $selected_blog_id is equal to each other.
    // If that's the case, get the page ID instead of global $post->ID that returns.
    // the ID of the first post object inside the loop.
    $blog_id = intval(get_option('page_for_posts'));
    if (is_home()) {
        if ($blog_id === $login_page_id) {
            $current_page_id = $blog_id;
        }
    }
    // Only execute the script for non-loggedin visitors.
    if (!is_user_logged_in()) {
        if ($current_page_id !== $login_page_id) {
            if (!in_array($current_page_id, $excluded_page, true)) {
                wp_safe_redirect(add_query_arg(array('_redirected' => 'yes'), $redirect_page));
                die;
            }
        }
    }
    return;
}
Exemple #2
0
/**
 * Handles the failure login attempt from customized login page
 *
 * @param  object $user WordPress callback function
 * @return void
 */
function subway_redirect_login_handle_failure($user)
{
    // Pull the sign-in page url
    $sign_in_page = wp_login_url();
    $custom_sign_in_page_url = subway_get_redirect_page_url();
    if (!empty($custom_sign_in_page_url)) {
        $sign_in_page = $custom_sign_in_page_url;
    }
    // check that were not on the default login page
    if (!empty($sign_in_page) && !strstr($sign_in_page, 'wp-login') && !strstr($sign_in_page, 'wp-admin') && null !== $user) {
        // make sure we don't already have a failed login attempt.
        if (!strstr($sign_in_page, '?login=failed')) {
            // Redirect to the login page and append a querystring of login failed.
            $permalink = add_query_arg(array('login' => 'failed'), $custom_sign_in_page_url);
            wp_safe_redirect(esc_url_raw($permalink));
            die;
        } else {
            wp_safe_redirect($sign_in_page);
            die;
        }
        return;
    }
    return;
}