[wp-hackers] wordpress auto update

Otto otto at ottodestruct.com
Fri Jul 1 20:23:30 UTC 2011


On Fri, Jul 1, 2011 at 2:54 PM, Christopher Ross <cross at thisismyurl.com> wrote:
> Nacin, I think does the trick but would need to be cleaned up before it was released live. I run it on my own sites to check for updates every 12 hours and email me once a week if there is an update pending.
>
> function thisismyurl_check_update() {
>        if (!get_transient('_site_transient_update_core_timer')) {
>                wp_version_check();
>                set_transient( '_site_transient_update_core_timer', true, (60*60*12));
>                $update_core = get_option('_site_transient_update_core');
>                if ($update_core) {
>                        if($update_core->updates[0]->response == 'upgrade' && !get_transient('_site_transient_update_core_message'))  {
>                                wp_mail( get_bloginfo('admin_email'), get_bloginfo('name').__(' core upgrade available.'), __('There is a core upgrade availale for ').get_bloginfo('name').__(' at ').get_bloginfo('url').'/wp-admin/update-core.php').'.';
>                                set_transient( '_site_transient_update_core_message', true, (60*60*24*7));
>                        }
>                }
>        }
> }
> add_action('wp_head','thisismyurl_check_update');

Kind of a long way around to do it, really. Better to use the
get/set_site_transient functions instead of using the _site_transient_
prefix yourself.

Also, you can just hook to the set_site_transient_update_core and take
your action then. That way, your code only runs when the core update
check actually occurs. Something like this:

add_action('set_site_transient_update_core', 'demo');

function demo() {
  $update_core = get_site_transient('update_core');
  if (... stuff here to check $update_core->updates array ...) {
     wp_mail(...);
  }
}


-Otto


More information about the wp-hackers mailing list