-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.Plugino.php
110 lines (81 loc) · 2.72 KB
/
class.Plugino.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
<?php
require_once(dirname(__FILE__) . '/class.i8Core.php');
class Plugino extends i8Core {
var $url;
var $path;
var $__FILE__;
function __construct($__FILE__ = false)
{
parent::__construct();
if ($__FILE__) {
$this->__FILE__ = $__FILE__;
} else {
# probably it would be cleaner to pass a filename as an argument, but by now this is easier for developer
$trace = debug_backtrace(false);
$this->__FILE__ = $trace[0]['file'];
}
# plugin urls and paths
$plugin_dir = plugin_basename(dirname($this->__FILE__));
$this->url = WP_PLUGIN_URL . '/' . $plugin_dir;
$this->path = WP_PLUGIN_DIR . '/' . $plugin_dir;
# check if uninstall has called this, logic will break here, if it has
if ($this->_uninstalling())
{
add_action('uninstall_' . plugin_basename($this->__FILE__), array($this, '_uninstall'), 0);
return;
}
# update from private repository
if (isset($this->repo))
add_filter('transient_update_plugins', array($this, '_check_4_updates'));
register_activation_hook( $this->__FILE__, array($this, '_activation_operations') );
register_deactivation_hook( $this->__FILE__, array($this, '_deactivation_operations') );
do_action("i8_{$this->namespace}initialized");
}
function _activation_operations()
{
$this->i8_data = get_plugin_data($this->__FILE__, false, false);
parent::_activation_operations();
register_uninstall_hook($this->__FILE__, '_uninstall');
if (method_exists($this, 'on_activate'))
$this->on_activate($this->i8_data);
}
function _deactivate()
{
unset($_GET['activate']);
deactivate_plugins(plugin_basename($this->__FILE__));
}
// Uninstall logic
function _uninstalling()
{
/* we could use WP_UNINSTALL_PLUGIN, but it's not being defined for uninstall triggered by
register_uninstall_hook, hence this workaround */
return $_POST['action'] == 'delete-selected' &&
$_POST['verify-delete'] == 1 &&
in_array(plugin_basename($this->__FILE__), $_POST['checked']);
}
function _uninstall()
{
// remove dummy callback
remove_action('uninstall_' . plugin_basename($this->__FILE__), '_uninstall');
if (!current_user_can('delete_plugins'))
return;
# delete tables
if (!empty($this->tables))
{
global $wpdb;
foreach ($this->tables as $table => $sql)
{
$table_name = strtolower($wpdb->prefix . $this->prefix . $table);
$wpdb->query("DROP TABLE `{$table_name}`");
}
}
# delete options
delete_option("{$this->namespace}options");
delete_option("{$this->namespace}version");
delete_option("{$this->namespace}info");
delete_option("{$this->namespace}cache");
if (method_exists($this, 'on_uninstall')) {
$this->on_uninstall($this->i8_data);
}
}
}