Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Hiding the "New Topic" Button from Members

  • Avatar of JJin26
    JJin26
    Participant

    @jjin26

    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

Viewing 25 replies - 1 through 25 (of 26 total)
  • Avatar of @mercime
    @mercime
    Keymaster

    @mercime

    @jjin26 please paste the code at pastebin.com and post the generated uri here

    Avatar of JJin26
    JJin26
    Participant

    @jjin26

    Thanks for the reply, here is the code: http://pastebin.com/26XtMc3k

    Avatar of bp-help
    bp-help
    Participant

    @bphelp

    @jjin26 The pastebin link above is blank. Please resubmit it and supply the new link.

    Avatar of JJin26
    JJin26
    Participant

    @jjin26

    Here is the link for the code: http://pastebin.com/fkfrEpdv

    Avatar of bp-help
    bp-help
    Participant

    @bphelp

    Untested but try changing line 1 in your code to:
    if ( !current_user_can( ‘manage_options’ ) )

    Avatar of JJin26
    JJin26
    Participant

    @jjin26

    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

    Avatar of bp-help
    bp-help
    Participant

    @bphelp

    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.php

    Avatar of danbpfr
    danbpfr
    Participant

    @chouf1

    @jjin26

    replace

    if ( is_user_logged_in() ) :

    with

    if ( bp_current_user_can( ‘bp_moderate’ ) ) : // this will apply for mods & admins

     

    Avatar of bp-help
    bp-help
    Participant

    @bphelp

    @chouf1 should I adjust the code on pastebin to reflect that change?

    Avatar of bp-help
    bp-help
    Participant

    @bphelp

    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.

    Avatar of danbpfr
    danbpfr
    Participant

    @chouf1

    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.

     

    Avatar of bp-help
    bp-help
    Participant

    @bphelp

    @chouf1

    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!

    Avatar of bp-help
    bp-help
    Participant

    @bphelp

    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?

    Avatar of danbpfr
    danbpfr
    Participant

    @chouf1

    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.

    Avatar of JJin26
    JJin26
    Participant

    @jjin26

    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.

    Avatar of JJin26
    JJin26
    Participant

    @jjin26

    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.

    Avatar of bp-help
    bp-help
    Participant

    @bphelp

    I updated the code:

    http://pastebin.com/xvGyHpBW

    Avatar of JJin26
    JJin26
    Participant

    @jjin26

    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.

    Avatar of bp-help
    bp-help
    Participant

    @bphelp

    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! :-(

    Avatar of JJin26
    JJin26
    Participant

    @jjin26

    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.

    Avatar of JJin26
    JJin26
    Participant

    @jjin26

    Help anyone I still need help with this problem

    Avatar of bp-help
    bp-help
    Participant

    @bphelp

    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!

    Avatar of bp-help
    bp-help
    Participant

    @bphelp

    @jjin26 I personally tested the code and it works good. Please let me know if it met your requirement.

    Avatar of JJin26
    JJin26
    Participant

    @jjin26

    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.

    Avatar of bp-help
    bp-help
    Participant

    @bphelp

    Cool, glad I could assist you and sorry it took awhile as I am still a novice at this myself. :-)

Viewing 25 replies - 1 through 25 (of 26 total)

You must be logged in to reply to this topic.