示例#1
0
/**
 * 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
/**
 * 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()
{
    /*	return statements are performed only if User does not need to login.
    	
    		First, check if User is on a Login panel.
    	*/
    global $jr_ps_is_login, $jr_ps_plugin_data;
    if (isset($jr_ps_is_login)) {
        return;
    }
    $settings = get_option('jr_ps_settings');
    /*	Next, check if User is already logged in, and has a Role on this Site.
     */
    $role = TRUE;
    if (is_user_logged_in()) {
        if (is_multisite()) {
            if (is_user_member_of_blog()) {
                return;
            } else {
                /*	User is logged on to a Site where he/she has no Role.
                 */
                if ($settings['check_role']) {
                    $role = FALSE;
                } else {
                    /*	User can see all of public site.
                     */
                    return;
                }
            }
        } else {
            return;
        }
    }
    /*	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;
            }
        }
    }
    /*	Point of No Return:
    		We now know that the Visitor must be forced to login
    		if the Visitor wants to see the current URL.
    	*/
    if (!$role) {
        /*	User is logged on to a Site where he/she has no Role.
         */
        $message = 'You (User "' . wp_get_current_user()->user_login . '") cannot view this Site ("' . get_bloginfo('name', 'display') . '").<hr />' . 'Your User ID has not been defined to this Site. ' . 'If you believe that you should be able to access this Site, ' . 'please contact your network administrator or this site\'s webmaster, ' . 'and mention that your access was blocked by the <em>' . $jr_ps_plugin_data['Name'] . '</em> plugin.';
        wp_die($message);
    }
    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;
}