[Resolved] Hiding the "New Topic" Button from Members
-
Need some help, I need code from forum.php that will hide the ‘New Topic’ button from Members but will show up for moderators and Admins. Here is the code that I’m struggling with. Also if there is a code I can use for functions.php. Thanks
-
@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.
Here is the link for the code: http://pastebin.com/fkfrEpdv
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?
http://pastebin.com/WKGL9Nf4
If the CSS selector is different then adjust it accordingly. This code can be placed in your themes functions.php or in bp-custom.phpreplace
if ( is_user_logged_in() ) :
with
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:
http://pastebin.com/xvGyHpBW
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.
I updated the code:
http://pastebin.com/xvGyHpBWbphelp 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.
Help anyone I still need help with this problem
I finally got it right:
http://pastebin.com/xvGyHpBW
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.
Cool, glad I could assist you and sorry it took awhile as I am still a novice at this myself.
You must be logged in to reply to this topic.