I need to block access to all other content except Index,wp-login.php, register.php till the user login. how to accomplish it.
i created everthing but, when i try mysite.com/members it shows the page how to disable it..
|
|
Functional code written using PHP 5.3+ Closures. Read the comments throughout to understand concept and flow.
Regards. |
|||||||||||||||||||
|
|
Depending on what 'members' actually is, and what other pages are you'll be able to restrict access to certain areas by using the As the simplest example (this goes in your template file): if ( !is_user_logged_in() ) exit( 'Access is restricted' ); You can also write you plugin to hook into the query and let it block the page or redirect in case certain criteria are met, like so:
The above code is simply there to illustrate the concept, it will not work out of the box. You can check |
|||||||
|
|
So you're looking to "lock-down" everything but the front page (or does it have to be index.php?) and the admin side of pages for register and login, correct? Unfortunately there is no template conditional tag to tell us when we're on the registration or login pages, but I found a blurb here that gives us that conditional tag: http://stackoverflow.com/questions/5266945/wordpress-how-detect-if-current-page-is-the-login-page From there it's a matter of writing the functions. I hooked it into the wp action hook because it's late enough that the template has been selected (we know if it's the home page). Anyway, try this script out.
|
|||||||||||||
|
|
I wrote the exact code you're looking for in a project a while back. The below code presumes you are using a child theme and that a 403.php file exists in your child directory. (I copied 404.php and made minor changes to it.) Note that Login/Register pages are available with this code, even though there is nothing in the code that might suggest that.
Additionally, if you want to modify your main menu to not include other links when the user is not logged in, you can utilize the |
||||
|
|