Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
T5 Force Log In
<?php # -*- coding: utf-8 -*-
/**
* Plugin Name: T5 Force Log In
* Description: Grant access after log in only
* Plugin URI: http://toscho.de/?p=2207
* Version: 2012.08.28
* Author: Thomas Scholz
* Author URI: http://toscho.de
* License: MIT
* License URI: http://www.opensource.org/licenses/mit-license.php
*/
add_action( 'template_redirect', function() {
is_user_logged_in() || auth_redirect();
});
@mrhenko

This comment has been minimized.

Show comment
Hide comment
@mrhenko

mrhenko Jan 1, 2015

I'm currently trying to set up a restricted WordPress to share pictures of my daughter (when she's born later this year) with my family. I want sharing to be fairly simple but I don't want the pictures to be easily available on "the open internet". I like your solution a lot since it's so gorgeously simple. How secure would you say it is? Better, worse or the same as more "fully featured" plugins such as WP-Members and Restricted Site Access?

mrhenko commented Jan 1, 2015

I'm currently trying to set up a restricted WordPress to share pictures of my daughter (when she's born later this year) with my family. I want sharing to be fairly simple but I don't want the pictures to be easily available on "the open internet". I like your solution a lot since it's so gorgeously simple. How secure would you say it is? Better, worse or the same as more "fully featured" plugins such as WP-Members and Restricted Site Access?

@thefuxia

This comment has been minimized.

Show comment
Hide comment
@thefuxia

thefuxia Jul 17, 2015

Sorry for the late response. I was never notified of this comment.

It is secure for the HTML content. Images, on the other hand, are not routed through WordPress, so anyone can see them if they are able to get their URLs by guessing them or sniffing network traffic.

Owner

thefuxia commented Jul 17, 2015

Sorry for the late response. I was never notified of this comment.

It is secure for the HTML content. Images, on the other hand, are not routed through WordPress, so anyone can see them if they are able to get their URLs by guessing them or sniffing network traffic.

@s2925534

This comment has been minimized.

Show comment
Hide comment
@s2925534

s2925534 Sep 17, 2015

Where do I apply this code?

Where do I apply this code?

@salvatorecapolupo

This comment has been minimized.

Show comment
Hide comment
@salvatorecapolupo

salvatorecapolupo Nov 23, 2015

If you got a customized login page via front-end, you need to modify code as:

add_action( 'template_redirect', function() {
    if ( !is_page( id_of_login_page ) ) 
        is_user_logged_in() || auth_redirect();
});

or you will get a redirect error.

If you got a customized login page via front-end, you need to modify code as:

add_action( 'template_redirect', function() {
    if ( !is_page( id_of_login_page ) ) 
        is_user_logged_in() || auth_redirect();
});

or you will get a redirect error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment