PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.8.1
GiveWP – Donation Plugin and Fundraising Platform v4.16.8.1
4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 All 254 releases
give / src / Subscriptions / SubscriptionsAdminPage.php

SubscriptionsAdminPage.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.8.1, at src/Subscriptions/SubscriptionsAdminPage.php

92 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Subscriptions;
4
5 use Give\Subscriptions\Actions\LoadSubscriptionDetailsAssets;
6 use Give\Subscriptions\Actions\LoadSubscriptionsListTableAssets;
7 use Give\Subscriptions\Models\Subscription;
8
9 class SubscriptionsAdminPage
10 {
11 /**
12 * @since 2.24.0
13 */
14 public function loadScripts()
15 {
16 give(LoadSubscriptionsListTableAssets::class)();
17 }
18
19 /**
20 * Render the Subscription Details page.
21 *
22 * @since 4.8.0
23 */
24 public function render()
25 {
26 if (self::isShowingDetailsPage()) {
27 remove_action('give_forms_page_give-subscriptions', 'give_subscriptions_page');
28
29 $subscription = Subscription::find(absint($_GET['id']));
30
31 if ( ! $subscription) {
32 wp_die(__('Subscription not found', 'give'), 404);
33 }
34
35 give(LoadSubscriptionDetailsAssets::class)();
36 } else {
37 give(LoadSubscriptionsListTableAssets::class)();
38 }
39
40 echo '<div id="give-admin-subscriptions-root"></div>';
41 }
42
43 /**
44 * Display a button on the old subscriptions table that switches to the React view
45 *
46 * @since 2.24.0
47 */
48 public function renderReactSwitch()
49 {
50 ?>
51 <script type="text/javascript">
52 function showReactTable () {
53 fetch( '<?php echo esc_url_raw(rest_url('give-api/v2/admin/subscriptions/view?isLegacy=0')) ?>', {
54 method: 'GET',
55 headers: {
56 ['X-WP-Nonce']: '<?php echo wp_create_nonce('wp_rest') ?>'
57 }
58 })
59 .then((res) => {
60 window.location.reload();
61 });
62 }
63 jQuery( function() {
64 jQuery(jQuery(".wrap .wp-header-end")).before(
65 '<button class="page-title-action" onclick="showReactTable()"><?php _e('Switch to New View', 'give') ?></button>'
66 );
67 });
68 </script>
69 <?php
70 }
71
72 /**
73 * Helper function to determine if current page is Give Subscriptions admin page
74 *
75 * @since 2.24.0
76 *
77 * @return bool
78 */
79 public static function isShowing()
80 {
81 return isset($_GET['page']) && $_GET['page'] === 'give-subscriptions' && ! isset($_GET['view']);
82 }
83
84 /**
85 * @since 4.8.0
86 */
87 public static function isShowingDetailsPage(): bool
88 {
89 return isset($_GET['id'], $_GET['page']) && 'give-subscriptions' === $_GET['page'];
90 }
91 }
92