• Resolved Kahil

    (@kahil)


    Heya,

    I have been looking around for a while, but I can’t find anything. I have seen a few plugins out there that will hide content that is in a post or page based on whether or not a user is logged in….but I have yet to find one that will also let you hide things in the sidebar, heard or footer. One plugin that I’ve tried is calls “ProtectContent”. You just wrap what you want to hide in some tags. The plugin is very simple, but my mods to try and let me do such things in the header and sidebar have failed. I’m just not that good at coding, but always wanting to learn.

    I’ve even tried looking around for something that would teach me how to use the “is_user_logged_in” stuff from wordpress, but no luck there neither.

    Can anyone help?

    Thanks in advance!!

Viewing 15 replies - 1 through 15 (of 21 total)
  • I too need to hide stuff. I would rather wordpress’ login keep out the unregistered / unapproved users than my current method of password protecting the wp installation directory. I’m using a plug-in right now that keeps posts hidden when not logged in (which works fine) But I need the sidebar contents to remain hidden as well.

    Thread Starter Kahil

    (@kahil)

    Yeah, it seems as though all the plugins out there only hide things within the content div… I can’t figure out how to mod them so that the other areas like the header and sidebar do the same. ??

    Not a plugin, just some basic code:
    https://www.ads-software.com/support/topic/92378?replies=4
    It should get you started: change the level of the user and change what is displayed for logged in or else…

    Thread Starter Kahil

    (@kahil)

    Thank you!!!! Took me a few minutes to figure it all out correctly, but it works!!!

    Someone should make a plugin out of all that.

    I agree someone should make a plugin.

    I’m a total php newb and am reading instructions that assume a certain level of knowledge.

    Can someone talk me through adding this code?

    Thread Starter Kahil

    (@kahil)

    What are you wanting to do? Give us an example cuz it can be a lil tricky getting certain thing to display correctly. I found that out after some trial and error with links and images, etc.

    I want to keep both posts and sidebar widget contents invisible until the user is logged in. Thus preventing unauthorized viewing of sensitive info. Currently the WP installation dir is pw protected but would rather it be WP’s login that protects the site’s contents.

    My category’s posts are already protected via a plugin but I don’t want the sidebar contents (comments, category names etc.) to be visible either.

    Thread Starter Kahil

    (@kahil)

    <?
    get_currentuserinfo() ;
    global $user_level;
    if ($user_level > 0) {
    echo “yes”;
    } else {
    no
    }
    ?>

    Well, everything you want people to NOT be able to see will go in where yes is. Just remember that whatever code you put in there, you replace all the ” with ‘

    anything you want them to see goes where no is

    Thanks Kahil. But can you tell me which .php file in which directory that code goes into? Is it the index.php or the sidebar.php in my chosen theme folder?

    Am I understanding right that the line would be something like:

    echo "sidebar";
    or
    echo "categories";

    with ‘ where the ” are?

    I tried adding the above code into index.php in my theme folder in between

    <?php get_sidebar(); ?>

    and

    <?php get_footer(); ?>

    I tried modifying

    echo "yes";

    into

    echo "sidebar";

    and

    echo "sidebar.php";

    but that gave me errors. What am I doing wrong?

    Thread Starter Kahil

    (@kahil)

    don’t know how it’ll work or turn out by doing what you are trying to do… it just sounds like there is a better way to do all that, but ok…

    use get_sidebar();

    Please just spell it out for me!!!

    This is what I have (based on my understanding of what you’ve told me.)

    index.php :

    <?php get_sidebar(); ?>
    
    <!-- This is my test code to keep the sidebar hidden unless use is logged in. -->
    
    <?
    get_currentuserinfo() ;
    global $user_level;
    if ($user_level > 0) {
    echo "use get_sidebar();";
    } else {
    no
    }
    ?>
    
    <!-- This is my test code to keep the sidebar hidden unless use is logged in. -->
    
    <?php get_footer(); ?>
    Thread Starter Kahil

    (@kahil)

    Try this…

    <?
    get_currentuserinfo() ;
    global $user_level;
    if ($user_level > 0) {
    echo "get_sidebar();";
    } else {
    no
    }
    ?>

    This is not working. Clearly we have some kind of communication problem.

    Thread Starter Kahil

    (@kahil)

    I don’t know why it isn’t working for you, it worked great for me.

    Why don’t you just have a different page using a template that doesn’t call the sidebar or footer, etc. Set that as your homepage. Then use the Login Anywhere plugin on it so that for them to continue they have to login

Viewing 15 replies - 1 through 15 (of 21 total)
  • The topic ‘Hiding more than just post content unless admin…’ is closed to new replies.