views
3 years ago
AbstractExport.php
1 year ago
CustomersExport.php
6 months ago
OrdersExport.php
3 years ago
PlansExport.php
3 years ago
ProductSalesExport.php
3 years ago
SalesEarningsExport.php
3 years ago
SettingsPage.php
1 year ago
SubscriptionsExport.php
3 years ago
index.php
3 years ago
SettingsPage.php
158 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePress\Core\Admin\SettingsPages\Membership\ExportPage; |
| 4 | |
| 5 | use ProfilePress\Core\Admin\SettingsPages\AbstractSettingsPage; |
| 6 | use ProfilePress\Core\Membership\Models\Order\OrderStatus; |
| 7 | use ProfilePress\Core\Membership\Models\Subscription\SubscriptionStatus; |
| 8 | use ProfilePress\Core\Membership\PaymentMethods\PaymentMethods; |
| 9 | use ProfilePress\Core\Membership\Repositories\PlanRepository; |
| 10 | use ProfilePress\Custom_Settings_Page_Api; |
| 11 | |
| 12 | class SettingsPage extends AbstractSettingsPage |
| 13 | { |
| 14 | function __construct() |
| 15 | { |
| 16 | add_action('ppress_admin_settings_page_export', [$this, 'settings_page_function']); |
| 17 | add_filter('ppress_membership_dashboard_settings_page_title', [$this, 'admin_page_title']); |
| 18 | |
| 19 | add_action('admin_init', [$this, 'handle_export']); |
| 20 | } |
| 21 | |
| 22 | public function admin_page_title($title = '') |
| 23 | { |
| 24 | if (ppressGET_var('view') == 'export') { |
| 25 | $title = esc_html__('Export', 'wp-user-avatar'); |
| 26 | } |
| 27 | |
| 28 | return $title; |
| 29 | } |
| 30 | |
| 31 | public function settings_page_function() |
| 32 | { |
| 33 | add_filter('wp_cspa_main_content_area', [$this, 'admin_settings_page_callback'], 10, 2); |
| 34 | |
| 35 | $instance = Custom_Settings_Page_Api::instance(); |
| 36 | $instance->option_name('ppview'); // adds ppview css class to #poststuff |
| 37 | $instance->page_header($this->admin_page_title()); |
| 38 | $instance->remove_page_form_tag(); |
| 39 | $instance->build(true); |
| 40 | } |
| 41 | |
| 42 | public function handle_export() |
| 43 | { |
| 44 | if (isset($_POST['ppress_do_export'])) { |
| 45 | |
| 46 | if (current_user_can('manage_options')) { |
| 47 | |
| 48 | if (check_admin_referer('ppress_export_' . ppressPOST_var('ppress_export_type'))) { |
| 49 | |
| 50 | $class = sprintf( |
| 51 | '\ProfilePress\Core\Admin\SettingsPages\Membership\ExportPage\%s', |
| 52 | sanitize_text_field(ppressPOST_var('ppress_export_type', '')) |
| 53 | ); |
| 54 | |
| 55 | if (class_exists($class) && method_exists($class, 'execute')) { |
| 56 | (new $class(ppress_clean($_POST)))->execute(); |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | private function render_form_view($path) |
| 64 | { |
| 65 | $membership_plans = ppress_cache_transform('ppress_export_membership_plans', function () { |
| 66 | return PlanRepository::init()->retrieveAll(); |
| 67 | }); |
| 68 | |
| 69 | $payment_methods = ppress_cache_transform('ppress_export_payment_methods', function () { |
| 70 | return PaymentMethods::get_instance()->get_all(); |
| 71 | }); |
| 72 | |
| 73 | $order_statuses = ppress_cache_transform('ppress_export_order_statuses', function () { |
| 74 | return OrderStatus::get_all(); |
| 75 | }); |
| 76 | |
| 77 | $subscription_statuses = ppress_cache_transform('ppress_export_subscription_statuses', function () { |
| 78 | return SubscriptionStatus::get_all(); |
| 79 | }); |
| 80 | |
| 81 | ob_start(); |
| 82 | require dirname(__FILE__) . '/views/' . $path . '.php'; |
| 83 | |
| 84 | return ob_get_clean(); |
| 85 | } |
| 86 | |
| 87 | public function admin_settings_page_callback() |
| 88 | { |
| 89 | $exports = apply_filters('ppress_csv_exports', [ |
| 90 | 'SalesEarningsExport' => [ |
| 91 | 'title' => esc_html__('Export Sales and Earnings', 'wp-user-avatar'), |
| 92 | 'description' => esc_html__('Download a CSV of all sales or earnings on a day-by-day basis.', 'wp-user-avatar'), |
| 93 | 'form' => $this->render_form_view('sales-earnings') |
| 94 | ], |
| 95 | 'ProductSalesExport' => [ |
| 96 | 'title' => esc_html__('Export Plan Sales', 'wp-user-avatar'), |
| 97 | 'description' => esc_html__('Download a CSV file containing a record of each sale of a plan along with the customer information.', 'wp-user-avatar'), |
| 98 | 'form' => $this->render_form_view('product-sales') |
| 99 | ], |
| 100 | 'OrdersExport' => [ |
| 101 | 'title' => esc_html__('Export Orders', 'wp-user-avatar'), |
| 102 | 'description' => esc_html__('Download a CSV of all orders.', 'wp-user-avatar'), |
| 103 | 'form' => $this->render_form_view('orders') |
| 104 | ], |
| 105 | 'SubscriptionsExport' => [ |
| 106 | 'title' => esc_html__('Export Subscriptions', 'wp-user-avatar'), |
| 107 | 'description' => esc_html__('Download a CSV of subscriptions.', 'wp-user-avatar'), |
| 108 | 'form' => $this->render_form_view('subscriptions') |
| 109 | ], |
| 110 | 'CustomersExport' => [ |
| 111 | 'title' => esc_html__('Export Customers', 'wp-user-avatar'), |
| 112 | 'description' => esc_html__('Download a CSV of customers.', 'wp-user-avatar'), |
| 113 | 'form' => $this->render_form_view('customers') |
| 114 | ], |
| 115 | 'PlansExport' => [ |
| 116 | 'title' => esc_html__('Export Plans', 'wp-user-avatar'), |
| 117 | 'description' => esc_html__('Download a CSV of membership plans.', 'wp-user-avatar'), |
| 118 | 'form' => $this->render_form_view('plans') |
| 119 | ] |
| 120 | ], $this); |
| 121 | ?> |
| 122 | <div class="ppress-export-cards-wrap"> |
| 123 | |
| 124 | <dl class="ppress-export-card-item-wrap"> |
| 125 | |
| 126 | <?php foreach ($exports as $export_id => $export) : ?> |
| 127 | |
| 128 | <div class="ppress-export-card-item"> |
| 129 | <dt class="ppress-export-card-item-header"> |
| 130 | <p><?php esc_html_e($export['title']); ?></p> |
| 131 | </dt> |
| 132 | <dd class="ppress-export-card-item-inside"> |
| 133 | <p><?php esc_html_e($export['description']); ?></p> |
| 134 | <form id="ppress-export-sales-earnings" class="ppress-export-form" method="post"> |
| 135 | <?php echo $export['form']; ?> |
| 136 | <?php wp_nonce_field('ppress_export_' . $export_id); ?> |
| 137 | <input type="hidden" name="ppress_export_type" value="<?php esc_attr_e($export_id); ?>"> |
| 138 | <input class="button" type="submit" name="ppress_do_export" value="<?php esc_html_e('Export', 'wp-user-avatar'); ?>"> |
| 139 | </form> |
| 140 | </dd> |
| 141 | </div> |
| 142 | <?php endforeach; ?> |
| 143 | </dl> |
| 144 | </div> |
| 145 | <?php |
| 146 | } |
| 147 | |
| 148 | public static function get_instance() |
| 149 | { |
| 150 | static $instance = null; |
| 151 | |
| 152 | if (is_null($instance)) { |
| 153 | $instance = new self(); |
| 154 | } |
| 155 | |
| 156 | return $instance; |
| 157 | } |
| 158 | } |