/**
  * Update the transient value of available theme updates right after
  * WordPress read it from the database.
  * We add the WPMUDEV theme-updates to the default list of theme updates.
  *
  * @since  1.0.0
  * @internal Action hook
  * @param  object $value The transient value that will be saved.
  * @return object Modified transient value.
  */
 public function filter_theme_update_count($value)
 {
     global $wp_version;
     $cur_wp_version = preg_replace('/-.*$/', '', $wp_version);
     if (!is_object($value)) {
         return $value;
     }
     if (!self::$_cache_themeupdates) {
         // First remove all installed WPMUDEV themes from the WP update data.
         $local_projects = WPMUDEV_Dashboard::$site->get_cached_projects();
         foreach ($local_projects as $id => $update) {
             if ('theme' != $update['type']) {
                 continue;
             }
             if (isset($value->response[$update['filename']])) {
                 unset($value->response[$update['filename']]);
             }
             if (isset($value->no_update[$update['filename']])) {
                 unset($value->no_update[$update['filename']]);
             }
         }
         // Value of 'updates_available' is set by API `calculate_upgrades()`.
         $updates = WPMUDEV_Dashboard::$site->get_option('updates_available');
         if (false === $updates) {
             $updates = WPMUDEV_Dashboard::$api->calculate_upgrades($local_projects);
         }
         if (is_array($updates) && count($updates)) {
             // Loop all available WPMUDEV updates and merge them into WP updates.
             foreach ($updates as $id => $theme) {
                 if ('theme' != $theme['type']) {
                     continue;
                 }
                 if ('1' != $theme['autoupdate']) {
                     continue;
                 }
                 $theme_slug = dirname($theme['filename']);
                 // Build theme listing.
                 $object = array();
                 $object['url'] = add_query_arg(array('action' => 'wdp-changelog', 'pid' => $id, 'hash' => wp_create_nonce('changelog')), admin_url('admin-ajax.php'));
                 $object['new_version'] = $theme['new_version'];
                 $object['package'] = WPMUDEV_Dashboard::$api->rest_url_auth('download/' . $id);
                 $object['theme'] = $theme_slug;
                 $object['tested'] = $cur_wp_version;
                 // Add changes back into response.
                 $value->response[$theme_slug] = $object;
             }
         }
         // Filter 133 theme pack themes from the list unless update is available.
         $themepack = WPMUDEV_Dashboard::$site->get_farm133_themepack();
         if (is_array($themepack) && count($themepack)) {
             foreach ($themepack as $slug => $theme) {
                 if (!isset($theme['filename'])) {
                     continue;
                 }
                 $local_version = $theme['version'];
                 $latest_version = $local_version;
                 $theme_slug = dirname($theme['filename']);
                 $theme_id = $theme['pid'];
                 // Remove the 133theme from WP update list.
                 if (!isset($value->response[$theme_slug])) {
                     $value->response[$theme_slug] = array();
                 }
                 // Add to count only if new version exists, otherwise remove.
                 if (isset($updates[$theme_id]) && isset($updates[$theme_id]['new_version'])) {
                     $latest_version = $updates[$theme_id]['new_version'];
                 }
                 if (version_compare($local_version, $latest_version, '<')) {
                     $value->response[$theme_slug]['new_version'] = $latest_version;
                     $value->response[$theme_slug]['package'] = '';
                 } else {
                     unset($value->response[$theme_slug]);
                 }
             }
         }
         self::$_cache_themeupdates = $value;
     }
     return self::$_cache_themeupdates;
 }