PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / 4.0.3
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress v4.0.3
4.17.3 4.17.2 4.17.1 4.17.0 4.16.19 4.16.18 4.16.17 4.16.16 trunk 1.0 1.0.1 1.0.2 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5a 1.1.6 1.1.7 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4 1.4.1 1.4.2 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.7 1.7.1 1.7.2 1.8 1.8.1 1.8.10 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.1.9 2.2.10 2.2.11 2.2.12 2.2.13 2.2.14 2.2.15 2.2.16 2.2.2 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 3.0 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.10.0 4.10.1 4.10.2 4.10.3 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.13.3 4.13.4 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.15.0 4.15.1 4.15.10 4.15.11 4.15.12 4.15.13 4.15.14 4.15.15 4.15.16 4.15.17 4.15.18 4.15.19 4.15.2 4.15.20 4.15.20.1 4.15.21 4.15.22 4.15.23 4.15.24 4.15.25 4.15.3 4.15.4 4.15.5 4.15.6 4.15.7 4.15.8 4.15.9 4.16.0 4.16.1 4.16.10 4.16.11 4.16.12 4.16.13 4.16.14 4.16.15 4.16.2 4.16.3 4.16.4 4.16.5 4.16.6 4.16.7 4.16.8 4.16.9 4.2.0 4.3.0 4.3.1 4.3.2 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.5.3 4.5.4 4.5.5 4.6.0 4.7.0 4.8.0 4.9.0
wp-user-avatar / src / Admin / SettingsPages / Membership / DashboardPage / SettingsPage.php
wp-user-avatar / src / Admin / SettingsPages / Membership / DashboardPage Last commit date
AbstractReport.php 4 years ago Orders.php 4 years ago PaymentMethods.php 4 years ago Refunds.php 4 years ago ReportFilterData.php 4 years ago ReportInterval.php 4 years ago Revenue.php 4 years ago SettingsPage.php 4 years ago Taxes.php 4 years ago TopPlans.php 4 years ago index.php 4 years ago
SettingsPage.php
434 lines
1 <?php
2
3 namespace ProfilePress\Core\Admin\SettingsPages\Membership\DashboardPage;
4
5 use ProfilePress\Core\Admin\SettingsPages\AbstractSettingsPage;
6 use ProfilePress\Core\Base;
7 use ProfilePress\Core\Membership\Models\Customer\CustomerStatus;
8 use ProfilePress\Core\Membership\Models\Order\OrderStatus;
9 use ProfilePress\Core\Membership\Models\Subscription\SubscriptionStatus;
10 use ProfilePress\Core\Membership\Repositories\CustomerRepository;
11 use ProfilePress\Core\Membership\Repositories\PlanRepository;
12 use ProfilePress\Core\Membership\Repositories\SubscriptionRepository;
13 use ProfilePress\Core\Membership\Services\Calculator;
14 use ProfilePress\Core\Membership\Services\TaxService;
15 use ProfilePress\Custom_Settings_Page_Api;
16 use ProfilePressVendor\Carbon\CarbonImmutable;
17
18 class SettingsPage extends AbstractSettingsPage
19 {
20 function __construct()
21 {
22 add_action('ppress_register_menu_page', [$this, 'register_cpf_settings_page']);
23 add_action('ppress_admin_settings_page_reports', [$this, 'reports_admin_page']);
24 }
25
26 public function admin_page_title()
27 {
28 return esc_html__('Dashboard', 'wp-user-avatar');
29 }
30
31 public function register_cpf_settings_page()
32 {
33 $hook = add_submenu_page(
34 PPRESS_DASHBOARD_SETTINGS_SLUG,
35 $this->admin_page_title() . ' - ProfilePress',
36 esc_html__('Dashboard', 'wp-user-avatar'),
37 'manage_options',
38 PPRESS_DASHBOARD_SETTINGS_SLUG,
39 array($this, 'admin_page_callback'));
40
41 do_action('ppress_membership_reports_settings_page_register', $hook);
42 }
43
44 public function default_header_menu()
45 {
46 return 'reports';
47 }
48
49 public function reports_admin_page()
50 {
51 add_action('admin_footer', [$this, 'js_script']);
52 add_action('wp_cspa_main_content_area', [$this, 'admin_settings_page_callback'], 10, 2);
53
54 $instance = Custom_Settings_Page_Api::instance();
55 $instance->option_name('ppview'); // adds ppview css class to #poststuff
56 $instance->form_method('get');
57 $instance->page_header($this->admin_page_title());
58 $instance->build(true);
59 }
60
61 public function get_filter_data()
62 {
63 $preset = ! empty($_GET['preset']) ? sanitize_text_field($_GET['preset']) : 'today';
64 $plan_id = ! empty($_GET['plan']) ? absint($_GET['plan']) : '';
65
66 $start_of_week = absint(get_option('start_of_week', 1));
67 $end_of_week = $start_of_week == 0 ? 6 : $start_of_week - 1;
68
69 $carbonNow = CarbonImmutable::now(wp_timezone());
70
71 switch ($preset) {
72 case 'today':
73 $start_date = $carbonNow->startOfDay()->toDateString();
74 $end_date = $carbonNow->endOfDay()->toDateString();
75 break;
76 case 'yesterday':
77 $start_date = $carbonNow->subDay()->startOfDay()->toDateString();
78 $end_date = $carbonNow->subDay()->endOfDay()->toDateString();
79 break;
80 case 'this_week':
81 $start_date = $carbonNow->startOfWeek($start_of_week)->toDateString();
82 $end_date = $carbonNow->endOfWeek($end_of_week)->toDateString();
83 break;
84 case 'last_week':
85 $start_date = $carbonNow->startOfWeek($start_of_week)->subWeek()->toDateString();
86 $end_date = $carbonNow->endOfWeek($end_of_week)->subWeek()->toDateString();
87 break;
88 case 'last_30_days':
89 $start_date = $carbonNow->subDays(29)->startOfDay()->toDateString();
90 $end_date = $carbonNow->endOfDay()->toDateString();
91 break;
92 case 'this_month':
93 $start_date = $carbonNow->startOfMonth()->toDateString();
94 $end_date = $carbonNow->endOfMonth()->toDateString();
95 break;
96 case 'last_month':
97 $start_date = $carbonNow->subMonthNoOverflow()->startOfMonth()->toDateString();
98 $end_date = $carbonNow->subMonthNoOverflow()->endOfMonth()->toDateString();
99 break;
100 case 'this_quarter':
101 $start_date = $carbonNow->startOfQuarter()->toDateString();
102 $end_date = $carbonNow->endOfQuarter()->toDateString();
103 break;
104 case 'last_quarter':
105 $start_date = $carbonNow->subQuarter()->startOfQuarter()->toDateString();
106 $end_date = $carbonNow->subQuarter()->endOfQuarter()->toDateString();
107 break;
108 case 'this_year':
109 $start_date = $carbonNow->startOfYear()->toDateString();
110 $end_date = $carbonNow->endOfYear()->toDateString();
111 break;
112 case 'last_year':
113 $start_date = $carbonNow->subYear()->startOfYear()->toDateString();
114 $end_date = $carbonNow->subYear()->endOfYear()->toDateString();
115 break;
116 default:
117 $start_date = sanitize_text_field(ppressGET_var('start_date', '', true));
118 $end_date = sanitize_text_field(ppressGET_var('end_date', '', true));
119 break;
120 }
121
122 $filterData = new ReportFilterData();
123 $filterData->start_date = $start_date;
124 $filterData->end_date = $end_date;
125 $filterData->plan_id = $plan_id;
126
127 return $filterData;
128 }
129
130 public function js_script()
131 {
132 ?>
133 <script type="text/javascript">
134 var currencySymbol = '<?= ppress_display_amount('00')?>', // 00 is placeholder replaced on the clientside
135 revenueStat = <?= wp_json_encode($this->get_revenue()) ?>,
136 taxesStat = <?= wp_json_encode($this->get_taxes()) ?>,
137 orderStat = <?= wp_json_encode($this->get_orders()) ?>,
138 topPlansStat = <?= wp_json_encode($this->get_top_plans()) ?>,
139 paymentMethodsStat = <?= wp_json_encode($this->get_payment_methods()) ?>,
140 refundStat = <?= wp_json_encode($this->get_refunds()) ?>;
141 </script>
142 <?php
143 }
144
145 public function cache_transformer($key, $callback)
146 {
147 static $cache = [];
148
149 if ( ! isset($cache[$key])) {
150 $cache[$key] = $callback;
151 }
152
153 return $cache[$key];
154 }
155
156 public function get_revenue()
157 {
158 return $this->cache_transformer(
159 __FUNCTION__,
160 (new Revenue($this->get_filter_data()))->val()
161 );
162 }
163
164 public function get_taxes()
165 {
166 return $this->cache_transformer(
167 __FUNCTION__,
168 (new Taxes($this->get_filter_data()))->val()
169 );
170 }
171
172 public function get_orders()
173 {
174 return $this->cache_transformer(
175 __FUNCTION__,
176 (new Orders($this->get_filter_data()))->val()
177 );
178 }
179
180 public function get_refunds()
181 {
182 return $this->cache_transformer(
183 __FUNCTION__,
184 (new Refunds($this->get_filter_data()))->val()
185 );
186 }
187
188 public function get_top_plans()
189 {
190 return $this->cache_transformer(
191 __FUNCTION__,
192 (new TopPlans($this->get_filter_data()))->val()
193 );
194 }
195
196 public function get_payment_methods()
197 {
198 return $this->cache_transformer(
199 __FUNCTION__,
200 (new PaymentMethods($this->get_filter_data()))->val()
201 );
202 }
203
204 public static function get_lifetime_revenue()
205 {
206 global $wpdb;
207
208 $order_table = Base::orders_db_table();
209
210 return $wpdb->get_var(
211 $wpdb->prepare("SELECT SUM(total) from $order_table WHERE status = %s", OrderStatus::COMPLETED)
212 );
213 }
214
215 public function admin_settings_page_callback()
216 {
217 echo '<style>.ppress-admin .ppview h2{display:none;}</style>';
218 echo '<input type="hidden" name="page" value="' . PPRESS_DASHBOARD_SETTINGS_SLUG . '" />';
219 echo '<div class="ppress-report-charts-container">';
220 $this->top_cards();
221 $this->range_picker();
222 $this->report_charts();
223 echo '</div>';
224 }
225
226 public function range_picker()
227 {
228 $start_date = isset($_GET['start_date']) ? sanitize_text_field($_GET['start_date']) : null;
229 $end_date = isset($_GET['end_date']) ? sanitize_text_field($_GET['end_date']) : null;
230 $plan_id = isset($_GET['plan']) ? sanitize_text_field($_GET['plan']) : 'all';
231 $preset = isset($_GET['preset']) ? sanitize_text_field($_GET['preset']) : 'today';
232
233 $clear_url = PPRESS_DASHBOARD_SETTINGS_PAGE;
234
235 $plans = PlanRepository::init()->retrieveAll();
236
237 $preset_args = [
238 'today' => esc_html__('Today', 'wp-user-avatar'),
239 'yesterday' => esc_html__('Yesterday', 'wp-user-avatar'),
240 'this_week' => esc_html__('This Week', 'wp-user-avatar'),
241 'last_week' => esc_html__('Last Week', 'wp-user-avatar'),
242 'last_30_days' => esc_html__('Last 30 Days', 'wp-user-avatar'),
243 'this_month' => esc_html__('This Month', 'wp-user-avatar'),
244 'last_month' => esc_html__('Last Month', 'wp-user-avatar'),
245 'this_quarter' => esc_html__('This Quarter', 'wp-user-avatar'),
246 'last_quarter' => esc_html__('Last Quarter', 'wp-user-avatar'),
247 'this_year' => esc_html__('This Year', 'wp-user-avatar'),
248 'last_year' => esc_html__('Last Year', 'wp-user-avatar'),
249 'custom' => esc_html__('Custom', 'wp-user-avatar'),
250 ];
251
252 echo '<div class="wp-filter" id="ppress-filters">';
253 echo '<div class="filter-items">';
254 echo '<span id="ppress-mode-filter">';
255 echo '<select name="preset">';
256 foreach ($preset_args as $index => $arg) {
257 printf('<option value="%1$s" %3$s>%2$s</option>', $index, $arg, selected($preset, $index, false));
258 }
259 echo '</select>';
260 echo '</span>';
261
262 echo '<span id="ppress-date-filters" class="ppress-from-to-wrapper" style="display:none">';
263 echo '<span class="ppress-start-date-wrap">';
264 echo '<input type="text" name="start_date" id="start-date" placeholder="' . _x('From', 'date filter', 'wp-user-avatar') . '" value="' . $start_date . '" class="ppress_datepicker">';
265 echo '</span>';
266 echo '<span id="ppress-end-date-wrap">';
267 echo '<input type="text" name="end_date" id="end-date" value="' . $end_date . '" placeholder="' . _x('To', 'date filter', 'wp-user-avatar') . '" class="ppress_datepicker">';
268 echo '</span>';
269 echo '</span>';
270
271 if ( ! empty($plans)) {
272 echo '<span id="ppress-gateway-filter">';
273 echo '<select name="plan">';
274 echo '<option value="all">' . esc_html__('All Plans', 'wp-user-avatar') . '</option>';
275 foreach ($plans as $plan) {
276 printf('<option value="%1$s" %3$s>%2$s</option>', $plan->id, $plan->name, selected($plan->id, $plan_id, false));
277 }
278 echo '</select>';
279 echo '</span>';
280 }
281
282 echo '<span id="ppress-after-core-filters">';
283 echo '<input type="submit" class="button button-secondary" value="' . esc_html__('Filter', 'wp-user-avatar') . '"/>&nbsp;';
284
285 if ( ! empty($start_date) || ! empty($end_date) || 'all' !== $plan_id || 'today' !== $preset) {
286 echo '<a href="' . esc_url($clear_url) . '" class="button-secondary">';
287 esc_html_e('Clear', 'wp-user-avatar');
288 echo '</a>';
289 }
290 echo '</span>';
291
292 echo '</div>';
293 echo '</div>';
294 }
295
296 public function single_report_card($id, $title, $total, $trend = '', $sign = '%')
297 {
298 ?>
299 <div class="ppress-report-chart-bottom-card-item">
300 <dt class="ppress-report-chart-bottom-card-item-header">
301 <p><?= $title ?></p>
302 </dt>
303 <dd class="ppress-report-chart-bottom-card-item-content-wrap">
304 <?php if ( ! is_null($total)) : ?>
305 <p><?php echo $total ?></p>
306 <?php endif; ?>
307 <?php if ( ! Calculator::init($trend)->isZero()) : ?>
308 <?php if (Calculator::init($trend)->isNegative()) : ?>
309 <p class="ppress-report-chart-bottom-card-item-trend negative"><?= $trend . $sign ?></p>
310 <?php else : ?>
311 <p class="ppress-report-chart-bottom-card-item-trend">+<?= $trend . $sign ?></p>
312 <?php endif; ?>
313 <?php endif; ?>
314 </dd>
315 <div class="ppress-report-chart-bottom-card-item-chart">
316 <canvas id="<?= $id ?>"></canvas>
317 </div>
318 </div>
319 <?php
320 }
321
322 /**
323 * @return void
324 */
325 public function top_cards()
326 {
327 ?>
328 <div class="ppress-report-chart-top-cards-wrap">
329 <dl class="ppress-report-chart-top-card-item-wrap">
330 <div class="ppress-report-chart-top-card-item">
331 <dt class="ppress-report-chart-top-card-item-header"><?php esc_html_e('Total Customers', 'wp-user-avatar') ?></dt>
332 <dd class="ppress-report-chart-top-card-item-content-wrap">
333 <div class="ppress-report-chart-top-card-item-content"><?php echo CustomerRepository::init()->record_count() ?></div>
334 </dd>
335 </div>
336
337 <div class="ppress-report-chart-top-card-item">
338 <dt class="ppress-report-chart-top-card-item-header"><?php esc_html_e('Active Customers', 'wp-user-avatar') ?></dt>
339 <dd class="ppress-report-chart-top-card-item-content-wrap">
340 <div class="ppress-report-chart-top-card-item-content"><?php echo CustomerRepository::init()->get_count_by_status(CustomerStatus::ACTIVE) ?></div>
341 </dd>
342 </div>
343
344 <div class="ppress-report-chart-top-card-item">
345 <dt class="ppress-report-chart-top-card-item-header"><?php esc_html_e('Active Subscriptions', 'wp-user-avatar') ?></dt>
346 <dd class="ppress-report-chart-top-card-item-content-wrap">
347 <div class="ppress-report-chart-top-card-item-content"><?php echo SubscriptionRepository::init()->get_count_by_status(SubscriptionStatus::ACTIVE) ?></div>
348 </dd>
349 </div>
350
351 <div class="ppress-report-chart-top-card-item">
352 <dt class="ppress-report-chart-top-card-item-header"><?php esc_html_e('Lifetime Revenue', 'wp-user-avatar') ?></dt>
353 <dd class="ppress-report-chart-top-card-item-content-wrap">
354 <div class="ppress-report-chart-top-card-item-content"><?php echo ppress_display_amount(self::get_lifetime_revenue()) ?></div>
355 </dd>
356 </div>
357
358 </dl>
359 </div>
360 <?php
361 }
362
363 public function report_charts()
364 {
365 $revenue = $this->get_revenue();
366 $orders = $this->get_orders();
367 $refunds = $this->get_refunds();
368 $taxes = $this->get_taxes();
369 $top_plans = $this->get_top_plans();
370 $payment_methods = $this->get_payment_methods();
371 ?>
372 <div class="ppress-report-chart-bottom-cards-wrap">
373 <dl class="ppress-report-chart-bottom-card-item-wrap">
374
375 <?php $this->single_report_card(
376 'ppress-report-revenue',
377 esc_html__('Revenue', 'wp-user-avatar'),
378 ppress_display_amount($revenue['total']),
379 $revenue['trend']
380 ) ?>
381
382 <?php $this->single_report_card(
383 'ppress-report-orders',
384 esc_html__('Orders', 'wp-user-avatar'),
385 $orders['total'],
386 $orders['trend']
387 ) ?>
388
389 <?php if (TaxService::init()->is_tax_enabled()) :
390 $this->single_report_card(
391 'ppress-report-tax',
392 esc_html__('Taxes', 'wp-user-avatar'),
393 ppress_display_amount($taxes['total']),
394 $taxes['trend']
395 );
396 endif; ?>
397
398 <?php $this->single_report_card(
399 'ppress-report-refunds',
400 esc_html__('Refunds', 'wp-user-avatar'),
401 $refunds['total'],
402 $refunds['trend']
403 ) ?>
404
405 <?php $this->single_report_card(
406 'ppress-report-top-plans',
407 esc_html__('Top Plans', 'wp-user-avatar'),
408 $top_plans['total'],
409 $top_plans['trend']
410 ) ?>
411
412 <?php $this->single_report_card(
413 'ppress-report-payment-methods',
414 esc_html__('Payment Methods', 'wp-user-avatar'),
415 $payment_methods['total'],
416 $payment_methods['trend']
417 ) ?>
418
419 </dl>
420 </div>
421 <?php
422 }
423
424 public static function get_instance()
425 {
426 static $instance = null;
427
428 if (is_null($instance)) {
429 $instance = new self();
430 }
431
432 return $instance;
433 }
434 }