WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin- HidePost] Protect Content with Role Issue ! (2 posts)

  1. kohatian
    Member
    Posted 1 year ago #

    Hi Sir/Madam,

    i need some problem with this plugin .i was looking for a code but i found this plugin and it works really great to hide some content in the post for guests :( ! but here is problem the Protect Content with Role: code is not working [hidepost=level][/hidepost]

    this code is not working :( but i write this in a wordpress page so guest is getting the same message like [hidepost][/hidepost] the role code is not working so kindly can you tell me how to fix this issue and also can you tell me how to hide content in wordpress for guest but leave a message to guest like this

    "Register users can see this content !"

    and when a user loggin it so he/she will be able to see the contect instead Register users can see this content !

    i mean like this

    [hidepost=if user logged in]
    here is content for register user

    else

    only register user can see

    [/hidepost]

  2. bcworkz
    Member
    Posted 1 year ago #

    I'm sorry I'm not able to tell you how to fix an unsupported plugin. If you know some PHP, this functionality is not too difficult to make yourself. Read the Shortcode API. The code you make can be made into a simple plugin or added to your theme functions.php file.

    The key function to use in an if...else structure is is_user_logged_in() for simple guest restriction and current_user_can() to restrict by level. You could just use the shortcode like so: [hide_excerpt]This text is only shown to logged in users[/hide_excerpt].

    Your short code handler is passed the content between the tags, so your handler function might only need to contain;

    if (is_user_logged_in()) {
       return $content;
    } else {
       return 'Please register to see this content.';
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.