コード例 #1
0
ファイル: public.php プロジェクト: paulmedwal/edxforumspublic
/**
 * Present a login screen to anyone not logged in
 * 
 * Check for already logged in or just logged in.
 * Only called when is_admin() is FALSE
 *
 * @return   NULL                Nothing is returned
 */
function jr_ps_force_login()
{
    global $jr_ps_is_login;
    if (is_user_logged_in() || isset($jr_ps_is_login)) {
        return;
    }
    $settings = get_option('jr_ps_settings');
    /*	URL of current page without http://, i.e. - starting with domain
     */
    $current_url = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
    if ($settings['excl_home'] && jr_v1_same_url(get_home_url(), $current_url)) {
        return;
    }
    if ($settings['custom_login'] && !empty($settings['login_url']) && jr_v1_same_url($settings['login_url'], $current_url)) {
        return;
    }
    if (isset($settings['excl_url'])) {
        foreach ($settings['excl_url'] as $arr) {
            /*	Test the pre-parsed URL in the URL Exclusion list
             */
            if (jr_v1_same_url($arr[1], $current_url)) {
                return;
            }
        }
    }
    if (isset($settings['excl_url_prefix'])) {
        foreach ($settings['excl_url_prefix'] as $arr) {
            /*	Test the pre-parsed URL in the Prefix URL Exclusion list
             */
            if (jr_v1_same_prefix_url($arr[1], $current_url)) {
                return;
            }
        }
    }
    if ($settings['reveal_registration']) {
        $buddypress_path = 'buddypress/bp-loader.php';
        $buddypress_active = is_plugin_active($buddypress_path);
        /*	URL of Registration Page varies between Multisite (Network)
        			and Single Site WordPress.
        			Plus, wp_registration_url function was introduced in
        			WordPress Version 3.6.
        		*/
        if (is_multisite()) {
            $reg_url = get_site_url(0, 'wp-signup.php');
            $buddypress_active = $buddypress_active || is_plugin_active_for_network($buddypress_path);
        } else {
            if (function_exists('wp_registration_url')) {
                $reg_url = wp_registration_url();
            } else {
                $reg_url = get_site_url(0, 'wp-login.php?action=register');
            }
        }
        if (jr_v1_same_url($reg_url, $current_url) || $buddypress_active && (jr_v1_same_url(get_site_url(0, 'register'), $current_url) || jr_v1_same_url(get_site_url(0, 'activate'), parse_url($current_url, PHP_URL_HOST) . parse_url($current_url, PHP_URL_PATH)))) {
            /*	BuddyPress plugin redirects Registration URL to
            				either {current site}/register/ or {main site}/register/
            				and has its own Activation at /activate/?key=...
            			*/
            return;
        }
    }
    /*	Must exclude all of the pages generated by the Theme My Login plugin
     */
    $theme_my_login_path = 'theme-my-login/theme-my-login.php';
    $theme_my_login_active = is_plugin_active($theme_my_login_path);
    if (is_multisite()) {
        $theme_my_login_active = $theme_my_login_active || is_plugin_active_for_network($theme_my_login_path);
    }
    if ($theme_my_login_active) {
        if (NULL !== ($page = get_post($null = NULL))) {
            /*	Some Versions of WordPress required that get_post() have a parameter
             */
            if ('page' === $page->post_type && in_array($page->post_name, array('login', 'logout', 'lostpassword', 'register', 'resetpass')) && stripos($page->post_content, 'theme-my-login')) {
                return;
            }
        }
    }
    if ($settings['custom_login'] && !empty($settings['login_url'])) {
        $url = jr_ps_login_url($settings['login_url']);
    } else {
        /*	wp_login_url() returns the standard WordPress login URL,
        			but the login_url Filter adds the ?redirect_to= query in the URL.
        		*/
        $url = wp_login_url();
    }
    /*	wp_redirect( $url ) goes to $url right after exit on the line that follows.
     */
    wp_redirect($url);
    exit;
}
コード例 #2
0
ファイル: public.php プロジェクト: alejandrososa/AB
function jr_ps_login_failed()
{
    $settings = get_option('jr_ps_settings');
    if ($settings['custom_login'] && !empty($settings['login_url'])) {
        /*	wp_redirect( $url ) goes to $url right after exit on the line that follows.
         */
        wp_redirect(jr_ps_login_url($settings['login_url']));
        exit;
    } else {
        return;
    }
}