6

Is there any way to disable WP core updates but to have notification email sent that WP update is available to install? I know that notification email about WP update is sent after the fact when WP got updated and how to disable all (core update and notifications).

I'm trying to utilize code below:

function core_update_notification(){
    global $wp_version;

   $core_update = wp_version_check();

   if ($core_update != NULL || $core_update !=FALSE){
      $to = "[email protected]";
      $subject = "WP update is available!";
      $message = "You have WP update ready to install";
      $headers = 'From: My Website <[email protected]>' . "\r\n";

      wp_mail( $to, $subject, $message, $headers );
   }

}

   add_action( 'init', 'core_update_notification' );
   add_filter( 'auto_update_core', '__return_false' );

but somehow that idea is not working the way I have expected.

UPDATE #1 It looks like that wp_version_check() performs the version check, and then sets the update_core transient if there's a new version. It doesn't return anything of value that is why code above is failing. Need to use get_site_transient('update_core') and updated code looks like

function core_update_notification(){
   global $wp_version;

   $installed_version = $wp_version;

   $uc_transient = get_site_transient('update_core');
   if ( empty($uc_transient->updates) ) return;
   $updates = $uc_transient->updates;
   $current_version = $updates[0]->current;

   if (version_compare($installed_version, $current_version, "<")) {
      $to = "[email protected]";
      $subject = "WP update is available!";
      $message = "You have WP update ready to install";
      $headers = 'From: My Website <[email protected]>' . "\r\n";

      wp_mail( $to, $subject, $message, $headers );
   }

}

   add_action( 'init', 'core_update_notification' );
   add_filter( 'auto_update_core', '__return_false' );

but somehow an email is not sent

1 Answer 1

3

It looks like after switching code to check get_site_transient('update_core') I have got what I need just action must be executed in a proper priority or a hook (thoughts/suggestions?). Working code below:

function core_update_notification(){
   global $wp_version;

   $installed_version = $wp_version;

   $uc_transient = get_site_transient('update_core');
   if ( empty($uc_transient->updates) ) return;
   $updates = $uc_transient->updates;
   $current_version = $updates[0]->current;

   if (version_compare($installed_version, $current_version, "<")) {
      $to = "[email protected]";
      $subject = "WP update is available!";
      $message = "You have WP update ready to install";
      $headers = 'From: My Website <[email protected]>' . "\r\n";

      wp_mail( $to, $subject, $message, $headers );
   }

}

   add_action( 'init', 'core_update_notification' );
   add_filter( 'auto_update_core', '__return_false' );

I think the best solution it will be to use daily wp_schedule_event in that case following steps from here: https://codex.wordpress.org/Function_Reference/wp_schedule_event

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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