PluginProbe
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More / 2.2.1
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More v2.2.1
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 1.0.5 1.0.6 All 66 releases
better-payment / includes / Admin / Settings.php

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

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