admin管理员组

文章数量:1314514

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).

UPDATE

Ok. Sterling Hamilton 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???

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).

UPDATE

Ok. Sterling Hamilton 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 question edited Nov 24, 2020 at 13:55 brasofilo 22.1k8 gold badges70 silver badges264 bronze badges asked Feb 17, 2012 at 18:06 ArionArion 352 silver badges5 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

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/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/forum/showthread.php?t=169337

Relevant documentation:

http://codex.wordpress/AJAX_in_Plugins

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

本文标签: databaseCan you refresh ONLY the wordpress adminbar and not the whole page