PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / 4.17.1
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress v4.17.1
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 / Admin / SettingsPages / Membership / CouponsPage / CouponWPListTable.php
wp-user-avatar / src / Admin / SettingsPages / Membership / CouponsPage Last commit date
CouponWPListTable.php 1 year ago SettingsPage.php 1 year ago index.php 4 years ago
CouponWPListTable.php
291 lines
1 <?php
2
3 namespace ProfilePress\Core\Admin\SettingsPages\Membership\CouponsPage;
4
5 use ProfilePress\Core\Membership\Models\Coupon\CouponEntity;
6 use ProfilePress\Core\Membership\Models\Coupon\CouponFactory;
7 use ProfilePress\Core\Membership\Models\Coupon\CouponUnit;
8 use ProfilePress\Core\Membership\Repositories\CouponRepository;
9
10 class CouponWPListTable extends \WP_List_Table
11 {
12 public function __construct()
13 {
14 parent::__construct([
15 'singular' => 'ppress-coupon-code',
16 'plural' => 'ppress-coupon-codes',
17 'ajax' => false
18 ]);
19 }
20
21 public function no_items()
22 {
23 _e('No coupon code found.', 'wp-user-avatar');
24 }
25
26 public function get_columns()
27 {
28 return [
29 'cb' => '<input type="checkbox" />',
30 'coupon_code' => esc_html__('Code', 'wp-user-avatar'),
31 'discount' => esc_html__('Discount', 'wp-user-avatar'),
32 'redemption' => esc_html__('Redemptions', 'wp-user-avatar'),
33 'status' => esc_html__('Status', 'wp-user-avatar'),
34 'start_date' => esc_html__('Start Date', 'wp-user-avatar'),
35 'end_date' => esc_html__('End Date', 'wp-user-avatar'),
36 ];
37 }
38
39 /**
40 * Render the bulk edit checkbox
41 *
42 * @param CouponEntity $item
43 *
44 * @return string
45 */
46 public function column_cb($item)
47 {
48 return sprintf('<input type="checkbox" name="coupon_id[]" value="%s" />', $item->id);
49 }
50
51
52 public function column_coupon_code(CouponEntity $item)
53 {
54 $coupon_id = absint($item->id);
55
56 $is_active = $item->is_active();
57
58 $edit_link = esc_url(add_query_arg(['ppress_coupon_action' => 'edit', 'id' => $coupon_id], PPRESS_MEMBERSHIP_COUPONS_SETTINGS_PAGE));
59 $activate_link = esc_url(add_query_arg(['ppress_coupon_action' => 'activate', 'id' => $coupon_id, '_wpnonce' => wp_create_nonce('pp_coupon_activate_rule')], PPRESS_MEMBERSHIP_COUPONS_SETTINGS_PAGE));
60 $deactivate_link = esc_url(add_query_arg(['ppress_coupon_action' => 'deactivate', 'id' => $coupon_id, '_wpnonce' => wp_create_nonce('pp_coupon_deactivate_rule')], PPRESS_MEMBERSHIP_COUPONS_SETTINGS_PAGE));
61 $delete_link = self::delete_coupon_url($coupon_id);
62
63 $actions = [
64 'edit' => sprintf('<a href="%s">%s</a>', $edit_link, esc_html__('Edit', 'wp-user-avatar')),
65 ];
66
67 if (true === $is_active) {
68 $actions['deactivate'] = sprintf('<a href="%s">%s</a>', $deactivate_link, esc_html__('Deactivate', 'wp-user-avatar'));
69 }
70
71 if (false === $is_active) {
72 $actions['activate'] = sprintf('<a href="%s">%s</a>', $activate_link, esc_html__('Activate', 'wp-user-avatar'));
73 }
74
75 $actions['delete'] = sprintf('<a class="pp-confirm-delete" href="%s">%s</a>', $delete_link, esc_html__('Delete', 'wp-user-avatar'));
76
77 $a = '<a href="' . $edit_link . '">' . esc_html($item->code) . '</a>';
78
79 $coupon_type = $item->is_recurring() ? esc_html__('Recurring', 'wp-user-avatar') : esc_html__('First Payment', 'wp-user-avatar');
80
81 $a .= '&nbsp;<span class="post-state"> — ' . $coupon_type . '</span>';
82
83 return '<strong>' . $a . '</strong>' . $this->row_actions($actions);
84 }
85
86 public function column_discount(CouponEntity $item)
87 {
88 $unit = $item->unit;
89
90 if (CouponUnit::FLAT == $unit) {
91 return ppress_display_amount($item->amount);
92 }
93
94 return $item->amount . '%';
95 }
96
97 public function column_start_date(CouponEntity $item)
98 {
99 $date = $item->start_date;
100
101 if (empty($date)) return '&mdash;';
102
103 return gmdate(get_option('date_format'), strtotime($date . ' UTC'));
104 }
105
106 public function column_end_date(CouponEntity $item)
107 {
108 $date = $item->end_date;
109
110 if (empty($date)) return '&mdash;';
111
112 return gmdate(get_option('date_format'), strtotime($date . ' UTC'));
113 }
114
115 public function column_redemption(CouponEntity $item)
116 {
117 $usage_limit = absint($item->usage_limit);
118
119 if (empty($usage_limit) || $usage_limit === 0) {
120 $usage_limit = esc_html__('Unlimited', 'wp-user-avatar');
121 }
122
123 return sprintf('<a href="%s">%s</a>',
124 add_query_arg(['coupon_code' => $item->code], PPRESS_MEMBERSHIP_ORDERS_SETTINGS_PAGE),
125 $item->get_usage_count() . ' / ' . $usage_limit
126 );
127 }
128
129 public function column_status(CouponEntity $item)
130 {
131 $status = sprintf('<span class="dashicons-before dashicons-yes">%s</span>', esc_html__('Active', 'wp-user-avatar'));
132 if ( ! $item->is_active()) {
133 $status = sprintf('<span class="dashicons-before dashicons-no-alt">%s</span>', esc_html__('Inactive', 'wp-user-avatar'));
134 }
135
136 if ($item->is_expired()) {
137 $status = sprintf('<span class="dashicons-before dashicons-no-alt">%s</span>', esc_html__('Expired', 'wp-user-avatar'));
138 }
139
140 return $status;
141 }
142
143 public static function delete_coupon_url($coupon_id)
144 {
145 $nonce_delete = wp_create_nonce('pp_coupon_delete_rule');
146
147 return add_query_arg(['action' => 'delete', 'id' => $coupon_id, '_wpnonce' => $nonce_delete], PPRESS_MEMBERSHIP_COUPONS_SETTINGS_PAGE);
148 }
149
150 public function get_coupons($per_page, $current_page = 1)
151 {
152 return CouponRepository::init()->retrieveAll($per_page, $current_page);
153 }
154
155 public function record_count()
156 {
157 return CouponRepository::init()->record_count();
158 }
159
160 public function prepare_items()
161 {
162 $this->_column_headers = $this->get_column_info();
163
164 $this->process_bulk_action();
165
166 $per_page = $this->get_items_per_page('coupons_per_page', 10);
167 $current_page = $this->get_pagenum();
168 $total_items = $this->record_count();
169
170 $this->set_pagination_args([
171 'total_items' => $total_items, //WE have to calculate the total number of items
172 'per_page' => $per_page //WE have to determine how many items to show on a page
173 ]);
174
175 $this->items = $this->get_coupons($per_page, $current_page);
176 }
177
178 public function current_action()
179 {
180 if (isset($_REQUEST['filter_action']) && ! empty($_REQUEST['filter_action'])) {
181 return false;
182 }
183
184 if (isset($_REQUEST['action']) && -1 != $_REQUEST['action']) {
185 return $_REQUEST['action'];
186 }
187
188 if (isset($_REQUEST['ppress_coupon_action']) && -1 != $_REQUEST['ppress_coupon_action']) {
189 return $_REQUEST['ppress_coupon_action'];
190 }
191
192 return false;
193 }
194
195 public function get_bulk_actions()
196 {
197 $actions = [
198 'bulk-delete' => esc_html__('Delete', 'wp-user-avatar'),
199 'bulk-activate' => esc_html__('Activate', 'wp-user-avatar'),
200 'bulk-deactivate' => esc_html__('Deactivate', 'wp-user-avatar')
201 ];
202
203 return $actions;
204 }
205
206 public function process_bulk_action()
207 {
208 $coupon_id = absint(ppress_var($_GET, 'id', 0));
209
210 $couponObj = CouponFactory::fromId($coupon_id);
211
212 if ('deactivate' === $this->current_action()) {
213
214 check_admin_referer('pp_coupon_deactivate_rule');
215
216 if ( ! current_user_can('manage_options')) return;
217
218 $couponObj->deactivate();
219 }
220
221 if ('activate' === $this->current_action()) {
222
223 check_admin_referer('pp_coupon_activate_rule');
224
225 if ( ! current_user_can('manage_options')) return;
226
227 $couponObj->activate();
228 }
229
230 if ('delete' === $this->current_action()) {
231
232 check_admin_referer('pp_coupon_delete_rule');
233
234 if ( ! current_user_can('manage_options')) return;
235
236 CouponRepository::init()->delete($coupon_id);
237 }
238
239 if ('bulk-delete' === $this->current_action()) {
240
241 check_admin_referer('bulk-' . $this->_args['plural']);
242
243 if ( ! current_user_can('manage_options')) return;
244
245 $coupon_ids = array_map('absint', $_POST['coupon_id']);
246
247 foreach ($coupon_ids as $coupon_id) {
248 CouponRepository::init()->delete($coupon_id);
249 }
250 }
251
252 if ('bulk-activate' === $this->current_action()) {
253
254 check_admin_referer('bulk-' . $this->_args['plural']);
255
256 if ( ! current_user_can('manage_options')) return;
257
258 $coupon_ids = array_map('absint', $_POST['coupon_id']);
259
260 foreach ($coupon_ids as $coupon_id) {
261 CouponFactory::fromId($coupon_id)->activate();
262 }
263 }
264
265 if ('bulk-deactivate' === $this->current_action()) {
266
267 check_admin_referer('bulk-' . $this->_args['plural']);
268
269 if ( ! current_user_can('manage_options')) return;
270
271 $coupon_ids = array_map('absint', $_POST['coupon_id']);
272
273 foreach ($coupon_ids as $coupon_id) {
274 CouponFactory::fromId($coupon_id)->deactivate();
275 }
276 }
277
278 if ($this->current_action() !== false) {
279 ppress_do_admin_redirect(PPRESS_MEMBERSHIP_COUPONS_SETTINGS_PAGE);
280 }
281 }
282
283 /**
284 * @return array List of CSS classes for the table tag.
285 */
286 public function get_table_classes()
287 {
288 return array('widefat', 'fixed', 'striped', 'coupon', 'ppview');
289 }
290 }
291