• Hello,
    I can’t figure out how to to check in php if a post content is restricted.
    I use Ultimate member to restrict access but I would like to display a menu for logged-in user ONLY if they are on a restricted page.
    Thanks for your help !
    Yann

Viewing 12 replies - 1 through 12 (of 12 total)
  • Your question is not clear enough. What do your mean by checking in “php”? A restricted page means nobody but a determined user role can view it so there is no point in having a menu with a link to a restricted page if users can’t see it.

    Thread Starter YannLes

    (@yannles)

    Sorry, I will try to better express myself .
    I just want to know if a page has been restricted with UM.
    Here’s an example of code i would like to use

    <?php if ( is_user_logged_in() && IF_IT_IS_A_UM_RESTRICTED_PAGE) {
    //then do something;
    }

    Thanks for your help !

    • This reply was modified 8 years, 3 months ago by YannLes.

    If you just want to see when a page is restricted, just wrap this shortcode [um_loggedin show_lock=yes] some content in the middle here [/um_loggedin] inside a page. Update the page. Log out.

    Go to that page and now you should see a message instead: “This content has been restricted to logged in users only. Please login to view this content.”

    Thread Starter YannLes

    (@yannles)

    Thank you for your answer Boris. I thought to this solution but it doesn’t really suit me because I want to put some code in the header.php file of my site. This is why i’m looking for a php solution like

    <?php if ( is_user_logged_in() && IF_IT_IS_A_UM_RESTRICTED_PAGE) {
    //then do something;
    }

    OK, one more try. So are you saying it doesn’t suit you because it is a shortcode and needs to be manually inserted? Or, is it the function that doesn’t suit your needs?

    Thread Starter YannLes

    (@yannles)

    The function is ok but I want it to be dynamic. I want to detect if the page is restricted. If a user is logged in and if he is on a restricted page a special menu will appear. If he is on a public page a different menu should appear.
    I try this in my header.php file but it nothing occured
    do_shortcode( '[um_loggedin show_lock=yes] This text can only be seen by logged in users [/um_loggedin]' );

    Please stop. That’s not PHP language. You can’t add shortcodes on php headers. I urge you to hire a web developer instead before you destroy your web site and come back crying.

    We are not supposed to discuss modifications such as what you are suggesting on this support board anyway.

    Thread Starter YannLes

    (@yannles)

    Boris,
    What do you mean by this is not php ?
    I’m developing WordPress sites and modifying php templates for many years now and I swear you I never cried ?? In fact, i even know rather well php. do_shortcode() is a wp function.
    I don’t understand why it seems so difficult to do a simple test in php to kwow wether a page is um private or not.
    If you don’t know how to do it, that’s ok, thanks anyway for trying to help me.

    • This reply was modified 8 years, 3 months ago by YannLes.

    I am talking about the php syntax code that a header would need to execute the type of function you want to have for your site. Your thoughts before were correct (e.g. <?php if ( is_user_logged_in() && IF_IT_IS_A_UM_RESTRICTED_PAGE) {//then do something;})

    The last post is not.

    I don’t understand why it seems so difficult to do a simple test in php to kwow wether a page is um private or not.

    Not difficult, just totally impractical. What is the point of “checking if a page is restricted”?
    If you are logged out and can’t see it, then it is. No need for a “PHP test”. Am I missing something?

    Thread Starter YannLes

    (@yannles)

    Probably i’m unclear, sorry. When auser is logged in there is to possibilities
    1 – he is on a um restricted page
    2 – he is on a public page
    I would like to display a different menu when he is on a restricted page. In the public pages, the logged in user will see the same public menu as logged out user.
    That’s why i would like to know if there is an existing function to see if the page is restricted.
    Sorry, english is not my native langage and it’s somehow difficult for me to be accurate.

    Have you checked Admin Menu > Appearance > Menus and do exactly what you are describing (add a page menu with controlled access by user role). Otherwise, I don’t get it.

    Thread Starter YannLes

    (@yannles)

    Hello Boris,
    Yes, i cheked it but, for some reason, it doesn’t suit me. What I really need to know is if there is a simple function or instruction to replace IF_IT_IS_A_UM_RESTRICTED_PAGE in this kind of code :
    <php if ( is_user_logged_in() && IF_IT_IS_A_UM_RESTRICTED_PAGE) {//then do something;}) ?>

    • This reply was modified 8 years, 3 months ago by YannLes.
Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Check if post content is restricted in UM Php’ is closed to new replies.