-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.php
executable file
·138 lines (106 loc) · 3.56 KB
/
update.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
if (!class_exists('WP_Memory_Login_Auto_Update'))
{
class WP_Memory_Login_Auto_Update
{
public $respository_url = "https://githubversions.optimizaclick.com/repositories/view/66937235";
public $temp_name = "temp-wp-memory-login.zip";
public $main_file = "memory-login.php";
public $url_main_file = "no-more-passwords-wp-master/memory-login.php";
public $url_update = "wpmemorylogin-update";
public $url_version = "wpmemorylogin-version";
function __construct()
{
if ( ! function_exists( 'register_activation_hook' ) )
require_once ABSPATH . 'wp-admin/includes/plugin.php';
//ACTION TO DO WHEN USER LOGIN
add_action( 'wp_login', array( $this, 'auto_update_plugin' ));
//ACTIONS TO CHECK THE URL
add_action( 'init', array( $this, 'force_update' ));
add_action( 'init', array( $this, 'show_version' ));
//ACTION TO DO WHEN PLUGINS ACTIVATE
register_activation_hook(__DIR__ ."/".$this->main_file, array( $this,'activate_cron_accions_wp_memory_login'));
//ACTION TO DO WHEN PLUGINS DEACTIVATE
register_deactivation_hook(__DIR__ ."/".$this->main_file, array( $this,'desactivate_cron_accions_wp_memory_login'));
}
//CHECK URL TO FORCE THE UPDATE
public function force_update()
{
if( basename($_SERVER['REQUEST_URI']) == $this->url_update)
{
$this->auto_update_plugin();
wp_redirect(get_home_url()."/".$this->url_version);
exit();
}
}
//CHECK URL TO SHOW THE VERSION PLUGIN
public function show_version()
{
if( basename($_SERVER['REQUEST_URI']) == $this->url_version)
{
echo $this->get_version_plugin();
exit();
}
}
//FUNCTION TO DO WHEN PLUGINS ACTIVATE
public function activate_cron_accions_wp_memory_login()
{
//DEFINE ACTION TO DAILY CRON ACTION
if (! wp_next_scheduled ( 'auto_update_wp_memory_login' ))
wp_schedule_event(time(), 'daily', 'auto_update_wp_memory_login');
//ADD ACTION FOR UPDATE CRON ACTION
add_action('auto_update_wp_memory_login', array( $this,'auto_update_plugin'));
}
//ACTION TO DO ON DEACTIVE PLUGIN
public function desactivate_cron_accions_wp_memory_login()
{
wp_clear_scheduled_hook('auto_update_wp_memory_login');
}
//UPDATE PLUGIN FUNCTION
public function auto_update_plugin()
{
//CHECK ACTUAL VERSION OF PLUGIN AND REPOSITORY VERSION
if($this->get_version_plugin() < $this->get_repository_values("version"))
{
$link = $this->get_repository_values("url");
if(strpos($_SERVER['REQUEST_URI'], "/wp-admin/") === false)
{
$file = "./wp-content/plugins/".$this->temp_name;
$dir = "./wp-content/plugins/";
}
else
{
$file = "../wp-content/plugins/".$this->temp_name;
$dir = "../wp-content/plugins/";
}
file_put_contents($file, fopen($link, 'r'));
$zip = new ZipArchive;
if ($zip->open($file) === TRUE)
{
$zip->extractTo($dir);
$zip->close();
}
unlink($file);
}
}
//RETURNS THE CURRENT VERSION OF PLUGIN
public function get_version_plugin()
{
if ( ! function_exists( 'get_plugins' ) )
require_once ABSPATH . 'wp-admin/includes/plugin.php';
$plugins = get_plugins();
return $plugins[$this->url_main_file]["Version"];
}
//RETURNS THE REPOSITORY VERSION PLUGIN OR THE .ZIP URL TO DOWNLOAD
public function get_repository_values($data)
{
$content = file_get_contents($this->respository_url);
$values = explode("|", $content);
if($data == "version")
return $values[0];
else
return $values[1];
}
}
}
?>