PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / 4.0.3
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress v4.0.3
4.17.2 4.17.1 4.17.0 4.16.19 4.16.18 4.16.17 4.16.16 trunk 1.0 1.0.1 1.0.2 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5a 1.1.6 1.1.7 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4 1.4.1 1.4.2 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.7 1.7.1 1.7.2 1.8 1.8.1 1.8.10 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.1.9 2.2.10 2.2.11 2.2.12 2.2.13 2.2.14 2.2.15 2.2.16 2.2.2 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 3.0 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.10.0 4.10.1 4.10.2 4.10.3 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.13.3 4.13.4 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.15.0 4.15.1 4.15.10 4.15.11 4.15.12 4.15.13 4.15.14 4.15.15 4.15.16 4.15.17 4.15.18 4.15.19 4.15.2 4.15.20 4.15.20.1 4.15.21 4.15.22 4.15.23 4.15.24 4.15.25 4.15.3 4.15.4 4.15.5 4.15.6 4.15.7 4.15.8 4.15.9 4.16.0 4.16.1 4.16.10 4.16.11 4.16.12 4.16.13 4.16.14 4.16.15 4.16.2 4.16.3 4.16.4 4.16.5 4.16.6 4.16.7 4.16.8 4.16.9 4.2.0 4.3.0 4.3.1 4.3.2 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.5.3 4.5.4 4.5.5 4.6.0 4.7.0 4.8.0 4.9.0
wp-user-avatar / src / Membership / Models / Plan / PlanEntity.php
wp-user-avatar / src / Membership / Models / Plan Last commit date
PlanEntity.php 4 years ago PlanFactory.php 4 years ago index.php 4 years ago
PlanEntity.php
231 lines
1 <?php
2
3 namespace ProfilePress\Core\Membership\Models\Plan;
4
5 use ProfilePress\Core\Membership\Models\AbstractModel;
6 use ProfilePress\Core\Membership\Models\ModelInterface;
7 use ProfilePress\Core\Membership\Models\Subscription\SubscriptionBillingFrequency;
8 use ProfilePress\Core\Membership\Models\Subscription\SubscriptionTrialPeriod;
9 use ProfilePress\Core\Membership\Repositories\PlanRepository;
10 use ProfilePress\Core\Membership\Services\Calculator;
11 use ProfilePress\Core\Membership\Services\OrderService;
12
13 /**
14 * @property int $id
15 * @property string $name
16 * @property string $description
17 * @property string $price
18 * @property string $billing_frequency
19 * @property string $subscription_length
20 * @property int $total_payments
21 * @property string $signup_fee
22 * @property string $free_trial
23 */
24 class PlanEntity extends AbstractModel implements ModelInterface
25 {
26 protected $id = 0;
27
28 protected $name = '';
29
30 protected $description = '';
31
32 protected $price = '0';
33
34 protected $billing_frequency = SubscriptionBillingFrequency::MONTHLY;
35
36 protected $subscription_length = 'renew_indefinitely';
37
38 // 0 indicates renew indefinitely.
39 protected $total_payments = 0;
40
41 protected $signup_fee = '0';
42
43 protected $free_trial = SubscriptionTrialPeriod::DISABLED;
44
45 protected $status = 'false';
46
47 protected $meta_data = [];
48
49 public function __construct($data = [])
50 {
51 if (is_array($data) && ! empty($data)) {
52
53 foreach ($data as $key => $value) {
54 $this->$key = $value;
55
56 if ($key == 'meta_data') {
57 $this->meta_data = ! empty($value) && ppress_is_json($value) ? \json_decode($value, true) : [];
58 }
59 }
60 }
61 }
62
63 /**
64 * @return bool
65 */
66 public function exists()
67 {
68 return ! empty($this->id);
69 }
70
71 public function get_id()
72 {
73 return absint($this->id);
74 }
75
76 public function get_name()
77 {
78 return $this->name;
79 }
80
81 public function is_active()
82 {
83 return $this->status == 'true';
84 }
85
86 public function is_recurring()
87 {
88 return ! empty($this->billing_frequency) && $this->billing_frequency != 'lifetime';
89 }
90
91 public function has_free_trial()
92 {
93 return $this->is_recurring() &&
94 $this->free_trial != SubscriptionTrialPeriod::DISABLED &&
95 ! OrderService::init()->customer_has_trialled($this->id);
96 }
97
98 public function has_signup_fee()
99 {
100 return ! Calculator::init($this->signup_fee)->isNegativeOrZero();
101 }
102
103 public function get_description()
104 {
105 return apply_filters('ppress_subscription_plan_description', wpautop($this->description), $this->get_id());
106 }
107
108 /**
109 * @return string
110 */
111 public function get_price()
112 {
113 return ppress_sanitize_amount($this->price);
114 }
115
116 public function get_billing_frequency()
117 {
118 return $this->billing_frequency;
119 }
120
121 public function get_subscription_length()
122 {
123 return $this->subscription_length;
124 }
125
126 public function get_total_payments()
127 {
128 return absint($this->total_payments);
129 }
130
131 /**
132 * @return string
133 */
134 public function get_signup_fee()
135 {
136 return ppress_sanitize_amount($this->signup_fee);
137 }
138
139 public function get_free_trial()
140 {
141 return sanitize_text_field($this->free_trial);
142 }
143
144 public function get_edit_plan_url()
145 {
146 return add_query_arg(['ppress_subp_action' => 'edit', 'id' => $this->id], PPRESS_MEMBERSHIP_SUBSCRIPTION_PLANS_SETTINGS_PAGE);
147 }
148
149 /**
150 * @return false|int
151 */
152 public function save()
153 {
154 if ($this->id > 0) {
155
156 $result = PlanRepository::init()->update($this);
157
158 do_action('ppress_membership_update_plan', $result, $this);
159
160 return $result;
161 }
162
163 $result = PlanRepository::init()->add($this);
164
165 do_action('ppress_membership_add_plan', $result, $this);
166
167 return $result;
168 }
169
170 /**
171 * @return false|string
172 */
173 public function get_checkout_url()
174 {
175 return ppress_plan_checkout_url($this->get_id());
176 }
177
178 public function update_meta($meta_key, $meta_value)
179 {
180 $this->meta_data[$meta_key] = $meta_value;
181
182 return PlanRepository::init()->updateColumn(
183 $this->get_id(),
184 'meta_data',
185 \wp_json_encode($this->meta_data)
186 );
187 }
188
189 /**
190 * @param $meta_key
191 *
192 * @return false|mixed
193 */
194 public function get_meta($meta_key)
195 {
196 return ppress_var($this->meta_data, $meta_key);
197 }
198
199 /**
200 * @param $meta_key
201 *
202 * @return false|int
203 */
204 public function delete_meta($meta_key)
205 {
206 unset($this->meta_data[$meta_key]);
207
208 return PlanRepository::init()->updateColumn(
209 $this->get_id(),
210 'meta_data',
211 \wp_json_encode($this->meta_data)
212 );
213
214 }
215
216 /**
217 * @return false|int
218 */
219 public function activate()
220 {
221 return PlanRepository::init()->updateColumn($this->id, 'status', 'true');
222 }
223
224 /**
225 * @return false|int
226 */
227 public function deactivate()
228 {
229 return PlanRepository::init()->updateColumn($this->id, 'status', 'false');
230 }
231 }