* This file is part of the ManageWP Worker plugin.
* (c) ManageWP LLC <contact@managewp.com>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
class MWP_Updater_UpdateManager
public function __construct(MWP_WordPress_Context $context)
$this->context = $context;
* @return int|null UNIX timestamp of last update check.
public function getLastChecked()
if (empty($this->pluginInfo->last_checked)) {
return $this->pluginInfo->last_checked;
* @param string $pluginBasename Ie. 'worker/init.php'
* @return MWP_Updater_PluginUpdate|null
public function getPluginUpdate($pluginBasename)
if (empty($this->pluginInfo->response[$pluginBasename])) {
$info = $this->pluginInfo->response[$pluginBasename];
$update = new MWP_Updater_PluginUpdate();
$update->version = $info->new_version;
$update->basename = $pluginBasename;
$update->url = $info->url;
$update->package = $info->package;
$update->slug = $info->plugin;
* @param string $themeSlug Ie. 'twentyeleven'.
* @return MWP_Updater_ThemeUpdate|null
public function getThemeUpdate($themeSlug)
if (empty($this->themeInfo->response[$themeSlug])) {
$info = $this->themeInfo->response[$themeSlug];
$update = new MWP_Updater_ThemeUpdate();
$update->slug = $info['theme']; // === $themeSlug
$update->version = $info['new_version'];
$update->url = $info['url'];
$update->package = $info['package'];
* @return MWP_Updater_PluginUpdate[]
public function getPluginUpdates()
if (empty($this->pluginInfo->response)) {
foreach (array_keys($this->pluginInfo->response) as $basename) {
$updates[] = $this->getPluginUpdate($basename);
* @return MWP_Updater_ThemeUpdate[]
public function getThemeUpdates()
if (empty($this->themeInfo->response)) {
foreach (array_keys($this->themeInfo->response) as $slug) {
$updates[] = $this->getThemeUpdate($slug);
* @return MWP_Updater_CoreUpdate[]
* @see core_upgrade_preamble
public function getCoreUpdates()
if (empty($this->coreInfo->updates)) {
$firstUpdate = $this->coreInfo->updates[0];
if (!isset($firstUpdate->response) || 'latest' === $firstUpdate->response) {
$locale = $this->context->getLocale();
foreach ($this->coreInfo->updates as $update) {
if ($update->response === 'upgrade' && $update->locale === $locale) {
if ($latestUpdate !== null) {
$showUpdate = new MWP_Updater_CoreUpdate();
$showUpdate->locale = $latestUpdate->locale;
$showUpdate->type = $latestUpdate->response;
$showUpdate->version = $latestUpdate->version;
$showUpdate->phpVersion = $latestUpdate->php_version;
$showUpdate->mysqlVersion = $latestUpdate->mysql_version;
$updates[] = $showUpdate;
private function reload()
$this->coreInfo = $this->context->transientGet('update_core');
$this->pluginInfo = $this->context->transientGet('update_plugins');
$this->themeInfo = $this->context->transientGet('update_themes');