Support » Fixing WordPress » Show content only to particular user

  • jami1955

    (@jami1955)


    I have a members section, created with the Members plugin, and I want to hard code into the page for individual members a conditional which determines if the logged in user id IS THE SAME AS the permalink for the page. IF it is the same, then print the content, if it is not print a different statement. Something like this:

    <?php global $current_user;
          get_currentuserinfo();
          if ( is_user_logged_in() )
          if $current_user->user_login = wp_url( get_permalink() )
    {
    	echo ' the_content(); ';
    } else {
        echo 'Please login to see this page.';
    }
    ?>

    the user id is going to be the permalink for the page, they will be identical. So I know the above code is ludicrous, absurd and does not work, but it gives the idea I’m going for.

    Can anyone write the code that would work? See if the logged in user id matches the permalink for the page, and if it does then print the content?
    thanks!!!!!1

Viewing 2 replies - 1 through 2 (of 2 total)
  • Perhaps something like this will work:

    $siteurl = site_url();
    $pageurl = get_permalink();
    global $current_user;
    get_currentuserinfo();
    if ( is_user_logged_in() ) {
       $testurl = "$siteurl/$current_user->user_login/";
       // echo "TESTURL:$testurl<br />";
       if ( $testurl == $pageurl ) {
    	   echo 'You can see the content.';
       } else {
          echo 'Please login to see this page.';
       }
    }

    @jami1955, did you get anywhere with this? I have exactly the same need. Shame there isn’t an affordable plugin out there that does this.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Show content only to particular user’ is closed to new replies.