WordPress.org

Ready to get started?Download WordPress

Forums

Show content only to particular user (3 posts)

  1. jami1955
    Member
    Posted 1 year ago #

    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

  2. vtxyzzy
    Member
    Posted 1 year ago #

    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.';
       }
    }
  3. Adam
    Member
    Posted 1 year ago #

    @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.

Topic Closed

This topic has been closed to new replies.

About this Topic