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 $description; |
18
|
|
|
protected $slug; |
19
|
|
|
protected $url; |
20
|
|
|
protected $buy_url; |
21
|
|
|
protected $upsell_title; |
22
|
|
|
protected $upsell_message; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Construct AddonInfo from an array. |
26
|
|
|
* |
27
|
|
|
* @param array $details Details about the add-on. |
28
|
|
|
*/ |
29
|
|
|
public function __construct( $details = array() ) { |
30
|
|
|
if ( ! is_array( $details ) ) { |
|
|
|
|
31
|
|
|
return; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
$keys = array( |
35
|
|
|
'name', |
36
|
|
|
'description', |
37
|
|
|
'slug', |
38
|
|
|
'url', |
39
|
|
|
'buy_url', |
40
|
|
|
'upsell_title', |
41
|
|
|
'upsell_message', |
42
|
|
|
); |
43
|
|
|
|
44
|
|
|
foreach ( $keys as $key ) { |
45
|
|
|
if ( array_key_exists( $key, $details ) ) { |
46
|
|
|
$this->{$key} = $details[ $key ]; |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function get_name() { |
52
|
|
|
return $this->name; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function get_description() { |
56
|
|
|
return $this->description; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function get_slug() { |
60
|
|
|
return $this->slug; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function get_url() { |
64
|
|
|
return $this->url; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Get the url where users can buy the add-on. |
69
|
|
|
* |
70
|
|
|
* This url might include GA campaign parameters. |
71
|
|
|
* Addon url is used if buy url is not explicitly set. |
72
|
|
|
* |
73
|
|
|
* @return string Url from where the add-on could be bought or just url if it not set. |
74
|
|
|
*/ |
75
|
|
|
public function get_buy_url() { |
76
|
|
|
if ( empty( $this->buy_url ) ) { |
77
|
|
|
return $this->url; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return $this->buy_url; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Get upsell title for the addon. |
85
|
|
|
* |
86
|
|
|
* Name is used if title is not explicitly set. |
87
|
|
|
* |
88
|
|
|
* @return string Upsell title for addon or Name if it not set. |
89
|
|
|
*/ |
90
|
|
|
public function get_upsell_title() { |
91
|
|
|
if ( empty( $this->upsell_title ) ) { |
92
|
|
|
return $this->name; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return $this->upsell_title; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Get upsell message for the addon. |
100
|
|
|
* |
101
|
|
|
* Description is used if title is not explicitly set. |
102
|
|
|
* |
103
|
|
|
* @return string Upsell description for addon or Description if it not set. |
104
|
|
|
*/ |
105
|
|
|
public function get_upsell_message() { |
106
|
|
|
if ( empty( $this->upsell_message ) ) { |
107
|
|
|
return $this->description; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
return $this->upsell_message; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|