class.swpm-payments-admin-menu.php 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. class SwpmPaymentsAdminMenu {
  3. function __construct() {
  4. }
  5. function handle_main_payments_admin_menu() {
  6. do_action('swpm_payments_menu_start');
  7. //Check current_user_can() or die.
  8. SwpmMiscUtils::check_user_permission_and_is_admin('Main Payments Admin Menu');
  9. $output = '';
  10. $tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : '';
  11. $selected = $tab;
  12. ?>
  13. <div class="wrap swpm-admin-menu-wrap"><!-- start wrap -->
  14. <h1><?php echo SwpmUtils::_('Simple Membership::Payments') ?></h1><!-- page title -->
  15. <!-- start nav menu tabs -->
  16. <h2 class="nav-tab-wrapper">
  17. <a class="nav-tab <?php echo ($tab == '') ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership_payments"><?php SwpmUtils::e('Transactions'); ?></a>
  18. <a class="nav-tab <?php echo ($tab == 'payment_buttons') ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership_payments&tab=payment_buttons"><?php SwpmUtils::e('Manage Payment Buttons'); ?></a>
  19. <a class="nav-tab <?php echo ($tab == 'create_new_button') ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership_payments&tab=create_new_button"><?php SwpmUtils::e('Create New Button'); ?></a>
  20. <?php
  21. if ($tab == 'edit_button') {//Only show the "edit button" tab when a button is being edited.
  22. echo '<a class="nav-tab nav-tab-active" href="#">Edit Button</a>';
  23. }
  24. //Trigger hooks that allows an extension to add extra nav tabs in the payments menu.
  25. do_action ('swpm_payments_menu_nav_tabs', $selected);
  26. $menu_tabs = apply_filters('swpm_payments_menu_additional_menu_tabs_array', array());
  27. foreach ($menu_tabs as $menu_action => $title){
  28. ?>
  29. <a class="nav-tab <?php echo ($selected == $menu_action) ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership_payments&tab=<?php echo $menu_action; ?>" ><?php SwpmUtils::e($title); ?></a>
  30. <?php
  31. }
  32. ?>
  33. </h2>
  34. <!-- end nav menu tabs -->
  35. <?php
  36. do_action('swpm_payments_menu_after_nav_tabs');
  37. //Allows an addon to completely override the body section of the payments admin menu for a given action.
  38. $output = apply_filters('swpm_payments_menu_body_override', '', $tab);
  39. if (!empty($output)) {
  40. //An addon has overriden the body of this page for the given tab/action. So no need to do anything in core.
  41. echo $output;
  42. echo '</div>';//<!-- end of wrap -->
  43. return;
  44. }
  45. echo '<div id="poststuff"><div id="post-body">';
  46. //TODO - move most of the following includes to functions of this class instead.
  47. //Switch case for the various different tabs handled by the core plugin.
  48. switch ($tab) {
  49. case 'payment_buttons':
  50. include_once(SIMPLE_WP_MEMBERSHIP_PATH . '/views/payments/admin_payment_buttons.php');
  51. break;
  52. case 'create_new_button':
  53. include_once(SIMPLE_WP_MEMBERSHIP_PATH . '/views/payments/admin_create_payment_buttons.php');
  54. break;
  55. case 'edit_button':
  56. include_once(SIMPLE_WP_MEMBERSHIP_PATH . '/views/payments/admin_edit_payment_buttons.php');
  57. break;
  58. case 'all_txns':
  59. include_once(SIMPLE_WP_MEMBERSHIP_PATH . '/views/payments/admin_all_payment_transactions.php');
  60. break;
  61. case 'add_new_txn':
  62. include_once(SIMPLE_WP_MEMBERSHIP_PATH . '/views/payments/admin_add_edit_transaction_manually.php');
  63. swpm_handle_add_new_txn_manually();
  64. break;
  65. default:
  66. include_once(SIMPLE_WP_MEMBERSHIP_PATH . '/views/payments/admin_all_payment_transactions.php');
  67. break;
  68. }
  69. echo '</div></div>'; //<!-- end of post-body -->
  70. echo '</div>'; //<!-- end of .wrap -->
  71. }
  72. }