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 / GroupsPage / GroupWPListTable.php
wp-user-avatar / src / Admin / SettingsPages / Membership / GroupsPage Last commit date
GroupWPListTable.php 1 year ago SettingsPage.php 1 year ago index.php 3 years ago
GroupWPListTable.php
215 lines
1 <?php
2
3 namespace ProfilePress\Core\Admin\SettingsPages\Membership\GroupsPage;
4
5 use ProfilePress\Core\Admin\SettingsPages\Membership\PlansPage\PlanWPListTable;
6 use ProfilePress\Core\Membership\Models\Group\GroupEntity;
7 use ProfilePress\Core\Membership\Repositories\GroupRepository;
8
9 class GroupWPListTable extends \WP_List_Table
10 {
11 public function __construct()
12 {
13 parent::__construct(array(
14 'singular' => 'ppress-group-code',
15 'plural' => 'ppress-group-codes',
16 'ajax' => false
17 ));
18 }
19
20 public function no_items()
21 {
22 _e('No group found.', 'wp-user-avatar');
23 }
24
25 public function get_columns()
26 {
27 return [
28 'cb' => '<input type="checkbox" />',
29 'group_name' => esc_html__('Group Name', 'wp-user-avatar'),
30 'group_plans' => esc_html__('Plans in Group', 'wp-user-avatar'),
31 'checkout_url' => esc_html__('Checkout URL', 'wp-user-avatar')
32 ];
33 }
34
35 /**
36 * Render the bulk edit checkbox
37 *
38 * @param GroupEntity $item
39 *
40 * @return string
41 */
42 public function column_cb($item)
43 {
44 return sprintf('<input type="checkbox" name="group_id[]" value="%s" />', $item->id);
45 }
46
47 public function column_group_name(GroupEntity $item)
48 {
49 $group_id = absint($item->id);
50
51 $edit_link = esc_url(add_query_arg([
52 'ppress_group_action' => 'edit',
53 'id' => $group_id
54 ], PPRESS_MEMBERSHIP_GROUPS_SETTINGS_PAGE));
55 $delete_link = self::delete_group_url($group_id);
56
57 $actions = [
58 'edit' => sprintf('<a href="%s">%s</a>', $edit_link, esc_html__('Edit', 'wp-user-avatar')),
59 ];
60
61 $actions['delete'] = sprintf('<a class="pp-confirm-delete" href="%s">%s</a>', $delete_link, esc_html__('Delete', 'wp-user-avatar'));
62
63 $a = '<a href="' . $edit_link . '">' . esc_html($item->name) . '</a>';
64
65 return '<strong>' . $a . '</strong>' . $this->row_actions($actions);
66 }
67
68 public function column_group_plans(GroupEntity $item)
69 {
70 $plans = $item->plan_ids;
71
72 if (empty($plans)) return '&mdash;&mdash;&mdash;';
73
74 $plans = array_map(function ($plan_id) {
75
76 $plan = ppress_get_plan($plan_id);
77
78 return sprintf(
79 '<a target="_blank" href="%s">%s</a>',
80 $plan->get_edit_plan_url(),
81 $plan->get_name()
82 );
83
84 }, $plans);
85
86 return sprintf('%s', implode(', ', $plans));
87 }
88
89 public function column_checkout_url(GroupEntity $item)
90 {
91 $url = $item->get_checkout_url();
92
93 if ( ! $url) return esc_html__('Checkout page not found', 'wp-user-avatar');
94
95 ob_start();
96 ?>
97 <div style="display: flex; align-items: center; gap: 5px;">
98 <input type="text" class="ppress-checkout-url" onfocus="this.select();" readonly="readonly" value="<?php echo esc_url($url); ?>" style="min-width: 200px;"/>
99
100 <button type="button" class="button ppress-copy-url-icon" title="<?php esc_attr_e('Copy URL', 'wp-user-avatar'); ?>">
101 <span class="dashicons dashicons-admin-page"></span>
102 </button>
103 <span class="ppress-copy-msg" style="display:none; color:green;"><?php esc_html_e('Copied!', 'wp-user-avatar'); ?></span>
104 </div>
105 <?php
106 return ob_get_clean();
107
108 }
109
110 public static function delete_group_url($group_id)
111 {
112 return add_query_arg([
113 'action' => 'delete',
114 'id' => $group_id,
115 '_wpnonce' => wp_create_nonce('pp_group_delete_rule')
116 ], PPRESS_MEMBERSHIP_GROUPS_SETTINGS_PAGE);
117 }
118
119 public function get_groups($per_page, $current_page = 1)
120 {
121 return GroupRepository::init()->retrieveAll($per_page, $current_page);
122 }
123
124 public function record_count()
125 {
126 return GroupRepository::init()->retrieveAll(0, 1, 'DESC', true);
127 }
128
129 public function prepare_items()
130 {
131 $this->_column_headers = $this->get_column_info();
132
133 $this->process_bulk_action();
134
135 $per_page = $this->get_items_per_page('groups_per_page', 10);
136 $current_page = $this->get_pagenum();
137 $total_items = $this->record_count();
138
139 $this->set_pagination_args([
140 'total_items' => $total_items, //WE have to calculate the total number of items
141 'per_page' => $per_page //WE have to determine how many items to show on a page
142 ]);
143
144 $this->items = $this->get_groups($per_page, $current_page);
145 }
146
147 public function current_action()
148 {
149 if (isset($_REQUEST['filter_action']) && ! empty($_REQUEST['filter_action'])) {
150 return false;
151 }
152
153 if (isset($_REQUEST['action']) && -1 != $_REQUEST['action']) {
154 return $_REQUEST['action'];
155 }
156
157 if (isset($_REQUEST['ppress_group_action']) && -1 != $_REQUEST['ppress_group_action']) {
158 return $_REQUEST['ppress_group_action'];
159 }
160
161 return false;
162 }
163
164 public function get_bulk_actions()
165 {
166 $actions = [
167 'bulk-delete' => esc_html__('Delete', 'wp-user-avatar')
168 ];
169
170 return $actions;
171 }
172
173 public function process_bulk_action()
174 {
175 $group_id = absint(ppress_var($_GET, 'id', 0));
176
177 // Bail if user is not an admin or without admin privileges.
178 if ( ! current_user_can('manage_options')) return;
179
180 if ('delete' === $this->current_action()) {
181
182 check_admin_referer('pp_group_delete_rule');
183
184 if ( ! current_user_can('manage_options')) return;
185
186 GroupRepository::init()->delete($group_id);
187 }
188
189 if ('bulk-delete' === $this->current_action()) {
190
191 check_admin_referer('bulk-' . $this->_args['plural']);
192
193 if ( ! current_user_can('manage_options')) return;
194
195 $group_ids = array_map('absint', $_POST['group_id']);
196
197 foreach ($group_ids as $group_id) {
198 GroupRepository::init()->delete($group_id);
199 }
200 }
201
202 if ($this->current_action() !== false) {
203 ppress_do_admin_redirect(PPRESS_MEMBERSHIP_GROUPS_SETTINGS_PAGE);
204 }
205 }
206
207 /**
208 * @return array List of CSS classes for the table tag.
209 */
210 public function get_table_classes()
211 {
212 return array('widefat', 'fixed', 'striped', 'group', 'ppview');
213 }
214 }
215