Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Here is my challenge:

I have included an electronic wallet in the admin bar of my wordpress site and what I need to do is to refresh ONLY the admin bar so that, upon a purchase, the electronic wallet is updated and reflects the new total from the database with the purchase amount subtracted from it without having to refresh the whole page.

I mainly do this to avoid excessive bandwidth usage and the reinitializing of certain plugins I have on the site such as an mp3 player.

Does anyone have any ideas? Been trying to write a function for it and call that function when the database is being updated but I haven't been able to figure it out, (pretty new at this).

Any suggestions will be greatly appreciated. Thanks in advance!

share|improve this question
add comment

1 Answer

I would approach that problem slightly differently.

The entire bar does not need to reload. Instead it needs to stay "current".

So to do that you load your initial value...let's say $100.00

Then you use Javascript to see if new values have been added and then you update it client side.

You could even do a cool little fade out and fade in of the old vs new value.

Just have your script check every 60 seconds.

Example: https://www.google.com/search?btnG=1&pws=0&q=google+stock

Just wait like 60 seconds and look at Google's Stock numbers - they just update on their own.

Tutorial: http://www.webdeveloper.com/forum/showthread.php?t=169337

Relevant documentation:

http://codex.wordpress.org/AJAX_in_Plugins

http://www.garyc40.com/2010/03/5-tips-for-using-ajax-in-wordpress/

UPDATE

Ok. This answer was definitely helpful but I need a bit more. I tried to implement the Javascript to refresh every 10 seconds and it works beautifully but the information being refreshed needs the function get_current_user_info(); to be called so the text in the tag can reflect the new data in the database.

You see, on the webpage I have an electronic wallet where people click and buy things. On clicking, the database is updated but the electronic wallet, which I have in the wp_admin_bar needs to be refreshed as well in order to reflect the database changes. As far as I understand, this requires that I re-call the function get_current_user_info(); and have the text in the refresh and show the actual amount in the e-wallet.

I have looked into all the action hooks available but none serve the purpose of refreshing every 30 seconds, let's say, so I haven't been able to make a plugin or hard code the php. Does anyone have any suggestions???

share|improve this answer
    
B-E-A-UTIFUL!!!!!!! Thanks Sterling Hamilton! I have yet to implement and test it but it sounds like exactly what I need. I'll post here if I run into any problems, hopefully I won't. You and Stack Exchange rock! Thanks again. –  Arion Feb 17 '12 at 20:54
    
@arion - please accept answers that solve you problem by clicking the tick next to them. It makes it easier for others to identify what worked for you, and clears your question off the unanswered pile :D. –  Stephen Harris Feb 18 '12 at 0:34
    
Ok. This answer was definitely helpful but I need a bit more. I tried to implement the Javascript to refresh every 10 seconds and it works beautifully but the information being refreshed needs the function get_current_user_info(); to be called so the text in the <div> tag can reflect the new data in the database. –  Arion Feb 29 '12 at 22:29
    
You see, on the webpage I have an electronic wallet where people click and buy things. On clicking, the database is updated but the electronic wallet, which I have in the wp_admin_bar needs to be refreshed as well in order to reflect the database changes. As far as I understand, this requires that I re-call the function get_current_user_info(); and have the text in the <div> refresh and show the actual amount in the e-wallet. –  Arion Feb 29 '12 at 22:37
    
I have looked into all the action hooks available but none serve the purpose of refreshing every 30 seconds, let's say, so I haven't been able to make a plugin or hard code the php. Does anyone have any suggestions??? –  Arion Feb 29 '12 at 22:37
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.