Remove “New Announcement” Link from Menu


Home Forums Front End PM PRO Remove “New Announcement” Link from Menu

This topic is: Not Resolved
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #38392
    Jeff Adanac
    Participant

    Hi there, I’m trying to remove the “New Announcement” menu link in the front-end for users without manage options privs but the following function seems to remove the whole menu rather than just that menu link. I’ve tried variations of the “New Announcement” condition (‘new_announcement’,’New Announcement’, etc) but all seem to make the whole menu disappear. Any recommendations would be wonderful! thanks

    add_filter( 'fep_menu_buttons', 'fep_cus_fep_menu_buttons', 99 );
    
    function fep_cus_fep_menu_buttons( $menu )
    {
      if( ! current_user_can('manage_options') ){
        unset( $menu['New Announcement'] );
        return $menu;
      }
    }
    

    [MODERATOR] – Keep code between backtick

    #38395
    Shamim Hasan
    Keymaster

    By default “New Announcement” button is visible only to admins. No code require.
    Let me know if this is not the case for you.

    #38397
    Jeff Adanac
    Participant

    Thanks for your reply Shamim! Actually I’m looking to allow non-admin users with manage_options caps to see the “New Announcement” button and be able to create new announcements. All other roles (except) admin need to be prevented from doing so. Can you recommend a way to do this?

    Thanks so much!

    #38422
    Shamim Hasan
    Keymaster

    Users with manage_options capability are admin. They should see that button not the other users.
    Did you logged in as any other user (who does not have manage_options capability) and see if you see that button?

    #38426
    Jeff Adanac
    Participant

    Thanks Shamim! Yes that’s what I was hoping to be the case but my issue is that my function above makes the whole menu disappear, rather than just the “New Announcement” menu button. Can you see anything wrong with my function that might cause this?

    #38430
    Shamim Hasan
    Keymaster

    Yes, your code is not returning anything if user do not have manage_options capability. Use like following

    add_filter( 'fep_menu_buttons', 'fep_cus_fep_menu_buttons', 99 );
    
    function fep_cus_fep_menu_buttons( $menu )
    {
      if( ! current_user_can('manage_options') ){
        unset( $menu['new_announcement'] );
      }
      return $menu;
    }
    
    #38434
    Jeff Adanac
    Participant

    That worked! a misplaced close on the if statement. Rookie mistake. Thank you very much. Another question, is there a way to filter the list of recipient roles to ‘subscribers’ only when creating a new announcement?

    #38439
    Shamim Hasan
    Keymaster
Viewing 8 posts - 1 through 8 (of 8 total)

You need to purchase ‘Front End PM PRO’ to create topic in this support forum.

If you already purchased ‘Front End PM PRO’ please LOGIN.