WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] some wp admin bar related snippets (16 posts)

  1. Ovidiu
    Member
    Posted 2 years ago #

    first of all, here is the site I will be talking about: http://zice.ro

    I am using a php file from inside mu-plugins to modify the wp admin bar to my likings and need some help.

    a) the part on the far left of the bar where it says: zice.ro is generated by this snippet:

    function addLinkHome( $wp_admin_bar) {
                            $wp_admin_bar->add_menu( array( 'title' => __( 'zice.ro' ), 'href' => 'http://zice.ro/' ) );
                                    ?>
                    <style type="text/css">
                    #wp-admin-bar-zice-ro { background: #FA0502 url('http://zice.ro/favicon.ico') no-repeat left top;}
                    </style>
                    <?php
                                                                                                            }
    
                    add_action( 'admin_bar_menu', 'addLinkHome', 0 ); //try add_action( 'admin_bar_menu', 'addLinkMenu', 999 );

    I was trying to put the favicon of the site in front of it just like the avatar that appears when you are logged in, check this screen shot: http://screencast.com/t/HoIX3RYzvbK

    a) The second part from the left, where it says "Blog aleator" should actually be on the far right hand side but I can't position it there. Here is the code that generates it:

    function addLinkRandom( $wp_admin_bar) {
                                    $wp_admin_bar->add_menu( array( 'title' => __( 'Blog aleator' ), 'href' => 'http://zice.ro/next.php' ) );}
    
                    add_action( 'admin_bar_menu', 'addLinkRandom', 0 ); //try add_action( 'admin_bar_menu', 'addLinkMenu', 999 );

    Unfortunately this code generates the menu into the .quicklinks part. How to get it to show on the far right hand side?

    c) what is the difference between these two snippets as c1) works and c2) doesn't

    c1)

    function addNetworkComments() {
                                    global $wp_admin_bar;
    
                                   if ( is_user_logged_in() ){
                                    $wp_admin_bar->add_menu( array( 'parent' => 'comments', 'title' => __( 'Discutiile mele'),
                                    'href' => admin_url( 'index.php?page=my_network_comments' )
                                                                                                            ) );
                                                                                                    }}
                                    add_action('wp_before_admin_bar_render', 'addNetworkComments', 0);

    c2)

    function addNetworkComments( $wp_admin_bar) {
                                    if ( is_user_logged_in() ){
                                    $wp_admin_bar->add_menu( array( 'parent' => 'comments', 'title' => __( 'Discutiile mele'),
                                    'href' => admin_url( 'index.php?page=my_network_comments' )
                                                                                                            ) );
                                                                                                    }}
                                    add_action('admin_bar_menu', 'addNetworkComments', 0);
  2. Ovidiu
    Member
    Posted 2 years ago #

    anyone?

  3. I was just experimenting with this.

    These are what I came up with:

    function add_menu_left( ) {
                    global $wp_admin_bar;
                    <CODE FOR LEFTHAND MENU>                              }
    add_action('admin_bar_menu', 'add_menu_left', 10);
    
    function add_menu_right( ) {
                    global $wp_admin_bar;
                    <CODE FOR RIGHTHAND MENU>                                                                                                }
    add_action('wp_before_admin_bar_render', 'add_menu_right', 0);
  4. Ovidiu
    Member
    Posted 2 years ago #

    thx Ipstenu. that is halfway there: have a look: http://zice.ro its on the right but not where the search box used to be in the original unmodified admin bar. I am looking to get this to the far right and replace the search box with it...

    it looks like I can't do this with CSS as its inside a complex structure...

    there msut be a way to get this to replace the search box....

    any idea on c) ?

  5. Looking at http://core.trac.wordpress.org/browser/tags/3.1.2/wp-includes/class-wp-admin-bar.php

    The search is wrapped in

    <div id="adminbarsearch-wrap">
    	                                <form action="<?php echo home_url(); ?>" method="get" id="adminbarsearch">
    	                                        <input class="adminbar-input" name="s" id="adminbar-search" type="text" value="" maxlength="150" />
    	                                        <input type="submit" class="adminbar-button" value="<?php _e('Search'); ?>"/>
    	                                </form>
    </div>

    Unlike the quicklinks part of the site, which is a foreach on the array. There is no way to remove it using PHP - it's baked directly in the render() method for the admin bar class. BUT.

    To hide it, just toss this in your CSS #wpadminbar #adminbarsearch {display: none;}

    (Per http://wordpress.org/extend/plugins/hide-admin-bar-search/ - Helen says you can't remove it apparently, and I believe her. She haz the smart)

  6. Ovidiu
    Member
    Posted 2 years ago #

    I did hide it already. please see live: http://zice.ro

    as stated I would like to get this code to show on the top right hand side and replace the search code, I mean appear in the same place.

    see a more detailed description in this screen shot please: http://screencast.com/t/q2ASl1os24

    I hope that explains it better than I could with words :-)

  7. What I'm getting at is that you'd probably have to wrap it in a div, like <div id="adminbarsearch-wrap"> to make it show on the far far far right.

  8. Ovidiu
    Member
    Posted 2 years ago #

    ok, but from the admin bar code you posted above from trac it looks like this:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    and I can only inject it into the <div class="quicklinks"> part via $wp_admin_bar->add_menu( array( 'title' => __( 'Blog aleator' ), 'href' => 'http://zice.ro/next.php' ) );}

    I understand now what you are hinting at but I do not know how to get it over there... since the search is inside <div id="adminbarsearch-wrap"> I can't create a new one since IDs must be unique.

    am I missing the obvious here? sorry if I do

    and how would I wrap this: $wp_admin_bar->add_menu( array( 'title' => __( 'Blog aleator' ), 'href' => 'http://zice.ro/next.php' ) );} into a div?

  9. Yeah, I don't know either which is why I didn't just post the code ;)

    In THEORY if you could echo a </div><div class="quicklinks"> in between the left and righthand stuff, it might work.

  10. Ovidiu
    Member
    Posted 2 years ago #

    @the anonymous moderator who felt the need to moderate my post, I take it you are referring to this rule: http://codex.wordpress.org/Forum_Welcome#Posting_Code

    according to that, I can post up to ten lines of code, so I insist in doing so:

    <div class="quicklinks">
    	<ul><?php foreach ( (array) $this->menu as $id => $menu_item ) : ?>
    		<?php $this->recursive_render( $id, $menu_item ) ?>
    		<?php endforeach; ?></ul>
    </div>
    <div id="adminbarsearch-wrap">
    	<form action="<?php echo home_url(); ?>" method="get" id="adminbarsearch">
    		<input class="adminbar-input" name="s" id="adminbar-search" type="text" value="" maxlength="150" />
    		<input type="submit" class="adminbar-button" value="<?php _e('Search'); ?>"/></form></div>
    </div>

    @Ipstenu:

    back to the issue at hand, I understand now. thanks for the hints though. you are right but I need to figure out a way to insert that piece of html in there.
    have to read up on this: $wp_admin_bar->add_menu( array( 'title' => __( 'Blog aleator' ), 'href' => 'http://zice.ro/next.php' ) );} and see if one can pass some code or formatting along with the link, but since it injects it exactly into the ul menu as a li tag there won't be a chance of that I guess :-(

    will leave this issue as open maybe someone will add some more ideas to it.

  11. The only reason we (yes we, I are a mod) moderate short code bits is when they trip the spam filter. Don't take it personally, and don't bite the hands that mod you ;)

    Have you looked at http://wordpress.org/extend/plugins/wp-custom-admin-bar/ ? The code in tehre may have clues!

  12. Ovidiu
    Member
    Posted 2 years ago #

    @Ipstenu: I know you're a mod, that's why I am nice to you (just kidding ;-)

    will have a look at that one - maybe the author can help or has an idea

  13. eugenie33
    Member
    Posted 2 years ago #

    Hi,
    Like you I'm trying to have some text or picture at the far right of the admin bar.
    I just saw that somehow you managed to do it but I can't find anything helping me to reach the same result as you.
    Could you tell me how you did it please ?
    Thank you very much in advance

  14. Ovidiu
    Member
    Posted 2 years ago #

    hehe, sure thing!

    //add the random link to the admin bar
        function addLinkRandom( $wp_admin_bar) {
            global $wp_admin_bar;
            $wp_admin_bar->add_menu( array( 'title' => __( 'Blog aleator' ), 'href' => 'http://zice.ro/next.php' ) );
            ?>
            <style type="text/css">
            #wpadminbar .quicklinks ul #wp-admin-bar-blog-aleator { float: right !important;
    text-indent:-10000px;
    background: transparent url('http://zice.ro/package_games_board.png') no-repeat left top!important;
    display:inline;
    height:25px;
    width:25px;
    vertical-align:middle;
    margin:1px 4px 0!important;
    }
    #wpadminbar .quicklinks ul #wp-admin-bar-blog-aleator a {
    border:none !important;
    }
            </style>
            <?php }
    
        add_action( 'wp_before_admin_bar_render', 'addLinkRandom', 0 ); //try add_action( 'admin_bar_menu', 'addLinkMenu', 999 );

    and here is the link to where I got that solution from: http://premium.wpmudev.org/forums/topic/need-some-help-customizing-the-admin-bar

  15. eugenie33
    Member
    Posted 2 years ago #

    Hello again thank you so much for your quick answer. It's working perfectly well. ^^
    Have a nice day and thank you again

  16. Ovidiu
    Member
    Posted 2 years ago #

    you're welcome.
    I totally forgot to close and update this thread :-)

Topic Closed

This topic has been closed to new replies.

About this Topic