1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BulkWP\BulkDelete\Core\Addon; |
4
|
|
|
|
5
|
|
|
defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Data about an add-on. |
9
|
|
|
* |
10
|
|
|
* This is a `Record` class that only contains data about a particular add-on. |
11
|
|
|
* `Info` suffix is generally considered bad, but this is an exception since the suffix makes sense here. |
12
|
|
|
* |
13
|
|
|
* @since 6.0.0 |
14
|
|
|
*/ |
15
|
|
|
class AddonInfo { |
16
|
|
|
protected $name; |
17
|
|
|
protected $code; |
18
|
|
|
protected $version; |
19
|
|
|
protected $author = 'Sudar Muthu'; |
20
|
|
|
protected $root_file; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Does this add-on has license? |
24
|
|
|
* |
25
|
|
|
* License handling may be disabled for some custom built one off add-ons. |
26
|
|
|
* |
27
|
|
|
* @since 6.1.0 |
28
|
|
|
* |
29
|
|
|
* @var bool |
30
|
|
|
*/ |
31
|
|
|
protected $has_license = true; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Construct AddonInfo from an array. |
35
|
|
|
* |
36
|
|
|
* @param array $details Details about the add-on. |
37
|
|
|
*/ |
38
|
|
|
public function __construct( $details = array() ) { |
39
|
|
|
if ( ! is_array( $details ) ) { |
|
|
|
|
40
|
|
|
return; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$keys = array( |
44
|
|
|
'name', |
45
|
|
|
'code', |
46
|
|
|
'version', |
47
|
|
|
'author', |
48
|
|
|
'has_license', |
49
|
|
|
'root_file', |
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
foreach ( $keys as $key ) { |
53
|
|
|
if ( array_key_exists( $key, $details ) ) { |
54
|
|
|
$this->{$key} = $details[ $key ]; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function get_name() { |
60
|
|
|
return $this->name; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function get_code() { |
64
|
|
|
return $this->code; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function get_version() { |
68
|
|
|
return $this->version; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function get_author() { |
72
|
|
|
return $this->author; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function has_license() { |
76
|
|
|
return $this->has_license; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function get_root_file() { |
80
|
|
|
return $this->root_file; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Return add-on slug. |
85
|
|
|
* |
86
|
|
|
* Add-on slug is the name of the root file without file extension. |
87
|
|
|
* |
88
|
|
|
* @since 6.0.1 |
89
|
|
|
* |
90
|
|
|
* @return string Add-on slug. |
91
|
|
|
*/ |
92
|
|
|
public function get_addon_slug() { |
93
|
|
|
return basename( $this->root_file, '.php' ); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function get_addon_directory() { |
97
|
|
|
return plugin_dir_path( $this->root_file ); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function get_addon_directory_url() { |
101
|
|
|
return plugin_dir_url( $this->root_file ); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|