| 1 |
<?php |
| 2 |
defined('ABSPATH') || exit(); |
| 3 |
|
| 4 |
class BetterPayment_Settings |
| 5 |
{ |
| 6 |
var $page_slug_prefix = ''; |
| 7 |
/** |
| 8 |
* @var int|string |
| 9 |
*/ |
| 10 |
|
| 11 |
protected $file_version; |
| 12 |
|
| 13 |
public function __construct($page_slug_prefix = 'betterpayment') |
| 14 |
{ |
| 15 |
$this->page_slug_prefix = $page_slug_prefix; |
| 16 |
|
| 17 |
add_action('admin_enqueue_scripts', [$this, 'handle_scripts_and_styles']); |
| 18 |
$this->file_version = defined('WP_DEBUG') && WP_DEBUG ? time() : WPBP_PLUGIN_VERSION; |
| 19 |
|
| 20 |
add_action('admin_menu', [$this, 'register_menu']); |
| 21 |
add_action('wp_ajax_betterpayment_settings_action', [$this, 'save_settings_ajax']); |
| 22 |
|
| 23 |
//Transactions page: actions |
| 24 |
add_action('wp_ajax_betterpayment-delete-transaction', [$this, 'admin_transaction_delete']); |
| 25 |
add_action('wp_ajax_betterpayment-filter-transaction', [$this, 'admin_transaction_filter']); |
| 26 |
add_action('wp_ajax_betterpayment-view-transaction', [$this, 'admin_transaction_view']); |
| 27 |
|
| 28 |
//EL Editor Style |
| 29 |
add_action('elementor/editor/before_enqueue_scripts', [$this, 'editor_enqueue_scripts']); |
| 30 |
} |
| 31 |
|
| 32 |
public function handle_scripts_and_styles() |
| 33 |
{ |
| 34 |
$menu_slugs = $this->betterpayment_menu_slugs(); |
| 35 |
|
| 36 |
if (!empty($_REQUEST['page']) && in_array($_REQUEST['page'], $menu_slugs)) { |
| 37 |
$this->enqueue_styles(); |
| 38 |
$this->enqueue_scripts(); |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
public function enqueue_scripts() |
| 43 |
{ |
| 44 |
wp_enqueue_script('bp-admin-settings', WPBP_ADMIN_ASSET_URL . 'js/admin.min.js', ['jquery'], $this->file_version, true); |
| 45 |
|
| 46 |
wp_localize_script('bp-admin-settings', 'betterpaymentObj', array( |
| 47 |
'nonce' => wp_create_nonce('betterpayment_admin_nonce'), |
| 48 |
'alerts' => [ |
| 49 |
'confirm' => __('Are you sure?', 'better-payment'), |
| 50 |
'confirm_description' => __("You won't be able to revert this!", 'better-payment'), |
| 51 |
'yes' => __('Yes, delete it!', 'better-payment'), |
| 52 |
'no' => __('No, cancel!', 'better-payment'), |
| 53 |
], |
| 54 |
'messages' => [ |
| 55 |
'success' => __('Changes saved successfully!', 'better-payment'), |
| 56 |
'error' => __('Opps! something went wrong!', 'better-payment'), |
| 57 |
'no_action_taken' => __('No action taken!', 'better-payment'), |
| 58 |
] |
| 59 |
)); |
| 60 |
|
| 61 |
wp_enqueue_script('toastr-js-admin', WPBP_PLUGIN_URL . 'asset/vendor/toastr/js/toastr.min.js', array('jquery'), WPBP_PLUGIN_VERSION, true); |
| 62 |
wp_enqueue_script( 'sweetalert2-js', WPBP_PLUGIN_URL . 'asset/vendor/sweetalert2/js/sweetalert2.min.js', array( 'jquery' ), WPBP_PLUGIN_VERSION, true ); |
| 63 |
wp_enqueue_script( 'jquery-ui-datepicker' ); |
| 64 |
} |
| 65 |
|
| 66 |
public function enqueue_styles() |
| 67 |
{ |
| 68 |
wp_register_style( 'jquery-ui', WPBP_PLUGIN_URL . 'asset/vendor/jquery-ui/css/jquery-ui.min.css' ); |
| 69 |
wp_enqueue_style( 'jquery-ui' ); |
| 70 |
|
| 71 |
wp_enqueue_style('bp-settings-style', WPBP_ADMIN_ASSET_URL . 'css/style.min.css', null, $this->file_version); |
| 72 |
wp_enqueue_style('bp-icon-admin', WPBP_ADMIN_ASSET_URL . 'icon/style.min.css'); |
| 73 |
wp_enqueue_style('toastr-css-admin', WPBP_PLUGIN_URL . 'asset/vendor/toastr/css/toastr.min.css'); |
| 74 |
wp_enqueue_style( 'sweetalert2-css', WPBP_PLUGIN_URL . 'asset/vendor/sweetalert2/css/sweetalert2.min.css' ); |
| 75 |
} |
| 76 |
|
| 77 |
// editor styles |
| 78 |
public function editor_enqueue_scripts() |
| 79 |
{ |
| 80 |
// bp icon font |
| 81 |
wp_enqueue_style( |
| 82 |
'bp-icon-admin-editor', |
| 83 |
WPBP_ADMIN_ASSET_URL . 'icon/style.min.css', |
| 84 |
false |
| 85 |
); |
| 86 |
} |
| 87 |
|
| 88 |
public function register_menu() |
| 89 |
{ |
| 90 |
add_menu_page( |
| 91 |
__('BetterPayment', 'better-payment'), |
| 92 |
__('BetterPayment', 'better-payment'), |
| 93 |
'manage_options', |
| 94 |
$this->page_slug_prefix . '-settings', |
| 95 |
[$this, 'render_betterpayment_admin_pages'], |
| 96 |
WPBP_ADMIN_ASSET_URL . 'img/betterpayment-icon-white-small.png', |
| 97 |
64 |
| 98 |
); |
| 99 |
|
| 100 |
add_submenu_page( |
| 101 |
$this->page_slug_prefix . '-settings', |
| 102 |
__('Settings', 'better-payment'), |
| 103 |
__('Settings', 'better-payment'), |
| 104 |
'manage_options', |
| 105 |
$this->page_slug_prefix . '-settings', |
| 106 |
[$this, 'render_betterpayment_admin_pages'], |
| 107 |
64 |
| 108 |
); |
| 109 |
|
| 110 |
add_submenu_page( |
| 111 |
$this->page_slug_prefix . '-settings', |
| 112 |
__('Transactions', 'better-payment'), |
| 113 |
__('Transactions', 'better-payment'), |
| 114 |
'manage_options', |
| 115 |
$this->page_slug_prefix . '-transactions', |
| 116 |
[$this, 'render_betterpayment_admin_pages'], |
| 117 |
64 |
| 118 |
); |
| 119 |
} |
| 120 |
|
| 121 |
public function render_betterpayment_admin_pages() |
| 122 |
{ |
| 123 |
$bp_admin_saved_settings = BetterPayment_DB::get_settings(); |
| 124 |
$bp_admin_all_transactions_count = BetterPayment_DB::get_transaction_count(); |
| 125 |
|
| 126 |
$template = !empty($_GET['page']) ? sanitize_text_field($_GET['page']) : 'betterpayment-settings'; |
| 127 |
|
| 128 |
$menu_slugs = $this->betterpayment_menu_slugs(); |
| 129 |
$template = in_array($template, $menu_slugs) ? $template : 'betterpayment-settings'; |
| 130 |
|
| 131 |
$transaction_pagination_args = []; |
| 132 |
$bp_admin_all_transactions_paginations = ''; |
| 133 |
$viewMode = 0; |
| 134 |
|
| 135 |
if ($template == 'betterpayment-transactions') { |
| 136 |
//Transactions Page |
| 137 |
$action = isset($_GET['action']) ? sanitize_text_field($_GET['action']) : 'list'; |
| 138 |
$id = isset($_GET['id']) ? intval($_GET['id']) : 0; |
| 139 |
$template = 'betterpayment-transaction'; |
| 140 |
|
| 141 |
switch ($action) { |
| 142 |
case 'edit': |
| 143 |
$template .= '-edit'; |
| 144 |
break; |
| 145 |
|
| 146 |
case 'view': |
| 147 |
$viewMode = 1; |
| 148 |
$template .= '-view'; |
| 149 |
break; |
| 150 |
|
| 151 |
default: |
| 152 |
$template .= '-list'; |
| 153 |
break; |
| 154 |
} |
| 155 |
|
| 156 |
$ui_postfix = ''; |
| 157 |
$template .= $ui_postfix; |
| 158 |
|
| 159 |
//Pagination |
| 160 |
$transaction_pagination_paged = isset($_GET['paged']) && intval($_GET['paged']) > 1 ? intval($_GET['paged']) : 1; |
| 161 |
$transaction_pagination_order = isset($_GET['order']) ? sanitize_text_field($_GET['order']) : 'DESC'; |
| 162 |
$transaction_pagination_orderby = isset($_GET['orderby']) ? sanitize_text_field($_GET['orderby']) : 'id'; |
| 163 |
$transaction_pagination_per_page = isset($_GET['per_page']) ? intval($_GET['per_page']) : 20; |
| 164 |
$transaction_pagination_source = isset($_GET['source']) ? sanitize_text_field($_GET['source']) : ''; |
| 165 |
|
| 166 |
if ($transaction_pagination_paged) { |
| 167 |
$transaction_pagination_args = [ |
| 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 |
]; |
| 173 |
} |
| 174 |
$bp_admin_all_transactions_paginations = self::bp_paginate_links($transaction_pagination_paged, $transaction_pagination_per_page, $bp_admin_all_transactions_count); |
| 175 |
$paginations_showing_entities_html = self::bp_paginate_showing_entities_html(intval($transaction_pagination_paged), intval($transaction_pagination_per_page), intval($bp_admin_all_transactions_count)); |
| 176 |
} |
| 177 |
|
| 178 |
$bp_admin_all_transactions = BetterPayment_DB::get_transactions($transaction_pagination_args); |
| 179 |
$bp_admin_all_transactions_analytics = BetterPayment_DB::get_transactions_analytics(); |
| 180 |
|
| 181 |
//Transaction details/view page |
| 182 |
if($viewMode){ |
| 183 |
$transaction_id = isset($_REQUEST['id']) ? (int) sanitize_text_field($_REQUEST['id']) : 0; |
| 184 |
if($transaction_id == 0){ |
| 185 |
_e('Record not found!', 'better-payment'); |
| 186 |
exit; |
| 187 |
} |
| 188 |
$bp_admin_transaction = BetterPayment_DB::get_transaction($transaction_id); |
| 189 |
|
| 190 |
//Fetch referer content |
| 191 |
$betterpayment_helper = new BetterPayment_Helper(); |
| 192 |
$bp_admin_transaction_form_fields = is_object($bp_admin_transaction) && isset($bp_admin_transaction) ? maybe_unserialize($bp_admin_transaction->form_fields_info) : []; |
| 193 |
$referer_page_id = !empty($bp_admin_transaction_form_fields['referer_page_id']) ? $bp_admin_transaction_form_fields['referer_page_id'] : ''; |
| 194 |
$referer_widget_id = !empty($bp_admin_transaction_form_fields['referer_widget_id']) ? $bp_admin_transaction_form_fields['referer_widget_id'] : ''; |
| 195 |
|
| 196 |
$bp_transaction_referer_content = ''; |
| 197 |
|
| 198 |
if($referer_page_id != '' && $referer_widget_id != ''){ |
| 199 |
$bp_transaction_referer_content = $betterpayment_helper->get_betterpayment_widget_settings($referer_page_id, $referer_widget_id); |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
include_once WPBP_ADMIN_VIEW_PATH . "$template.php"; |
| 204 |
} |
| 205 |
|
| 206 |
public function betterpayment_menu_slugs() |
| 207 |
{ |
| 208 |
return ['betterpayment-settings', 'betterpayment-transactions']; |
| 209 |
} |
| 210 |
|
| 211 |
public static function save_settings_ajax() |
| 212 |
{ |
| 213 |
/** |
| 214 |
* Verify the Nonce |
| 215 |
*/ |
| 216 |
if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'betterpayment_admin_nonce')) { |
| 217 |
return; |
| 218 |
} |
| 219 |
|
| 220 |
if (isset($_POST['form_data']) && $_POST['reset_button'] == 'true') { |
| 221 |
self::save_default_settings(1); |
| 222 |
wp_send_json_success("success"); |
| 223 |
} else if (isset($_POST['form_data'])) { |
| 224 |
self::save_settings($_POST['form_data']); |
| 225 |
wp_send_json_success("success"); |
| 226 |
} else { |
| 227 |
wp_send_json_error("error"); |
| 228 |
} |
| 229 |
|
| 230 |
die; |
| 231 |
} |
| 232 |
|
| 233 |
/** |
| 234 |
* This function is responsible for |
| 235 |
* save all settings data, including checking the disable field to prevent |
| 236 |
* users manipulation. |
| 237 |
* |
| 238 |
* @param array $values |
| 239 |
* @return void |
| 240 |
*/ |
| 241 |
public static function save_settings($posted_fields = []) |
| 242 |
{ |
| 243 |
$saved_settings = BetterPayment_DB::get_settings(); |
| 244 |
|
| 245 |
$data = []; |
| 246 |
|
| 247 |
if (!empty($posted_fields)) { |
| 248 |
$new_posted_fields = []; |
| 249 |
foreach ($posted_fields as $posted_field) { |
| 250 |
$new_posted_fields[$posted_field['name']] = $posted_field['value']; |
| 251 |
} |
| 252 |
} |
| 253 |
|
| 254 |
if (count($new_posted_fields)) { |
| 255 |
foreach ($saved_settings as $saved_settings_item_key => $saved_settings_item_value) { |
| 256 |
if (isset($new_posted_fields[$saved_settings_item_key]) && $new_posted_fields[$saved_settings_item_key] != '') { |
| 257 |
$data[$saved_settings_item_key] = self::sanitize_field($saved_settings_item_key, $new_posted_fields[$saved_settings_item_key]); |
| 258 |
} else { |
| 259 |
$data[$saved_settings_item_key] = $saved_settings_item_value; |
| 260 |
} |
| 261 |
} |
| 262 |
} |
| 263 |
|
| 264 |
if (count($data)) { |
| 265 |
BetterPayment_DB::update_settings($data); |
| 266 |
} |
| 267 |
|
| 268 |
return; |
| 269 |
} |
| 270 |
|
| 271 |
public static function save_default_settings($reset = 0) |
| 272 |
{ |
| 273 |
$default_settings = BetterPayment_DB::default_settings(); |
| 274 |
$saved_settings = BetterPayment_DB::get_settings(); |
| 275 |
|
| 276 |
//Do nothing : if already saved && not reset |
| 277 |
if (!empty($saved_settings) && (!$reset)) { |
| 278 |
return false; |
| 279 |
} |
| 280 |
|
| 281 |
return BetterPayment_DB::update_settings($default_settings); |
| 282 |
} |
| 283 |
|
| 284 |
public function admin_transaction_view() |
| 285 |
{ |
| 286 |
$response = []; |
| 287 |
|
| 288 |
if (!wp_verify_nonce($_REQUEST['nonce'], 'betterpayment_admin_nonce')) { |
| 289 |
$response['message'] = __("Access Denied!", 'better-payment'); |
| 290 |
wp_send_json_error($response); |
| 291 |
} |
| 292 |
|
| 293 |
if (!current_user_can('manage_options')) { |
| 294 |
$response['message'] = __("Access Denied!", 'better-payment'); |
| 295 |
wp_send_json_error($response); |
| 296 |
} |
| 297 |
|
| 298 |
$transaction_id = isset($_REQUEST['id']) ? (int) sanitize_text_field($_REQUEST['id']) : 0; |
| 299 |
|
| 300 |
$bp_admin_transaction = ''; |
| 301 |
|
| 302 |
if($transaction_id == 0){ |
| 303 |
return __('Record not found!', 'better-payment'); |
| 304 |
} |
| 305 |
|
| 306 |
$bp_admin_transaction = BetterPayment_DB::get_transaction($transaction_id); |
| 307 |
|
| 308 |
include_once WPBP_ADMIN_VIEW_PATH . "template-transaction-view.php"; |
| 309 |
exit; |
| 310 |
} |
| 311 |
|
| 312 |
public function admin_transaction_delete() |
| 313 |
{ |
| 314 |
$response = []; |
| 315 |
|
| 316 |
if (!wp_verify_nonce($_REQUEST['nonce'], 'betterpayment_admin_nonce')) { |
| 317 |
$response['message'] = __("Access Denied!", 'better-payment'); |
| 318 |
wp_send_json_error($response); |
| 319 |
} |
| 320 |
|
| 321 |
if (!current_user_can('manage_options')) { |
| 322 |
$response['message'] = __("Access Denied!", 'better-payment'); |
| 323 |
wp_send_json_error($response); |
| 324 |
} |
| 325 |
|
| 326 |
$id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0; |
| 327 |
|
| 328 |
if (BetterPayment_DB::delete_transaction($id)) { |
| 329 |
$response['message'] = __("Deleted successfully", 'better-payment'); |
| 330 |
|
| 331 |
$current_page = sanitize_text_field($_REQUEST['currentPage']); |
| 332 |
$per_page = sanitize_text_field($_REQUEST['perPage']); |
| 333 |
$total_entry_count = sanitize_text_field($_REQUEST['totalEntryCount']); |
| 334 |
|
| 335 |
$response['pagination_showing_entities_html'] = self::bp_paginate_showing_entities_html(intval($current_page), intval($per_page), intval($total_entry_count) - 1); |
| 336 |
|
| 337 |
wp_send_json_success($response); |
| 338 |
} else { |
| 339 |
$response['message'] = __("Something went wrong!", 'better-payment'); |
| 340 |
wp_send_json_error( $response ); |
| 341 |
} |
| 342 |
} |
| 343 |
|
| 344 |
public function admin_transaction_filter() |
| 345 |
{ |
| 346 |
$response = []; |
| 347 |
|
| 348 |
if (!wp_verify_nonce($_REQUEST['nonce'], 'betterpayment_admin_nonce')) { |
| 349 |
$response['message'] = __("Access Denied!", 'better-payment'); |
| 350 |
wp_send_json_error($response); |
| 351 |
} |
| 352 |
|
| 353 |
if (!current_user_can('manage_options')) { |
| 354 |
$response['message'] = __("Access Denied!", 'better-payment'); |
| 355 |
wp_send_json_error($response); |
| 356 |
} |
| 357 |
|
| 358 |
$filter_search_text = ( isset($_REQUEST['filterFormData']['search_text']) && !empty($_REQUEST['filterFormData']['search_text']) ) ? sanitize_text_field( $_REQUEST['filterFormData']['search_text'] ) : ''; |
| 359 |
$filter_payment_date_from = ( isset($_REQUEST['filterFormData']['payment_date_from']) && !empty($_REQUEST['filterFormData']['payment_date_from']) ) ? sanitize_text_field( $_REQUEST['filterFormData']['payment_date_from'] ) : ''; |
| 360 |
$filter_payment_date_to = ( isset($_REQUEST['filterFormData']['payment_date_to']) && !empty($_REQUEST['filterFormData']['payment_date_to']) ) ? sanitize_text_field( $_REQUEST['filterFormData']['payment_date_to'] ) : ''; |
| 361 |
$filter_order_by = ( isset($_REQUEST['filterFormData']['order_by']) && !empty($_REQUEST['filterFormData']['order_by']) ) ? sanitize_text_field( $_REQUEST['filterFormData']['order_by'] ) : 'id'; |
| 362 |
$filter_order = ( isset($_REQUEST['filterFormData']['order']) && !empty($_REQUEST['filterFormData']['order']) ) ? sanitize_text_field( $_REQUEST['filterFormData']['order'] ) : 'DESC'; |
| 363 |
$filter_source = ( isset($_REQUEST['filterFormData']['source']) && !empty($_REQUEST['filterFormData']['source']) ) ? sanitize_text_field( $_REQUEST['filterFormData']['source'] ) : ''; |
| 364 |
$filter_paged = ( isset($_REQUEST['filterFormData']['paged']) && !empty($_REQUEST['filterFormData']['paged']) ) ? intval( $_REQUEST['filterFormData']['paged'] ) : 1; |
| 365 |
$filter_per_page = ( isset($_REQUEST['filterFormData']['per_page']) && !empty($_REQUEST['filterFormData']['per_page']) ) ? intval( $_REQUEST['filterFormData']['per_page'] ) : 20; |
| 366 |
|
| 367 |
$args = array( |
| 368 |
'search_text' => $filter_search_text, |
| 369 |
'payment_date_from' => $filter_payment_date_from, |
| 370 |
'payment_date_to' => $filter_payment_date_to, |
| 371 |
'order_by' => $filter_order_by, |
| 372 |
'order' => $filter_order, |
| 373 |
'source' => $filter_source, |
| 374 |
'paged' => $filter_paged, |
| 375 |
'per_page' => $filter_per_page, |
| 376 |
); |
| 377 |
|
| 378 |
if( !empty($args['payment_date_from']) ){ |
| 379 |
$args['payment_date_from'] = date('Y-m-d H:i:s',strtotime($args['payment_date_from'])); |
| 380 |
} |
| 381 |
if( !empty($args['payment_date_to']) ){ |
| 382 |
$args['payment_date_to'] = date('Y-m-d H:i:s',strtotime($args['payment_date_to'])); |
| 383 |
} |
| 384 |
|
| 385 |
$args['offset'] = ( $args['paged'] - 1) * $args['per_page']; |
| 386 |
$bp_admin_all_transactions = BetterPayment_DB::get_transactions($args); |
| 387 |
|
| 388 |
//Pagination |
| 389 |
$bp_admin_all_transactions_count = BetterPayment_DB::get_transaction_count($args); |
| 390 |
$bp_admin_all_transactions_paginations = self::bp_paginate_links($args['paged'], $args['per_page'], $bp_admin_all_transactions_count ); |
| 391 |
$paginations_showing_entities_html = self::bp_paginate_showing_entities_html($args['paged'], $args['per_page'], $bp_admin_all_transactions_count ); |
| 392 |
|
| 393 |
include_once WPBP_ADMIN_VIEW_PATH . "template-transaction-list.php"; |
| 394 |
exit; |
| 395 |
} |
| 396 |
|
| 397 |
public static function bp_paginate_links($current_page, $per_page, $total_entry_count) |
| 398 |
{ |
| 399 |
$pagination_html = ''; |
| 400 |
|
| 401 |
$current_page = intval($current_page); |
| 402 |
$per_page = intval($per_page); |
| 403 |
$total_entry_count = intval($total_entry_count); |
| 404 |
|
| 405 |
$total_page_count = ceil($total_entry_count / $per_page); |
| 406 |
|
| 407 |
$previous_page = $current_page - 1; |
| 408 |
$next_page = $current_page + 1; |
| 409 |
|
| 410 |
$prev_button_disabled = (1 == $current_page) ? 'disabled' : ''; |
| 411 |
$next_button_disabled = $total_page_count == $current_page ? 'disabled' : ''; |
| 412 |
|
| 413 |
$prev_button_link = ($current_page > 1) ? admin_url("admin.php?page=betterpayment-transactions&per_page={$per_page}&paged={$previous_page}") : "#"; |
| 414 |
$next_button_link = ($current_page < $total_page_count) ? admin_url("admin.php?page=betterpayment-transactions&per_page={$per_page}&paged={$next_page}") : "#"; |
| 415 |
|
| 416 |
$showing_entry_from = $per_page * ($current_page - 1) + 1; |
| 417 |
|
| 418 |
$pagination_html .= "<ul class=''>"; |
| 419 |
|
| 420 |
//Showing entries content |
| 421 |
if ($showing_entry_from > $total_entry_count) { |
| 422 |
return ''; |
| 423 |
} |
| 424 |
|
| 425 |
if ( $total_page_count == 1 ) { |
| 426 |
return ''; |
| 427 |
} |
| 428 |
|
| 429 |
//Previous button |
| 430 |
if($current_page > 1){ |
| 431 |
$pagination_html .= "<li><a href='$prev_button_link' $prev_button_disabled class='pagination-previous'><i class='bp-icon bp-caret-left'></i></a></li>"; |
| 432 |
} |
| 433 |
|
| 434 |
//Pagination links |
| 435 |
for ($i = 1; $i <= $total_page_count; $i++) { |
| 436 |
$is_current_class = ($i == $current_page) ? 'is-current active' : ''; |
| 437 |
$page_link = admin_url("admin.php?page=betterpayment-transactions&per_page={$per_page}&paged={$i}"); |
| 438 |
|
| 439 |
$pagination_html .= " |
| 440 |
<li> |
| 441 |
<a href=\"$page_link\" class=\"pagination-link $is_current_class \" aria-label=\"Page $i\"> $i </a> |
| 442 |
</li> |
| 443 |
"; |
| 444 |
} |
| 445 |
|
| 446 |
//Next button |
| 447 |
if($current_page < $total_page_count){ |
| 448 |
$pagination_html .= "<li><a href='$next_button_link' class='pagination-next' $next_button_disabled><i class='bp-icon bp-caret-right'></i></a></li>"; |
| 449 |
} |
| 450 |
|
| 451 |
$pagination_html .= "</ul>"; |
| 452 |
|
| 453 |
return $pagination_html; |
| 454 |
} |
| 455 |
|
| 456 |
public static function bp_paginate_showing_entities_html($current_page, $per_page, $total_entry_count) |
| 457 |
{ |
| 458 |
$pagination_showing_entries_html = ''; |
| 459 |
|
| 460 |
$current_page = intval($current_page); |
| 461 |
$per_page = intval($per_page); |
| 462 |
$total_entry_count = intval($total_entry_count); |
| 463 |
|
| 464 |
$total_page_count = ceil($total_entry_count / $per_page); |
| 465 |
|
| 466 |
$showing_entry_from = $per_page * ($current_page - 1) + 1; |
| 467 |
$showing_entry_to = $per_page * $current_page; |
| 468 |
|
| 469 |
//Showing entries content |
| 470 |
if ($total_page_count == 1 || $current_page == $total_page_count) { |
| 471 |
$showing_entry_to = $total_entry_count; |
| 472 |
} |
| 473 |
|
| 474 |
$pagination_showing_entries_html = __("Showing {$showing_entry_from}-{$showing_entry_to} of $total_entry_count entries", "better-payment"); |
| 475 |
|
| 476 |
if ($showing_entry_from > $total_entry_count) { |
| 477 |
return ''; |
| 478 |
} |
| 479 |
|
| 480 |
if ($total_page_count == 1) { |
| 481 |
return $pagination_showing_entries_html; |
| 482 |
} |
| 483 |
|
| 484 |
return $pagination_showing_entries_html; |
| 485 |
} |
| 486 |
|
| 487 |
/** |
| 488 |
* This function is responsible for the data sanitization |
| 489 |
* |
| 490 |
* @param array $field |
| 491 |
* @param string|array $value |
| 492 |
* @return string|array |
| 493 |
*/ |
| 494 |
public static function sanitize_field($field, $value) |
| 495 |
{ |
| 496 |
if (isset($field['sanitize']) && !empty($field['sanitize'])) { |
| 497 |
if (function_exists($field['sanitize'])) { |
| 498 |
$value = call_user_func($field['sanitize'], $value); |
| 499 |
} |
| 500 |
return $value; |
| 501 |
} |
| 502 |
|
| 503 |
if (is_array($field) && isset($field['type'])) { |
| 504 |
switch ($field['type']) { |
| 505 |
case 'text': |
| 506 |
$value = sanitize_text_field($value); |
| 507 |
break; |
| 508 |
case 'textarea': |
| 509 |
$value = sanitize_textarea_field($value); |
| 510 |
break; |
| 511 |
case 'email': |
| 512 |
$value = sanitize_email($value); |
| 513 |
break; |
| 514 |
default: |
| 515 |
return $value; |
| 516 |
break; |
| 517 |
} |
| 518 |
} else { |
| 519 |
$value = sanitize_text_field($value); |
| 520 |
} |
| 521 |
|
| 522 |
return $value; |
| 523 |
} |
| 524 |
} |
| 525 |
|