Support » Plugins » Show text to non-subscribers

  • Hi,

    I am looking for a way to tell the public that there are more posts to be seen, and they can see it if they register, without bothering my registered users with this – to them – irrelevant information.

    I looked around and found the hidethis plugin by Mark Edwards and figured that would be a good start. I modified the code slightly to turn it into something a bit more like a showthis plugin.

    add_filter('the_content', 'show_some_content');

    function show_some_content($content) {
    global $current_user, $user_ID;

    if (($current_user->id > 0) && ($user_ID > 0)){

    $b = strpos($content, '<!--showthis-->');
    $e = strpos($content, '<!--/showthis-->');

    $pre = substr($content,0,$b);
    $suf .= substr($content,$e,strlen($content));

    return $pre.$suf;

    } else { return $content; }

    In stead of hiding text (between tags) from non-registered viewers, it now only shows the text to non-registered users (so level 0). I’m not sure whether this still works in WP 2.02 (due to the new user level structure). Maybe it just works for me since I’m using the Role Manager plugin. Doesn’t really matter for my question though.

    This only works for posts. But I want to use this functionality in the sidebar in stead. I believe that the content filter is the determining factor here but I couldn’t find any other relevant filters that could be applied to the sidebar. So my question is whether anyone knows of a way to do this? I’m obviously no PHP wizz.

    As a secondary issue it would be good if there were no ’empty rows’ if the message is not shown. I noticed that some browsers treat the hiding of text as empty space.

    If you’ve read this far, thanks for taking the time 🙂

Viewing 1 replies (of 1 total)
  • You could try something like this:

    if (!$user_ID) {

    “Text for non-registered users here”

    } else {

    “Text for registered users here”


    You could just omit the “Text for registered users here” and then that way your registered users won’t see anything.

Viewing 1 replies (of 1 total)
  • The topic ‘Show text to non-subscribers’ is closed to new replies.