The MU forums have moved to WordPress.org

AdminBar: How would a plugin insert itself into every theme? (25 posts)

  1. mrjcleaver
    Member
    Posted 16 years ago #

    In http://wpmudevorg.wordpress.com/project/MU-Admin-Bar I wrote: 2006-07-30 14:56:00

    I note that to use this I need to modify the theme in use. But as I have many themes installed, to use it must all themes be modified?

    kahless replied 2006-08-08 01:20:19:

    If someone can tell me a way to get the plugin to insert the code into the appropriate place in each theme

    As it is fairly insane for us all to make the same modifications over and over, where can we go for help so we can solve this problem just once and use the same code base going forward?

  2. drmike
    Member
    Posted 16 years ago #

    Since it goes into the output in a specific place, I think you're stuck with editing each theme's header.php.

    This is one of the reasons why I state that when you add in a theme, you need to have a plan of what you need to do each time. A simple checklist makes life a lot easier.

    And I really wish you would stop telling us what we need to do. It's really get on my nerves and I believe the nerves of others from the emails I've received from others around here.

  3. andrea_r
    Moderator
    Posted 16 years ago #

    "As it is fairly insane for us all to make the same modifications over and over, where can we go for help so we can solve this problem just once and use the same code base going forward?"

    Not all of us want to use the same code base, even for themes. If we added everything each of us wants, then we have code bloat. Which is anithesis to the core of WP - and WPMU - which you'd know if you read up more (in the codex, in the forums, lurking on lists, reading developer's blogs etc.. etc. ad nauseum...) and familiarized yourself more with *before* jumping in.

  4. drmike
    Member
    Posted 16 years ago #

    There's not code bloat but there's a lot of nested functions. One which calls another which calls another which calls another which...

  5. mrjcleaver
    Member
    Posted 16 years ago #

    I apologise if I am getting on your nerves.

    I welcome direct feedback - but if I am not told otherwise, I can only do what seems right to my mind relative to the projects I have been involved with in the past.

    I ask that all please do feel free to email me: my surname is Cleaver, and my email - Martin @mysurname.org

    Thanks,
    Martin.

  6. dsader
    Member
    Posted 16 years ago #

    Mrjcleaver:
    Will this help? I use a mu-plugin to insert a common footer into every theme. When I add a new theme, my footer appears automatically. Note the add action line at the end. Does your mu-admin plugin have an add action at the end? Do your themes have the corresponding functions where you want.


    <?php
    /*
    Plugin Name: WPMU Footer
    Plugin URI: http://www.domain.org
    Description: Adds a domain.org footer to every theme, site-wide.
    Author: D. Sader
    Version: 1.1
    Author URI: http://blog.domain.org
    */

    function wpmu_footer($blah)
    {

    echo '
    © '; echo(date('Y')); echo ' '; the_author('nickname'); echo '


    Terms of Service
    | Privacy Policy
    | Safety Tips
    | Contact
    | '; _e('RSS'); echo '
    | '; wp_loginout(); echo '

    '; echo get_num_queries(); echo ' students of Soren Kierkegaard created this page
    in '; timer_stop(1); echo ' seconds while awaiting the end of winter\'s frigid cycle.

    ';

    return $blah;

    }

    add_action('wp_footer', 'wpmu_footer');

    ?>

    Very few themes are missing the wp_footer function. Some hide it's output, but it's easy enough to uncover or add in the rare circumstance.

    Now, when I want a new link in a footer, ad, image, whatever, I edit my wpmu_footer.php and wham, all footers change to my footer.

  7. kahless
    Member
    Posted 16 years ago #

    Here's the problem. The code for the admin bar needs to go directly after the <body> tag in the header. in most themes the hook for the header action is appropriately at the end of the header.php file. So I don't see any way to resolve this. Obviously if the admin bar didn't have to go after <body> then this would work and it would have been done with the original plugin for WP.

  8. dsader
    Member
    Posted 16 years ago #

    I use the admin bar plugin but never had to do what you are doing. It sits at the top of the browser in a "fixed" position, works with every theme(130+). The only trouble is the occaisional theme with a "fixed" header, too. Very rare. Sorry, I'm no help.

  9. kahless
    Member
    Posted 16 years ago #

    Are you saying you paste the call for the admin bar at the top of your header.php or are you saying you alter the CSS for the admin bar to fix it to the top left corner and then having it called at the end of header.php doesn't matter because it will go to the top let anyhow?

  10. kahless
    Member
    Posted 16 years ago #

    Here is what is at the end of the mu-admin-bar plugin

    add_action('theme_header', 'wp_admin_bar');
    add_action('wp_head','wp_admin_bar_style');

    By looking at the source of a page you can see that the last one is working as the CSS shows in the <head> tag on the page. It seems like the first action should be the one to put the call to wp_admin_bar into the file but there is no theme_header hook. What we would need is a wp_body hook that would execute right after <body> but this would be a change to the core of WP, I think. You could also try altering the first line above to

    add_action('wp_footer', 'wp_admin_bar');

    This will call the function within the body and you'd have to hope that the fixed position would place it correctly. Someone please correct my thinking if I am wrong.

  11. kahless
    Member
    Posted 16 years ago #

    OK, here is a dirty hack to make this work without having to add any code to a theme. In mu-admin-bar.php uncomment the following

    /* -- for a fixed position --
    #wp-admin-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    } */

    which is near the bottom of the file. Change the fifth line from the bottom from

    add_action('theme_header', 'wp_admin_bar');
    to
    add_action('wp_footer', 'wp_admin_bar');

    This hack will work as long as the theme doesn't have a fixed header or some fixed element at the top of the page. This is actually better as the bar is still visible as you scroll down the page. It is not elegant as the bar is loaded in the footer and it really should be loaded right after body is called. Maybe donncha can get someone to add a wp_body hook to WP and then this plugin could work as we would like.

    I am reluctant to change the file I have up on WPMUDEV.org with this hack but all are welcome to edit their installs.

  12. mrjcleaver
    Member
    Posted 16 years ago #

    Great: thanks so much for these creative suggestions - I will certainly try them tomorrow.

    I really want to contain changes to my codebase - every deviation from stock files means more checking on upgrades and constrains the speed that we can go at.

  13. vincenzo
    Member
    Posted 16 years ago #

    What do I add to the actual code to make this appear on all the other blogs after I make the changes noted above by kathless??

  14. kahless
    Member
    Posted 16 years ago #

    Nothing. That was the whole point. You just alter the mu-admin-bar.php code as described above and drop it into mu-plugins. Login to a blog and then view it to see the admin bar at the top.

  15. shirou
    Member
    Posted 16 years ago #

    Hello there is an error on line 127:
    "Unexpected } on line 127"

    I put In comment:
    if ( call_user_func_array('current_user_can', $user_caps) )

    and the error dissapears but I think there must be some few codes add after =)

  16. shirou
    Member
    Posted 16 years ago #

    It's fun because the admin bar works with Firefox but not with IE 6.0. I Think lot of users have a old computer like me with Windows XP SP1 or older, it's not very pleasant to them to have to refresh their browser in order to have the TinyMCE editor and to have the admin bar in bottom! Snif, I think I must improve my php skills for my "future" users olalaa é_è

  17. kahless
    Member
    Posted 16 years ago #

    What version do you have? Version 1.2 works on all the sites I maintain. I don't have access to IE. I run Macs and crippled it on the PC in my office at school and run Firefox. I don't really have time to try and work around IE's lack of standards support. If someone figures out what CSS work arounds need to be implemented for IE, I'll gladly incorporate them.

  18. suleiman
    Member
    Posted 16 years ago #

    I am so fed up of IE's lack of support for standard CSS. I've designed multiple websites, worked with multiple Content Management Systems, and throughout it all the one consitent pain in the butt is IE.

    I hate you, Microsoft.

  19. drmike
    Member
    Posted 16 years ago #

    Trying to get their attorneys over here? ;)

  20. suleiman
    Member
    Posted 16 years ago #

    always dr.mike, always ;)

  21. Ovidiu
    Member
    Posted 15 years ago #

    any advice on how to get the admin bar working with all themes?

    somewhere I read to check for the eistence of a call to wp head inside header.php if I remember right, but I can't find that advice again.

    so if a theme correctly calls wp head and still does not display the admin bar, what else could I do?

  22. kahless
    Member
    Posted 15 years ago #

    With the latest version you shouldn't need to do anything. The bar inserts itself into the wp_footer call (which every theme I have looked at has) and then uses absolute or fixed positioning to place itself at the top of the page. Some themes may need to have padding added to move them down by 28 px (the width of the adminbar).

  23. billnoyes
    Member
    Posted 15 years ago #

    Hey. I have what I hope is a quick question. I am using the code posted from dsader and it is working great at adding a little something to all theme footers. How can I add some javascript to this code and get it to work? I am trying to learn php and have played around with adding the script but am getting various parse errors. Any help would be appreciated. Thanks.

  24. dsader
    Member
    Posted 15 years ago #

    A common screw-up for me when is not changing double-quotes to single-quotes or vice-versa.

  25. billnoyes
    Member
    Posted 15 years ago #

    Thanks dsader. I will play with the quotes and see if I can get it.

About this Topic

  • Started 16 years ago by mrjcleaver
  • Latest reply from billnoyes