WordPress.org

Ready to get started?Download WordPress

Forums

Members
How to get the post's content permissions? (6 posts)

  1. kathatp
    Member
    Posted 2 years ago #

    I want to check a posts content permissions (which user roles are allowed to see it). Anyone got some code for this?

    Reason behind this is to instead of showing "Sorry, but you do not have permission to view this content" I want to not even show the entry in the post listing.

    I'm sure someone wanted to do this before me, nah??!!

    ANY HELP GREATLY APPRECIATED!!!!!

    http://wordpress.org/extend/plugins/members/

  2. galihfirm
    Member
    Posted 2 years ago #

    yep, the same case with.
    I need to marked the title protected post with lock image
    but I never the answer for this this thing.

    I hope someone can help me, to solve this.

  3. kathatp
    Member
    Posted 2 years ago #

    Hi.

    This might help:

    <?php if ( is_user_logged_in() ) { ?>

    CONTENT

    <?php } else { ?>

    LOGIN FORM

    <?php } ?>

  4. kathatp
    Member
    Posted 2 years ago #

    Also I got this in there....

    <?php
    foreach((get_the_category()) as $category) {
    if( $current_user->user_login == $category->cat_name ) {
    $goshow = TRUE;
    }
    }
    if( $goshow == TRUE || $current_user->user_login == "admin" ) {
    ?>

    CONTENT

    <?php } ?>

  5. galihfirm
    Member
    Posted 2 years ago #

    thank you for the answer Kathtp, but I need to separate the post by the user role.

    how do I get the post/page permission?

  6. galihfirm
    Member
    Posted 2 years ago #

    I think I found the function to get the post permission on members plugin.
    try with members_can_current_user_view_post( get_the_ID() )

    and you start with this code :

    <?php $permission = members_can_current_user_view_post( get_the_ID() );
    if( $permission == 1 ){
       the_title();
    }else{
       echo "locked post";
    }
    ?>

    maybe it useful for another

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic