-
AuthorPosts
-
March 2, 2015 at 2:38 pm #218684
harleyltdParticipantIs it possible to hide a row or column based on a user’s role? I can see that it is possible to use a class to hide a row but I am not savvy enough to know how to create a class to the functions.php file identifying a user role. http://codex.wordpress.org/Function_Reference/body_class#Add_Classes_By_Filters
If the user role is Subscriber or a unique role I added such as Hero, would you be willing to show me how to tweak this code to make it work?
// Add specific CSS class by filter add_filter( 'body_class', 'my_class_names' ); function my_class_names( $classes ) { // add 'class-name' to the $classes array $classes[] = 'class-name'; // return the $classes array return $classes; }Then I can add that class to the child css file and using it in the rows. PLEASE and thank you!
March 2, 2015 at 6:43 pm #218827
harleyltdParticipantI had previously asked, via Themeforest comments, if it was possible to hide a row or column based on logged in/logged out. The response given did not work. It hid the whole age and not just the row. Here was the suggestion provided.
WordPress adds a class to the <body> element when a user is logged in that is (surprisingly enough) called logged-in. If you added a custom class to a Content Band such as:
[content_band class="my-class"] ... [/content_band]Then you could implement some CSS in your child theme like so to hide the band when logged in:
.logged-in .my-class { display: none !important; }I added the CSS and then added the class to the Content Band settings but it hid the whole page instead of just the row. What did I do wrong?
March 2, 2015 at 9:18 pm #218897
Rue NelModeratorHi There,
To add a custom class for logged in user, you can use this custom filter in your functions.php
// Add specific CSS class by filter add_filter( 'body_class', 'logged_user_roles' ); function logged_user_roles( $classes ) { if ( is_user_logged_in() ) { $current_user = wp_get_current_user(); // add 'logged-in-roles' to the $classes array $classes[] = 'logged-in-' . implode(' logged-in-', $current_user->roles); } // return the $classes array return $classes; }Make sure that you enclose your content for that user roles in a separate content band.
[content_band] can be viewed by anyone [/content_band] [content_band class="custom-class"] Only for subscribers [/content_band]And in your css, you use this.
.logged-in-subscriber .custom-class { display: none !important; }Please let us know if this works for you.
March 2, 2015 at 9:53 pm #218921
harleyltdParticipantThat worked great. Thank you!!!
March 2, 2015 at 10:11 pm #218937
harleyltdParticipantJust realized that only fixed half the problem. I want to show one row/content band if the user is logged in and a different one if the visitor is logged out which means I need to create a version to display: none if they are logged out? I hate to be a bother but can you share the code to make this happen? This may be a cool option to go ahead and include in future releases. THANK YOU for all of your help.
March 2, 2015 at 11:11 pm #218957
Rue NelModeratorHi There,
Using our previous codes above, we could have something like this,
[content_band class="logged-out"] can be viewed by anyone [/content_band] [content_band class="logged-in"] Only for LOGGED IN subscribers [/content_band]And in your css, you use this,
.logged-out { display:block !important; } .logged-in { display: none !important; } .logged-in-subscriber .logged-out { display: none !important; } .logged-in-subscriber .logged-in { display: block !important; }Please let us know if this works.
March 3, 2015 at 11:54 am #219395
harleyltdParticipantIf I only wanted to show a block to a logged in user, wouldn’t it be the opposite? logged-out = display:none and logged-in = display:block? If that is true, would the second half have stay the same or would it have to be reversed as well?
March 3, 2015 at 5:58 pm #219643
Rue NelModeratorHi There,
The first two set are the general setting which means that the public view of the boxes. The second set overrides the first set because the user has logged in.
Hope this make sense.
Thank you.
March 3, 2015 at 9:36 pm #219765
harleyltdParticipantUnfortunately, it doesn’t work. When I add that snippet to the custom css section under customize, the whole page disappears. Any other ideas? I’d love for this to work
March 3, 2015 at 9:53 pm #219774
Rue NelModeratorHi There,
Would you mind providing us the url of your site with login credentials, if necessary, so we can take a closer look? We need to check your custom functions and css. To do this, you can make a post with the following info:
– Link to your site
– WordPress Admin username / password (only if necessary)Don’t forget to select Set as private reply. This ensures your information is only visible to our staff.
Thank you.
March 3, 2015 at 10:52 pm #219793
harleyltdParticipantThis reply has been marked as private.March 4, 2015 at 12:19 am #219831
Rue NelModeratorHi There,
Sorry about the confusion. We used the custom class as an example. You are meant to change that to your own name. We will start again here:
[content_band class="for-logged-out-users"] can be viewed by anyone [/content_band] [content_band class="for-logged-in-users"] Only for LOGGED IN {user role} [/content_band]and in our custom css, we would have this:
.for-logged-out-users { display:block !important; } .for-logged-in-users { display: none !important; } .logged-in-{role} .for-logged-out-users { display: none !important; } .logged-in-{role} .for-logged-out-users { display: block !important; }We hope it makes sense this time around 🙂
March 4, 2015 at 11:34 am #220261
harleyltdParticipantWORKS PERFECTLY!!! Thank you
March 4, 2015 at 8:40 pm #220581
Rue NelModeratorAwesome! We’re glad it perfectly works for you 😉
March 17, 2015 at 12:25 pm #229325
harleyltdParticipantCan you elaborate on one item in the code you shared above? Listed here below. The last two sections have the same class but different display. Is that correct? Or was it typed wrong? For example should one of them be ‘for-logged-in-users’ and one ‘for-logged-out-users’?
.for-logged-out-users { display:block !important; } .for-logged-in-users { display: none !important; } .logged-in-{role} .for-logged-out-users { display: none !important; } .logged-in-{role} .for-logged-out-users { display: block !important; }And then if I wanted on one user-role type to see the content, I would use the class=logged-in-administrator
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-218684 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
