added time cache (1 day)
This commit is contained in:
parent
d1275eb680
commit
e880f1e937
1 changed files with 23 additions and 3 deletions
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue