1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Copyright (c) 2017 Salah Alkhwlani <[email protected]> |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view |
7
|
|
|
* the LICENSE file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Yemenifree\WpSecurity\Modules; |
11
|
|
|
|
12
|
|
|
use Yemenifree\WpSecurity\Interfaces\Activable; |
13
|
|
|
use Yemenifree\WpSecurity\Interfaces\Loadable; |
14
|
|
|
|
15
|
|
|
class PluginSecurity implements Loadable, Activable |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Basename of plugin. |
19
|
|
|
* |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
private $basename; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* lock filename. |
26
|
|
|
* |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
private $lock_filename = '.wp-security-lock'; |
30
|
|
|
|
31
|
|
|
public function __construct($basename) |
32
|
|
|
{ |
33
|
|
|
$this->basename = $basename; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Load module (perform any tasks that should be done immediately on plugin load). |
38
|
|
|
*/ |
39
|
|
|
public function load() |
40
|
|
|
{ |
41
|
|
|
add_action('deactivate_plugin', [$this, 'disable_deactivate_plugin'], 99, 2); |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Disabled upload zip files ( plugins & themes ) via admin account. |
46
|
|
|
* |
47
|
|
|
* @param $plugin |
48
|
|
|
* @param $network_deactivating |
49
|
|
|
*/ |
50
|
|
|
public function disable_deactivate_plugin($plugin, $network_deactivating) |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
if ($this->basename !== $plugin) { |
53
|
|
|
return; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
// if deactivate is lock. |
57
|
|
|
if (\file_exists($this->getLockFilename())) { |
58
|
|
|
wp_die(__('Sorry, you should remove file ' . $this->getLockFilename() . ' to allow to deactivate this plugin.')); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* get full path of lock file. |
64
|
|
|
* |
65
|
|
|
* @return string |
66
|
|
|
*/ |
67
|
|
|
public function getLockFilename() |
68
|
|
|
{ |
69
|
|
|
return \rtrim(WC_SECURITY_PATH, '/') . '/' . $this->lock_filename; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* {@inheritdoc} |
74
|
|
|
*/ |
75
|
|
|
public function activate() |
76
|
|
|
{ |
77
|
|
|
\touch($this->getLockFilename()); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* {@inheritdoc} |
82
|
|
|
*/ |
83
|
|
|
public function deactivate() |
84
|
|
|
{ |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|