[Resolved] Hiding the "New Topic" Button from Members
@jjin26 please paste the code at pastebin.com and post the generated uri here
Thanks for the reply, here is the code: http://pastebin.com/26XtMc3k
@jjin26 The pastebin link above is blank. Please resubmit it and supply the new link.
Untested but try changing line 1 in your code to:
if ( !current_user_can( ‘manage_options’ ) )
Nope the code doesn’t hide the New Topic tab from members, I’ve uploaded the code so you can take a look : http://pastebin.com/dGPUWgtA
Couldn’t you just hide the button using CSS within a function?
If the CSS selector is different then adjust it accordingly. This code can be placed in your themes functions.php or in bp-custom.php
if ( is_user_logged_in() ) :
if ( bp_current_user_can( ‘bp_moderate’ ) ) : // this will apply for mods & admins
@chouf1 should I adjust the code on pastebin to reflect that change?
I adjusted it:
As stated before If the CSS selector is different then adjust line 6 in the code snippet accordingly.
The if statement i mentionned above hide the “new topic” button to any logged members EXCEPT mods and admins. This answer to the question how to show this button only to mods & admins ?
@bphelp ‘s CSS trick is another solution. Don’t use both together !
Just be warned that using display: none is not the best practice in this case ! Display:none doesn’t remove button from the page, it just hides it from visitors.
And because the button has an ID and a class, it could be styled from within the child theme css file. It’s a much proper way as using php to inject css into html – it works often, but it’s not intended for.
PHP is server language. JS, HTML and CSS are browser (aka. client side) languages.
Just be warned that using display: none is not the best practice in this case ! Display:none doesn’t remove button from the page, it just hides it from visitors
Maybe I am confused but isn’t hiding the button so it is not accessible the same as removing it? If it can’t be used then isn’t the purpose served? Just curious about this! Thanks!
Just because my curiosity is peaked on this is there some different code I ought to include or does what I provided serve its purpose?
Hidding something and remove something is not the same thing i guess.
If you hide the button with css, the visitor doesn’t see it.
But this same visitor can view the page code source in his browser and can check for a button access. And as this code is still in, he can use the button.
If you remove the button, there is no possibility to access it. Normal user won’t do that. But have you normal user if you need to hide such a service button ? If you don’t trust them to publish, why do you trust them for not searching in the source code ?
I would suggest to let this tread as is and give your tricks or solution but don’t make a unecessary plugin.
This “new topic” button is appearing in several places, and not only on the forum.php as stated by @jjin.
If you want to help, do it but test your code before you publish it. This will avoid correction and unecessary confusion.
The if you first used: manage_option applies to each member, so it had no effect on what was asked.
After that you used !bp_current_user_can( ‘bp_moderate’ )
You could also use !is_logged_in and many other conditions, depending on which page or what you need to do.
Still having an issue, As an admin or Moderator I cant see the New Topic button link, so half the the problem is fix but as an admin I need to see that button link.
tried both codes and none are coming out the way how I want. Simply put Admins and mods need to see this button link, Members I want to hide this link. Please anyone help.
bphelp your code doesnt work with CSS, the issue I continue to have is vice versa where member can see the button, but admins and mods cant and vice versa. I need a definite code in php where members cant see the button link in forum.php whether there in a group or not. Admin and mod must see the button link.
I am defeated! I tested my code and it doesn’t work I will leave it up in case anyone with more experience can figure out where I failed. The code doesn’t fire off any errors but it also doesn’t affect display of the button based on user roles in this case moderators! Sorry I could not help as I am a novice but at least I tried!
The only code that works 95% is if ( bp_group_is_member() ) but the only thing is when you join the group as a member you still the New topic button link. I need that button not to appear period whether in a group or not. Admin and mods must see the button.
I finally got it right:
I had to do a little searching on bbpress codex to get this right so this should help!
@jjin26 I personally tested the code and it works good. Please let me know if it met your requirement.
Hey bphelp Your code works my friend, I stil need to test it as a moderator but so far so good, thanks for the help.
- The topic ‘[Resolved] Hiding the "New Topic" Button from Members’ is closed to new replies.