Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Function in Admin Bar

  • Avatar of osasko
    osasko
    Participant

    @osasko

    Hi,

    I just wanted to know how you modify the buddypress admin bar at the top.

    Because I want to add a search function there.

    Thanks in advance.

Viewing 12 replies - 1 through 12 (of 12 total)
  • Avatar of Nick Watson
    Nick Watson
    Participant

    @nickbwatson

    in your plugins folder (if you don’t already have one created) create a file called bp-custom.php

    within that file put:

    <?php

    function new_search_action() {
    global $bp;

    return apply_filters( 'new_search_action', $bp->root_domain . '/search' );
    }

    function custom_adminbar_search() {
    $mobSearch = '
    <li class="align-right"><form action="' . new_search_action() . '" method="post" id="search-form">
    <input type="text" id="search-terms" name="search-terms" value="" />
    <input type="submit" name="search-submit" id="search-submit" value="" />

    ' . bp_search_form_type_select() . '

    ' . wp_nonce_field( 'bp_search_form' ) . '
    </form></li>
    ';

    echo apply_filters( 'bp_search_form', $mobSearch );
    }
    add_action('bp_adminbar_menus', 'custom_adminbar_search', 100);

    ?>

    This will get your search to the top, and placed on top of your “visit” button. If you get rid of the class="align-right" in the list tag, then it’ll put it beside the notification button. You’ll notice that things seem a little screwy when you scale the page, so you’ll need to play around with putting a div around it etc etc. But at least this’ll get it up there for you.

    To remove items from your admin bar:

    function modify_adminbar(){
    remove_action( 'bp_adminbar_logo', 'bp_adminbar_logo' );
    remove_action( 'bp_adminbar_menus', 'bp_adminbar_login_menu', 2 );
    remove_action( 'bp_adminbar_menus', 'bp_adminbar_account_menu', 4 );
    remove_action( 'bp_adminbar_menus', 'bp_adminbar_blogs_menu', 6 );
    remove_action( 'bp_adminbar_menus', 'bp_adminbar_notifications_menu', 8 );
    remove_action( 'bp_adminbar_menus', 'bp_adminbar_authors_menu', 12 );
    remove_action( 'bp_adminbar_menus', 'bp_adminbar_random_menu', 100 );
    }
    add_action('plugins_loaded','modify_adminbar',99);

    This removes ALL of the previous functions, so lets say you want to remove.. the visit button:

    function modify_adminbar(){
    remove_action( 'bp_adminbar_menus', 'bp_adminbar_random_menu', 100 );
    }
    add_action('plugins_loaded','modify_adminbar',99);

    And there you go. Hope that helped.

    Avatar of osasko
    osasko
    Participant

    @osasko

    Awesome!

    Thanks – exactly what I wanted to do.

    I like it on the right top – just struggling to move it a little to the left – cos the ” Visit” tab covers part of it.

    I added style = margin-right:30px – but it is obviously not right as it doesn’t do anything?

    Thanks for the help.

    Avatar of Kevin Pine
    Kevin Pine
    Participant

    @kevinpine

    To move the search try adding this to your CSS:

    #search-form {margin-right:30px;}

    You can also hide the ‘Visit’ menu item with the following CSS:

    #bp-adminbar-visitrandom-menu{display:none}

    Hi,

    Thanks for this tips ! It works very well. But I don’t understand why the search button and the serch field are bigger than those wich are in the header ?

    Thanks.

    Excuse my english.

    Guillaume.

    Avatar of Jens Wedin
    Jens Wedin
    Participant

    @jedisthlm

    @Nick Watson: Sorry for using the thread but I still haven’t figured out how to add new navigation items to the admin bar. I would for example like to add WP categories and some hard coded links in the admin bar. How do I do?

    Avatar of Chau kar
    Chau kar
    Participant

    @animeonsen

    The color changes on mouse over. How to disable that for the search form?

    Avatar of bennadler
    BenNadler
    Member

    @bennadler

    In your theme’s CSS file, you need to declare this:


    #wp-admin-bar ul.main-nav li.align-right:hover{
    background: none !important;
    }

    That should do it, as long as you have not modified the code above at all.

    Avatar of Chau kar
    Chau kar
    Participant

    @animeonsen

    It searches for members,groups and forums……but I also want to let it search on the site itself……just the normal search.

    There is a dropdown where I can search for members,groups,forums

    Is it possible to change to search: site,members,groups and forums?

    Avatar of justbishop
    justbishop
    Member

    @justbishop

    Hi guys! Awesome thread, but can someone help me get rid of the little downward triangle from the “visit” item? I removed the item according to the code @nickbwatson posted above, but the little arrow thing is still there, showing behind the text of my new admin bar search’s submit button. It goes away when hovered over, if that explains anything. I’m kind of at a loss.

    Here’s my site. The search bar in question is at the far right of my admin bar, and the submit button says “find it!”

    TIA!

    ETA: I guess a link would help, lol

    http://www.riotcart.com

    Avatar of justbishop
    justbishop
    Member

    @justbishop

    Nevermind, figured it out!

    had to add `style=”background:none;”` to the list item the search bar is in.

    I followed nick’s instructions above to remove the visit link from the admin bar. I must have done something wrong because it is still there. Any ideas?

    http://isportsweb.com

    Avatar of boldmedia
    BoldMedia
    Member

    @boldmedia

    Hi all, so I added BP profile search to my adminbar using the instructions here.

    Initially all was well, but since the plugin was updated, the search bar is suddenly using the Blog URL rather than the Site URL. Very strange. I’ve been tearing hair out trying to fix this and can’t find where the problem is occurring anywhere.

    I’d greatly appreciate some help if anyone knows what might be causing this.

    Here’s the site: http://www.unistudybuddy.com/

    You can see most links seem to be fine and the $bp->root_domain is correctly using the Site URL. But if you try searching (top-right), it’ll throw in the “/wordpress/” subdirectory and cause an error.

    Thanks in advance.

    Jack

Viewing 12 replies - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.