PluginProbe ʕ •ᴥ•ʔ
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 4.6.0
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v4.6.0
4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.11.0 1.11.1 1.11.2 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.5.0 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.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.9.0 1.9.1 1.9.2 1.9.3 1.9.4 1.9.5 2.0.0 2.0.1 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.10.0 2.10.1 2.11.0 2.11.1 2.11.2 2.11.3 2.11.4 2.12.0 2.13.0 2.14.0 2.14.1 2.15.0 2.15.1 2.16.0 2.16.1 2.16.2 2.16.3 2.17.0 2.17.1 2.17.2 2.18.0 2.19.0 2.19.2 2.19.3 2.19.4 2.2.0 2.2.1 2.20.0 2.20.1 2.20.2 2.20.3 2.20.4 2.20.5 2.20.6 2.21.0 2.22.0 2.22.1 2.23.0 2.24.0 2.25.0 2.25.1 2.25.2 2.26.0 2.27.0 2.27.1 2.28.0 2.29.0 2.29.1 2.29.2 2.29.3 2.29.4 2.3.0 2.3.1 2.30.0 2.31.0 2.31.1 2.31.2 2.31.3 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.40.0 2.40.1 2.5.0 2.5.1 2.5.2 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.9.0 3.0.0 3.0.0-RC1 3.0.0-RC2 3.0.0-beta1 3.0.0-beta2 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.10.0 3.10.1 3.11.0 3.12.0 3.13.0 3.13.1 3.13.2 3.13.3 3.13.4 3.14.0 3.15.0 3.15.1 3.15.2 3.15.3 3.15.4 3.15.5 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.16.6 3.16.7 3.16.8 3.17.0 3.17.1 3.17.2 3.17.3 3.17.4 3.17.5 3.17.6 3.18.0 3.19.0 3.19.1 3.19.2 3.2.0 3.2.1 3.2.2 3.20.0 3.20.1 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 4.0.0 4.0.1 4.0.2 4.0.3 trunk 4.1.0 0.2.19.1 4.1.1 1.0.0 4.2.0 1.0.1 1.0.2
surecart / app / src / Controllers / Admin / Customers / CustomersListTable.php
surecart / app / src / Controllers / Admin / Customers Last commit date
CustomersController.php 8 months ago CustomersListTable.php 2 months ago CustomersScriptsController.php 3 months ago
CustomersListTable.php
334 lines
1 <?php
2
3 namespace SureCart\Controllers\Admin\Customers;
4
5 use SureCart\Models\Customer;
6 use SureCart\Controllers\Admin\Tables\ListTable;
7 use SureCart\Controllers\Admin\Tables\HasModeFilter;
8
9 /**
10 * Create a new table class that will extend the WP_List_Table
11 */
12 class CustomersListTable extends ListTable {
13 use HasModeFilter;
14
15 /**
16 * The checkbox.
17 *
18 * @var bool
19 */
20 public $checkbox = true;
21
22 /**
23 * The error message.
24 *
25 * @var string
26 */
27 public $error = '';
28
29 /**
30 * The BulkActionService instance.
31 *
32 * @var \SureCart\Background\BulkActionService
33 */
34 public $bulk_actions = null;
35
36 /**
37 * Constructor.
38 *
39 * @param \SureCart\Background\BulkActionService $bulk_actions The BulkActionService instance.
40 */
41 public function __construct( \SureCart\Background\BulkActionService $bulk_actions ) {
42 parent::__construct();
43
44 $this->bulk_actions = $bulk_actions;
45
46 add_action( 'admin_notices', [ $this, 'show_bulk_action_admin_notice' ] );
47 }
48
49 /**
50 * Show bulk action admin notice.
51 */
52 public function show_bulk_action_admin_notice() {
53 $this->bulk_actions->showBulkActionAdminNotice( 'delete_customers' );
54 }
55
56 /**
57 * Prepare the items for the table to process
58 *
59 * @return Void
60 */
61 public function prepare_items() {
62 $columns = $this->get_columns();
63 $hidden = $this->get_hidden_columns();
64 $sortable = $this->get_sortable_columns();
65
66 $this->_column_headers = array( $columns, $hidden, $sortable );
67
68 $query = $this->table_data();
69 if ( is_wp_error( $query ) ) {
70 $this->error = $query->get_error_message();
71 $this->items = [];
72 return;
73 }
74
75 $this->set_pagination_args(
76 [
77 'total_items' => $query->pagination->count,
78 'per_page' => $this->get_items_per_page( 'customerss' ),
79 ]
80 );
81
82 $this->items = $query->data;
83 }
84
85 /**
86 * Override the parent columns method. Defines the columns to use in your listing table
87 *
88 * @return array
89 */
90 public function get_columns() {
91 return array_merge(
92 [
93 'cb' => '<input type="checkbox" />',
94 'name' => __( 'Name', 'surecart' ),
95 'email' => __( 'Email', 'surecart' ),
96 'created' => __( 'Created', 'surecart' ),
97 'mode' => '',
98 ],
99 parent::get_columns()
100 );
101 }
102
103 /**
104 * Displays the checkbox column.
105 *
106 * @param Customer $customer The customer model.
107 */
108 public function column_cb( $customer ) {
109 ?>
110 <label class="screen-reader-text" for="cb-select-<?php echo esc_attr( $customer['id'] ); ?>"><?php esc_html_e( 'Select customer', 'surecart' ); ?></label>
111 <input id="cb-select-<?php echo esc_attr( $customer['id'] ); ?>" type="checkbox" name="bulk_action_customer_ids[]" value="<?php echo esc_attr( $customer['id'] ); ?>" />
112 <?php
113 }
114
115 /**
116 * Define which columns are hidden
117 *
118 * @return array
119 */
120 public function get_hidden_columns() {
121 return array();
122 }
123
124 /**
125 * Define the sortable columns
126 *
127 * @return array
128 */
129 public function get_sortable_columns() {
130 return array( 'title' => array( 'title', false ) );
131 }
132
133 /**
134 * Get the table data
135 *
136 * @return object|\WP_Error
137 */
138 private function table_data() {
139 $mode = sanitize_text_field( wp_unslash( $_GET['mode'] ?? '' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
140 $conditions = array(
141 'query' => $this->get_search_query(),
142 );
143
144 if ( ! empty( $mode ) ) {
145 $conditions['live_mode'] = 'live' === $mode;
146 }
147
148 return Customer::where( $conditions )
149 ->paginate(
150 [
151 'per_page' => $this->get_items_per_page( 'customers' ),
152 'page' => $this->get_pagenum(),
153 ]
154 );
155 }
156
157 /**
158 * Nothing found.
159 *
160 * @return void
161 */
162 public function no_items() {
163 if ( $this->error ) {
164 echo esc_html( $this->error );
165 return;
166 }
167 echo esc_html_e( 'No customers found.', 'surecart' );
168 }
169
170 /**
171 * The customer email.
172 *
173 * @param \SureCart\Models\Customer $customer The customer model.
174 *
175 * @return string
176 */
177 public function column_email( $customer ) {
178 return sanitize_email( $customer->email );
179 }
180
181 /**
182 * Name column
183 *
184 * @param \SureCart\Models\Customer $customer Customer model.
185 *
186 * @return string
187 */
188 public function column_name( $customer ) {
189 $pending_record_ids = $this->bulk_actions->getRecordIds( 'delete_customers', 'pending' );
190 $processing_record_ids = $this->bulk_actions->getRecordIds( 'delete_customers', 'processing' );
191 $succeeded_record_ids = $this->bulk_actions->getRecordIds( 'delete_customers', 'succeeded' );
192 $bulk_status = '';
193 if ( ! empty( $pending_record_ids ) && in_array( $customer->id, $pending_record_ids, true ) ) {
194 $bulk_status = 'pending';
195 } elseif ( ! empty( $processing_record_ids ) && in_array( $customer->id, $processing_record_ids, true ) ) {
196 $bulk_status = 'processing';
197 } elseif ( ! empty( $succeeded_record_ids ) && in_array( $customer->id, $succeeded_record_ids, true ) ) {
198 $bulk_status = 'succeeded';
199 }
200
201 ob_start();
202 ?>
203 <a class="row-title" aria-label="<?php esc_attr_e( 'Edit Customer', 'surecart' ); ?>" href="<?php echo esc_url( \SureCart::getUrl()->edit( 'customers', $customer->id ) ); ?>">
204 <?php echo esc_html( $customer->name ?? $customer->email ); ?>
205 </a>
206
207 <?php
208 echo wp_kses_post( $this->getRowActions( $customer, $bulk_status ) );
209 ?>
210
211 <?php
212 return ob_get_clean();
213 }
214
215 /**
216 * Get row actions.
217 *
218 * @param \SureCart\Models\Customer $customer Customer model.
219 * @param string $bulk_status Bulk status.
220 *
221 * @return string
222 */
223 public function getRowActions( $customer, $bulk_status ) {
224 if ( 'succeeded' === $bulk_status ) {
225 return '<div>' . esc_html__( 'Successfully deleted.', 'surecart' ) . '</div>';
226 }
227
228 if ( 'pending' === $bulk_status || 'processing' === $bulk_status ) {
229 return '<div>' . esc_html__( 'Queued for deletion.', 'surecart' ) . '</div>';
230 }
231
232 return $this->row_actions(
233 [
234 'edit' => '<a href="' . esc_url( \SureCart::getUrl()->edit( 'customers', $customer->id ) ) . '" aria-label="' . esc_attr__( 'Edit Customer', 'surecart' ) . '">' . __( 'Edit', 'surecart' ) . '</a>',
235 ],
236 );
237 }
238
239 /**
240 * Define what data to show on each column of the table
241 *
242 * @param Customer $customer Customer model.
243 * @param string $column_name - Current column name.
244 *
245 * @return mixed
246 */
247 public function column_default( $customer, $column_name ) {
248 // Call the parent method to handle custom columns.
249 parent::column_default( $customer, $column_name );
250
251 switch ( $column_name ) {
252 case 'description':
253 return $customer->$column_name ?? '';
254 }
255 }
256
257 /**
258 * Displays extra table navigation.
259 *
260 * @param string $which Top or bottom placement.
261 */
262 protected function extra_tablenav( $which ) {
263 ?>
264 <input type="hidden" name="page" value="sc-customers" />
265
266 <div class="alignleft actions">
267 <?php
268 if ( 'top' === $which ) {
269 ob_start();
270 $this->mode_dropdown();
271
272 /**
273 * Fires before the Filter button on the Posts and Pages list tables.
274 *
275 * The Filter button allows sorting by date and/or category on the
276 * Posts list table, and sorting by date on the Pages list table.
277 *
278 * @since 2.1.0
279 * @since 4.4.0 The `$post_type` parameter was added.
280 * @since 4.6.0 The `$which` parameter was added.
281 *
282 * @param string $post_type The post type slug.
283 * @param string $which The location of the extra table nav markup:
284 * 'top' or 'bottom' for WP_Posts_List_Table,
285 * 'bar' for WP_Media_List_Table.
286 */
287 do_action( 'restrict_manage_customers', $this->screen->post_type, $which );
288
289 $output = ob_get_clean();
290
291 if ( ! empty( $output ) ) {
292 echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
293 submit_button( __( 'Filter', 'surecart' ), '', 'filter_action', false, array( 'id' => 'filter-by-mode-submit' ) );
294 }
295 }
296
297 ?>
298 </div>
299
300 <?php
301 /**
302 * Fires immediately following the closing "actions" div in the tablenav
303 * for the affiliate referrals list table.
304 *
305 * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
306 */
307 do_action( 'manage_customers_extra_tablenav', $which );
308 }
309
310 /**
311 * Get bulk actions.
312 *
313 * @return array
314 */
315 protected function get_bulk_actions() {
316 $actions = array();
317 $actions['delete'] = __( 'Delete permanently', 'surecart' );
318 return $actions;
319 }
320
321 /**
322 * Gets the current action selected from the bulk actions dropdown.
323 *
324 * @return string|false The action name. False if no action was selected.
325 */
326 public function current_action() {
327 if ( ! empty( $_REQUEST['delete_all'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
328 return 'delete_all';
329 }
330
331 return parent::current_action();
332 }
333 }
334