WordPress.org

Ready to get started?Download WordPress

Forums

block access to urls? (2 posts)

  1. newuser2
    Member
    Posted 1 year ago #

    Is there a plugin or a way to block all of a blog except for a single page or post i allow. This could be any page within the blog, possibly allowed through adding a string to the end of a URL or something???

    For example i wish to send out a newsletter and allow people to access the single posts i link to in it. However to read the rest of the blog they must first register with us.

    Kind of like Quora allows you to see some of the content but you must register to see the rest.

    if this doesn't exist is it an easy task to do?

    I know there are plugins that require a visitor to login to access 'set' pages, but i don't want to set pages, just to allow access to the single page i link to and not the rest.

    Make sense?

  2. curlybracket
    Member
    Posted 1 year ago #

    Solution 1
    You could add this to your a page template :

    <?
    if (!is_user_logged_in()) {
        $option_redirect_to = wp_login_url(get_bloginfo('url'));
        $status = "302";
        wp_redirect( $option_redirect_to, $status ); exit;
    }
    ?>

    Then create a page template without this code for the page that should be public. When it should not be public anymore, assign the other template.

    Solution 2
    Add this to your page template or any other template you need to protect:

    <?
    if ($_GET['access'] !== "mysecretcode") {
        $option_redirect_to = wp_login_url(get_bloginfo('url'));
        $status = "302";
        wp_redirect( $option_redirect_to, $status ); exit;
    } else {
    // code of your page template here, the loop
    }
    ?>

    In your newsletter you could then have the URL http://example.com/page?access=mysecretcode

    If you get errors with wp_redirect, try to start a session.

    In addition to all this, if you want to restrict all other info (posts, categories, feeds etc.) of the website, feel free to try and/or to modify this plugin of mine http://wordpress.org/extend/plugins/very-basic-content-restriction/

Topic Closed

This topic has been closed to new replies.

About this Topic