added time cache (1 day)

This commit is contained in:
Pau Capó 2018-03-03 23:36:28 +01:00
parent d1275eb680
commit e880f1e937

View file

@ -3,7 +3,7 @@
* Plugin Name: Gitea Updater
* Plugin URI: http://www.paucapo.com
* Description: Plugins updater
* Version: 0.3
* Version: 0.3.1
* Author: Pau Capó
* Author URI: http://www.paucapo.com
* Text Domain: gitea
@ -35,6 +35,8 @@ class Gitea_Updater
return self::$_instance;
}
private $cache = 86400; // 1 day in seconds
public $plugins = array();
public $themes = array();
@ -62,8 +64,7 @@ class Gitea_Updater
function admin_init()
{
if (get_option('gitea_plugins_updated') === false || get_option('gitea_themes_updated') === false)
{
if (get_option('gitea_plugins_updated') === false || get_option('gitea_themes_updated') === false) {
$this->get_all();
}
}
@ -79,8 +80,22 @@ class Gitea_Updater
$this->get_themes();
}
function update($type)
{
if (isset($_GET['force-check'])) {
return true;
}
$last_update = get_option('gitea_' . $type . '_updated');
return ($last_update + $this->cache) > time();
}
function get_plugins()
{
if (!$this->update('plugins')) {
return;
}
$this->plugins = array();
$plugins = get_plugins();
@ -131,6 +146,11 @@ class Gitea_Updater
function get_themes()
{
if (!$this->update('themes')) {
return;
}
$this->themes = array();
$themes = wp_get_themes();