• Resolved waseemsoa

    (@waseemsoa)


    hi,
    how can I add s2member user role into body tag as classname frontend and backend.

    thank you

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Cristián Lávaque

    (@clavaque)

    Hi @waseemsoa

    Well, you’d edit your theme’s template with a bit of PHP that gets the current user’s s2 level role to put it in the body tag’s class attribute. E.g.

    <body class="<?php echo get_user_field('s2member_access_role'); ?>">

    https://www.s2member.com/codex/stable/s2member/api_functions/package-functions/#src_doc_get_user_field()

    🙂

    Thread Starter waseemsoa

    (@waseemsoa)

    thanks for your immediate response
    there is one question about it. After adding this code if it will be applied only on s2member profile or any other profile too.
    for example if we have two users user1 and user 2, user1 have s2member role and user2 did not. if user1 see own profile then there will be s2member user role into body tag but when user1 see user2 profile then s2member user role can not be on body tag as class.

    I need same as example

    thank you

    • This reply was modified 1 year, 4 months ago by waseemsoa.
    Plugin Author Cristián Lávaque

    (@clavaque)

    Just try the code and see the effect with the different users. If the current user doesn’t have an s2Member Level, no s2Member level will be gotten from that code. That code only gets the name of the current user’s s2member_access_role, it doesn’t give one to the user.

    And you don’t have to use s2’s function for that, that was just an example to help you. You can use a regular WordPress function to get the current user’s WordPress role, too. https://wordpress.stackexchange.com/questions/239769/how-to-get-the-role-name-of-the-current-user-wordpress

    🙂

    Thread Starter waseemsoa

    (@waseemsoa)

    I try the code and after trying
    <body <?php echo get_user_field(‘s2member_access_level’) body_class(); ?>> there is a message “there has been a critical error on this website.

    Actually I have some customisation only for premium members on profile page with user role s2member.

    • This reply was modified 1 year, 4 months ago by waseemsoa.
    Plugin Author Cristián Lávaque

    (@clavaque)

    I see. Well, maybe s2 isn’t yet loaded at that point, maybe. Then you can try other code, like with WP’s functions. Mine was just an example. If your body tag is already in an echo, opening PHP tag would give an error, so you need to study your code to make sure it’s right for your template.

    If you want to customize some content on a page based on the role, maybe the s2If shortcode would help. https://s2member.com/kb-article/s2if-simple-shortcode-conditionals/

    🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘s2member user role into body tag’ is closed to new replies.