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.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 / Admin / SettingsPages / Membership / CustomersPage / CustomerWPListTable.php
wp-user-avatar / src / Admin / SettingsPages / Membership / CustomersPage Last commit date
CustomerWPListTable.php 4 years ago SettingsPage.php 4 years ago index.php 4 years ago
CustomerWPListTable.php
341 lines
1 <?php
2
3 namespace ProfilePress\Core\Admin\SettingsPages\Membership\CustomersPage;
4
5 use ProfilePress\Core\Admin\SettingsPages\Membership\SubscriptionsPage\SubscriptionWPListTable;
6 use ProfilePress\Core\Membership\Models\Customer\CustomerEntity;
7 use ProfilePress\Core\Membership\Models\Customer\CustomerStatus;
8 use ProfilePress\Core\Membership\Models\Plan\PlanFactory;
9 use ProfilePress\Core\Membership\Models\Subscription\SubscriptionStatus;
10 use ProfilePress\Core\Membership\Repositories\CustomerRepository;
11 use ProfilePress\Core\Membership\Repositories\SubscriptionRepository;
12 use ProfilePress\Core\Membership\Services\CustomerService;
13 use ProfilePress\Core\Membership\Services\OrderService;
14
15 class CustomerWPListTable extends \WP_List_Table
16 {
17 private $views_count = [];
18
19 public function __construct()
20 {
21 parent::__construct([
22 'singular' => 'ppress-customer',
23 'plural' => 'ppress-customers',
24 'ajax' => false
25 ]);
26
27 $statuses = array_keys(CustomerStatus::get_all());
28 $statuses[] = 'all';
29
30 foreach ($statuses as $id) {
31
32 if ('all' == $id) {
33 $this->views_count[$id] = CustomerRepository::init()->record_count();
34 } else {
35 $this->views_count[$id] = CustomerRepository::init()->get_count_by_status($id);
36 }
37 }
38 }
39
40 public function no_items()
41 {
42 _e('No customers found.', 'wp-user-avatar');
43 }
44
45 public function get_columns()
46 {
47 $columns = [
48 'cb' => '<input type="checkbox" />',
49 'customer_name' => esc_html__('Name', 'wp-user-avatar'),
50 'customer_email' => esc_html__('Email', 'wp-user-avatar'),
51 'customer_subscriptions' => esc_html__('Active Subscriptions', 'wp-user-avatar'),
52 'customer_since' => esc_html__('Customer Since', 'wp-user-avatar'),
53 'customer_last_login' => esc_html__('Last Login', 'wp-user-avatar'),
54 ];
55
56 return $columns;
57 }
58
59 public static function delete_customer_url($customer_id)
60 {
61 $nonce_delete = wp_create_nonce('pp_customer_delete_rule');
62
63 return add_query_arg(['ppress_customer_action' => 'delete', 'id' => $customer_id, '_wpnonce' => $nonce_delete], PPRESS_MEMBERSHIP_CUSTOMERS_SETTINGS_PAGE);
64 }
65
66 public static function view_customer_url($customer_id)
67 {
68 return add_query_arg(['ppress_customer_action' => 'view', 'id' => $customer_id], PPRESS_MEMBERSHIP_CUSTOMERS_SETTINGS_PAGE);
69 }
70
71 /**
72 * @param CustomerEntity $customer
73 *
74 * @return string
75 */
76 public function column_customer_name($customer)
77 {
78 $customer_id = absint($customer->id);
79
80 $view_link = esc_url(self::view_customer_url($customer_id));
81 $orders_link = OrderService::init()->get_customer_orders_url($customer->id);
82 $subs_link = add_query_arg(['by_ci' => $customer_id], PPRESS_MEMBERSHIP_SUBSCRIPTIONS_SETTINGS_PAGE);
83
84 $actions = [
85 'view_customer' => sprintf('<a href="%s">%s</a>', $view_link, esc_html__('Edit', 'wp-user-avatar')),
86 'view_orders' => sprintf('<a href="%s">%s</a>', $orders_link, esc_html__('View Orders', 'wp-user-avatar')),
87 'view_subscriptions' => sprintf('<a href="%s">%s</a>', $subs_link, esc_html__('View Subscriptions', 'wp-user-avatar')),
88 ];
89
90 $customer_name = $customer->get_name();
91
92 $title = sprintf('<a class="row-title" href="%s">%s</a>', $view_link, $customer_name);
93
94 return $title . $this->row_actions($actions);
95 }
96
97 /**
98 * @param CustomerEntity $customer
99 *
100 * @return string
101 */
102 public function column_customer_email($customer)
103 {
104 return ! empty($customer->get_email()) ? $customer->get_email() : '&mdash;&mdash;&mdash;';
105 }
106
107 /**
108 * @param CustomerEntity $customer
109 *
110 * @return string
111 */
112 public function column_customer_since($customer)
113 {
114 return ppress_format_date($customer->get_date_created());
115 }
116
117 /**
118 * @param CustomerEntity $customer
119 *
120 * @return string
121 */
122 public function column_customer_last_login($customer)
123 {
124 return ! empty($customer->get_last_login()) ? $customer->get_last_login() : '&mdash;&mdash;&mdash;';
125 }
126
127 /**
128 * @param CustomerEntity $customer
129 *
130 * @return string
131 */
132 public function column_customer_subscriptions($customer)
133 {
134 $subs = $customer->get_active_subscriptions();
135
136 if (empty($subs)) return '&mdash;&mdash;&mdash;';
137
138 $subs = array_map(function ($sub) {
139
140 return sprintf(
141 '<a target="_blank" href="%s">%s</a>',
142 SubscriptionWPListTable::view_edit_subscription_url($sub->id),
143 PlanFactory::fromId($sub->get_plan_id())->get_name()
144 );
145 }, $subs);
146
147 return sprintf(
148 '<a target="_blank" href="%s">%s</a>',
149 add_query_arg(['by_ci' => $customer->id], PPRESS_MEMBERSHIP_SUBSCRIPTIONS_SETTINGS_PAGE),
150 implode(', ', $subs)
151 );
152 }
153
154 public function get_views()
155 {
156 $views = [];
157
158 $args = ['all' => esc_html__('All', 'wp-user-avatar')] + CustomerStatus::get_all();
159
160 foreach ($args as $id => $status) {
161
162 $url = $id == 'all' ? PPRESS_MEMBERSHIP_CUSTOMERS_SETTINGS_PAGE : add_query_arg(['status' => $id], PPRESS_MEMBERSHIP_CUSTOMERS_SETTINGS_PAGE);
163
164 $views[$id] = sprintf(
165 '<a href="%s"%s>%s <span class="count">(%s)</span></a>',
166 $url,
167 ppressGET_var('status', 'all') == $id ? ' class="current"' : '',
168 $status,
169 $this->views_count[$id]
170 );
171 }
172
173 return $views;
174 }
175
176 /**
177 * Render the bulk edit checkbox
178 *
179 * @param CustomerEntity $customer
180 *
181 * @return string
182 */
183 public function column_cb($customer)
184 {
185 return sprintf('<input type="checkbox" name="customer_id[]" value="%s" />', $customer->id);
186 }
187
188 public function record_count()
189 {
190 $status = ppressGET_var('status', 'all');
191
192 if ($status != 'all') {
193 return $this->views_count[$status];
194 }
195
196 return SubscriptionRepository::init()->record_count();
197 }
198
199 public function prepare_items()
200 {
201 $this->_column_headers = $this->get_column_info();
202
203 $this->process_bulk_action();
204
205 $per_page = $this->get_items_per_page('customers_per_page', 10);
206 $current_page = $this->get_pagenum();
207 $offset = ($current_page - 1) * $per_page;
208
209 $search = ! empty($_GET['s']) ? sanitize_text_field($_GET['s']) : '';
210
211 $start_date = ppressGET_var('start_date');
212 $end_date = ppressGET_var('end_date');
213 $status = ppressGET_var('status');
214
215 $query_args = [
216 'number' => $per_page,
217 'offset' => $offset,
218 'search' => $search,
219 'status' => $status,
220 'start_date' => $start_date,
221 'end_date' => $end_date
222 ];
223
224 $this->items = CustomerRepository::init()->retrieveBy($query_args);
225
226 $total_items = CustomerRepository::init()->retrieveBy($query_args, true);
227
228 $this->set_pagination_args([
229 'total_items' => $total_items,
230 'per_page' => $per_page
231 ]);
232 }
233
234 public function current_action()
235 {
236 if (isset($_REQUEST['filter_action']) && ! empty($_REQUEST['filter_action'])) {
237 return false;
238 }
239
240 if (isset($_REQUEST['action']) && -1 != $_REQUEST['action']) {
241 return $_REQUEST['action'];
242 }
243
244 if (isset($_REQUEST['ppress_customer_action']) && -1 != $_REQUEST['ppress_customer_action']) {
245 return $_REQUEST['ppress_customer_action'];
246 }
247
248 return false;
249 }
250
251 public function get_bulk_actions()
252 {
253 $actions = [
254 'bulk-delete' => esc_html__('Delete', 'wp-user-avatar')
255 ];
256
257 return $actions;
258 }
259
260 public function process_bulk_action()
261 {
262 $customer_id = absint(ppress_var($_GET, 'id', 0));
263
264 if ( ! current_user_can('manage_options')) return;
265
266 if ('delete' === $this->current_action()) {
267
268 check_admin_referer('pp_customer_delete_rule');
269
270 if ( ! current_user_can('manage_options')) return;
271
272 CustomerService::init()->delete_customer($customer_id);
273 }
274
275 if ('bulk-delete' === $this->current_action()) {
276
277 check_admin_referer('bulk-' . $this->_args['plural']);
278
279 if ( ! current_user_can('manage_options')) return;
280
281 $customer_ids = array_map('absint', $_GET['customer_id']);
282
283 foreach ($customer_ids as $customer_id) {
284 CustomerService::init()->delete_customer($customer_id);
285 }
286 }
287
288 if ($this->current_action() !== false) {
289 wp_safe_redirect(PPRESS_MEMBERSHIP_CUSTOMERS_SETTINGS_PAGE);
290 exit;
291 }
292 }
293
294 public function filter_bar()
295 {
296 $start_date = isset($_GET['start_date']) ? sanitize_text_field($_GET['start_date']) : null;
297 $end_date = isset($_GET['end_date']) ? sanitize_text_field($_GET['end_date']) : null;
298
299 $status = ppressGET_var('status');
300 $clear_url = PPRESS_MEMBERSHIP_CUSTOMERS_SETTINGS_PAGE;
301
302 echo '<div class="wp-filter" id="ppress-filters">';
303 echo '<div class="filter-items">';
304 ?>
305
306 <span id="ppress-date-filters" class="ppress-from-to-wrapper">
307 <span class="ppress-start-date-wrap">
308 <input type="text" name="start_date" id="start-date" placeholder="<?= _x('From', 'date filter', 'wp-user-avatar') ?>" value="<?= $start_date ?>" class="ppress_datepicker">
309 </span>
310 <span id="ppress-end-date-wrap">
311 <input type="text" name="end_date" id="end-date" value="<?= $end_date ?>" placeholder="<?= _x('To', 'date filter', 'wp-user-avatar') ?>" class="ppress_datepicker">
312 </span>
313 </span>
314
315 <span id="ppress-after-core-filters">
316 <input type="submit" class="button button-secondary" value="<?php esc_html_e('Filter', 'wp-user-avatar'); ?>"/>
317
318 <?php if ( ! empty($_GET['s']) || ! empty($start_date) || ! empty($end_date)) : ?>
319 <a href="<?php echo esc_url($clear_url); ?>" class="button-secondary">
320 <?php esc_html_e('Clear', 'wp-user-avatar'); ?>
321 </a>
322 <?php endif; ?>
323 </span>
324
325 <?php if ( ! empty($status)) : ?>
326 <input type="hidden" name="status" value="<?php echo esc_attr($status); ?>"/>
327 <?php endif;
328 echo '</div>';
329 $this->search_box(__('Search Customers', 'wp-user-avatar'), 'ppress_customer_search');
330 echo '</div>';
331 }
332
333 /**
334 * @return array List of CSS classes for the table tag.
335 */
336 public function get_table_classes()
337 {
338 return array('widefat', 'fixed', 'striped', 'customer', 'ppview');
339 }
340 }
341