Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 273 Vote(s) - 3.48 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Wordpress force user to login before view any site content

#1
In wordpress I am trying to force user login first before see anything. Means I want my user to first login to view any single page, post or archive and only they can se FAQ page. I am trying with below code but problem is as soon as I loged in, its redirect me again to login page.


However my site structure would be like below and in same manner I want this code to work...

// Force user to login on welcome
function my_force_login() {
global $post;

if (is_single() || is_front_page() || is_page() && !is_page('login') && !is_user_logged_in()){
auth_redirect();
}
}

Welcomd-Login screen (like facebook)
-Home page
-Blog
-About
-contact
-FAQ

So I want to allow visitor only can see Welcome Login screen and FAQ, contact page to view rest of the site I want to force them to login..

I need great help of you people.. Thanks a lot in advance..
Reply

#2
There's a plugin you can use for this. [Private Only](

[To see links please register here]

)
Reply

#3
I think you are missing a parenthesis:

if ( ( is_single() || is_front_page() || is_page() )
&& !is_page('login') && !is_user_logged_in()){
auth_redirect();
}
Reply

#4
Easy way

// Require login for site
get_currentuserinfo();
global $user_ID;
if ($user_ID == '') {
header('Location: /wp-login.php'); exit();
}
Reply

#5
This seems to work pretty well for me.

``` PHP
function _nok_force_user_login() {
if ( !is_page('login') && !is_user_logged_in() ){
auth_redirect();
}
}
add_action( 'template_redirect', '_nok_force_user_login' );
```
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through