PluginProbe
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More / 0.0.5
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More v0.0.5
2.4.1 2.4.0 2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.2 2.2.1 2.2.0 2.1.2 2.1.1 trunk 0.0.1 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 All 68 releases
better-payment / includes / Admin / Better_Payment_Settings.php

Better_Payment_Settings.php in Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More 0.0.5, at includes/Admin/Better_Payment_Settings.php

648 lines 21.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Better_Payment\Lite\Admin;
4
5 use Better_Payment\Lite\Classes\Better_Payment_Helper;
6 use Better_Payment\Lite\Controller;
7
8 /**
9 * Exit if accessed directly
10 */
11 if (!defined('ABSPATH')) {
12 exit;
13 }
14
15 /**
16 * The plugin settings class
17 *
18 * @since 0.0.1
19 */
20 class Better_Payment_Settings extends Controller
21 {
22 var $page_slug_prefix = '';
23 /**
24 * @var int|string
25 */
26
27 protected $file_version;
28
29 /**
30 * Constructor
31 *
32 * @since 0.0.1
33 */
34 public function __construct($page_slug_prefix = 'better-payment')
35 {
36 $this->page_slug_prefix = $page_slug_prefix;
37 $this->file_version = defined('WP_DEBUG') && WP_DEBUG ? time() : BETTER_PAYMENT_VERSION;
38
39 add_action('admin_menu', [$this, 'register_menu']);
40 add_action('wp_ajax_better_payment_settings_action', [$this, 'save_settings_ajax']);
41
42 //Transactions page: actions
43 add_action('wp_ajax_better-payment-delete-transaction', [$this, 'admin_transaction_delete']);
44 add_action('wp_ajax_better-payment-filter-transaction', [$this, 'admin_transaction_filter']);
45 add_action('wp_ajax_better-payment-view-transaction', [$this, 'admin_transaction_view']);
46
47 //EL Editor Style
48 add_action('elementor/editor/before_enqueue_scripts', [$this, 'editor_enqueue_scripts']);
49 }
50
51 /**
52 * Enqueue editor scripts
53 *
54 * @since 0.0.1
55 */
56 public function editor_enqueue_scripts()
57 {
58 // bp icon font
59 wp_enqueue_style(
60 'bp-icon-admin-editor',
61 BETTER_PAYMENT_ASSETS . '/icon/style.min.css',
62 false
63 );
64 }
65
66 /**
67 * Register menu
68 *
69 * @since 0.0.1
70 */
71 public function register_menu()
72 {
73 add_menu_page(
74 __('Better Payment', 'better-payment'),
75 __('Better Payment', 'better-payment'),
76 'manage_options',
77 $this->page_slug_prefix . '-settings',
78 [$this, 'render_better_payment_admin_pages'],
79 BETTER_PAYMENT_ASSETS . '/img/better-payment-icon-white-small.png',
80 64
81 );
82
83 add_submenu_page(
84 $this->page_slug_prefix . '-settings',
85 __('Settings', 'better-payment'),
86 __('Settings', 'better-payment'),
87 'manage_options',
88 $this->page_slug_prefix . '-settings',
89 [$this, 'render_better_payment_admin_pages'],
90 64
91 );
92
93 $settings = apply_filters( 'better_payment/admin/get_submenu_page_list', array(
94 $this->page_slug_prefix . '-transactions' => array(
95 'title' => __('Transactions', 'better-payment'),
96 'capability' => 'manage_options',
97 'callback' => [$this, 'render_better_payment_admin_pages'],
98 ),
99 ), $this->page_slug_prefix );
100
101 foreach( $settings as $slug => $setting ) {
102 $cap = isset( $setting['capability'] ) ? $setting['capability'] : 'manage_options';
103 add_submenu_page( $this->page_slug_prefix . '-settings', $setting['title'], $setting['title'], $cap, $slug, $setting['callback'] );
104 }
105 }
106
107 /**
108 * Admin pages
109 *
110 * @since 0.0.1
111 */
112 public function render_better_payment_admin_pages()
113 {
114 $bp_admin_saved_settings = Better_Payment_DB::get_settings();
115 $bp_admin_all_transactions_count = Better_Payment_DB::get_transaction_count();
116 $bp_admin_completed_transactions_count = Better_Payment_DB::get_transaction_count('', 'v2', 0, 'completed');
117 $bp_admin_incomplete_transactions_count = Better_Payment_DB::get_transaction_count('', 'v2', 1, 'incomplete');
118
119 $template = !empty($_GET['page']) ? sanitize_text_field($_GET['page']) : 'better-payment-settings';
120
121 $menuObj = new Menu();
122 $menu_slugs = $menuObj->better_payment_menu_slugs();
123 $template = in_array($template, $menu_slugs) ? $template : 'better-payment-settings';
124
125 $transaction_pagination_args = [];
126 $bp_admin_all_transactions_paginations = '';
127 $viewMode = 0;
128
129 if ($template == 'better-payment-transactions') {
130 //Transactions Page
131 $action = isset($_GET['action']) ? sanitize_text_field($_GET['action']) : 'list';
132 $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
133 $template = 'better-payment-transaction';
134
135 switch ($action) {
136 case 'edit':
137 $template .= '-edit';
138 break;
139
140 case 'view':
141 $viewMode = 1;
142 $template .= '-view';
143 break;
144
145 default:
146 $template .= '-list';
147 break;
148 }
149
150 $ui_postfix = '';
151 $template .= $ui_postfix;
152
153 //Pagination
154 $transaction_pagination_paged = isset($_GET['paged']) && intval($_GET['paged']) > 1 ? intval($_GET['paged']) : 1;
155 $transaction_pagination_order = isset($_GET['order']) ? sanitize_text_field($_GET['order']) : 'DESC';
156 $transaction_pagination_orderby = isset($_GET['orderby']) ? sanitize_text_field($_GET['orderby']) : 'id';
157 $transaction_pagination_per_page = isset($_GET['per_page']) ? intval($_GET['per_page']) : 20;
158 $transaction_pagination_source = isset($_GET['source']) ? sanitize_text_field($_GET['source']) : '';
159 $transaction_pagination_status = isset($_GET['status']) ? sanitize_text_field($_GET['status']) : 'all';
160 $transaction_pagination_search_text = isset($_GET['search_text']) ? sanitize_text_field($_GET['search_text']) : '';
161
162 if ($transaction_pagination_paged) {
163 $args =
164 $transaction_pagination_args = [
165 'search_text' => $transaction_pagination_search_text,
166 'per_page' => $transaction_pagination_per_page,
167 'paged' => $transaction_pagination_paged,
168 'number' => $transaction_pagination_per_page,
169 'offset' => ($transaction_pagination_paged - 1) * $transaction_pagination_per_page,
170 'orderby' => $transaction_pagination_orderby,
171 'order' => $transaction_pagination_order,
172 'status' => $transaction_pagination_status
173 ];
174 }
175 $bp_admin_filtered_all_transactions_count = Better_Payment_DB::get_transaction_count( $transaction_pagination_args, 'v2', 1);
176 $bp_admin_filtered_all_transactions_count = $transaction_pagination_search_text ? $bp_admin_filtered_all_transactions_count : $bp_admin_all_transactions_count;
177
178 $bp_admin_all_transactions_paginations = self::bp_paginate_links( $transaction_pagination_args, $bp_admin_filtered_all_transactions_count );
179 $paginations_showing_entities_html = self::bp_paginate_showing_entities_html( $transaction_pagination_args, $bp_admin_filtered_all_transactions_count );
180
181 $fetchNullIfIncomplete = $transaction_pagination_status === 'incomplete' ? 1 : 0;
182 $bp_admin_all_transactions = Better_Payment_DB::get_transactions($transaction_pagination_args, 0, 'v2', $fetchNullIfIncomplete);
183 }
184
185 $bp_admin_all_transactions_analytics = Better_Payment_DB::get_transactions_analytics();
186
187 //Transaction details/view page
188 if($viewMode){
189 $transaction_id = isset($_REQUEST['id']) ? (int) sanitize_text_field($_REQUEST['id']) : 0;
190 if($transaction_id == 0){
191 _e('Record not found!', 'better-payment');
192 exit;
193 }
194 $bp_admin_transaction = Better_Payment_DB::get_transaction($transaction_id);
195
196 //Fetch referer content
197 $better_payment_helper = new Better_Payment_Helper();
198 $bp_admin_transaction_form_fields = is_object($bp_admin_transaction) && isset($bp_admin_transaction) ? maybe_unserialize($bp_admin_transaction->form_fields_info) : [];
199 $referer_page_id = !empty($bp_admin_transaction_form_fields['referer_page_id']) ? $bp_admin_transaction_form_fields['referer_page_id'] : '';
200 $referer_widget_id = !empty($bp_admin_transaction_form_fields['referer_widget_id']) ? $bp_admin_transaction_form_fields['referer_widget_id'] : '';
201
202 $bp_transaction_referer_content = '';
203
204 if($referer_page_id != '' && $referer_widget_id != ''){
205 $bp_transaction_referer_content = $better_payment_helper->get_better_payment_widget_settings($referer_page_id, $referer_widget_id);
206 }
207 }
208
209 include_once BETTER_PAYMENT_ADMIN_VIEWS_PATH . '/' . "$template.php";
210 }
211
212 /**
213 * Settings save ajax
214 *
215 * @since 0.0.1
216 */
217 public static function save_settings_ajax()
218 {
219 /**
220 * Verify the Nonce
221 */
222 if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'better_payment_admin_nonce')) {
223 return;
224 }
225
226 if (isset($_POST['form_data']) && $_POST['reset_button'] == 'true') {
227 self::save_default_settings(1);
228 wp_send_json_success("success");
229 } else if (isset($_POST['form_data'])) {
230 self::save_settings($_POST['form_data']);
231 wp_send_json_success("success");
232 } else {
233 wp_send_json_error("error");
234 }
235
236 die;
237 }
238
239 /**
240 * This function is responsible for
241 * save all settings data, including checking the disable field to prevent
242 * users manipulation.
243 *
244 * @param array $values
245 * @return void
246 * @since 0.0.1
247 */
248 public static function save_settings($posted_fields = [])
249 {
250 $saved_settings = Better_Payment_DB::get_settings();
251 $default_settings = Better_Payment_DB::default_settings();
252
253 $saved_settings = wp_parse_args($default_settings, $saved_settings); // newly added default values to merge
254
255 $data = [];
256 $new_posted_fields = [];
257
258 if (!empty($posted_fields)) {
259 foreach ($posted_fields as $posted_field) {
260 $new_posted_fields[$posted_field['name']] = $posted_field['value'];
261 }
262 }
263
264 if (count($new_posted_fields)) {
265
266 foreach ($saved_settings as $saved_settings_item_key => $saved_settings_item_value) {
267 if (isset($new_posted_fields[$saved_settings_item_key]) && $new_posted_fields[$saved_settings_item_key] != '') {
268 $data[$saved_settings_item_key] = self::sanitize_field($saved_settings_item_key, $new_posted_fields[$saved_settings_item_key]);
269 } else {
270 $data[$saved_settings_item_key] = $saved_settings_item_value;
271 }
272 }
273 }
274
275 if (count($data)) {
276 Better_Payment_DB::update_settings($data);
277 }
278
279 return;
280 }
281
282 /**
283 * Save default settings
284 *
285 * @since 0.0.1
286 */
287 public static function save_default_settings($reset = 0)
288 {
289 $default_settings = Better_Payment_DB::default_settings();
290 $saved_settings = Better_Payment_DB::get_settings();
291
292 //Do nothing : if already saved && not reset
293 if (!empty($saved_settings) && (!$reset)) {
294 return false;
295 }
296
297 return Better_Payment_DB::update_settings($default_settings);
298 }
299
300 /**
301 * transaction template
302 *
303 * @since 0.0.1
304 */
305 public function admin_transaction_view()
306 {
307 $response = [];
308
309 if (!wp_verify_nonce($_REQUEST['nonce'], 'better_payment_admin_nonce')) {
310 $response['message'] = __("Access Denied!", 'better-payment');
311 wp_send_json_error($response);
312 }
313
314 if (!current_user_can('manage_options')) {
315 $response['message'] = __("Access Denied!", 'better-payment');
316 wp_send_json_error($response);
317 }
318
319 $transaction_id = isset($_REQUEST['id']) ? (int) sanitize_text_field($_REQUEST['id']) : 0;
320
321 $bp_admin_transaction = '';
322
323 if($transaction_id == 0){
324 return __('Record not found!', 'better-payment');
325 }
326
327 $bp_admin_transaction = Better_Payment_DB::get_transaction($transaction_id);
328
329 include_once BETTER_PAYMENT_ADMIN_VIEWS_PATH . "/template-transaction-view.php";
330 exit;
331 }
332
333 /**
334 * Transaction delete
335 *
336 * @since 0.0.1
337 */
338 public function admin_transaction_delete()
339 {
340 $response = [];
341
342 if (!wp_verify_nonce($_REQUEST['nonce'], 'better_payment_admin_nonce')) {
343 $response['message'] = __("Access Denied!", 'better-payment');
344 wp_send_json_error($response);
345 }
346
347 if (!current_user_can('manage_options')) {
348 $response['message'] = __("Access Denied!", 'better-payment');
349 wp_send_json_error($response);
350 }
351
352 $id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
353
354 if (Better_Payment_DB::delete_transaction($id)) {
355 $response['message'] = __("Deleted successfully", 'better-payment');
356
357 $current_page = sanitize_text_field($_REQUEST['currentPage']);
358 $per_page = sanitize_text_field($_REQUEST['perPage']);
359 $total_entry_count = sanitize_text_field($_REQUEST['totalEntryCount']);
360
361 $args = [
362 'paged' => $current_page,
363 'per_page' => $per_page,
364 ];
365
366 $response['pagination_showing_entities_html'] = self::bp_paginate_showing_entities_html($args, intval($total_entry_count) - 1);
367
368 wp_send_json_success($response);
369 } else {
370 $response['message'] = __("Something went wrong!", 'better-payment');
371 wp_send_json_error( $response );
372 }
373 }
374
375 /**
376 * Transaction filter
377 *
378 * @since 0.0.1
379 */
380 public function admin_transaction_filter()
381 {
382 $response = [];
383
384 if (!wp_verify_nonce($_REQUEST['nonce'], 'better_payment_admin_nonce')) {
385 $response['message'] = __("Access Denied!", 'better-payment');
386 wp_send_json_error($response);
387 }
388
389 if (!current_user_can('manage_options')) {
390 $response['message'] = __("Access Denied!", 'better-payment');
391 wp_send_json_error($response);
392 }
393
394 $filter_search_text = ( isset($_REQUEST['filterFormData']['search_text']) && !empty($_REQUEST['filterFormData']['search_text']) ) ? sanitize_text_field( $_REQUEST['filterFormData']['search_text'] ) : '';
395 $filter_payment_date_from = ( isset($_REQUEST['filterFormData']['payment_date_from']) && !empty($_REQUEST['filterFormData']['payment_date_from']) ) ? sanitize_text_field( $_REQUEST['filterFormData']['payment_date_from'] ) : '';
396 $filter_payment_date_to = ( isset($_REQUEST['filterFormData']['payment_date_to']) && !empty($_REQUEST['filterFormData']['payment_date_to']) ) ? sanitize_text_field( $_REQUEST['filterFormData']['payment_date_to'] ) : '';
397 $filter_order_by = ( isset($_REQUEST['filterFormData']['order_by']) && !empty($_REQUEST['filterFormData']['order_by']) ) ? sanitize_text_field( $_REQUEST['filterFormData']['order_by'] ) : 'id';
398 $filter_order = ( isset($_REQUEST['filterFormData']['order']) && !empty($_REQUEST['filterFormData']['order']) ) ? sanitize_text_field( $_REQUEST['filterFormData']['order'] ) : 'DESC';
399 $filter_status = ( isset($_REQUEST['filterFormData']['status']) && !empty($_REQUEST['filterFormData']['status']) ) ? sanitize_text_field( $_REQUEST['filterFormData']['status'] ) : 'all';
400 $filter_source = ( isset($_REQUEST['filterFormData']['source']) && !empty($_REQUEST['filterFormData']['source']) ) ? sanitize_text_field( $_REQUEST['filterFormData']['source'] ) : '';
401 $filter_paged = ( isset($_REQUEST['filterFormData']['paged']) && !empty($_REQUEST['filterFormData']['paged']) ) ? intval( $_REQUEST['filterFormData']['paged'] ) : 1;
402 $filter_per_page = ( isset($_REQUEST['filterFormData']['per_page']) && !empty($_REQUEST['filterFormData']['per_page']) ) ? intval( $_REQUEST['filterFormData']['per_page'] ) : 20;
403
404 $args = array(
405 'search_text' => $filter_search_text,
406 'payment_date_from' => $filter_payment_date_from,
407 'payment_date_to' => $filter_payment_date_to,
408 'order_by' => $filter_order_by,
409 'order' => $filter_order,
410 'status' => $filter_status,
411 'source' => $filter_source,
412 'paged' => $filter_paged,
413 'per_page' => $filter_per_page,
414 );
415
416 if( !empty($args['payment_date_from']) ){
417 $args['payment_date_from'] = date('Y-m-d H:i:s',strtotime($args['payment_date_from']));
418 }
419 if( !empty($args['payment_date_to']) ){
420 $args['payment_date_to'] = date('Y-m-d H:i:s',strtotime($args['payment_date_to']));
421 }
422
423 $args['offset'] = ( $args['paged'] - 1) * $args['per_page'];
424
425 $fetchNullIfIncomplete = !empty($args['status']) && 'incomplete' === $args['status'] ? 1 : 0;
426 $bp_admin_all_transactions = Better_Payment_DB::get_transactions($args, 0, 'v2', $fetchNullIfIncomplete);
427
428 //Pagination
429 $fetchNull = !empty($args['status']) && 'incomplete' === $args['status'] ? 1 : 0;
430 $only_incompleted_transactions = !empty($args['status']) && 'incomplete' === $args['status'] ? 1 : 0;
431 $only_completed_transactions = !empty($args['status']) && 'completed' === $args['status'] ? 1 : 0;
432
433 $bp_admin_all_transactions_count = Better_Payment_DB::get_transaction_count($args, 'v2', $fetchNull);
434 $bp_admin_all_transactions_paginations = self::bp_paginate_links($args, $bp_admin_all_transactions_count );
435 $paginations_showing_entities_html = self::bp_paginate_showing_entities_html($args, $bp_admin_all_transactions_count );
436
437 $bp_admin_completed_transactions_count = Better_Payment_DB::get_transaction_count($args, 'v2', 0, 'completed');
438 $bp_admin_incomplete_transactions_count = Better_Payment_DB::get_transaction_count($args, 'v2', 1, 'incomplete');
439
440 $bp_admin_completed_transactions_count = $only_incompleted_transactions ? 0 : $bp_admin_completed_transactions_count;
441 $bp_admin_incomplete_transactions_count = $only_completed_transactions ? 0 : $bp_admin_incomplete_transactions_count;
442
443 include_once BETTER_PAYMENT_ADMIN_VIEWS_PATH . "/template-transaction-list.php";
444 exit;
445 }
446
447 /**
448 * Paging links
449 *
450 * @since 0.0.1
451 */
452 public static function bp_paginate_links($args, $total_entry_count )
453 {
454 $pagination_html = '';
455
456 $defaults = array(
457 'search_text' => '',
458 'per_page' => 20,
459 'paged' => 1,
460 );
461
462 $args = wp_parse_args($args, $defaults);
463
464 $current_page = intval($args['paged']);
465 $per_page = intval($args['per_page']);
466 $total_entry_count = intval($total_entry_count);
467 $total_page_count = ceil($total_entry_count / $per_page);
468
469 $previous_page = $current_page - 1;
470 $next_page = $current_page + 1;
471
472 $prev_button_disabled = (1 == $current_page) ? 'disabled' : '';
473 $next_button_disabled = $total_page_count == $current_page ? 'disabled' : '';
474
475 $prev_button_link = ($current_page > 1) ? self::get_pagination_link($args, $previous_page) : "#";
476 $next_button_link = ($current_page < $total_page_count) ? self::get_pagination_link($args, $next_page) : "#";
477
478 $showing_entry_from = $per_page * ($current_page - 1) + 1;
479
480 $pagination_html .= "<ul class=''>";
481
482 //Showing entries content
483 if ($showing_entry_from > $total_entry_count) {
484 return '';
485 }
486
487 if ( $total_page_count == 1 ) {
488 return '';
489 }
490
491 //Previous button
492 if($current_page > 1){
493 $pagination_html .= "<li><a href='$prev_button_link' $prev_button_disabled class='pagination-previous'><i class='bp-icon bp-caret-left'></i></a></li>";
494 }
495
496 //Pagination links
497 for ($i = 1; $i <= $total_page_count; $i++) {
498 $is_current_class = ($i == $current_page) ? 'is-current active' : '';
499 $page_link = self::get_pagination_link($args, $i);
500
501 if ( $total_page_count > 5 ) {
502 $first_page = 1;
503 $last_page = $total_page_count;
504
505 switch( $i ){
506 case $first_page :
507 case $last_page :
508 case $current_page - 2 :
509 case $current_page - 1 :
510 case $current_page :
511 case $current_page + 1 :
512 case $current_page + 2 :
513 case $i + 3 && $current_page < 6 && $i < 6:
514 case $i + 4 && $current_page < 6 && $i < 6:
515 $pagination_html .= "
516 <li>
517 <a href=\"$page_link\" class=\"pagination-link $is_current_class \" aria-label=\"Page $i\"> $i </a>
518 </li>
519 ";
520 break;
521 case $current_page - 3 :
522 case $current_page + 3 :
523 $pagination_html .= "
524 <li>
525 ...
526 </li>
527 ";
528 break;
529 default:
530 break;
531 }
532
533 } else {
534 $pagination_html .= "
535 <li>
536 <a href=\"$page_link\" class=\"pagination-link $is_current_class \" aria-label=\"Page $i\"> $i </a>
537 </li>
538 ";
539 }
540 }
541
542 //Next button
543 if($current_page < $total_page_count){
544 $pagination_html .= "<li><a href='$next_button_link' class='pagination-next' $next_button_disabled><i class='bp-icon bp-caret-right'></i></a></li>";
545 }
546
547 $pagination_html .= "</ul>";
548
549 return $pagination_html;
550 }
551
552 protected static function get_pagination_link( $args, $target_paged ){
553 $per_page = ! empty( $args['per_page'] ) ? intval( $args['per_page'] ) : 20;
554 $search_text = ! empty( $args['search_text'] ) ? sanitize_text_field( $args['search_text'] ) : '';
555 $valid_search_text = $search_text != '' && strlen($search_text) >= 2;
556
557 $button_link = admin_url("admin.php?page=better-payment-transactions&per_page={$per_page}&paged={$target_paged}");
558
559 if($valid_search_text){
560 $button_link = admin_url("admin.php?page=better-payment-transactions&per_page={$per_page}&paged={$target_paged}&search_text={$search_text}");
561 }
562
563 return $button_link;
564 }
565
566 /**
567 * Pagination showing entities html
568 *
569 * @since 0.0.1
570 */
571 public static function bp_paginate_showing_entities_html($args, $total_entry_count)
572 {
573 $pagination_showing_entries_html = '';
574
575 $defaults = array(
576 'per_page' => 20,
577 'paged' => 1,
578 );
579
580 $args = wp_parse_args($args, $defaults);
581
582 $current_page = intval($args['paged']);
583 $per_page = intval($args['per_page']);
584
585 $total_entry_count = intval($total_entry_count);
586 $total_page_count = ceil($total_entry_count / $per_page);
587
588 $showing_entry_from = $per_page * ($current_page - 1) + 1;
589 $showing_entry_to = $per_page * $current_page;
590
591 //Showing entries content
592 if ($total_page_count == 1 || $current_page == $total_page_count) {
593 $showing_entry_to = $total_entry_count;
594 }
595
596 $pagination_showing_entries_html = __("Showing {$showing_entry_from}-{$showing_entry_to} of $total_entry_count entries", "better-payment");
597
598 if ($showing_entry_from > $total_entry_count) {
599 return '';
600 }
601
602 if ($total_page_count == 1) {
603 return $pagination_showing_entries_html;
604 }
605
606 return $pagination_showing_entries_html;
607 }
608
609 /**
610 * This function is responsible for the data sanitization
611 *
612 * @param array $field
613 * @param string|array $value
614 * @return string|array
615 * @since 0.0.1
616 */
617 public static function sanitize_field($field, $value)
618 {
619 if (isset($field['sanitize']) && !empty($field['sanitize'])) {
620 if (function_exists($field['sanitize'])) {
621 $value = call_user_func($field['sanitize'], $value);
622 }
623 return $value;
624 }
625
626 if (is_array($field) && isset($field['type'])) {
627 switch ($field['type']) {
628 case 'text':
629 $value = sanitize_text_field($value);
630 break;
631 case 'textarea':
632 $value = sanitize_textarea_field($value);
633 break;
634 case 'email':
635 $value = sanitize_email($value);
636 break;
637 default:
638 return $value;
639 break;
640 }
641 } else {
642 $value = sanitize_text_field($value);
643 }
644
645 return $value;
646 }
647 }
648