• Resolved bhupinder01

    (@bhupinder01)


    Hi,

    Great plugin but I’m facing 2 issues on my site.

    1. Logout link not working. I can’t able to logout from site, when I clicked on logout it redirects to login page (‘/login/’) and can’t able to logout from the site.
    2. When anyone came from Facebook to access the content, it will redirect to login.php instead of that particular content.

    By default if anyone logged in on my site, it will redirect to homepage first – (WP User Manager Plugin setting).
    Also, I’m using customized login page (‘/login/’ – WP User Manager plugin) for my site. So I had disabled the default WordPress login page. Below is the code:

    /**
    * Disable default WordPress login
    **/
    function custom_wp_redirect_admin_locations() {
    global $wp_rewrite;
    if ( ! ( is_404() && $wp_rewrite->using_permalinks() ) )
    return;

    $admins = array(
    home_url( ‘wp-admin’, ‘relative’ ),
    home_url( ‘dashboard’, ‘relative’ ),
    home_url( ‘admin’, ‘relative’ ),
    site_url( ‘dashboard’, ‘relative’ ),
    site_url( ‘admin’, ‘relative’ ),
    );
    if ( in_array( untrailingslashit( $_SERVER[‘REQUEST_URI’] ), $admins ) ) {
    wp_redirect( admin_url() );
    exit;
    }

    $logins = array(
    home_url( ‘wp-login.php’, ‘relative’ )
    );
    if ( in_array( untrailingslashit( $_SERVER[‘REQUEST_URI’] ), $logins ) ) {
    wp_redirect( site_url( ‘wp-login.php’, ‘login’ ) );
    exit;
    }
    }

    function remove_default_login_redirect() {
    remove_action(‘template_redirect’, ‘wp_redirect_admin_locations’, 1000);
    add_action( ‘template_redirect’, ‘custom_wp_redirect_admin_locations’, 1000 );
    }

    add_action(‘init’,’remove_default_login_redirect’);

    /**
    * Change default WordPress login URL
    **/
    function login_redirect() {
    global $pagenow;
    if ($pagenow == ‘wp-login.php’ && empty($_POST)) {
    wp_redirect(‘/user-login/’);
    exit();
    }
    }
    add_action(‘init’,’login_redirect’);

    /**
    * Redirect user once Logged In
    **/
    function redirect_login_page() {
    $login_page = home_url( ‘/login/’ );
    $page_viewed = basename($_SERVER[‘REQUEST_URI’]);
    if ($page_viewed == “wp-login.php” && $_SERVER[‘REQUEST_METHOD’] == ‘GET’) {
    wp_redirect($login_page);
    exit;
    }
    }
    add_action(‘init’,’redirect_login_page’);

    /**
    * Whitelist specified URLs/pages
    **/
    function my_forcelogin_whitelist( $whitelist ) {
    $whitelist[] = site_url( ‘/login/’ );
    $whitelist[] = site_url( ‘/sign-up/’ );
    $whitelist[] = site_url( ‘/register/’ );
    $whitelist[] = site_url( ‘/product/premium-membership/’ );
    $whitelist[] = site_url( ‘/product/annual-premium-membership/’ );
    $whitelist[] = site_url( ‘/cart/’ );
    $whitelist[] = site_url( ‘/checkout/’ );
    $whitelist[] = site_url( ‘/home/’ );
    $whitelist[] = site_url( ‘/password-reset/’ );

    return $whitelist;
    }
    add_filter(‘v_forcelogin_whitelist’, ‘my_forcelogin_whitelist’, 10, 1);

    Kindly check my code and suggest the necessary solution.
    Looking for the quick reply.
    Thanks in advance!!
    Regards,

Viewing 1 replies (of 1 total)
  • Plugin Author Kevin Vess

    (@kevinvess)

    Given all the custom changes you’ve made to the WordPress login functionality, I suspect the cause to both these issue could be a result of that. If you remove your custom login changes, does Force Login work as expected?

    Also, I noticed you’ve whitelisted /cart/ and /checkout/ – if you’re also using an ecommerce plugin, like WooCommerce, there may be other login or user account configurations being made to your site that are causing conflicts with your custom login code.

    1. Logout link not working. I can’t able to logout from site, when I clicked on logout it redirects to login page (‘/login/’) and can’t able to logout from the site.

    I suspect your issue with logging-out is from all the custom changes you’ve made to the WordPress login. Specifically, I would look at the following two filters you’re using: login_redirect() and redirect_login_page().

    One appears to change the login URL to /user-login/ and the other uses /login/ – maybe that is causing the logout issue? Make sure everything is consistent.

    2. When anyone came from Facebook to access the content, it will redirect to login.php instead of that particular content.

    As for your issue with visitors coming to the site from Facebook; I wonder if you’re asking about the same issue as this post?
    https://ww.wp.xz.cn/support/topic/post-share-on-facebook/#post-8536276

    Otherwise, if the visitor is not logged-in to your site, then clicking on links in Facebook should send them to the login screen. If you are logged-in and still being redirected to the login screen – try removing your custom WordPress login changes you’ve made to verify that’s not causing the issue.

    Thanks for using Force Login!

Viewing 1 replies (of 1 total)

The topic ‘Logout Not Working’ is closed to new replies.